2026-01-02 11:35:56 +09:00
|
|
|
import type { OhMyOpenCodeConfig } from "../config";
|
2026-04-02 14:55:01 +09:00
|
|
|
import { setAdditionalAllowedMcpEnvVars } from "../features/claude-code-mcp-loader";
|
2026-01-02 11:35:56 +09:00
|
|
|
import type { ModelCacheState } from "../plugin-state";
|
2026-02-08 16:25:25 +09:00
|
|
|
import { log } from "../shared";
|
|
|
|
|
import { applyAgentConfig } from "./agent-config-handler";
|
|
|
|
|
import { applyCommandConfig } from "./command-config-handler";
|
2026-05-19 14:03:13 +08:00
|
|
|
import { applyHookConfig } from "./hook-config-handler";
|
2026-02-08 16:25:25 +09:00
|
|
|
import { applyMcpConfig } from "./mcp-config-handler";
|
|
|
|
|
import { applyProviderConfig } from "./provider-config-handler";
|
|
|
|
|
import { loadPluginComponents } from "./plugin-components-loader";
|
|
|
|
|
import { applyToolConfig } from "./tool-config-handler";
|
2026-03-23 18:46:44 +09:00
|
|
|
import { clearFormatterCache } from "../tools/hashline-edit/formatter-trigger"
|
2026-02-08 16:25:25 +09:00
|
|
|
|
|
|
|
|
export { resolveCategoryConfig } from "./category-config-resolver";
|
2026-01-02 11:35:56 +09:00
|
|
|
|
2026-05-24 00:30:40 +09:00
|
|
|
function collectTrustedVisionCapableModels(
|
|
|
|
|
pluginConfig: OhMyOpenCodeConfig,
|
|
|
|
|
): string[] {
|
|
|
|
|
const trusted: string[] = []
|
|
|
|
|
const multimodalLookerOverride = pluginConfig.agents?.["multimodal-looker"]
|
|
|
|
|
const configuredModel = multimodalLookerOverride?.model
|
|
|
|
|
if (typeof configuredModel === "string" && configuredModel.includes("/")) {
|
|
|
|
|
trusted.push(configuredModel)
|
|
|
|
|
}
|
|
|
|
|
return trusted
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-02 11:35:56 +09:00
|
|
|
export interface ConfigHandlerDeps {
|
2026-01-22 22:48:36 +09:00
|
|
|
ctx: { directory: string; client?: any };
|
2026-01-02 11:35:56 +09:00
|
|
|
pluginConfig: OhMyOpenCodeConfig;
|
|
|
|
|
modelCacheState: ModelCacheState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createConfigHandler(deps: ConfigHandlerDeps) {
|
|
|
|
|
const { ctx, pluginConfig, modelCacheState } = deps;
|
|
|
|
|
|
|
|
|
|
return async (config: Record<string, unknown>) => {
|
2026-02-26 21:00:18 +09:00
|
|
|
const formatterConfig = config.formatter;
|
|
|
|
|
|
2026-04-02 14:55:01 +09:00
|
|
|
setAdditionalAllowedMcpEnvVars(pluginConfig.mcp_env_allowlist ?? [])
|
2026-05-24 00:30:40 +09:00
|
|
|
applyProviderConfig({
|
|
|
|
|
config,
|
|
|
|
|
modelCacheState,
|
|
|
|
|
trustedVisionCapableModels: collectTrustedVisionCapableModels(pluginConfig),
|
|
|
|
|
});
|
2026-03-23 18:46:44 +09:00
|
|
|
clearFormatterCache()
|
2026-02-08 16:25:25 +09:00
|
|
|
|
|
|
|
|
const pluginComponents = await loadPluginComponents({ pluginConfig });
|
|
|
|
|
|
2026-05-20 22:30:25 +08:00
|
|
|
applyHookConfig({ pluginComponents, ctx });
|
2026-05-19 14:03:13 +08:00
|
|
|
|
2026-02-08 16:25:25 +09:00
|
|
|
const agentResult = await applyAgentConfig({
|
|
|
|
|
config,
|
|
|
|
|
pluginConfig,
|
|
|
|
|
ctx,
|
|
|
|
|
pluginComponents,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
applyToolConfig({ config, pluginConfig, agentResult });
|
2026-05-18 21:19:24 +09:00
|
|
|
await applyMcpConfig({ config, pluginConfig, ctx, pluginComponents });
|
2026-02-13 11:08:22 +09:00
|
|
|
await applyCommandConfig({ config, pluginConfig, ctx, pluginComponents });
|
2026-02-08 16:25:25 +09:00
|
|
|
|
2026-02-26 21:00:18 +09:00
|
|
|
config.formatter = formatterConfig;
|
|
|
|
|
|
2026-02-08 16:25:25 +09:00
|
|
|
log("[config-handler] config handler applied", {
|
|
|
|
|
agentCount: Object.keys(agentResult).length,
|
|
|
|
|
commandCount: Object.keys((config.command as Record<string, unknown>) ?? {})
|
|
|
|
|
.length,
|
|
|
|
|
});
|
2026-01-02 11:35:56 +09:00
|
|
|
};
|
|
|
|
|
}
|