Files
oh-my-opencode/src/features/opencode-skill-loader/skill-content.ts
T

63 lines
1.9 KiB
TypeScript
Raw Normal View History

2026-01-09 02:24:43 +09:00
import { createBuiltinSkills } from "../builtin-skills/skills"
import type { GitMasterConfig } from "../../config/schema"
2026-01-09 02:24:43 +09:00
export interface SkillResolutionOptions {
gitMasterConfig?: GitMasterConfig
}
function injectGitMasterConfig(template: string, config?: GitMasterConfig): string {
if (!config) return template
const commitFooter = config.commit_footer ?? true
const includeCoAuthoredBy = config.include_co_authored_by ?? true
const configHeader = `## Git Master Configuration (from oh-my-opencode.json)
**IMPORTANT: These values override the defaults in section 5.5:**
- \`commit_footer\`: ${commitFooter} ${!commitFooter ? "(DISABLED - do NOT add footer)" : ""}
- \`include_co_authored_by\`: ${includeCoAuthoredBy} ${!includeCoAuthoredBy ? "(DISABLED - do NOT add Co-authored-by)" : ""}
---
`
return configHeader + template
}
export function resolveSkillContent(skillName: string, options?: SkillResolutionOptions): string | null {
2026-01-09 02:24:43 +09:00
const skills = createBuiltinSkills()
const skill = skills.find((s) => s.name === skillName)
if (!skill) return null
if (skillName === "git-master" && options?.gitMasterConfig) {
return injectGitMasterConfig(skill.template, options.gitMasterConfig)
}
return skill.template
2026-01-09 02:24:43 +09:00
}
export function resolveMultipleSkills(skillNames: string[], options?: SkillResolutionOptions): {
2026-01-09 02:24:43 +09:00
resolved: Map<string, string>
notFound: string[]
} {
const skills = createBuiltinSkills()
const skillMap = new Map(skills.map((s) => [s.name, s.template]))
const resolved = new Map<string, string>()
const notFound: string[] = []
for (const name of skillNames) {
const template = skillMap.get(name)
if (template) {
if (name === "git-master" && options?.gitMasterConfig) {
resolved.set(name, injectGitMasterConfig(template, options.gitMasterConfig))
} else {
resolved.set(name, template)
}
2026-01-09 02:24:43 +09:00
} else {
notFound.push(name)
}
}
return { resolved, notFound }
}