Files
oh-my-opencode/src/plugin-handlers/config-handler.ts
T
JacobZyy 4d105d0559 fix(hooks): merge marketplace plugin hooksConfigs into claude-code-hooks at config time
Previously, loadPluginHooksConfigs() loaded plugin hooks from marketplace
plugins (hookify, superpowers, zzcommon, zzfe, etc.) into
pluginComponents.hooksConfigs, but config-handler.ts never consumed them.
This meant plugin hooks were discovered but never merged into the runtime
hooks dispatch system.

Changes:
- Extend ClaudeHookEvent and ClaudeHooksConfig to support all 12 event
  types (PostToolUseFailure, PermissionRequest, Notification,
  SubagentStart, SubagentStop, SessionStart, SessionEnd) in addition to
  the existing 5
- Add ALL_HOOK_EVENT_TYPES constant as single source of truth for event
  type iteration
- Add mergePluginHooksConfigs() to unwrap plugin HooksConfig (with hooks
  wrapper) into flat ClaudeHooksConfig, filtering out unsupported
  prompt/agent hook types
- Add setPluginHooksConfigs() to store pending plugin configs and
  invalidate the config cache
- Create applyHookConfig() handler following existing applyXxxConfig
  pattern, wired into config-handler after loadPluginComponents()
- Extend DisabledHooksConfig and mergeDisabledHooks for all 12 events

Closes #4179
2026-05-19 14:03:13 +08:00

56 lines
2.0 KiB
TypeScript

import type { OhMyOpenCodeConfig } from "../config";
import { setAdditionalAllowedMcpEnvVars } from "../features/claude-code-mcp-loader";
import type { ModelCacheState } from "../plugin-state";
import { log } from "../shared";
import { applyAgentConfig } from "./agent-config-handler";
import { applyCommandConfig } from "./command-config-handler";
import { applyHookConfig } from "./hook-config-handler";
import { applyMcpConfig } from "./mcp-config-handler";
import { applyProviderConfig } from "./provider-config-handler";
import { loadPluginComponents } from "./plugin-components-loader";
import { applyToolConfig } from "./tool-config-handler";
import { clearFormatterCache } from "../tools/hashline-edit/formatter-trigger"
export { resolveCategoryConfig } from "./category-config-resolver";
export interface ConfigHandlerDeps {
ctx: { directory: string; client?: any };
pluginConfig: OhMyOpenCodeConfig;
modelCacheState: ModelCacheState;
}
export function createConfigHandler(deps: ConfigHandlerDeps) {
const { ctx, pluginConfig, modelCacheState } = deps;
return async (config: Record<string, unknown>) => {
const formatterConfig = config.formatter;
setAdditionalAllowedMcpEnvVars(pluginConfig.mcp_env_allowlist ?? [])
applyProviderConfig({ config, modelCacheState });
clearFormatterCache()
const pluginComponents = await loadPluginComponents({ pluginConfig });
applyHookConfig({ pluginComponents });
const agentResult = await applyAgentConfig({
config,
pluginConfig,
ctx,
pluginComponents,
});
applyToolConfig({ config, pluginConfig, agentResult });
await applyMcpConfig({ config, pluginConfig, ctx, 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>) ?? {})
.length,
});
};
}