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,87 @@
|
||||
import type { AvailableSkill } from "../agents/dynamic-agent-prompt-builder"
|
||||
import type { OhMyOpenCodeConfig } from "../config"
|
||||
import type { BrowserAutomationProvider } from "../config/schema/browser-automation"
|
||||
import type {
|
||||
LoadedSkill,
|
||||
SkillScope,
|
||||
} from "../features/opencode-skill-loader/types"
|
||||
|
||||
import {
|
||||
discoverUserClaudeSkills,
|
||||
discoverProjectClaudeSkills,
|
||||
discoverOpencodeGlobalSkills,
|
||||
discoverOpencodeProjectSkills,
|
||||
mergeSkills,
|
||||
} from "../features/opencode-skill-loader"
|
||||
import { createBuiltinSkills } from "../features/builtin-skills"
|
||||
import { getSystemMcpServerNames } from "../features/claude-code-mcp-loader"
|
||||
|
||||
export type SkillContext = {
|
||||
mergedSkills: LoadedSkill[]
|
||||
availableSkills: AvailableSkill[]
|
||||
browserProvider: BrowserAutomationProvider
|
||||
disabledSkills: Set<string>
|
||||
}
|
||||
|
||||
function mapScopeToLocation(scope: SkillScope): AvailableSkill["location"] {
|
||||
if (scope === "user" || scope === "opencode") return "user"
|
||||
if (scope === "project" || scope === "opencode-project") return "project"
|
||||
return "plugin"
|
||||
}
|
||||
|
||||
export async function createSkillContext(args: {
|
||||
directory: string
|
||||
pluginConfig: OhMyOpenCodeConfig
|
||||
}): Promise<SkillContext> {
|
||||
const { directory, pluginConfig } = args
|
||||
|
||||
const browserProvider: BrowserAutomationProvider =
|
||||
pluginConfig.browser_automation_engine?.provider ?? "playwright"
|
||||
|
||||
const disabledSkills = new Set<string>(pluginConfig.disabled_skills ?? [])
|
||||
const systemMcpNames = getSystemMcpServerNames()
|
||||
|
||||
const builtinSkills = createBuiltinSkills({
|
||||
browserProvider,
|
||||
disabledSkills,
|
||||
}).filter((skill) => {
|
||||
if (skill.mcpConfig) {
|
||||
for (const mcpName of Object.keys(skill.mcpConfig)) {
|
||||
if (systemMcpNames.has(mcpName)) return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
const includeClaudeSkills = pluginConfig.claude_code?.skills !== false
|
||||
const [userSkills, globalSkills, projectSkills, opencodeProjectSkills] =
|
||||
await Promise.all([
|
||||
includeClaudeSkills ? discoverUserClaudeSkills() : Promise.resolve([]),
|
||||
discoverOpencodeGlobalSkills(),
|
||||
includeClaudeSkills ? discoverProjectClaudeSkills() : Promise.resolve([]),
|
||||
discoverOpencodeProjectSkills(),
|
||||
])
|
||||
|
||||
const mergedSkills = mergeSkills(
|
||||
builtinSkills,
|
||||
pluginConfig.skills,
|
||||
userSkills,
|
||||
globalSkills,
|
||||
projectSkills,
|
||||
opencodeProjectSkills,
|
||||
{ configDir: directory },
|
||||
)
|
||||
|
||||
const availableSkills: AvailableSkill[] = mergedSkills.map((skill) => ({
|
||||
name: skill.name,
|
||||
description: skill.definition.description ?? "",
|
||||
location: mapScopeToLocation(skill.scope),
|
||||
}))
|
||||
|
||||
return {
|
||||
mergedSkills,
|
||||
availableSkills,
|
||||
browserProvider,
|
||||
disabledSkills,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user