refactor(core): split index.ts and config-handler.ts into focused modules
Main entry point: - create-hooks.ts, create-tools.ts, create-managers.ts - plugin-interface.ts: plugin interface types - plugin/ directory: plugin lifecycle modules Config handler: - agent-config-handler.ts, command-config-handler.ts - tool-config-handler.ts, mcp-config-handler.ts - provider-config-handler.ts, category-config-resolver.ts - agent-priority-order.ts, prometheus-agent-config-builder.ts - plugin-components-loader.ts
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
import type { HookName, OhMyOpenCodeConfig } from "../../config"
|
||||
import type { BackgroundManager } from "../../features/background-agent"
|
||||
import type { PluginContext } from "../types"
|
||||
|
||||
import {
|
||||
createTodoContinuationEnforcer,
|
||||
createBackgroundNotificationHook,
|
||||
createStopContinuationGuardHook,
|
||||
createCompactionContextInjector,
|
||||
createCompactionTodoPreserverHook,
|
||||
createAtlasHook,
|
||||
} from "../../hooks"
|
||||
import { safeCreateHook } from "../../shared/safe-create-hook"
|
||||
import { createUnstableAgentBabysitter } from "../unstable-agent-babysitter"
|
||||
|
||||
export type ContinuationHooks = {
|
||||
stopContinuationGuard: ReturnType<typeof createStopContinuationGuardHook> | null
|
||||
compactionContextInjector: ReturnType<typeof createCompactionContextInjector> | null
|
||||
compactionTodoPreserver: ReturnType<typeof createCompactionTodoPreserverHook> | null
|
||||
todoContinuationEnforcer: ReturnType<typeof createTodoContinuationEnforcer> | null
|
||||
unstableAgentBabysitter: ReturnType<typeof createUnstableAgentBabysitter> | null
|
||||
backgroundNotificationHook: ReturnType<typeof createBackgroundNotificationHook> | null
|
||||
atlasHook: ReturnType<typeof createAtlasHook> | null
|
||||
}
|
||||
|
||||
type SessionRecovery = {
|
||||
setOnAbortCallback: (callback: (sessionID: string) => void) => void
|
||||
setOnRecoveryCompleteCallback: (callback: (sessionID: string) => void) => void
|
||||
} | null
|
||||
|
||||
export function createContinuationHooks(args: {
|
||||
ctx: PluginContext
|
||||
pluginConfig: OhMyOpenCodeConfig
|
||||
isHookEnabled: (hookName: HookName) => boolean
|
||||
safeHookEnabled: boolean
|
||||
backgroundManager: BackgroundManager
|
||||
sessionRecovery: SessionRecovery
|
||||
}): ContinuationHooks {
|
||||
const {
|
||||
ctx,
|
||||
pluginConfig,
|
||||
isHookEnabled,
|
||||
safeHookEnabled,
|
||||
backgroundManager,
|
||||
sessionRecovery,
|
||||
} = args
|
||||
|
||||
const safeHook = <T>(hookName: HookName, factory: () => T): T | null =>
|
||||
safeCreateHook(hookName, factory, { enabled: safeHookEnabled })
|
||||
|
||||
const stopContinuationGuard = isHookEnabled("stop-continuation-guard")
|
||||
? safeHook("stop-continuation-guard", () => createStopContinuationGuardHook(ctx))
|
||||
: null
|
||||
|
||||
const compactionContextInjector = isHookEnabled("compaction-context-injector")
|
||||
? safeHook("compaction-context-injector", () => createCompactionContextInjector())
|
||||
: null
|
||||
|
||||
const compactionTodoPreserver = isHookEnabled("compaction-todo-preserver")
|
||||
? safeHook("compaction-todo-preserver", () => createCompactionTodoPreserverHook(ctx))
|
||||
: null
|
||||
|
||||
const todoContinuationEnforcer = isHookEnabled("todo-continuation-enforcer")
|
||||
? safeHook("todo-continuation-enforcer", () =>
|
||||
createTodoContinuationEnforcer(ctx, {
|
||||
backgroundManager,
|
||||
isContinuationStopped: stopContinuationGuard?.isStopped,
|
||||
}))
|
||||
: null
|
||||
|
||||
const unstableAgentBabysitter = isHookEnabled("unstable-agent-babysitter")
|
||||
? safeHook("unstable-agent-babysitter", () =>
|
||||
createUnstableAgentBabysitter({ ctx, backgroundManager, pluginConfig }))
|
||||
: null
|
||||
|
||||
if (sessionRecovery && todoContinuationEnforcer) {
|
||||
sessionRecovery.setOnAbortCallback(todoContinuationEnforcer.markRecovering)
|
||||
sessionRecovery.setOnRecoveryCompleteCallback(todoContinuationEnforcer.markRecoveryComplete)
|
||||
}
|
||||
|
||||
const backgroundNotificationHook = isHookEnabled("background-notification")
|
||||
? safeHook("background-notification", () => createBackgroundNotificationHook(backgroundManager))
|
||||
: null
|
||||
|
||||
const atlasHook = isHookEnabled("atlas")
|
||||
? safeHook("atlas", () =>
|
||||
createAtlasHook(ctx, {
|
||||
directory: ctx.directory,
|
||||
backgroundManager,
|
||||
isContinuationStopped: (sessionID: string) =>
|
||||
stopContinuationGuard?.isStopped(sessionID) ?? false,
|
||||
}))
|
||||
: null
|
||||
|
||||
return {
|
||||
stopContinuationGuard,
|
||||
compactionContextInjector,
|
||||
compactionTodoPreserver,
|
||||
todoContinuationEnforcer,
|
||||
unstableAgentBabysitter,
|
||||
backgroundNotificationHook,
|
||||
atlasHook,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import type { HookName, OhMyOpenCodeConfig } from "../../config"
|
||||
import type { PluginContext } from "../types"
|
||||
|
||||
import { createSessionHooks } from "./create-session-hooks"
|
||||
import { createToolGuardHooks } from "./create-tool-guard-hooks"
|
||||
import { createTransformHooks } from "./create-transform-hooks"
|
||||
|
||||
export function createCoreHooks(args: {
|
||||
ctx: PluginContext
|
||||
pluginConfig: OhMyOpenCodeConfig
|
||||
isHookEnabled: (hookName: HookName) => boolean
|
||||
safeHookEnabled: boolean
|
||||
}) {
|
||||
const { ctx, pluginConfig, isHookEnabled, safeHookEnabled } = args
|
||||
|
||||
const session = createSessionHooks({
|
||||
ctx,
|
||||
pluginConfig,
|
||||
isHookEnabled,
|
||||
safeHookEnabled,
|
||||
})
|
||||
|
||||
const tool = createToolGuardHooks({
|
||||
ctx,
|
||||
pluginConfig,
|
||||
isHookEnabled,
|
||||
safeHookEnabled,
|
||||
})
|
||||
|
||||
const transform = createTransformHooks({
|
||||
ctx,
|
||||
pluginConfig,
|
||||
isHookEnabled: (name) => isHookEnabled(name as HookName),
|
||||
safeHookEnabled,
|
||||
})
|
||||
|
||||
return {
|
||||
...session,
|
||||
...tool,
|
||||
...transform,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
import type { OhMyOpenCodeConfig, HookName } from "../../config"
|
||||
import type { PluginContext } from "../types"
|
||||
|
||||
import {
|
||||
createContextWindowMonitorHook,
|
||||
createSessionRecoveryHook,
|
||||
createSessionNotification,
|
||||
createThinkModeHook,
|
||||
createAnthropicContextWindowLimitRecoveryHook,
|
||||
createAutoUpdateCheckerHook,
|
||||
createAgentUsageReminderHook,
|
||||
createNonInteractiveEnvHook,
|
||||
createInteractiveBashSessionHook,
|
||||
createRalphLoopHook,
|
||||
createEditErrorRecoveryHook,
|
||||
createDelegateTaskRetryHook,
|
||||
createTaskResumeInfoHook,
|
||||
createStartWorkHook,
|
||||
createPrometheusMdOnlyHook,
|
||||
createSisyphusJuniorNotepadHook,
|
||||
createQuestionLabelTruncatorHook,
|
||||
createSubagentQuestionBlockerHook,
|
||||
createPreemptiveCompactionHook,
|
||||
} from "../../hooks"
|
||||
import { createAnthropicEffortHook } from "../../hooks/anthropic-effort"
|
||||
import {
|
||||
detectExternalNotificationPlugin,
|
||||
getNotificationConflictWarning,
|
||||
log,
|
||||
} from "../../shared"
|
||||
import { safeCreateHook } from "../../shared/safe-create-hook"
|
||||
import { sessionExists } from "../../tools"
|
||||
|
||||
export type SessionHooks = {
|
||||
contextWindowMonitor: ReturnType<typeof createContextWindowMonitorHook> | null
|
||||
preemptiveCompaction: ReturnType<typeof createPreemptiveCompactionHook> | null
|
||||
sessionRecovery: ReturnType<typeof createSessionRecoveryHook> | null
|
||||
sessionNotification: ReturnType<typeof createSessionNotification> | null
|
||||
thinkMode: ReturnType<typeof createThinkModeHook> | null
|
||||
anthropicContextWindowLimitRecovery: ReturnType<typeof createAnthropicContextWindowLimitRecoveryHook> | null
|
||||
autoUpdateChecker: ReturnType<typeof createAutoUpdateCheckerHook> | null
|
||||
agentUsageReminder: ReturnType<typeof createAgentUsageReminderHook> | null
|
||||
nonInteractiveEnv: ReturnType<typeof createNonInteractiveEnvHook> | null
|
||||
interactiveBashSession: ReturnType<typeof createInteractiveBashSessionHook> | null
|
||||
ralphLoop: ReturnType<typeof createRalphLoopHook> | null
|
||||
editErrorRecovery: ReturnType<typeof createEditErrorRecoveryHook> | null
|
||||
delegateTaskRetry: ReturnType<typeof createDelegateTaskRetryHook> | null
|
||||
startWork: ReturnType<typeof createStartWorkHook> | null
|
||||
prometheusMdOnly: ReturnType<typeof createPrometheusMdOnlyHook> | null
|
||||
sisyphusJuniorNotepad: ReturnType<typeof createSisyphusJuniorNotepadHook> | null
|
||||
questionLabelTruncator: ReturnType<typeof createQuestionLabelTruncatorHook>
|
||||
subagentQuestionBlocker: ReturnType<typeof createSubagentQuestionBlockerHook>
|
||||
taskResumeInfo: ReturnType<typeof createTaskResumeInfoHook>
|
||||
anthropicEffort: ReturnType<typeof createAnthropicEffortHook> | null
|
||||
}
|
||||
|
||||
export function createSessionHooks(args: {
|
||||
ctx: PluginContext
|
||||
pluginConfig: OhMyOpenCodeConfig
|
||||
isHookEnabled: (hookName: HookName) => boolean
|
||||
safeHookEnabled: boolean
|
||||
}): SessionHooks {
|
||||
const { ctx, pluginConfig, isHookEnabled, safeHookEnabled } = args
|
||||
const safeHook = <T>(hookName: HookName, factory: () => T): T | null =>
|
||||
safeCreateHook(hookName, factory, { enabled: safeHookEnabled })
|
||||
|
||||
const contextWindowMonitor = isHookEnabled("context-window-monitor")
|
||||
? safeHook("context-window-monitor", () => createContextWindowMonitorHook(ctx))
|
||||
: null
|
||||
|
||||
const preemptiveCompaction =
|
||||
isHookEnabled("preemptive-compaction") &&
|
||||
pluginConfig.experimental?.preemptive_compaction
|
||||
? safeHook("preemptive-compaction", () => createPreemptiveCompactionHook(ctx))
|
||||
: null
|
||||
|
||||
const sessionRecovery = isHookEnabled("session-recovery")
|
||||
? safeHook("session-recovery", () =>
|
||||
createSessionRecoveryHook(ctx, { experimental: pluginConfig.experimental }))
|
||||
: null
|
||||
|
||||
let sessionNotification: ReturnType<typeof createSessionNotification> | null = null
|
||||
if (isHookEnabled("session-notification")) {
|
||||
const forceEnable = pluginConfig.notification?.force_enable ?? false
|
||||
const externalNotifier = detectExternalNotificationPlugin(ctx.directory)
|
||||
if (externalNotifier.detected && !forceEnable) {
|
||||
log(getNotificationConflictWarning(externalNotifier.pluginName!))
|
||||
} else {
|
||||
sessionNotification = safeHook("session-notification", () => createSessionNotification(ctx))
|
||||
}
|
||||
}
|
||||
|
||||
const thinkMode = isHookEnabled("think-mode")
|
||||
? safeHook("think-mode", () => createThinkModeHook())
|
||||
: null
|
||||
|
||||
const anthropicContextWindowLimitRecovery = isHookEnabled("anthropic-context-window-limit-recovery")
|
||||
? safeHook("anthropic-context-window-limit-recovery", () =>
|
||||
createAnthropicContextWindowLimitRecoveryHook(ctx, { experimental: pluginConfig.experimental }))
|
||||
: null
|
||||
|
||||
const autoUpdateChecker = isHookEnabled("auto-update-checker")
|
||||
? safeHook("auto-update-checker", () =>
|
||||
createAutoUpdateCheckerHook(ctx, {
|
||||
showStartupToast: isHookEnabled("startup-toast"),
|
||||
isSisyphusEnabled: pluginConfig.sisyphus_agent?.disabled !== true,
|
||||
autoUpdate: pluginConfig.auto_update ?? true,
|
||||
}))
|
||||
: null
|
||||
|
||||
const agentUsageReminder = isHookEnabled("agent-usage-reminder")
|
||||
? safeHook("agent-usage-reminder", () => createAgentUsageReminderHook(ctx))
|
||||
: null
|
||||
|
||||
const nonInteractiveEnv = isHookEnabled("non-interactive-env")
|
||||
? safeHook("non-interactive-env", () => createNonInteractiveEnvHook(ctx))
|
||||
: null
|
||||
|
||||
const interactiveBashSession = isHookEnabled("interactive-bash-session")
|
||||
? safeHook("interactive-bash-session", () => createInteractiveBashSessionHook(ctx))
|
||||
: null
|
||||
|
||||
const ralphLoop = isHookEnabled("ralph-loop")
|
||||
? safeHook("ralph-loop", () =>
|
||||
createRalphLoopHook(ctx, {
|
||||
config: pluginConfig.ralph_loop,
|
||||
checkSessionExists: async (sessionId) => sessionExists(sessionId),
|
||||
}))
|
||||
: null
|
||||
|
||||
const editErrorRecovery = isHookEnabled("edit-error-recovery")
|
||||
? safeHook("edit-error-recovery", () => createEditErrorRecoveryHook(ctx))
|
||||
: null
|
||||
|
||||
const delegateTaskRetry = isHookEnabled("delegate-task-retry")
|
||||
? safeHook("delegate-task-retry", () => createDelegateTaskRetryHook(ctx))
|
||||
: null
|
||||
|
||||
const startWork = isHookEnabled("start-work")
|
||||
? safeHook("start-work", () => createStartWorkHook(ctx))
|
||||
: null
|
||||
|
||||
const prometheusMdOnly = isHookEnabled("prometheus-md-only")
|
||||
? safeHook("prometheus-md-only", () => createPrometheusMdOnlyHook(ctx))
|
||||
: null
|
||||
|
||||
const sisyphusJuniorNotepad = isHookEnabled("sisyphus-junior-notepad")
|
||||
? safeHook("sisyphus-junior-notepad", () => createSisyphusJuniorNotepadHook(ctx))
|
||||
: null
|
||||
|
||||
const questionLabelTruncator = createQuestionLabelTruncatorHook()
|
||||
const subagentQuestionBlocker = createSubagentQuestionBlockerHook()
|
||||
const taskResumeInfo = createTaskResumeInfoHook()
|
||||
|
||||
const anthropicEffort = isHookEnabled("anthropic-effort")
|
||||
? safeHook("anthropic-effort", () => createAnthropicEffortHook())
|
||||
: null
|
||||
|
||||
return {
|
||||
contextWindowMonitor,
|
||||
preemptiveCompaction,
|
||||
sessionRecovery,
|
||||
sessionNotification,
|
||||
thinkMode,
|
||||
anthropicContextWindowLimitRecovery,
|
||||
autoUpdateChecker,
|
||||
agentUsageReminder,
|
||||
nonInteractiveEnv,
|
||||
interactiveBashSession,
|
||||
ralphLoop,
|
||||
editErrorRecovery,
|
||||
delegateTaskRetry,
|
||||
startWork,
|
||||
prometheusMdOnly,
|
||||
sisyphusJuniorNotepad,
|
||||
questionLabelTruncator,
|
||||
subagentQuestionBlocker,
|
||||
taskResumeInfo,
|
||||
anthropicEffort,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import type { AvailableSkill } from "../../agents/dynamic-agent-prompt-builder"
|
||||
import type { HookName } from "../../config"
|
||||
import type { LoadedSkill } from "../../features/opencode-skill-loader/types"
|
||||
import type { PluginContext } from "../types"
|
||||
|
||||
import { createAutoSlashCommandHook, createCategorySkillReminderHook } from "../../hooks"
|
||||
import { safeCreateHook } from "../../shared/safe-create-hook"
|
||||
|
||||
export type SkillHooks = {
|
||||
categorySkillReminder: ReturnType<typeof createCategorySkillReminderHook> | null
|
||||
autoSlashCommand: ReturnType<typeof createAutoSlashCommandHook> | null
|
||||
}
|
||||
|
||||
export function createSkillHooks(args: {
|
||||
ctx: PluginContext
|
||||
isHookEnabled: (hookName: HookName) => boolean
|
||||
safeHookEnabled: boolean
|
||||
mergedSkills: LoadedSkill[]
|
||||
availableSkills: AvailableSkill[]
|
||||
}): SkillHooks {
|
||||
const { ctx, isHookEnabled, safeHookEnabled, mergedSkills, availableSkills } = args
|
||||
|
||||
const safeHook = <T>(hookName: HookName, factory: () => T): T | null =>
|
||||
safeCreateHook(hookName, factory, { enabled: safeHookEnabled })
|
||||
|
||||
const categorySkillReminder = isHookEnabled("category-skill-reminder")
|
||||
? safeHook("category-skill-reminder", () =>
|
||||
createCategorySkillReminderHook(ctx, availableSkills))
|
||||
: null
|
||||
|
||||
const autoSlashCommand = isHookEnabled("auto-slash-command")
|
||||
? safeHook("auto-slash-command", () =>
|
||||
createAutoSlashCommandHook({ skills: mergedSkills }))
|
||||
: null
|
||||
|
||||
return { categorySkillReminder, autoSlashCommand }
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
import type { HookName, OhMyOpenCodeConfig } from "../../config"
|
||||
import type { PluginContext } from "../types"
|
||||
|
||||
import {
|
||||
createCommentCheckerHooks,
|
||||
createToolOutputTruncatorHook,
|
||||
createDirectoryAgentsInjectorHook,
|
||||
createDirectoryReadmeInjectorHook,
|
||||
createEmptyTaskResponseDetectorHook,
|
||||
createRulesInjectorHook,
|
||||
createTasksTodowriteDisablerHook,
|
||||
createWriteExistingFileGuardHook,
|
||||
} from "../../hooks"
|
||||
import {
|
||||
getOpenCodeVersion,
|
||||
isOpenCodeVersionAtLeast,
|
||||
log,
|
||||
OPENCODE_NATIVE_AGENTS_INJECTION_VERSION,
|
||||
} from "../../shared"
|
||||
import { safeCreateHook } from "../../shared/safe-create-hook"
|
||||
|
||||
export type ToolGuardHooks = {
|
||||
commentChecker: ReturnType<typeof createCommentCheckerHooks> | null
|
||||
toolOutputTruncator: ReturnType<typeof createToolOutputTruncatorHook> | null
|
||||
directoryAgentsInjector: ReturnType<typeof createDirectoryAgentsInjectorHook> | null
|
||||
directoryReadmeInjector: ReturnType<typeof createDirectoryReadmeInjectorHook> | null
|
||||
emptyTaskResponseDetector: ReturnType<typeof createEmptyTaskResponseDetectorHook> | null
|
||||
rulesInjector: ReturnType<typeof createRulesInjectorHook> | null
|
||||
tasksTodowriteDisabler: ReturnType<typeof createTasksTodowriteDisablerHook> | null
|
||||
writeExistingFileGuard: ReturnType<typeof createWriteExistingFileGuardHook> | null
|
||||
}
|
||||
|
||||
export function createToolGuardHooks(args: {
|
||||
ctx: PluginContext
|
||||
pluginConfig: OhMyOpenCodeConfig
|
||||
isHookEnabled: (hookName: HookName) => boolean
|
||||
safeHookEnabled: boolean
|
||||
}): ToolGuardHooks {
|
||||
const { ctx, pluginConfig, isHookEnabled, safeHookEnabled } = args
|
||||
const safeHook = <T>(hookName: HookName, factory: () => T): T | null =>
|
||||
safeCreateHook(hookName, factory, { enabled: safeHookEnabled })
|
||||
|
||||
const commentChecker = isHookEnabled("comment-checker")
|
||||
? safeHook("comment-checker", () => createCommentCheckerHooks(pluginConfig.comment_checker))
|
||||
: null
|
||||
|
||||
const toolOutputTruncator = isHookEnabled("tool-output-truncator")
|
||||
? safeHook("tool-output-truncator", () =>
|
||||
createToolOutputTruncatorHook(ctx, { experimental: pluginConfig.experimental }))
|
||||
: null
|
||||
|
||||
let directoryAgentsInjector: ReturnType<typeof createDirectoryAgentsInjectorHook> | null = null
|
||||
if (isHookEnabled("directory-agents-injector")) {
|
||||
const currentVersion = getOpenCodeVersion()
|
||||
const hasNativeSupport =
|
||||
currentVersion !== null && isOpenCodeVersionAtLeast(OPENCODE_NATIVE_AGENTS_INJECTION_VERSION)
|
||||
if (hasNativeSupport) {
|
||||
log("directory-agents-injector auto-disabled due to native OpenCode support", {
|
||||
currentVersion,
|
||||
nativeVersion: OPENCODE_NATIVE_AGENTS_INJECTION_VERSION,
|
||||
})
|
||||
} else {
|
||||
directoryAgentsInjector = safeHook("directory-agents-injector", () => createDirectoryAgentsInjectorHook(ctx))
|
||||
}
|
||||
}
|
||||
|
||||
const directoryReadmeInjector = isHookEnabled("directory-readme-injector")
|
||||
? safeHook("directory-readme-injector", () => createDirectoryReadmeInjectorHook(ctx))
|
||||
: null
|
||||
|
||||
const emptyTaskResponseDetector = isHookEnabled("empty-task-response-detector")
|
||||
? safeHook("empty-task-response-detector", () => createEmptyTaskResponseDetectorHook(ctx))
|
||||
: null
|
||||
|
||||
const rulesInjector = isHookEnabled("rules-injector")
|
||||
? safeHook("rules-injector", () => createRulesInjectorHook(ctx))
|
||||
: null
|
||||
|
||||
const tasksTodowriteDisabler = isHookEnabled("tasks-todowrite-disabler")
|
||||
? safeHook("tasks-todowrite-disabler", () =>
|
||||
createTasksTodowriteDisablerHook({ experimental: pluginConfig.experimental }))
|
||||
: null
|
||||
|
||||
const writeExistingFileGuard = isHookEnabled("write-existing-file-guard")
|
||||
? safeHook("write-existing-file-guard", () => createWriteExistingFileGuardHook(ctx))
|
||||
: null
|
||||
|
||||
return {
|
||||
commentChecker,
|
||||
toolOutputTruncator,
|
||||
directoryAgentsInjector,
|
||||
directoryReadmeInjector,
|
||||
emptyTaskResponseDetector,
|
||||
rulesInjector,
|
||||
tasksTodowriteDisabler,
|
||||
writeExistingFileGuard,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import type { OhMyOpenCodeConfig } from "../../config"
|
||||
import type { PluginContext } from "../types"
|
||||
|
||||
import {
|
||||
createClaudeCodeHooksHook,
|
||||
createKeywordDetectorHook,
|
||||
createThinkingBlockValidatorHook,
|
||||
} from "../../hooks"
|
||||
import {
|
||||
contextCollector,
|
||||
createContextInjectorMessagesTransformHook,
|
||||
} from "../../features/context-injector"
|
||||
import { safeCreateHook } from "../../shared/safe-create-hook"
|
||||
|
||||
export type TransformHooks = {
|
||||
claudeCodeHooks: ReturnType<typeof createClaudeCodeHooksHook>
|
||||
keywordDetector: ReturnType<typeof createKeywordDetectorHook> | null
|
||||
contextInjectorMessagesTransform: ReturnType<typeof createContextInjectorMessagesTransformHook>
|
||||
thinkingBlockValidator: ReturnType<typeof createThinkingBlockValidatorHook> | null
|
||||
}
|
||||
|
||||
export function createTransformHooks(args: {
|
||||
ctx: PluginContext
|
||||
pluginConfig: OhMyOpenCodeConfig
|
||||
isHookEnabled: (hookName: string) => boolean
|
||||
safeHookEnabled?: boolean
|
||||
}): TransformHooks {
|
||||
const { ctx, pluginConfig, isHookEnabled } = args
|
||||
const safeHookEnabled = args.safeHookEnabled ?? true
|
||||
|
||||
const claudeCodeHooks = createClaudeCodeHooksHook(
|
||||
ctx,
|
||||
{
|
||||
disabledHooks: (pluginConfig.claude_code?.hooks ?? true) ? undefined : true,
|
||||
keywordDetectorDisabled: !isHookEnabled("keyword-detector"),
|
||||
},
|
||||
contextCollector,
|
||||
)
|
||||
|
||||
const keywordDetector = isHookEnabled("keyword-detector")
|
||||
? safeCreateHook(
|
||||
"keyword-detector",
|
||||
() => createKeywordDetectorHook(ctx, contextCollector),
|
||||
{ enabled: safeHookEnabled },
|
||||
)
|
||||
: null
|
||||
|
||||
const contextInjectorMessagesTransform =
|
||||
createContextInjectorMessagesTransformHook(contextCollector)
|
||||
|
||||
const thinkingBlockValidator = isHookEnabled("thinking-block-validator")
|
||||
? safeCreateHook(
|
||||
"thinking-block-validator",
|
||||
() => createThinkingBlockValidatorHook(),
|
||||
{ enabled: safeHookEnabled },
|
||||
)
|
||||
: null
|
||||
|
||||
return {
|
||||
claudeCodeHooks,
|
||||
keywordDetector,
|
||||
contextInjectorMessagesTransform,
|
||||
thinkingBlockValidator,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user