@skillbase/compiler 0.2.2 → 0.2.4
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/dist/index.cjs +60 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +60 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -135,17 +135,15 @@ function serializeSkill(skill) {
|
|
|
135
135
|
}
|
|
136
136
|
function splitBodyIntoSections(body) {
|
|
137
137
|
const lines = body.split("\n");
|
|
138
|
-
let preamble = "";
|
|
139
138
|
const sections = [];
|
|
140
139
|
let currentLabel = null;
|
|
141
140
|
let currentLines = [];
|
|
142
141
|
for (const line of lines) {
|
|
143
142
|
const h2Match = line.match(/^## (.+)$/);
|
|
144
143
|
if (h2Match) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
preamble = currentLines.join("\n").trim();
|
|
144
|
+
const text2 = currentLines.join("\n").trim();
|
|
145
|
+
if (currentLabel !== null || text2) {
|
|
146
|
+
sections.push({ label: currentLabel ?? "", content: text2 });
|
|
149
147
|
}
|
|
150
148
|
currentLabel = h2Match[1].trim();
|
|
151
149
|
currentLines = [];
|
|
@@ -153,23 +151,22 @@ function splitBodyIntoSections(body) {
|
|
|
153
151
|
currentLines.push(line);
|
|
154
152
|
}
|
|
155
153
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
preamble = currentLines.join("\n").trim();
|
|
154
|
+
const text = currentLines.join("\n").trim();
|
|
155
|
+
if (currentLabel !== null || text) {
|
|
156
|
+
sections.push({ label: currentLabel ?? "", content: text });
|
|
160
157
|
}
|
|
161
|
-
return {
|
|
158
|
+
return { sections };
|
|
162
159
|
}
|
|
163
160
|
function normalizeCanonical(canonical) {
|
|
164
161
|
const { content, sections } = canonical.instructions;
|
|
165
162
|
if (sections && sections.length > 0) return canonical;
|
|
166
|
-
if (!content
|
|
167
|
-
const {
|
|
163
|
+
if (!content) return canonical;
|
|
164
|
+
const { sections: parsed } = splitBodyIntoSections(content);
|
|
168
165
|
if (parsed.length === 0) return canonical;
|
|
169
166
|
return {
|
|
170
167
|
...canonical,
|
|
171
168
|
instructions: {
|
|
172
|
-
content:
|
|
169
|
+
content: "",
|
|
173
170
|
sections: parsed.map((s) => ({
|
|
174
171
|
type: "custom",
|
|
175
172
|
label: s.label,
|
|
@@ -180,7 +177,7 @@ function normalizeCanonical(canonical) {
|
|
|
180
177
|
}
|
|
181
178
|
function parsedSkillToCanonical(skill) {
|
|
182
179
|
const fm = skill.frontmatter;
|
|
183
|
-
const {
|
|
180
|
+
const { sections } = splitBodyIntoSections(skill.body);
|
|
184
181
|
const canonical = {
|
|
185
182
|
meta: {
|
|
186
183
|
name: fm.name,
|
|
@@ -194,14 +191,12 @@ function parsedSkillToCanonical(skill) {
|
|
|
194
191
|
confidence: 1
|
|
195
192
|
},
|
|
196
193
|
instructions: {
|
|
197
|
-
content:
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}))
|
|
204
|
-
}
|
|
194
|
+
content: "",
|
|
195
|
+
sections: sections.map((s) => ({
|
|
196
|
+
type: "custom",
|
|
197
|
+
label: s.label,
|
|
198
|
+
content: s.content
|
|
199
|
+
}))
|
|
205
200
|
},
|
|
206
201
|
rawBody: skill.body,
|
|
207
202
|
sourceFormat: "skill-md"
|
|
@@ -1299,6 +1294,48 @@ function buildFlatBody(canonical, options) {
|
|
|
1299
1294
|
}
|
|
1300
1295
|
|
|
1301
1296
|
// src/compile/skill-md.ts
|
|
1297
|
+
function buildBody(canonical) {
|
|
1298
|
+
const parts = [];
|
|
1299
|
+
if (canonical.identity) {
|
|
1300
|
+
const id = canonical.identity;
|
|
1301
|
+
const lines = [];
|
|
1302
|
+
if (id.role) lines.push(id.role);
|
|
1303
|
+
if (id.expertise?.length) lines.push(`**Expertise:** ${id.expertise.join(", ")}`);
|
|
1304
|
+
if (id.tone) lines.push(`**Tone:** ${id.tone}`);
|
|
1305
|
+
if (lines.length) parts.push(lines.join("\n"));
|
|
1306
|
+
}
|
|
1307
|
+
if (canonical.instructions.content) {
|
|
1308
|
+
parts.push(canonical.instructions.content);
|
|
1309
|
+
}
|
|
1310
|
+
const sections = canonical.instructions.sections ?? [];
|
|
1311
|
+
for (const s of sections) {
|
|
1312
|
+
if (s.label || s.content) {
|
|
1313
|
+
if (s.label) {
|
|
1314
|
+
parts.push(`## ${s.label}
|
|
1315
|
+
|
|
1316
|
+
${s.content}`);
|
|
1317
|
+
} else {
|
|
1318
|
+
parts.push(s.content);
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
if (canonical.constraints) {
|
|
1323
|
+
const lines = [];
|
|
1324
|
+
if (canonical.constraints.always?.length) {
|
|
1325
|
+
lines.push("**Always:**");
|
|
1326
|
+
for (const r of canonical.constraints.always) lines.push(`- ${r}`);
|
|
1327
|
+
}
|
|
1328
|
+
if (canonical.constraints.never?.length) {
|
|
1329
|
+
if (lines.length) lines.push("");
|
|
1330
|
+
lines.push("**Never:**");
|
|
1331
|
+
for (const r of canonical.constraints.never) lines.push(`- ${r}`);
|
|
1332
|
+
}
|
|
1333
|
+
if (lines.length) parts.push(`## Constraints
|
|
1334
|
+
|
|
1335
|
+
${lines.join("\n")}`);
|
|
1336
|
+
}
|
|
1337
|
+
return parts.join("\n\n");
|
|
1338
|
+
}
|
|
1302
1339
|
var skillMdCompiler = {
|
|
1303
1340
|
id: "skill-md",
|
|
1304
1341
|
name: "SKILL.md (Skillbase)",
|
|
@@ -1370,7 +1407,7 @@ var skillMdCompiler = {
|
|
|
1370
1407
|
priority_pages: canonical.knowledge.priorityPages
|
|
1371
1408
|
};
|
|
1372
1409
|
}
|
|
1373
|
-
let body = canonical
|
|
1410
|
+
let body = buildBody(canonical);
|
|
1374
1411
|
const knowledgeSection = buildKnowledgeSection(canonical, options);
|
|
1375
1412
|
if (knowledgeSection) {
|
|
1376
1413
|
body = body + "\n\n" + knowledgeSection;
|