mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-02 23:45:53 +00:00
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { Plugin, Skill } from "@opencode/plugin"
|
|
import { readFile } from "node:fs/promises"
|
|
import { fileURLToPath } from "node:url"
|
|
import matter from "gray-matter"
|
|
import source from "./skills-source.json" with { type: "json" }
|
|
|
|
export default Plugin.define({
|
|
id: "opencode.figma",
|
|
async setup(ctx) {
|
|
await ctx.mcp.transform((editor) => {
|
|
if (editor.get("figma")) return
|
|
editor.set("figma", {
|
|
type: "remote",
|
|
url: "https://mcp.figma.com/mcp",
|
|
})
|
|
})
|
|
|
|
const directory = new URL("./skills/", import.meta.url)
|
|
const skills = await Promise.all(
|
|
source.skills.map(async (name) => {
|
|
const file = new URL(`${name}/SKILL.md`, directory)
|
|
const markdown = matter(await readFile(file, "utf8"))
|
|
return Skill.Info.make({
|
|
id: Skill.ID.make(name),
|
|
name: Skill.Name.make(markdown.data.name),
|
|
description: markdown.data.description,
|
|
autoinvoke: markdown.data["disable-model-invocation"] !== true,
|
|
path: Skill.Info.fields.path.make(fileURLToPath(file)),
|
|
content: markdown.content,
|
|
})
|
|
}),
|
|
)
|
|
await ctx.skill.transform((editor) => {
|
|
skills.forEach((skill) => {
|
|
if (!editor.get(skill.id)) editor.add(skill)
|
|
})
|
|
})
|
|
},
|
|
})
|