@h-rig/skill-loader 0.0.6-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/src/index.js +53 -0
- package/package.json +25 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @h-rig/skill-loader
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/skill-loader/src/index.ts
|
|
3
|
+
import { readFileSync } from "fs";
|
|
4
|
+
var FRONTMATTER_RE = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/;
|
|
5
|
+
function parseFrontmatter(raw) {
|
|
6
|
+
const m = raw.match(FRONTMATTER_RE);
|
|
7
|
+
if (!m) {
|
|
8
|
+
return { meta: {}, body: raw };
|
|
9
|
+
}
|
|
10
|
+
const yaml = m[1] ?? "";
|
|
11
|
+
const body = m[2] ?? "";
|
|
12
|
+
const meta = {};
|
|
13
|
+
for (const line of yaml.split(/\r?\n/)) {
|
|
14
|
+
const trimmed = line.trim();
|
|
15
|
+
if (!trimmed || trimmed.startsWith("#"))
|
|
16
|
+
continue;
|
|
17
|
+
const idx = trimmed.indexOf(":");
|
|
18
|
+
if (idx === -1)
|
|
19
|
+
continue;
|
|
20
|
+
const key = trimmed.slice(0, idx).trim();
|
|
21
|
+
let value = trimmed.slice(idx + 1).trim();
|
|
22
|
+
if (typeof value === "string") {
|
|
23
|
+
const s = value;
|
|
24
|
+
if (s.startsWith('"') && s.endsWith('"') || s.startsWith("'") && s.endsWith("'")) {
|
|
25
|
+
value = s.slice(1, -1);
|
|
26
|
+
} else if (s === "true")
|
|
27
|
+
value = true;
|
|
28
|
+
else if (s === "false")
|
|
29
|
+
value = false;
|
|
30
|
+
else if (/^-?\d+$/.test(s))
|
|
31
|
+
value = parseInt(s, 10);
|
|
32
|
+
else if (/^-?\d+\.\d+$/.test(s))
|
|
33
|
+
value = parseFloat(s);
|
|
34
|
+
}
|
|
35
|
+
meta[key] = value;
|
|
36
|
+
}
|
|
37
|
+
return { meta, body };
|
|
38
|
+
}
|
|
39
|
+
async function loadSkill(path) {
|
|
40
|
+
const raw = readFileSync(path, "utf-8");
|
|
41
|
+
const { meta, body } = parseFrontmatter(raw);
|
|
42
|
+
if (typeof meta.name !== "string") {
|
|
43
|
+
throw new Error(`SKILL.md missing required field "name": ${path}`);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
...meta,
|
|
47
|
+
body: body.trimStart(),
|
|
48
|
+
path
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
loadSkill
|
|
53
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@h-rig/skill-loader",
|
|
3
|
+
"version": "0.0.6-alpha.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Rig package",
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/src/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"bun": ">=1.3.11"
|
|
18
|
+
},
|
|
19
|
+
"main": "./dist/src/index.js",
|
|
20
|
+
"module": "./dist/src/index.js",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.0",
|
|
23
|
+
"effect": "4.0.0-beta.78"
|
|
24
|
+
}
|
|
25
|
+
}
|