Merge remote-tracking branch 'origin/dev' into feat/custom-agents
# Conflicts: # src/agents/utils.test.ts # src/plugin-handlers/agent-config-handler.ts
This commit is contained in:
@@ -135,7 +135,14 @@ export async function applyAgentConfig(params: {
|
||||
useTaskSystem,
|
||||
disableOmoEnv,
|
||||
);
|
||||
const disabledAgentNames = new Set(
|
||||
(migratedDisabledAgents ?? []).map(a => a.toLowerCase())
|
||||
);
|
||||
|
||||
const filterDisabledAgents = (agents: Record<string, unknown>) =>
|
||||
Object.fromEntries(
|
||||
Object.entries(agents).filter(([name]) => !disabledAgentNames.has(name.toLowerCase()))
|
||||
);
|
||||
const isSisyphusEnabled = params.pluginConfig.sisyphus_agent?.disabled !== true;
|
||||
const builderEnabled =
|
||||
params.pluginConfig.sisyphus_agent?.default_builder_enabled ?? false;
|
||||
@@ -223,9 +230,9 @@ export async function applyAgentConfig(params: {
|
||||
...Object.fromEntries(
|
||||
Object.entries(builtinAgents).filter(([key]) => key !== "sisyphus"),
|
||||
),
|
||||
...userAgents,
|
||||
...projectAgents,
|
||||
...pluginAgents,
|
||||
...filterDisabledAgents(userAgents),
|
||||
...filterDisabledAgents(projectAgents),
|
||||
...filterDisabledAgents(pluginAgents),
|
||||
...filteredConfigAgents,
|
||||
build: { ...migratedBuild, mode: "subagent", hidden: true },
|
||||
...(planDemoteConfig ? { plan: planDemoteConfig } : {}),
|
||||
@@ -233,9 +240,9 @@ export async function applyAgentConfig(params: {
|
||||
} else {
|
||||
params.config.agent = {
|
||||
...builtinAgents,
|
||||
...userAgents,
|
||||
...projectAgents,
|
||||
...pluginAgents,
|
||||
...filterDisabledAgents(userAgents),
|
||||
...filterDisabledAgents(projectAgents),
|
||||
...filterDisabledAgents(pluginAgents),
|
||||
...configAgent,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { describe, it, expect } from "bun:test"
|
||||
import { remapAgentKeysToDisplayNames } from "./agent-key-remapper"
|
||||
|
||||
describe("remapAgentKeysToDisplayNames", () => {
|
||||
it("remaps known agent keys to display names", () => {
|
||||
it("remaps known agent keys to display names while preserving original keys", () => {
|
||||
// given agents with lowercase keys
|
||||
const agents = {
|
||||
sisyphus: { prompt: "test", mode: "primary" },
|
||||
@@ -12,10 +12,11 @@ describe("remapAgentKeysToDisplayNames", () => {
|
||||
// when remapping
|
||||
const result = remapAgentKeysToDisplayNames(agents)
|
||||
|
||||
// then known agents get display name keys
|
||||
// then known agents get display name keys and original keys remain accessible
|
||||
expect(result["Sisyphus (Ultraworker)"]).toBeDefined()
|
||||
expect(result["oracle"]).toBeDefined()
|
||||
expect(result["sisyphus"]).toBeUndefined()
|
||||
expect(result["sisyphus"]).toBeDefined()
|
||||
expect(result["Sisyphus (Ultraworker)"]).toBe(result["sisyphus"])
|
||||
})
|
||||
|
||||
it("preserves unknown agent keys unchanged", () => {
|
||||
@@ -31,7 +32,7 @@ describe("remapAgentKeysToDisplayNames", () => {
|
||||
expect(result["custom-agent"]).toBeDefined()
|
||||
})
|
||||
|
||||
it("remaps all core agents", () => {
|
||||
it("remaps all core agents while preserving original keys", () => {
|
||||
// given all core agents
|
||||
const agents = {
|
||||
sisyphus: {},
|
||||
@@ -46,15 +47,20 @@ describe("remapAgentKeysToDisplayNames", () => {
|
||||
// when remapping
|
||||
const result = remapAgentKeysToDisplayNames(agents)
|
||||
|
||||
// then all get display name keys
|
||||
expect(Object.keys(result)).toEqual([
|
||||
"Sisyphus (Ultraworker)",
|
||||
"Hephaestus (Deep Agent)",
|
||||
"Prometheus (Plan Builder)",
|
||||
"Atlas (Plan Executor)",
|
||||
"Metis (Plan Consultant)",
|
||||
"Momus (Plan Critic)",
|
||||
"Sisyphus-Junior",
|
||||
])
|
||||
// then all get display name keys while original keys still work
|
||||
expect(result["Sisyphus (Ultraworker)"]).toBeDefined()
|
||||
expect(result["sisyphus"]).toBeDefined()
|
||||
expect(result["Hephaestus (Deep Agent)"]).toBeDefined()
|
||||
expect(result["hephaestus"]).toBeDefined()
|
||||
expect(result["Prometheus (Plan Builder)"]).toBeDefined()
|
||||
expect(result["prometheus"]).toBeDefined()
|
||||
expect(result["Atlas (Plan Executor)"]).toBeDefined()
|
||||
expect(result["atlas"]).toBeDefined()
|
||||
expect(result["Metis (Plan Consultant)"]).toBeDefined()
|
||||
expect(result["metis"]).toBeDefined()
|
||||
expect(result["Momus (Plan Critic)"]).toBeDefined()
|
||||
expect(result["momus"]).toBeDefined()
|
||||
expect(result["Sisyphus-Junior"]).toBeDefined()
|
||||
expect(result["sisyphus-junior"]).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -9,6 +9,7 @@ export function remapAgentKeysToDisplayNames(
|
||||
const displayName = AGENT_DISPLAY_NAMES[key]
|
||||
if (displayName && displayName !== key) {
|
||||
result[displayName] = value
|
||||
result[key] = value
|
||||
} else {
|
||||
result[key] = value
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test"
|
||||
|
||||
import type { OhMyOpenCodeConfig } from "../config"
|
||||
import { createConfigHandler } from "./config-handler"
|
||||
import * as agentConfigHandler from "./agent-config-handler"
|
||||
import * as commandConfigHandler from "./command-config-handler"
|
||||
import * as mcpConfigHandler from "./mcp-config-handler"
|
||||
import * as pluginComponentsLoader from "./plugin-components-loader"
|
||||
import * as providerConfigHandler from "./provider-config-handler"
|
||||
import * as shared from "../shared"
|
||||
import * as toolConfigHandler from "./tool-config-handler"
|
||||
|
||||
let logSpy: ReturnType<typeof spyOn>
|
||||
let loadPluginComponentsSpy: ReturnType<typeof spyOn>
|
||||
let applyAgentConfigSpy: ReturnType<typeof spyOn>
|
||||
let applyToolConfigSpy: ReturnType<typeof spyOn>
|
||||
let applyMcpConfigSpy: ReturnType<typeof spyOn>
|
||||
let applyCommandConfigSpy: ReturnType<typeof spyOn>
|
||||
let applyProviderConfigSpy: ReturnType<typeof spyOn>
|
||||
|
||||
beforeEach(() => {
|
||||
logSpy = spyOn(shared, "log").mockImplementation(() => {})
|
||||
loadPluginComponentsSpy = spyOn(
|
||||
pluginComponentsLoader,
|
||||
"loadPluginComponents",
|
||||
).mockResolvedValue({
|
||||
commands: {},
|
||||
skills: {},
|
||||
agents: {},
|
||||
mcpServers: {},
|
||||
hooksConfigs: [],
|
||||
plugins: [],
|
||||
errors: [],
|
||||
})
|
||||
applyAgentConfigSpy = spyOn(agentConfigHandler, "applyAgentConfig").mockResolvedValue(
|
||||
{},
|
||||
)
|
||||
applyToolConfigSpy = spyOn(toolConfigHandler, "applyToolConfig").mockImplementation(
|
||||
() => {},
|
||||
)
|
||||
applyMcpConfigSpy = spyOn(mcpConfigHandler, "applyMcpConfig").mockResolvedValue()
|
||||
applyCommandConfigSpy = spyOn(
|
||||
commandConfigHandler,
|
||||
"applyCommandConfig",
|
||||
).mockResolvedValue()
|
||||
applyProviderConfigSpy = spyOn(
|
||||
providerConfigHandler,
|
||||
"applyProviderConfig",
|
||||
).mockImplementation(() => {})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
logSpy.mockRestore()
|
||||
loadPluginComponentsSpy.mockRestore()
|
||||
applyAgentConfigSpy.mockRestore()
|
||||
applyToolConfigSpy.mockRestore()
|
||||
applyMcpConfigSpy.mockRestore()
|
||||
applyCommandConfigSpy.mockRestore()
|
||||
applyProviderConfigSpy.mockRestore()
|
||||
})
|
||||
|
||||
describe("createConfigHandler formatter pass-through", () => {
|
||||
test("preserves formatter object configured in opencode config", async () => {
|
||||
// given
|
||||
const pluginConfig: OhMyOpenCodeConfig = {}
|
||||
const formatterConfig = {
|
||||
prettier: {
|
||||
command: ["prettier", "--write"],
|
||||
extensions: [".ts", ".tsx"],
|
||||
environment: {
|
||||
PRETTIERD_DEFAULT_CONFIG: ".prettierrc",
|
||||
},
|
||||
},
|
||||
eslint: {
|
||||
disabled: false,
|
||||
command: ["eslint", "--fix"],
|
||||
extensions: [".js", ".ts"],
|
||||
},
|
||||
}
|
||||
const config: Record<string, unknown> = {
|
||||
formatter: formatterConfig,
|
||||
}
|
||||
const handler = createConfigHandler({
|
||||
ctx: { directory: "/tmp" },
|
||||
pluginConfig,
|
||||
modelCacheState: {
|
||||
anthropicContext1MEnabled: false,
|
||||
modelContextLimitsCache: new Map(),
|
||||
},
|
||||
})
|
||||
|
||||
// when
|
||||
await handler(config)
|
||||
|
||||
// then
|
||||
expect(config.formatter).toEqual(formatterConfig)
|
||||
})
|
||||
|
||||
test("preserves formatter=false configured in opencode config", async () => {
|
||||
// given
|
||||
const pluginConfig: OhMyOpenCodeConfig = {}
|
||||
const config: Record<string, unknown> = {
|
||||
formatter: false,
|
||||
}
|
||||
const handler = createConfigHandler({
|
||||
ctx: { directory: "/tmp" },
|
||||
pluginConfig,
|
||||
modelCacheState: {
|
||||
anthropicContext1MEnabled: false,
|
||||
modelContextLimitsCache: new Map(),
|
||||
},
|
||||
})
|
||||
|
||||
// when
|
||||
await handler(config)
|
||||
|
||||
// then
|
||||
expect(config.formatter).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -823,7 +823,7 @@ describe("Prometheus category config resolution", () => {
|
||||
|
||||
// then
|
||||
expect(config).toBeDefined()
|
||||
expect(config?.model).toBe("google/gemini-3-pro")
|
||||
expect(config?.model).toBe("google/gemini-3.1-pro")
|
||||
})
|
||||
|
||||
test("user categories override default categories", () => {
|
||||
|
||||
@@ -20,6 +20,8 @@ export function createConfigHandler(deps: ConfigHandlerDeps) {
|
||||
const { ctx, pluginConfig, modelCacheState } = deps;
|
||||
|
||||
return async (config: Record<string, unknown>) => {
|
||||
const formatterConfig = config.formatter;
|
||||
|
||||
applyProviderConfig({ config, modelCacheState });
|
||||
|
||||
const pluginComponents = await loadPluginComponents({ pluginConfig });
|
||||
@@ -35,6 +37,8 @@ export function createConfigHandler(deps: ConfigHandlerDeps) {
|
||||
await applyMcpConfig({ config, pluginConfig, pluginComponents });
|
||||
await applyCommandConfig({ config, pluginConfig, ctx, pluginComponents });
|
||||
|
||||
config.formatter = formatterConfig;
|
||||
|
||||
log("[config-handler] config handler applied", {
|
||||
agentCount: Object.keys(agentResult).length,
|
||||
commandCount: Object.keys((config.command as Record<string, unknown>) ?? {})
|
||||
|
||||
Reference in New Issue
Block a user