fix: strip frontmatter from injected skill content and share parser from src

This commit is contained in:
haylan committed 2026-10-14 12:34:56 +02:00
1 parent 023e012eda
commit d301ef5a62
7 files changed
+108 -43

No files matched your search

+8 -2
View File
@@ -2,6 +2,7 @@ import { existsSync, readFileSync } from "node:fs"
import path from "node:path"
import { Plugin, Skill } from "@opencode/plugin"
import { blockedPattern, guardrailError, isShellTool, resolveOptions } from "./guardrails.ts"
import { parseFrontmatter } from "./frontmatter.ts"
import { loadManifest, packageRoot, packageVersion, skillFile } from "./manifest.ts"
const AGENT_IDS = ["pocock", "pocock-worker", "pocock-reviewer"] as const
@@ -22,6 +23,9 @@ export default Plugin.define({
await ctx.skill.transform((editor) => {
for (const entry of entries) {
const file = skillFile(entry)
// File-based skill loading strips frontmatter from content (core skill.ts uses
// markdown.content); match that so injected skills read identically.
const content = parseFrontmatter(readFileSync(file, "utf8")).body.trim()
// Brand types (Skill.ID/Name/AbsolutePath) are nominal-only; runtime values are plain
// strings, asserted by test/plugin.test.ts and the serve-based smoke run.
editor.add({
@@ -30,7 +34,7 @@ export default Plugin.define({
description: entry.description,
autoinvoke: entry.autoinvoke,
path: file,
content: readFileSync(file, "utf8"),
content,
} as unknown as Skill.Info)
}
})
@@ -56,7 +60,9 @@ export default Plugin.define({
const want = packageVersion()
const initCmd = "npx @haylan/opencode-pocock init"
if (!AGENT_IDS.some((id) => ids.has(id))) {
console.warn(`pocock: skills loaded, but the pocock agents are not installed — run: ${initCmd}`)
console.warn(
`pocock: skills loaded, but the pocock agents are not installed — run: ${initCmd}`,
)
} else if (have !== want) {
console.warn(
`pocock: installed agents are ${have ? `from v${have}` : "unversioned"}, package is v${want} — refresh: ${initCmd}`,