@skillbase/compiler 0.2.3 → 0.2.5
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 +39 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +38 -27
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -37,6 +37,7 @@ __export(index_exports, {
|
|
|
37
37
|
canonicalToParsedSoul: () => canonicalToParsedSoul,
|
|
38
38
|
compile: () => compile,
|
|
39
39
|
convertVercelToSpm: () => convertVercelToSpm,
|
|
40
|
+
denormalizeCanonical: () => denormalizeCanonical,
|
|
40
41
|
detectFormat: () => detectFormat,
|
|
41
42
|
getCompiler: () => getCompiler,
|
|
42
43
|
getImporter: () => getImporter,
|
|
@@ -135,17 +136,15 @@ function serializeSkill(skill) {
|
|
|
135
136
|
}
|
|
136
137
|
function splitBodyIntoSections(body) {
|
|
137
138
|
const lines = body.split("\n");
|
|
138
|
-
let preamble = "";
|
|
139
139
|
const sections = [];
|
|
140
140
|
let currentLabel = null;
|
|
141
141
|
let currentLines = [];
|
|
142
142
|
for (const line of lines) {
|
|
143
143
|
const h2Match = line.match(/^## (.+)$/);
|
|
144
144
|
if (h2Match) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
preamble = currentLines.join("\n").trim();
|
|
145
|
+
const text2 = currentLines.join("\n").trim();
|
|
146
|
+
if (currentLabel !== null || text2) {
|
|
147
|
+
sections.push({ label: currentLabel ?? "", content: text2 });
|
|
149
148
|
}
|
|
150
149
|
currentLabel = h2Match[1].trim();
|
|
151
150
|
currentLines = [];
|
|
@@ -153,24 +152,22 @@ function splitBodyIntoSections(body) {
|
|
|
153
152
|
currentLines.push(line);
|
|
154
153
|
}
|
|
155
154
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
preamble = currentLines.join("\n").trim();
|
|
155
|
+
const text = currentLines.join("\n").trim();
|
|
156
|
+
if (currentLabel !== null || text) {
|
|
157
|
+
sections.push({ label: currentLabel ?? "", content: text });
|
|
160
158
|
}
|
|
161
|
-
return {
|
|
159
|
+
return { sections };
|
|
162
160
|
}
|
|
163
161
|
function normalizeCanonical(canonical) {
|
|
164
|
-
const { content
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if (parsed.length === 0) return canonical;
|
|
162
|
+
const { content } = canonical.instructions;
|
|
163
|
+
if (!content) return canonical;
|
|
164
|
+
const { sections } = splitBodyIntoSections(content);
|
|
165
|
+
if (sections.length === 0) return canonical;
|
|
169
166
|
return {
|
|
170
167
|
...canonical,
|
|
171
168
|
instructions: {
|
|
172
|
-
content:
|
|
173
|
-
sections:
|
|
169
|
+
content: "",
|
|
170
|
+
sections: sections.map((s) => ({
|
|
174
171
|
type: "custom",
|
|
175
172
|
label: s.label,
|
|
176
173
|
content: s.content
|
|
@@ -178,9 +175,26 @@ function normalizeCanonical(canonical) {
|
|
|
178
175
|
}
|
|
179
176
|
};
|
|
180
177
|
}
|
|
178
|
+
function denormalizeCanonical(canonical) {
|
|
179
|
+
const sections = canonical.instructions.sections ?? [];
|
|
180
|
+
if (sections.length === 0) return canonical;
|
|
181
|
+
const parts = [];
|
|
182
|
+
for (const s of sections) {
|
|
183
|
+
if (s.label) {
|
|
184
|
+
parts.push(`## ${s.label}
|
|
185
|
+
|
|
186
|
+
${s.content}`);
|
|
187
|
+
} else if (s.content) {
|
|
188
|
+
parts.push(s.content);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
...canonical,
|
|
193
|
+
instructions: { content: parts.join("\n\n") }
|
|
194
|
+
};
|
|
195
|
+
}
|
|
181
196
|
function parsedSkillToCanonical(skill) {
|
|
182
197
|
const fm = skill.frontmatter;
|
|
183
|
-
const { preamble, sections } = splitBodyIntoSections(skill.body);
|
|
184
198
|
const canonical = {
|
|
185
199
|
meta: {
|
|
186
200
|
name: fm.name,
|
|
@@ -194,14 +208,7 @@ function parsedSkillToCanonical(skill) {
|
|
|
194
208
|
confidence: 1
|
|
195
209
|
},
|
|
196
210
|
instructions: {
|
|
197
|
-
content:
|
|
198
|
-
...sections.length > 0 && {
|
|
199
|
-
sections: sections.map((s) => ({
|
|
200
|
-
type: "custom",
|
|
201
|
-
label: s.label,
|
|
202
|
-
content: s.content
|
|
203
|
-
}))
|
|
204
|
-
}
|
|
211
|
+
content: skill.body
|
|
205
212
|
},
|
|
206
213
|
rawBody: skill.body,
|
|
207
214
|
sourceFormat: "skill-md"
|
|
@@ -1315,9 +1322,13 @@ function buildBody(canonical) {
|
|
|
1315
1322
|
const sections = canonical.instructions.sections ?? [];
|
|
1316
1323
|
for (const s of sections) {
|
|
1317
1324
|
if (s.label || s.content) {
|
|
1318
|
-
|
|
1325
|
+
if (s.label) {
|
|
1326
|
+
parts.push(`## ${s.label}
|
|
1319
1327
|
|
|
1320
1328
|
${s.content}`);
|
|
1329
|
+
} else {
|
|
1330
|
+
parts.push(s.content);
|
|
1331
|
+
}
|
|
1321
1332
|
}
|
|
1322
1333
|
}
|
|
1323
1334
|
if (canonical.constraints) {
|
|
@@ -1775,6 +1786,7 @@ function getCompiler(target) {
|
|
|
1775
1786
|
canonicalToParsedSoul,
|
|
1776
1787
|
compile,
|
|
1777
1788
|
convertVercelToSpm,
|
|
1789
|
+
denormalizeCanonical,
|
|
1778
1790
|
detectFormat,
|
|
1779
1791
|
getCompiler,
|
|
1780
1792
|
getImporter,
|