2026-02-08 16:25:25 +09:00
|
|
|
import type { OhMyOpenCodeConfig } from "../../config"
|
|
|
|
|
import type { PluginContext } from "../types"
|
2026-04-07 15:10:43 +09:00
|
|
|
import type { RalphLoopHook } from "../../hooks/ralph-loop"
|
2026-02-08 16:25:25 +09:00
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
createClaudeCodeHooksHook,
|
|
|
|
|
createKeywordDetectorHook,
|
2026-04-28 10:48:45 +09:00
|
|
|
createTeamMailboxInjector,
|
|
|
|
|
createTeamModeStatusInjector,
|
2026-02-08 16:25:25 +09:00
|
|
|
createThinkingBlockValidatorHook,
|
2026-04-02 13:31:48 +09:00
|
|
|
createToolPairValidatorHook,
|
2026-02-08 16:25:25 +09:00
|
|
|
} from "../../hooks"
|
|
|
|
|
import {
|
|
|
|
|
contextCollector,
|
|
|
|
|
createContextInjectorMessagesTransformHook,
|
|
|
|
|
} from "../../features/context-injector"
|
|
|
|
|
import { safeCreateHook } from "../../shared/safe-create-hook"
|
|
|
|
|
|
|
|
|
|
export type TransformHooks = {
|
2026-02-21 16:24:18 +09:00
|
|
|
claudeCodeHooks: ReturnType<typeof createClaudeCodeHooksHook> | null
|
2026-02-08 16:25:25 +09:00
|
|
|
keywordDetector: ReturnType<typeof createKeywordDetectorHook> | null
|
|
|
|
|
contextInjectorMessagesTransform: ReturnType<typeof createContextInjectorMessagesTransformHook>
|
2026-04-28 10:48:45 +09:00
|
|
|
teamModeStatusInjector: ReturnType<typeof createTeamModeStatusInjector> | null
|
|
|
|
|
teamMailboxInjector: ReturnType<typeof createTeamMailboxInjector> | null
|
2026-02-08 16:25:25 +09:00
|
|
|
thinkingBlockValidator: ReturnType<typeof createThinkingBlockValidatorHook> | null
|
2026-04-02 13:31:48 +09:00
|
|
|
toolPairValidator: ReturnType<typeof createToolPairValidatorHook> | null
|
2026-02-08 16:25:25 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createTransformHooks(args: {
|
|
|
|
|
ctx: PluginContext
|
|
|
|
|
pluginConfig: OhMyOpenCodeConfig
|
|
|
|
|
isHookEnabled: (hookName: string) => boolean
|
|
|
|
|
safeHookEnabled?: boolean
|
2026-04-07 15:10:43 +09:00
|
|
|
ralphLoop?: RalphLoopHook | null
|
2026-02-08 16:25:25 +09:00
|
|
|
}): TransformHooks {
|
2026-04-07 15:10:43 +09:00
|
|
|
const { ctx, pluginConfig, isHookEnabled, ralphLoop } = args
|
2026-02-08 16:25:25 +09:00
|
|
|
const safeHookEnabled = args.safeHookEnabled ?? true
|
|
|
|
|
|
2026-02-21 16:24:18 +09:00
|
|
|
const claudeCodeHooks = isHookEnabled("claude-code-hooks")
|
|
|
|
|
? safeCreateHook(
|
|
|
|
|
"claude-code-hooks",
|
|
|
|
|
() =>
|
|
|
|
|
createClaudeCodeHooksHook(
|
|
|
|
|
ctx,
|
|
|
|
|
{
|
|
|
|
|
disabledHooks: (pluginConfig.claude_code?.hooks ?? true) ? undefined : true,
|
|
|
|
|
keywordDetectorDisabled: !isHookEnabled("keyword-detector"),
|
|
|
|
|
},
|
|
|
|
|
contextCollector,
|
|
|
|
|
),
|
|
|
|
|
{ enabled: safeHookEnabled },
|
|
|
|
|
)
|
|
|
|
|
: null
|
2026-02-08 16:25:25 +09:00
|
|
|
|
|
|
|
|
const keywordDetector = isHookEnabled("keyword-detector")
|
|
|
|
|
? safeCreateHook(
|
|
|
|
|
"keyword-detector",
|
2026-04-28 14:20:35 +09:00
|
|
|
() =>
|
|
|
|
|
createKeywordDetectorHook(
|
|
|
|
|
ctx,
|
|
|
|
|
contextCollector,
|
|
|
|
|
ralphLoop ?? undefined,
|
|
|
|
|
pluginConfig.keyword_detector,
|
|
|
|
|
),
|
2026-02-08 16:25:25 +09:00
|
|
|
{ enabled: safeHookEnabled },
|
|
|
|
|
)
|
|
|
|
|
: null
|
|
|
|
|
|
|
|
|
|
const contextInjectorMessagesTransform =
|
|
|
|
|
createContextInjectorMessagesTransformHook(contextCollector)
|
|
|
|
|
|
2026-04-28 10:48:45 +09:00
|
|
|
const teamModeConfig = pluginConfig.team_mode
|
|
|
|
|
|
|
|
|
|
const teamModeStatusInjector = teamModeConfig?.enabled
|
|
|
|
|
? safeCreateHook(
|
|
|
|
|
"team-mode-status-injector",
|
2026-05-15 15:35:35 +09:00
|
|
|
() => createTeamModeStatusInjector(teamModeConfig, pluginConfig.keyword_detector),
|
2026-04-28 10:48:45 +09:00
|
|
|
{ enabled: safeHookEnabled },
|
|
|
|
|
)
|
|
|
|
|
: null
|
|
|
|
|
|
|
|
|
|
const teamMailboxInjector = teamModeConfig?.enabled
|
|
|
|
|
? safeCreateHook(
|
|
|
|
|
"team-mailbox-injector",
|
|
|
|
|
() => createTeamMailboxInjector(ctx, teamModeConfig),
|
|
|
|
|
{ enabled: safeHookEnabled },
|
|
|
|
|
)
|
|
|
|
|
: null
|
|
|
|
|
|
2026-02-08 16:25:25 +09:00
|
|
|
const thinkingBlockValidator = isHookEnabled("thinking-block-validator")
|
|
|
|
|
? safeCreateHook(
|
|
|
|
|
"thinking-block-validator",
|
|
|
|
|
() => createThinkingBlockValidatorHook(),
|
|
|
|
|
{ enabled: safeHookEnabled },
|
|
|
|
|
)
|
|
|
|
|
: null
|
|
|
|
|
|
2026-04-02 13:31:48 +09:00
|
|
|
const toolPairValidator = isHookEnabled("tool-pair-validator")
|
|
|
|
|
? safeCreateHook(
|
|
|
|
|
"tool-pair-validator",
|
|
|
|
|
() => createToolPairValidatorHook(),
|
|
|
|
|
{ enabled: safeHookEnabled },
|
|
|
|
|
)
|
|
|
|
|
: null
|
|
|
|
|
|
2026-02-08 16:25:25 +09:00
|
|
|
return {
|
|
|
|
|
claudeCodeHooks,
|
|
|
|
|
keywordDetector,
|
|
|
|
|
contextInjectorMessagesTransform,
|
2026-04-28 10:48:45 +09:00
|
|
|
teamModeStatusInjector,
|
|
|
|
|
teamMailboxInjector,
|
2026-02-08 16:25:25 +09:00
|
|
|
thinkingBlockValidator,
|
2026-04-02 13:31:48 +09:00
|
|
|
toolPairValidator,
|
2026-02-08 16:25:25 +09:00
|
|
|
}
|
|
|
|
|
}
|