Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (47 loc) · 1.62 KB
/
Copy pathindex.js
File metadata and controls
52 lines (47 loc) · 1.62 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
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
const here = dirname(fileURLToPath(import.meta.url));
// Each file ships one skill; its name/description come from the frontmatter.
const SKILL_FILES = ['SKILL.md', 'world-agent.md'];
export const name = 'world-engine';
export const inject = ['skills'];
export function apply(ctx) {
for (const file of SKILL_FILES) {
const skill = parseSkill(readFileSync(join(here, file), 'utf8'));
ctx.skills.register({
name: skill.name,
description: skill.description,
content: skill.content,
source: 'runtime',
invocation: { modelInvocable: true, userInvocable: true },
});
}
}
/**
* Minimal frontmatter parser for this package's controlled SKILL files:
* a leading `---` block with single-line `name` and `description` keys.
*/
function parseSkill(raw) {
const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/u.exec(raw);
if (!match) {
throw new Error('world-engine: a skill file is missing its YAML frontmatter');
}
const meta = {};
for (const line of match[1].split(/\r?\n/)) {
const colon = line.indexOf(':');
if (colon > 0) {
const key = line.slice(0, colon).trim();
const value = line.slice(colon + 1).trim();
if (key) meta[key] = value;
}
}
if (typeof meta.name !== 'string' || typeof meta.description !== 'string') {
throw new Error('world-engine: skill frontmatter requires `name` and `description`');
}
return {
name: meta.name,
description: meta.description,
content: raw.slice(match[0].length).trim(),
};
}