@skillbase/compiler 0.2.5 → 0.2.7
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 +123 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -3
- package/dist/index.d.ts +51 -3
- package/dist/index.js +116 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -30,8 +30,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
SECTION_ORDER: () => SECTION_ORDER,
|
|
34
|
+
SECTION_TYPE_LABELS: () => SECTION_TYPE_LABELS,
|
|
33
35
|
SkillParseError: () => SkillParseError,
|
|
34
36
|
SoulParseError: () => SoulParseError,
|
|
37
|
+
autoFixSections: () => autoFixSections,
|
|
35
38
|
buildLegacyBody: () => buildLegacyBody,
|
|
36
39
|
canonicalToParsedSkill: () => canonicalToParsedSkill,
|
|
37
40
|
canonicalToParsedSoul: () => canonicalToParsedSoul,
|
|
@@ -42,6 +45,7 @@ __export(index_exports, {
|
|
|
42
45
|
getCompiler: () => getCompiler,
|
|
43
46
|
getImporter: () => getImporter,
|
|
44
47
|
importFromFormat: () => importFromFormat,
|
|
48
|
+
inferSectionType: () => inferSectionType,
|
|
45
49
|
inferTags: () => inferTags,
|
|
46
50
|
isVercelFormat: () => isVercelFormat,
|
|
47
51
|
legacyPersonaToSoul: () => legacyPersonaToSoul,
|
|
@@ -52,9 +56,12 @@ __export(index_exports, {
|
|
|
52
56
|
parseSoul: () => parseSoul,
|
|
53
57
|
parsedSkillToCanonical: () => parsedSkillToCanonical,
|
|
54
58
|
parsedSoulToCanonical: () => parsedSoulToCanonical,
|
|
59
|
+
reorderSections: () => reorderSections,
|
|
55
60
|
resolveContextSlots: () => resolveContextSlots,
|
|
56
61
|
serializeSkill: () => serializeSkill,
|
|
57
62
|
serializeSoul: () => serializeSoul,
|
|
63
|
+
validateCanonicalOrder: () => validateCanonicalOrder,
|
|
64
|
+
validateSectionOrder: () => validateSectionOrder,
|
|
58
65
|
validateSkillFrontmatter: () => validateSkillFrontmatter,
|
|
59
66
|
validateSoulFrontmatter: () => validateSoulFrontmatter
|
|
60
67
|
});
|
|
@@ -86,6 +93,91 @@ ${yamlStr}
|
|
|
86
93
|
${content}`;
|
|
87
94
|
}
|
|
88
95
|
|
|
96
|
+
// src/section-order.ts
|
|
97
|
+
var SECTION_ORDER = {
|
|
98
|
+
context: 0,
|
|
99
|
+
instructions: 1,
|
|
100
|
+
guidelines: 2,
|
|
101
|
+
verification: 3,
|
|
102
|
+
examples: 4,
|
|
103
|
+
custom: 5
|
|
104
|
+
};
|
|
105
|
+
var SECTION_TYPE_LABELS = {
|
|
106
|
+
context: "Context",
|
|
107
|
+
instructions: "Instructions",
|
|
108
|
+
guidelines: "Guidelines",
|
|
109
|
+
verification: "Verification",
|
|
110
|
+
examples: "Examples",
|
|
111
|
+
custom: "Custom"
|
|
112
|
+
};
|
|
113
|
+
var TYPE_PATTERNS = [
|
|
114
|
+
{
|
|
115
|
+
type: "context",
|
|
116
|
+
keywords: /\b(context|background|overview|about|introduction|who you are|role|persona)\b/i
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
type: "examples",
|
|
120
|
+
keywords: /\b(example|sample|demo|few.?shot|illustration|showcase)\b/i
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
type: "guidelines",
|
|
124
|
+
keywords: /\b(guideline|style|convention|best.?practice|approach|principle|standard|rule|format|tone)\b/i
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
type: "verification",
|
|
128
|
+
keywords: /\b(verif|check|valid|review|self.?check|quality|assert|ensure|confirm|output.?requirement)\b/i
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
type: "instructions",
|
|
132
|
+
keywords: /\b(instruct|task|step|procedure|workflow|process|how to|implement|action|do)\b/i
|
|
133
|
+
}
|
|
134
|
+
];
|
|
135
|
+
function inferSectionType(label) {
|
|
136
|
+
if (!label) return "instructions";
|
|
137
|
+
for (const { type, keywords } of TYPE_PATTERNS) {
|
|
138
|
+
if (keywords.test(label)) return type;
|
|
139
|
+
}
|
|
140
|
+
return "custom";
|
|
141
|
+
}
|
|
142
|
+
function validateSectionOrder(sections) {
|
|
143
|
+
if (sections.length <= 1) return [];
|
|
144
|
+
const reordered = reorderSections(sections);
|
|
145
|
+
const issues = [];
|
|
146
|
+
for (let i = 0; i < sections.length; i++) {
|
|
147
|
+
const current = sections[i];
|
|
148
|
+
const expectedIdx = reordered.indexOf(current);
|
|
149
|
+
if (expectedIdx !== i) {
|
|
150
|
+
const typeLabel = SECTION_TYPE_LABELS[current.type] ?? current.type;
|
|
151
|
+
issues.push({
|
|
152
|
+
index: i,
|
|
153
|
+
section: current,
|
|
154
|
+
expectedIndex: expectedIdx,
|
|
155
|
+
message: `"${current.label || typeLabel}" is at position ${i + 1}, expected ${expectedIdx + 1}`
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return issues;
|
|
160
|
+
}
|
|
161
|
+
function reorderSections(sections) {
|
|
162
|
+
return [...sections].sort((a, b) => {
|
|
163
|
+
const orderA = SECTION_ORDER[a.type] ?? SECTION_ORDER.custom;
|
|
164
|
+
const orderB = SECTION_ORDER[b.type] ?? SECTION_ORDER.custom;
|
|
165
|
+
return orderA - orderB;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
function autoFixSections(sections) {
|
|
169
|
+
const typed = sections.map((s) => {
|
|
170
|
+
if (s.type !== "custom") return s;
|
|
171
|
+
return { ...s, type: inferSectionType(s.label ?? "") };
|
|
172
|
+
});
|
|
173
|
+
return reorderSections(typed);
|
|
174
|
+
}
|
|
175
|
+
function validateCanonicalOrder(canonical) {
|
|
176
|
+
const sections = canonical.instructions.sections;
|
|
177
|
+
if (!sections || sections.length <= 1) return [];
|
|
178
|
+
return validateSectionOrder(sections);
|
|
179
|
+
}
|
|
180
|
+
|
|
89
181
|
// src/parse/skill-parser.ts
|
|
90
182
|
var REQUIRED_FIELDS = [
|
|
91
183
|
"schema_version",
|
|
@@ -159,16 +251,17 @@ function splitBodyIntoSections(body) {
|
|
|
159
251
|
return { sections };
|
|
160
252
|
}
|
|
161
253
|
function normalizeCanonical(canonical) {
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
254
|
+
const flat = denormalizeCanonical(canonical);
|
|
255
|
+
const fullContent = flat.instructions.content;
|
|
256
|
+
if (!fullContent) return canonical;
|
|
257
|
+
const { sections } = splitBodyIntoSections(fullContent);
|
|
165
258
|
if (sections.length === 0) return canonical;
|
|
166
259
|
return {
|
|
167
260
|
...canonical,
|
|
168
261
|
instructions: {
|
|
169
262
|
content: "",
|
|
170
263
|
sections: sections.map((s) => ({
|
|
171
|
-
type:
|
|
264
|
+
type: inferSectionType(s.label),
|
|
172
265
|
label: s.label,
|
|
173
266
|
content: s.content
|
|
174
267
|
}))
|
|
@@ -179,6 +272,9 @@ function denormalizeCanonical(canonical) {
|
|
|
179
272
|
const sections = canonical.instructions.sections ?? [];
|
|
180
273
|
if (sections.length === 0) return canonical;
|
|
181
274
|
const parts = [];
|
|
275
|
+
if (canonical.instructions.content) {
|
|
276
|
+
parts.push(canonical.instructions.content);
|
|
277
|
+
}
|
|
182
278
|
for (const s of sections) {
|
|
183
279
|
if (s.label) {
|
|
184
280
|
parts.push(`## ${s.label}
|
|
@@ -1279,7 +1375,21 @@ function buildFlatBody(canonical, options) {
|
|
|
1279
1375
|
parts.push(`Tone: ${canonical.identity.tone}`, "");
|
|
1280
1376
|
}
|
|
1281
1377
|
}
|
|
1282
|
-
|
|
1378
|
+
const sections = canonical.instructions.sections;
|
|
1379
|
+
if (sections && sections.length > 0) {
|
|
1380
|
+
const sorted = reorderSections(sections);
|
|
1381
|
+
for (const s of sorted) {
|
|
1382
|
+
if (s.label) {
|
|
1383
|
+
parts.push(`## ${s.label}
|
|
1384
|
+
|
|
1385
|
+
${s.content}`);
|
|
1386
|
+
} else if (s.content) {
|
|
1387
|
+
parts.push(s.content);
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
} else {
|
|
1391
|
+
parts.push(canonical.rawBody ?? canonical.instructions.content);
|
|
1392
|
+
}
|
|
1283
1393
|
if (canonical.constraints) {
|
|
1284
1394
|
if (canonical.constraints.always && canonical.constraints.always.length > 0) {
|
|
1285
1395
|
parts.push(
|
|
@@ -1319,7 +1429,7 @@ function buildBody(canonical) {
|
|
|
1319
1429
|
if (canonical.instructions.content) {
|
|
1320
1430
|
parts.push(canonical.instructions.content);
|
|
1321
1431
|
}
|
|
1322
|
-
const sections = canonical.instructions.sections ?? [];
|
|
1432
|
+
const sections = reorderSections(canonical.instructions.sections ?? []);
|
|
1323
1433
|
for (const s of sections) {
|
|
1324
1434
|
if (s.label || s.content) {
|
|
1325
1435
|
if (s.label) {
|
|
@@ -1779,8 +1889,11 @@ function getCompiler(target) {
|
|
|
1779
1889
|
}
|
|
1780
1890
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1781
1891
|
0 && (module.exports = {
|
|
1892
|
+
SECTION_ORDER,
|
|
1893
|
+
SECTION_TYPE_LABELS,
|
|
1782
1894
|
SkillParseError,
|
|
1783
1895
|
SoulParseError,
|
|
1896
|
+
autoFixSections,
|
|
1784
1897
|
buildLegacyBody,
|
|
1785
1898
|
canonicalToParsedSkill,
|
|
1786
1899
|
canonicalToParsedSoul,
|
|
@@ -1791,6 +1904,7 @@ function getCompiler(target) {
|
|
|
1791
1904
|
getCompiler,
|
|
1792
1905
|
getImporter,
|
|
1793
1906
|
importFromFormat,
|
|
1907
|
+
inferSectionType,
|
|
1794
1908
|
inferTags,
|
|
1795
1909
|
isVercelFormat,
|
|
1796
1910
|
legacyPersonaToSoul,
|
|
@@ -1801,9 +1915,12 @@ function getCompiler(target) {
|
|
|
1801
1915
|
parseSoul,
|
|
1802
1916
|
parsedSkillToCanonical,
|
|
1803
1917
|
parsedSoulToCanonical,
|
|
1918
|
+
reorderSections,
|
|
1804
1919
|
resolveContextSlots,
|
|
1805
1920
|
serializeSkill,
|
|
1806
1921
|
serializeSoul,
|
|
1922
|
+
validateCanonicalOrder,
|
|
1923
|
+
validateSectionOrder,
|
|
1807
1924
|
validateSkillFrontmatter,
|
|
1808
1925
|
validateSoulFrontmatter
|
|
1809
1926
|
});
|