Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
56 lines (52 loc) · 2.2 KB
/
Copy pathindex.js
File metadata and controls
56 lines (52 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// dsh-plugin-guide bundle entry point.
//
// Registers the packaged guide as one on-demand agent skill. The skill body is
// SKILL.md; its relative references (./docs/...) resolve against the package
// directory through the directory resourceBase. The guide does not import the
// harness: it only consumes the `skills` service at apply time, so the peer
// dependency on `@deepseek-ai/dsh` is metadata-only (optional).
import { readFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
export const name = 'dsh-plugin-guide'
export const inject = ['skills']
const packageRoot = dirname(fileURLToPath(import.meta.url))
/**
* Strip the YAML frontmatter block from SKILL.md and return the description
* plus the instruction body. A malformed or missing block falls back to the
* full text as the body.
*
* @param text - raw SKILL.md content.
* @returns parsed description (when the frontmatter carries one) and body.
*/
export function splitFrontmatter(text) {
const open = /^---\r?\n/.exec(text)
if (!open) return { description: undefined, body: text }
const rest = text.slice(open[0].length)
const close = /\r?\n---[ \t]*(?:\r?\n|$)/.exec(rest)
if (!close) return { description: undefined, body: text }
const meta = rest.slice(0, close.index)
const body = rest.slice(close.index + close[0].length).replace(/^(?:[ \t]*\r?\n)+/, '')
const match = /^description:[ \t]*(.+?)[ \t]*$/m.exec(meta)
return { description: match?.[1]?.trim(), body }
}
/**
* Register the guide skill. Registration is an effect: the disposer returned
* by `ctx.skills.register()` removes the contribution on unload.
* @param ctx - Cordis context with the injected `skills` service.
*/
export function apply(ctx) {
const skillPath = join(packageRoot, 'SKILL.md')
const { description, body } = splitFrontmatter(readFileSync(skillPath, 'utf8'))
ctx.effect(() =>
ctx.skills.register({
name: 'dsh-plugin-guide',
source: 'bundled',
description:
description
?? 'DSH plugin quality guide: ENTRY, FLOW, and BOOST layers, with check routing and evidence rules.',
content: body,
resourceBase: { kind: 'directory', path: packageRoot },
}),
)
}