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,79 @@
|
||||
import type { OhMyOpenCodeConfig } from "./config"
|
||||
import type { ModelCacheState } from "./plugin-state"
|
||||
import type { PluginContext, TmuxConfig } from "./plugin/types"
|
||||
|
||||
import type { SubagentSessionCreatedEvent } from "./features/background-agent"
|
||||
import { BackgroundManager } from "./features/background-agent"
|
||||
import { SkillMcpManager } from "./features/skill-mcp-manager"
|
||||
import { initTaskToastManager } from "./features/task-toast-manager"
|
||||
import { TmuxSessionManager } from "./features/tmux-subagent"
|
||||
import { createConfigHandler } from "./plugin-handlers"
|
||||
import { log } from "./shared"
|
||||
|
||||
export type Managers = {
|
||||
tmuxSessionManager: TmuxSessionManager
|
||||
backgroundManager: BackgroundManager
|
||||
skillMcpManager: SkillMcpManager
|
||||
configHandler: ReturnType<typeof createConfigHandler>
|
||||
}
|
||||
|
||||
export function createManagers(args: {
|
||||
ctx: PluginContext
|
||||
pluginConfig: OhMyOpenCodeConfig
|
||||
tmuxConfig: TmuxConfig
|
||||
modelCacheState: ModelCacheState
|
||||
}): Managers {
|
||||
const { ctx, pluginConfig, tmuxConfig, modelCacheState } = args
|
||||
|
||||
const tmuxSessionManager = new TmuxSessionManager(ctx, tmuxConfig)
|
||||
|
||||
const backgroundManager = new BackgroundManager(
|
||||
ctx,
|
||||
pluginConfig.background_task,
|
||||
{
|
||||
tmuxConfig,
|
||||
onSubagentSessionCreated: async (event: SubagentSessionCreatedEvent) => {
|
||||
log("[index] onSubagentSessionCreated callback received", {
|
||||
sessionID: event.sessionID,
|
||||
parentID: event.parentID,
|
||||
title: event.title,
|
||||
})
|
||||
|
||||
await tmuxSessionManager.onSessionCreated({
|
||||
type: "session.created",
|
||||
properties: {
|
||||
info: {
|
||||
id: event.sessionID,
|
||||
parentID: event.parentID,
|
||||
title: event.title,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
log("[index] onSubagentSessionCreated callback completed")
|
||||
},
|
||||
onShutdown: () => {
|
||||
tmuxSessionManager.cleanup().catch((error) => {
|
||||
log("[index] tmux cleanup error during shutdown:", error)
|
||||
})
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
initTaskToastManager(ctx.client)
|
||||
|
||||
const skillMcpManager = new SkillMcpManager()
|
||||
|
||||
const configHandler = createConfigHandler({
|
||||
ctx: { directory: ctx.directory, client: ctx.client },
|
||||
pluginConfig,
|
||||
modelCacheState,
|
||||
})
|
||||
|
||||
return {
|
||||
tmuxSessionManager,
|
||||
backgroundManager,
|
||||
skillMcpManager,
|
||||
configHandler,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user