agent-skills-ts-sdk 2.0.6
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/LICENSE +21 -0
- package/README.md +216 -0
- package/dist/index.d.ts +1208 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7840 -0
- package/dist/index.js.map +1 -0
- package/package.json +56 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1208 @@
|
|
|
1
|
+
//#region src/models.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Data models for Agent Skills
|
|
4
|
+
*
|
|
5
|
+
* Reference: https://agentskills.io/specification
|
|
6
|
+
* Reference Implementation: https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/models.py
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Stable identifier for a stored skill record.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const id: SkillId = "skill_123"
|
|
14
|
+
* ```
|
|
15
|
+
* @see https://agentskills.io/specification
|
|
16
|
+
*/
|
|
17
|
+
type SkillId = string;
|
|
18
|
+
/**
|
|
19
|
+
* Raw `SKILL.md` file content.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const content: SkillContent = "---\nname: demo\ndescription: Demo\n---\n# Body"
|
|
24
|
+
* ```
|
|
25
|
+
* @see https://agentskills.io/specification
|
|
26
|
+
*/
|
|
27
|
+
type SkillContent = string;
|
|
28
|
+
/**
|
|
29
|
+
* Markdown body content after frontmatter is removed.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const body: SkillBody = "# Instructions"
|
|
34
|
+
* ```
|
|
35
|
+
* @see https://agentskills.io/specification
|
|
36
|
+
*/
|
|
37
|
+
type SkillBody = string;
|
|
38
|
+
/**
|
|
39
|
+
* A single tier-3 resource associated with a skill.
|
|
40
|
+
*
|
|
41
|
+
* Resources are loaded on demand by the host and can originate from
|
|
42
|
+
* `scripts/`, `references/`, or `assets/`.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const resource: SkillResource = {
|
|
47
|
+
* name: "build-pizza",
|
|
48
|
+
* path: "references/build-pizza",
|
|
49
|
+
* content: "# Build Pizza\n..."
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
* @see https://agentskills.io/specification
|
|
53
|
+
*/
|
|
54
|
+
interface SkillResource {
|
|
55
|
+
/** Resource identifier used by read handlers/tool calls. */
|
|
56
|
+
name: string;
|
|
57
|
+
/** Relative resource path from skill root. */
|
|
58
|
+
path: string;
|
|
59
|
+
/** Raw resource file contents. */
|
|
60
|
+
content: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Fully resolved in-memory skill used for progressive disclosure reads.
|
|
64
|
+
*
|
|
65
|
+
* This model intentionally includes only pure data so it can be shared across
|
|
66
|
+
* browser, server, and CLI hosts without coupling to storage or transport.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const skill: ResolvedSkill = {
|
|
71
|
+
* name: "pizza-maker",
|
|
72
|
+
* description: "Interactive pizza builder",
|
|
73
|
+
* body: "Use [build-pizza](references/build-pizza)",
|
|
74
|
+
* resources: [{ name: "build-pizza", path: "references/build-pizza", content: "..." }]
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
* @see https://agentskills.io/specification
|
|
78
|
+
*/
|
|
79
|
+
interface ResolvedSkill {
|
|
80
|
+
/** Skill identifier from frontmatter. */
|
|
81
|
+
name: SkillFrontmatter['name'];
|
|
82
|
+
/** Skill description from frontmatter. */
|
|
83
|
+
description: SkillFrontmatter['description'];
|
|
84
|
+
/** Tier-2 instruction body from SKILL.md. */
|
|
85
|
+
body: SkillBody;
|
|
86
|
+
/** Tier-3 resources associated with this skill. */
|
|
87
|
+
resources: SkillResource[];
|
|
88
|
+
/** Optional host location label (path/URL/etc). */
|
|
89
|
+
location?: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* String key-value metadata map from frontmatter.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* const metadata: SkillMetadataMap = { author: "example-org", version: "1.0" }
|
|
97
|
+
* ```
|
|
98
|
+
* @see https://agentskills.io/specification
|
|
99
|
+
*/
|
|
100
|
+
type SkillMetadataMap = Record<string, string>;
|
|
101
|
+
/**
|
|
102
|
+
* Space-delimited tool allowlist string (`allowed-tools` in frontmatter).
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* const allowed: SkillAllowedTools = "Bash(git:*) Read"
|
|
107
|
+
* ```
|
|
108
|
+
* @see https://agentskills.io/specification
|
|
109
|
+
*/
|
|
110
|
+
type SkillAllowedTools = string;
|
|
111
|
+
/**
|
|
112
|
+
* Token count estimate used for progressive disclosure.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* const tokens: SkillTokenCount = 120
|
|
117
|
+
* ```
|
|
118
|
+
* @see https://agentskills.io/specification
|
|
119
|
+
*/
|
|
120
|
+
type SkillTokenCount = number;
|
|
121
|
+
/**
|
|
122
|
+
* Unix timestamp in milliseconds.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* const updatedAt: UnixMillis = Date.now()
|
|
127
|
+
* ```
|
|
128
|
+
* @see https://agentskills.io/specification
|
|
129
|
+
*/
|
|
130
|
+
type UnixMillis = number;
|
|
131
|
+
/**
|
|
132
|
+
* Byte count for persisted skill content.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* const size: ByteCount = 2048
|
|
137
|
+
* ```
|
|
138
|
+
* @see https://agentskills.io/specification
|
|
139
|
+
*/
|
|
140
|
+
type ByteCount = number;
|
|
141
|
+
/**
|
|
142
|
+
* Minimal in-memory representation of a file entry.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* const entry: SkillContentEntry = { name: "SKILL.md", content: "---\n...\n---" }
|
|
147
|
+
* ```
|
|
148
|
+
* @see https://agentskills.io/specification
|
|
149
|
+
*/
|
|
150
|
+
interface SkillContentEntry {
|
|
151
|
+
/** File name (for example `SKILL.md`). */
|
|
152
|
+
name: string;
|
|
153
|
+
/** File contents. */
|
|
154
|
+
content: SkillContent;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Canonical frontmatter keys accepted by the spec.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* for (const key of SKILL_FRONTMATTER_KEYS) {
|
|
162
|
+
* console.log(key)
|
|
163
|
+
* }
|
|
164
|
+
* ```
|
|
165
|
+
* @see https://agentskills.io/specification
|
|
166
|
+
*/
|
|
167
|
+
declare const SKILL_FRONTMATTER_KEYS: readonly ["name", "description", "license", "compatibility", "allowed-tools", "metadata"];
|
|
168
|
+
/**
|
|
169
|
+
* Union of allowed frontmatter keys.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* const key: SkillFrontmatterKey = "allowed-tools"
|
|
174
|
+
* ```
|
|
175
|
+
* @see https://agentskills.io/specification
|
|
176
|
+
*/
|
|
177
|
+
type SkillFrontmatterKey = (typeof SKILL_FRONTMATTER_KEYS)[number];
|
|
178
|
+
/**
|
|
179
|
+
* Frontmatter shape as defined by the spec.
|
|
180
|
+
* Required: name, description.
|
|
181
|
+
* Optional: license, compatibility, allowed-tools, metadata.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```ts
|
|
185
|
+
* const frontmatter: SkillFrontmatter = {
|
|
186
|
+
* name: "demo-skill",
|
|
187
|
+
* description: "Demonstrates the format",
|
|
188
|
+
* "allowed-tools": "Bash(git:*)"
|
|
189
|
+
* }
|
|
190
|
+
* ```
|
|
191
|
+
* @see https://agentskills.io/specification
|
|
192
|
+
* @see https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/models.py
|
|
193
|
+
*/
|
|
194
|
+
interface SkillFrontmatter<TMetadata extends SkillMetadataMap = SkillMetadataMap> {
|
|
195
|
+
/** Required skill identifier. */
|
|
196
|
+
name: string;
|
|
197
|
+
/** Required skill description. */
|
|
198
|
+
description: string;
|
|
199
|
+
/** Optional license declaration. */
|
|
200
|
+
license?: string;
|
|
201
|
+
/** Optional host/runtime compatibility notes. */
|
|
202
|
+
compatibility?: string;
|
|
203
|
+
/** Optional space-delimited allowed-tools declaration. */
|
|
204
|
+
'allowed-tools'?: SkillAllowedTools;
|
|
205
|
+
/** Optional string metadata map. */
|
|
206
|
+
metadata?: TMetadata;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Result returned by `parseFrontmatter`.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts
|
|
213
|
+
* const result: SkillFrontmatterParseResult = {
|
|
214
|
+
* metadata: { name: "demo", description: "Demo" },
|
|
215
|
+
* body: "# Instructions"
|
|
216
|
+
* }
|
|
217
|
+
* ```
|
|
218
|
+
* @see https://agentskills.io/specification
|
|
219
|
+
*/
|
|
220
|
+
interface SkillFrontmatterParseResult<TMetadata extends SkillMetadataMap = SkillMetadataMap> {
|
|
221
|
+
/** Parsed spec-keyed frontmatter object. */
|
|
222
|
+
metadata: SkillFrontmatter<TMetadata>;
|
|
223
|
+
/** Markdown body after frontmatter removal. */
|
|
224
|
+
body: SkillBody;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Result returned by `parseSkillContent`.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```ts
|
|
231
|
+
* const result: SkillParseResult = {
|
|
232
|
+
* properties: { name: "demo", description: "Demo" },
|
|
233
|
+
* body: "# Instructions"
|
|
234
|
+
* }
|
|
235
|
+
* ```
|
|
236
|
+
* @see https://agentskills.io/specification
|
|
237
|
+
*/
|
|
238
|
+
interface SkillParseResult<TMetadata extends SkillMetadataMap = SkillMetadataMap> {
|
|
239
|
+
/** Parsed camel-cased properties for JS usage. */
|
|
240
|
+
properties: SkillProperties<TMetadata>;
|
|
241
|
+
/** Markdown body after frontmatter removal. */
|
|
242
|
+
body: SkillBody;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Frontmatter normalized for JavaScript usage.
|
|
246
|
+
* Matches the reference implementation semantics with camel-cased keys.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* const props: SkillProperties = {
|
|
251
|
+
* name: "demo",
|
|
252
|
+
* description: "Demo",
|
|
253
|
+
* allowedTools: "Read"
|
|
254
|
+
* }
|
|
255
|
+
* ```
|
|
256
|
+
* @see https://agentskills.io/specification
|
|
257
|
+
* @see https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/models.py
|
|
258
|
+
*/
|
|
259
|
+
interface SkillProperties<TMetadata extends SkillMetadataMap = SkillMetadataMap> {
|
|
260
|
+
/** Required skill identifier. */
|
|
261
|
+
name: SkillFrontmatter<TMetadata>['name'];
|
|
262
|
+
/** Required skill description. */
|
|
263
|
+
description: SkillFrontmatter<TMetadata>['description'];
|
|
264
|
+
/** Optional license declaration. */
|
|
265
|
+
license?: SkillFrontmatter<TMetadata>['license'];
|
|
266
|
+
/** Optional host/runtime compatibility notes. */
|
|
267
|
+
compatibility?: SkillFrontmatter<TMetadata>['compatibility'];
|
|
268
|
+
/** Optional space-delimited allowed-tools declaration. */
|
|
269
|
+
allowedTools?: SkillFrontmatter<TMetadata>['allowed-tools'];
|
|
270
|
+
/** Optional string metadata map. */
|
|
271
|
+
metadata?: SkillFrontmatter<TMetadata>['metadata'];
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Convert SkillProperties to dictionary, excluding null/undefined values.
|
|
275
|
+
* Matches Python reference implementation's to_dict() behavior.
|
|
276
|
+
*
|
|
277
|
+
* Note: `allowedTools` becomes `allowed-tools` with hyphen
|
|
278
|
+
* Empty metadata object is excluded
|
|
279
|
+
*
|
|
280
|
+
* @param props - JavaScript-friendly skill properties.
|
|
281
|
+
* @returns Spec-keyed frontmatter dictionary.
|
|
282
|
+
* @example
|
|
283
|
+
* ```ts
|
|
284
|
+
* const dict = skillPropertiesToDict({
|
|
285
|
+
* name: "demo",
|
|
286
|
+
* description: "Demo skill",
|
|
287
|
+
* allowedTools: "Read"
|
|
288
|
+
* })
|
|
289
|
+
* // => { name: "demo", description: "Demo skill", "allowed-tools": "Read" }
|
|
290
|
+
* ```
|
|
291
|
+
* @see https://agentskills.io/specification
|
|
292
|
+
* @see https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/models.py
|
|
293
|
+
*/
|
|
294
|
+
declare function skillPropertiesToDict<TMetadata extends SkillMetadataMap = SkillMetadataMap>(props: SkillProperties<TMetadata>): SkillFrontmatter<TMetadata>;
|
|
295
|
+
/**
|
|
296
|
+
* Full skill record suitable for storage in an app-owned persistence layer.
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```ts
|
|
300
|
+
* const file: SkillFile = {
|
|
301
|
+
* id: "skill_1",
|
|
302
|
+
* content: "---\nname: demo\ndescription: Demo\n---",
|
|
303
|
+
* properties: { name: "demo", description: "Demo" },
|
|
304
|
+
* size: 42,
|
|
305
|
+
* createdAt: Date.now(),
|
|
306
|
+
* updatedAt: Date.now()
|
|
307
|
+
* }
|
|
308
|
+
* ```
|
|
309
|
+
* @see https://agentskills.io/specification
|
|
310
|
+
*/
|
|
311
|
+
interface SkillFile<TMetadata extends SkillMetadataMap = SkillMetadataMap> {
|
|
312
|
+
/** Host-owned unique skill id. */
|
|
313
|
+
id: SkillId;
|
|
314
|
+
/** Raw SKILL.md content. */
|
|
315
|
+
content: SkillContent;
|
|
316
|
+
/** Parsed skill properties. */
|
|
317
|
+
properties: SkillProperties<TMetadata>;
|
|
318
|
+
/** Content byte size. */
|
|
319
|
+
size: ByteCount;
|
|
320
|
+
/** Record creation timestamp in milliseconds. */
|
|
321
|
+
createdAt: UnixMillis;
|
|
322
|
+
/** Record update timestamp in milliseconds. */
|
|
323
|
+
updatedAt: UnixMillis;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Lightweight metadata for progressive disclosure.
|
|
327
|
+
* Used in list views and skill selection UI.
|
|
328
|
+
*
|
|
329
|
+
* Progressive disclosure strategy:
|
|
330
|
+
* 1. Metadata (roughly 50-100 tokens): name + description loaded at startup
|
|
331
|
+
* 2. Full content (roughly 500-5000 tokens): loaded when activated
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* ```ts
|
|
335
|
+
* const metadata: SkillMetadata = {
|
|
336
|
+
* id: "skill_1",
|
|
337
|
+
* name: "demo",
|
|
338
|
+
* description: "Demo skill",
|
|
339
|
+
* metadataTokens: 80,
|
|
340
|
+
* fullTokens: 900,
|
|
341
|
+
* createdAt: Date.now(),
|
|
342
|
+
* updatedAt: Date.now()
|
|
343
|
+
* }
|
|
344
|
+
* ```
|
|
345
|
+
* @see https://agentskills.io/specification
|
|
346
|
+
*/
|
|
347
|
+
interface SkillMetadata<TMetadata extends SkillMetadataMap = SkillMetadataMap> {
|
|
348
|
+
/** Host-owned unique skill id. */
|
|
349
|
+
id: SkillId;
|
|
350
|
+
/** Skill identifier. */
|
|
351
|
+
name: SkillProperties<TMetadata>['name'];
|
|
352
|
+
/** Skill description. */
|
|
353
|
+
description: SkillProperties<TMetadata>['description'];
|
|
354
|
+
/** Optional license declaration. */
|
|
355
|
+
license?: SkillProperties<TMetadata>['license'];
|
|
356
|
+
/** Optional host/runtime compatibility notes. */
|
|
357
|
+
compatibility?: SkillProperties<TMetadata>['compatibility'];
|
|
358
|
+
/** Optional space-delimited allowed-tools declaration. */
|
|
359
|
+
allowedTools?: SkillProperties<TMetadata>['allowedTools'];
|
|
360
|
+
/** Optional string metadata map. */
|
|
361
|
+
metadata?: SkillProperties<TMetadata>['metadata'];
|
|
362
|
+
/** Estimated token size for metadata-only tier. */
|
|
363
|
+
metadataTokens: SkillTokenCount;
|
|
364
|
+
/** Estimated token size for full skill content. */
|
|
365
|
+
fullTokens: SkillTokenCount;
|
|
366
|
+
/** Record creation timestamp in milliseconds. */
|
|
367
|
+
createdAt: UnixMillis;
|
|
368
|
+
/** Record update timestamp in milliseconds. */
|
|
369
|
+
updatedAt: UnixMillis;
|
|
370
|
+
}
|
|
371
|
+
//#endregion
|
|
372
|
+
//#region src/disclosure.d.ts
|
|
373
|
+
declare const ERROR_CODE_SKILL_NOT_FOUND = "SKILL_NOT_FOUND";
|
|
374
|
+
declare const ERROR_CODE_RESOURCE_NOT_FOUND = "RESOURCE_NOT_FOUND";
|
|
375
|
+
/**
|
|
376
|
+
* Stable error codes for progressive disclosure read failures.
|
|
377
|
+
*/
|
|
378
|
+
type SkillReadErrorCode = typeof ERROR_CODE_SKILL_NOT_FOUND | typeof ERROR_CODE_RESOURCE_NOT_FOUND;
|
|
379
|
+
/**
|
|
380
|
+
* Tool call arguments for skill progressive disclosure reads.
|
|
381
|
+
*/
|
|
382
|
+
interface SkillReadArgs {
|
|
383
|
+
/** Skill identifier from the current skill set. */
|
|
384
|
+
name: ResolvedSkill['name'];
|
|
385
|
+
/** Optional resource identifier within the selected skill. */
|
|
386
|
+
resource?: SkillResource['name'];
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Successful result from a skill read request.
|
|
390
|
+
*/
|
|
391
|
+
interface SkillReadResult {
|
|
392
|
+
/** Indicates that the read resolved successfully. */
|
|
393
|
+
ok: true;
|
|
394
|
+
/** Skill body or resource content returned by the read. */
|
|
395
|
+
content: SkillBody | SkillResource['content'];
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Machine-readable read failure for hosts and UIs.
|
|
399
|
+
*/
|
|
400
|
+
interface SkillReadError {
|
|
401
|
+
/** Indicates that the read failed. */
|
|
402
|
+
ok: false;
|
|
403
|
+
/** Machine-readable error code for host-side branching. */
|
|
404
|
+
code: SkillReadErrorCode;
|
|
405
|
+
/** Human-readable error message. */
|
|
406
|
+
error: string;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Options for building the read tool schema declaration.
|
|
410
|
+
*/
|
|
411
|
+
interface ReadToolSchemaOptions {
|
|
412
|
+
/** Tool name override (defaults to `read_skill`). */
|
|
413
|
+
toolName?: string;
|
|
414
|
+
/** Tool description override. */
|
|
415
|
+
description?: string;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Format-agnostic read tool schema declaration.
|
|
419
|
+
*
|
|
420
|
+
* This shape maps cleanly to Gemini `functionDeclarations`, OpenAI tools,
|
|
421
|
+
* and MCP tool metadata.
|
|
422
|
+
*/
|
|
423
|
+
interface ReadToolSchema {
|
|
424
|
+
/** Tool name for the declaration payload. */
|
|
425
|
+
name: NonNullable<ReadToolSchemaOptions['toolName']>;
|
|
426
|
+
/** Human-readable tool description. */
|
|
427
|
+
description: NonNullable<ReadToolSchemaOptions['description']>;
|
|
428
|
+
/** JSON Schema object describing accepted arguments. */
|
|
429
|
+
parametersJsonSchema: object;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Handles a 2-level progressive disclosure read.
|
|
433
|
+
*
|
|
434
|
+
* - `name` only: returns skill body (tier 2)
|
|
435
|
+
* - `name` + `resource`: returns resource content (tier 3)
|
|
436
|
+
*
|
|
437
|
+
* @param skills - Fully resolved in-memory skills.
|
|
438
|
+
* @param args - Read request arguments.
|
|
439
|
+
* @returns Structured success or failure payload.
|
|
440
|
+
*/
|
|
441
|
+
declare function handleSkillRead(skills: ReadonlyArray<ResolvedSkill>, args: SkillReadArgs): SkillReadResult | SkillReadError;
|
|
442
|
+
/**
|
|
443
|
+
* Builds a strict JSON Schema declaration for the skill read tool.
|
|
444
|
+
*
|
|
445
|
+
* The `name` enum is derived from current skills. `resource` remains a free-form
|
|
446
|
+
* string because resources are typically discovered after reading the overview.
|
|
447
|
+
*
|
|
448
|
+
* @param skills - Skills available in the current host/session.
|
|
449
|
+
* @param options - Optional tool naming and description overrides.
|
|
450
|
+
* @returns Tool declaration object with `parametersJsonSchema`.
|
|
451
|
+
*/
|
|
452
|
+
declare function toReadToolSchema(skills: ReadonlyArray<Pick<ResolvedSkill, 'name'>>, options?: ReadToolSchemaOptions): ReadToolSchema;
|
|
453
|
+
//#endregion
|
|
454
|
+
//#region src/errors.d.ts
|
|
455
|
+
/**
|
|
456
|
+
* Error types for AgentSkills parsing and validation
|
|
457
|
+
*
|
|
458
|
+
* Reference: https://agentskills.io/specification
|
|
459
|
+
* Reference Implementation: https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/errors.py
|
|
460
|
+
*/
|
|
461
|
+
/**
|
|
462
|
+
* Error thrown during SKILL.md parsing (invalid YAML, missing frontmatter, etc.)
|
|
463
|
+
*
|
|
464
|
+
* Used for:
|
|
465
|
+
* - Missing or malformed frontmatter
|
|
466
|
+
* - Invalid YAML syntax
|
|
467
|
+
* - Non-mapping YAML structure
|
|
468
|
+
* - Missing SKILL.md inputs in a host-provided file list
|
|
469
|
+
*
|
|
470
|
+
* @param message - Human-readable parse failure detail.
|
|
471
|
+
* @example
|
|
472
|
+
* ```ts
|
|
473
|
+
* throw new ParseError("SKILL.md must start with YAML frontmatter (---)")
|
|
474
|
+
* ```
|
|
475
|
+
* @see https://agentskills.io/specification
|
|
476
|
+
* @see https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/errors.py
|
|
477
|
+
*/
|
|
478
|
+
declare class ParseError extends Error {
|
|
479
|
+
constructor(message: string);
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Error thrown during skill validation (invalid name, missing fields, etc.)
|
|
483
|
+
*
|
|
484
|
+
* Used for:
|
|
485
|
+
* - Missing required fields (name, description)
|
|
486
|
+
* - Invalid field formats (name not lowercase, etc.)
|
|
487
|
+
* - Field length violations (name > 64 chars, description > 1024 chars, etc.)
|
|
488
|
+
* - Unexpected frontmatter fields
|
|
489
|
+
*
|
|
490
|
+
* @param message - Human-readable validation failure detail.
|
|
491
|
+
* @example
|
|
492
|
+
* ```ts
|
|
493
|
+
* throw new ValidationError("Field 'name' must be a non-empty string")
|
|
494
|
+
* ```
|
|
495
|
+
* @see https://agentskills.io/specification
|
|
496
|
+
* @see https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/errors.py
|
|
497
|
+
*/
|
|
498
|
+
declare class ValidationError extends Error {
|
|
499
|
+
constructor(message: string);
|
|
500
|
+
}
|
|
501
|
+
//#endregion
|
|
502
|
+
//#region src/parser.d.ts
|
|
503
|
+
declare const INPUT_MODE_STRICT = "strict";
|
|
504
|
+
declare const INPUT_MODE_EMBEDDED = "embedded";
|
|
505
|
+
/**
|
|
506
|
+
* Finds SKILL.md in a list of file entries, preferring uppercase over lowercase.
|
|
507
|
+
*
|
|
508
|
+
* @param files - File entries from any storage backend.
|
|
509
|
+
* @returns The selected `SKILL.md` entry, or `null` when not found.
|
|
510
|
+
* @example
|
|
511
|
+
* ```ts
|
|
512
|
+
* const entry = findSkillMdFile([
|
|
513
|
+
* { name: "skill.md", content: "..." },
|
|
514
|
+
* { name: "SKILL.md", content: "..." }
|
|
515
|
+
* ])
|
|
516
|
+
* ```
|
|
517
|
+
* @see https://agentskills.io/specification
|
|
518
|
+
* @see https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/parser.py
|
|
519
|
+
*/
|
|
520
|
+
declare function findSkillMdFile<T extends Pick<SkillContentEntry, 'name'>>(files: Iterable<T>): T | null;
|
|
521
|
+
/**
|
|
522
|
+
* Options for `readSkillProperties`.
|
|
523
|
+
*/
|
|
524
|
+
interface ReadSkillPropertiesOptions {
|
|
525
|
+
/** Optional label used in parse errors when `SKILL.md` is missing. */
|
|
526
|
+
location?: string;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Reads and parses the SKILL.md content from an in-memory file list.
|
|
530
|
+
* The lookup mirrors the reference behavior by preferring SKILL.md over skill.md.
|
|
531
|
+
*
|
|
532
|
+
* @param files - File entries that may contain `SKILL.md`.
|
|
533
|
+
* @param options - Optional location label for parse errors.
|
|
534
|
+
* @returns Parsed `SkillProperties`.
|
|
535
|
+
* @throws {ParseError} If `SKILL.md` cannot be located.
|
|
536
|
+
* @throws {ValidationError} If required frontmatter fields are missing or invalid.
|
|
537
|
+
* @example
|
|
538
|
+
* ```ts
|
|
539
|
+
* const properties = readSkillProperties([
|
|
540
|
+
* { name: "SKILL.md", content: "---\nname: demo\ndescription: Demo\n---" }
|
|
541
|
+
* ])
|
|
542
|
+
* ```
|
|
543
|
+
* @see https://agentskills.io/specification
|
|
544
|
+
* @see https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/parser.py
|
|
545
|
+
*/
|
|
546
|
+
declare function readSkillProperties<T extends SkillContentEntry, TMetadata extends SkillMetadataMap = SkillMetadataMap>(files: Iterable<T>, options?: ReadSkillPropertiesOptions): SkillProperties<TMetadata>;
|
|
547
|
+
/**
|
|
548
|
+
* Converts hyphenated frontmatter keys into a JS-friendly properties shape.
|
|
549
|
+
*
|
|
550
|
+
* @param metadata - Parsed frontmatter using spec keys.
|
|
551
|
+
* @returns Camel-cased `SkillProperties` representation.
|
|
552
|
+
* @example
|
|
553
|
+
* ```ts
|
|
554
|
+
* const properties = frontmatterToProperties({
|
|
555
|
+
* name: "demo",
|
|
556
|
+
* description: "Demo skill",
|
|
557
|
+
* "allowed-tools": "Bash(git:*)"
|
|
558
|
+
* })
|
|
559
|
+
* ```
|
|
560
|
+
* @see https://agentskills.io/specification
|
|
561
|
+
* @see https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/models.py
|
|
562
|
+
*/
|
|
563
|
+
declare function frontmatterToProperties<TMetadata extends SkillMetadataMap = SkillMetadataMap>(metadata: SkillFrontmatter<TMetadata>): SkillProperties<TMetadata>;
|
|
564
|
+
/**
|
|
565
|
+
* Frontmatter parser options.
|
|
566
|
+
*
|
|
567
|
+
* `strict` follows the specification and reference parser behavior exactly:
|
|
568
|
+
* content must start with `---`.
|
|
569
|
+
*
|
|
570
|
+
* `embedded` is an explicit host opt-in for web extraction contexts where
|
|
571
|
+
* content may have a leading BOM or whitespace before frontmatter.
|
|
572
|
+
*/
|
|
573
|
+
interface ParseFrontmatterOptions {
|
|
574
|
+
/**
|
|
575
|
+
* Input handling mode.
|
|
576
|
+
* - `strict` (default): parse exactly as provided.
|
|
577
|
+
* - `embedded`: remove UTF-8 BOM and leading whitespace before strict parse.
|
|
578
|
+
*/
|
|
579
|
+
inputMode?: ParseFrontmatterInputMode;
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Supported parse modes for frontmatter input handling.
|
|
583
|
+
*/
|
|
584
|
+
type ParseFrontmatterInputMode = typeof INPUT_MODE_STRICT | typeof INPUT_MODE_EMBEDDED;
|
|
585
|
+
/**
|
|
586
|
+
* Parsed resource reference discovered in a skill body markdown link.
|
|
587
|
+
*/
|
|
588
|
+
interface ResourceLink {
|
|
589
|
+
/** Display identifier from markdown link text. */
|
|
590
|
+
name: SkillResource['name'];
|
|
591
|
+
/** Canonical resource path under scripts/, references/, or assets/. */
|
|
592
|
+
path: SkillResource['path'];
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Extracts tier-3 resource links from skill body markdown.
|
|
596
|
+
*
|
|
597
|
+
* Only links to `scripts/*`, `references/*`, and `assets/*` are returned.
|
|
598
|
+
* External URLs, anchors, and path traversal references are ignored.
|
|
599
|
+
* Leading `./` is accepted and normalized away.
|
|
600
|
+
*
|
|
601
|
+
* @param body - Skill markdown body (without frontmatter).
|
|
602
|
+
* @returns De-duplicated list of resource links.
|
|
603
|
+
*/
|
|
604
|
+
declare function extractResourceLinks(body: SkillBody): ResourceLink[];
|
|
605
|
+
/**
|
|
606
|
+
* Parse YAML frontmatter from SKILL.md content.
|
|
607
|
+
*
|
|
608
|
+
* @param content - Raw content of SKILL.md file
|
|
609
|
+
* @param options - Optional parsing mode. Defaults to strict spec behavior.
|
|
610
|
+
* @returns Parsed frontmatter metadata and trimmed markdown body.
|
|
611
|
+
* @throws {ParseError} If frontmatter is missing or invalid
|
|
612
|
+
* @throws {ValidationError} If required fields are missing or invalid
|
|
613
|
+
* @example
|
|
614
|
+
* ```ts
|
|
615
|
+
* const { metadata, body } = parseFrontmatter(`---
|
|
616
|
+
* name: demo
|
|
617
|
+
* description: Demo skill
|
|
618
|
+
* ---
|
|
619
|
+
* # Instructions`)
|
|
620
|
+
* ```
|
|
621
|
+
* @see https://agentskills.io/specification
|
|
622
|
+
* @see https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/parser.py
|
|
623
|
+
*
|
|
624
|
+
* Spec: https://agentskills.io/specification
|
|
625
|
+
* - File must start with `---`
|
|
626
|
+
* - Frontmatter must be closed with second `---`
|
|
627
|
+
* - YAML must be valid mapping (object)
|
|
628
|
+
* - Required fields: name, description
|
|
629
|
+
* - Required fields must be non-empty strings
|
|
630
|
+
*/
|
|
631
|
+
declare function parseFrontmatter<TMetadata extends SkillMetadataMap = SkillMetadataMap>(content: SkillContent, options?: ParseFrontmatterOptions): SkillFrontmatterParseResult<TMetadata>;
|
|
632
|
+
/**
|
|
633
|
+
* Extract markdown body from SKILL.md content (strips frontmatter).
|
|
634
|
+
*
|
|
635
|
+
* @param content - Raw content of SKILL.md file
|
|
636
|
+
* @returns Markdown body without frontmatter
|
|
637
|
+
* @example
|
|
638
|
+
* ```ts
|
|
639
|
+
* const body = extractBody(`---\nname: demo\ndescription: Demo\n---\n# Body`)
|
|
640
|
+
* ```
|
|
641
|
+
* @see https://agentskills.io/specification
|
|
642
|
+
* @see https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/parser.py
|
|
643
|
+
*
|
|
644
|
+
* If content doesn't have valid frontmatter, returns the content as-is.
|
|
645
|
+
*/
|
|
646
|
+
declare function extractBody(content: SkillContent): SkillBody;
|
|
647
|
+
/**
|
|
648
|
+
* Parse SKILL.md content into SkillProperties.
|
|
649
|
+
*
|
|
650
|
+
* @param content - Raw content of SKILL.md file
|
|
651
|
+
* @param options - Optional frontmatter parsing mode.
|
|
652
|
+
* @returns SkillProperties with parsed metadata and body
|
|
653
|
+
* @throws {ParseError} If SKILL.md has invalid format
|
|
654
|
+
* @throws {ValidationError} If required fields are missing
|
|
655
|
+
* @example
|
|
656
|
+
* ```ts
|
|
657
|
+
* const parsed = parseSkillContent(`---
|
|
658
|
+
* name: demo
|
|
659
|
+
* description: Demo skill
|
|
660
|
+
* ---
|
|
661
|
+
* # Instructions`)
|
|
662
|
+
* ```
|
|
663
|
+
* @see https://agentskills.io/specification
|
|
664
|
+
* @see https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/parser.py
|
|
665
|
+
*
|
|
666
|
+
* Spec: https://agentskills.io/specification
|
|
667
|
+
*/
|
|
668
|
+
declare function parseSkillContent<TMetadata extends SkillMetadataMap = SkillMetadataMap>(content: SkillContent, options?: ParseFrontmatterOptions): SkillParseResult<TMetadata>;
|
|
669
|
+
//#endregion
|
|
670
|
+
//#region src/validator.d.ts
|
|
671
|
+
/**
|
|
672
|
+
* Maximum allowed skill name length.
|
|
673
|
+
*
|
|
674
|
+
* @see https://agentskills.io/specification
|
|
675
|
+
* @example
|
|
676
|
+
* ```ts
|
|
677
|
+
* if (name.length > MAX_SKILL_NAME_LENGTH) {
|
|
678
|
+
* // invalid
|
|
679
|
+
* }
|
|
680
|
+
* ```
|
|
681
|
+
*/
|
|
682
|
+
declare const MAX_SKILL_NAME_LENGTH = 64;
|
|
683
|
+
/**
|
|
684
|
+
* Maximum allowed description length.
|
|
685
|
+
*
|
|
686
|
+
* @see https://agentskills.io/specification
|
|
687
|
+
* @example
|
|
688
|
+
* ```ts
|
|
689
|
+
* if (description.length > MAX_DESCRIPTION_LENGTH) {
|
|
690
|
+
* // invalid
|
|
691
|
+
* }
|
|
692
|
+
* ```
|
|
693
|
+
*/
|
|
694
|
+
declare const MAX_DESCRIPTION_LENGTH = 1024;
|
|
695
|
+
/**
|
|
696
|
+
* Maximum allowed compatibility string length.
|
|
697
|
+
*
|
|
698
|
+
* @see https://agentskills.io/specification
|
|
699
|
+
* @example
|
|
700
|
+
* ```ts
|
|
701
|
+
* if (compatibility.length > MAX_COMPATIBILITY_LENGTH) {
|
|
702
|
+
* // invalid
|
|
703
|
+
* }
|
|
704
|
+
* ```
|
|
705
|
+
*/
|
|
706
|
+
declare const MAX_COMPATIBILITY_LENGTH = 500;
|
|
707
|
+
/**
|
|
708
|
+
* Allowed frontmatter fields per Agent Skills Spec.
|
|
709
|
+
* https://agentskills.io/specification
|
|
710
|
+
*
|
|
711
|
+
* @example
|
|
712
|
+
* ```ts
|
|
713
|
+
* if (!ALLOWED_FIELDS.has("name")) {
|
|
714
|
+
* throw new Error("configuration bug")
|
|
715
|
+
* }
|
|
716
|
+
* ```
|
|
717
|
+
* @see https://agentskills.io/specification
|
|
718
|
+
* @see https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/validator.py
|
|
719
|
+
*/
|
|
720
|
+
declare const ALLOWED_FIELDS: Set<string>;
|
|
721
|
+
/**
|
|
722
|
+
* Optional host-level constraints for `validateSkillProperties`.
|
|
723
|
+
*/
|
|
724
|
+
interface ValidateSkillPropertiesOptions {
|
|
725
|
+
/** Expected skill name (for example, directory or slug match). */
|
|
726
|
+
expectedName?: SkillProperties['name'];
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Validate skill properties.
|
|
730
|
+
*
|
|
731
|
+
* This is the core validation function that works on parsed properties.
|
|
732
|
+
* Provide expectedName to enforce a host-level name match (directory, slug, or ID).
|
|
733
|
+
*
|
|
734
|
+
* @param properties - Parsed skill properties
|
|
735
|
+
* @param options - Validation options including optional expected skill name.
|
|
736
|
+
* @returns List of validation error messages. Empty list means valid.
|
|
737
|
+
* @example
|
|
738
|
+
* ```ts
|
|
739
|
+
* const errors = validateSkillProperties({
|
|
740
|
+
* name: "demo-skill",
|
|
741
|
+
* description: "Demo skill"
|
|
742
|
+
* })
|
|
743
|
+
* ```
|
|
744
|
+
* @see https://agentskills.io/specification
|
|
745
|
+
* @see https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/validator.py
|
|
746
|
+
*
|
|
747
|
+
* Spec: https://agentskills.io/specification
|
|
748
|
+
*/
|
|
749
|
+
declare function validateSkillProperties(properties: SkillProperties, options?: ValidateSkillPropertiesOptions): string[];
|
|
750
|
+
/**
|
|
751
|
+
* Validate complete SKILL.md content.
|
|
752
|
+
*
|
|
753
|
+
* Parses the content and validates the resulting properties.
|
|
754
|
+
*
|
|
755
|
+
* @param content - Raw SKILL.md content
|
|
756
|
+
* @returns List of validation error messages. Empty list means valid.
|
|
757
|
+
* @example
|
|
758
|
+
* ```ts
|
|
759
|
+
* const errors = validateSkillContent(`---
|
|
760
|
+
* name: demo
|
|
761
|
+
* description: Demo skill
|
|
762
|
+
* ---
|
|
763
|
+
* # Body`)
|
|
764
|
+
* ```
|
|
765
|
+
* @see https://agentskills.io/specification
|
|
766
|
+
* @see https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/validator.py
|
|
767
|
+
*
|
|
768
|
+
* Spec: https://agentskills.io/specification
|
|
769
|
+
*/
|
|
770
|
+
declare function validateSkillContent(content: SkillContent): string[];
|
|
771
|
+
/**
|
|
772
|
+
* Host-provided context for validating in-memory skill entries.
|
|
773
|
+
*
|
|
774
|
+
* @example
|
|
775
|
+
* ```ts
|
|
776
|
+
* const options: SkillValidationOptions = {
|
|
777
|
+
* location: "/skills/demo",
|
|
778
|
+
* expectedName: "demo",
|
|
779
|
+
* exists: true,
|
|
780
|
+
* isDirectory: true
|
|
781
|
+
* }
|
|
782
|
+
* ```
|
|
783
|
+
* @see https://agentskills.io/specification
|
|
784
|
+
* @see https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/validator.py
|
|
785
|
+
*/
|
|
786
|
+
interface SkillValidationOptions {
|
|
787
|
+
/** Optional location label included in error messages. */
|
|
788
|
+
location?: string;
|
|
789
|
+
/** Expected skill name (for example, directory or slug match). */
|
|
790
|
+
expectedName?: ValidateSkillPropertiesOptions['expectedName'];
|
|
791
|
+
/** Whether the host path exists. */
|
|
792
|
+
exists?: boolean;
|
|
793
|
+
/** Whether the host path is a directory. */
|
|
794
|
+
isDirectory?: boolean;
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Validates a skill represented as an in-memory file list.
|
|
798
|
+
* The host can map filesystem concepts (exists, isDirectory, name) into options.
|
|
799
|
+
*
|
|
800
|
+
* @param entries - In-memory file entries for one skill directory.
|
|
801
|
+
* @param options - Host context for path state and expected name checks.
|
|
802
|
+
* @returns List of validation errors. Empty list means valid.
|
|
803
|
+
* @example
|
|
804
|
+
* ```ts
|
|
805
|
+
* const errors = validateSkillEntries(
|
|
806
|
+
* [{ name: "SKILL.md", content: "---\nname: demo\ndescription: Demo\n---" }],
|
|
807
|
+
* { expectedName: "demo" }
|
|
808
|
+
* )
|
|
809
|
+
* ```
|
|
810
|
+
* @see https://agentskills.io/specification
|
|
811
|
+
* @see https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/validator.py
|
|
812
|
+
*/
|
|
813
|
+
declare function validateSkillEntries(entries: Iterable<SkillContentEntry> | null | undefined, options?: SkillValidationOptions): string[];
|
|
814
|
+
//#endregion
|
|
815
|
+
//#region src/patch.d.ts
|
|
816
|
+
/**
|
|
817
|
+
* Supported patch operation types.
|
|
818
|
+
*
|
|
819
|
+
* @example
|
|
820
|
+
* ```ts
|
|
821
|
+
* const type: SkillPatchOperationType = "replace"
|
|
822
|
+
* ```
|
|
823
|
+
* @see https://agentskills.io/specification
|
|
824
|
+
*/
|
|
825
|
+
type SkillPatchOperationType = 'replace' | 'insert' | 'delete';
|
|
826
|
+
/**
|
|
827
|
+
* Replace operation that swaps matched text with new text.
|
|
828
|
+
*
|
|
829
|
+
* @example
|
|
830
|
+
* ```ts
|
|
831
|
+
* const op: SkillPatchReplaceOperation = {
|
|
832
|
+
* type: "replace",
|
|
833
|
+
* before: "old",
|
|
834
|
+
* after: "new"
|
|
835
|
+
* }
|
|
836
|
+
* ```
|
|
837
|
+
* @see https://agentskills.io/specification
|
|
838
|
+
*/
|
|
839
|
+
interface SkillPatchReplaceOperation {
|
|
840
|
+
type: 'replace';
|
|
841
|
+
before: string;
|
|
842
|
+
after: string;
|
|
843
|
+
expectedMatches?: number;
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* Insert operation that adds text before or after an anchor.
|
|
847
|
+
*
|
|
848
|
+
* @example
|
|
849
|
+
* ```ts
|
|
850
|
+
* const op: SkillPatchInsertOperation = {
|
|
851
|
+
* type: "insert",
|
|
852
|
+
* anchor: "## Section",
|
|
853
|
+
* text: "\nNew line",
|
|
854
|
+
* position: "after"
|
|
855
|
+
* }
|
|
856
|
+
* ```
|
|
857
|
+
* @see https://agentskills.io/specification
|
|
858
|
+
*/
|
|
859
|
+
interface SkillPatchInsertOperation {
|
|
860
|
+
type: 'insert';
|
|
861
|
+
anchor: string;
|
|
862
|
+
text: string;
|
|
863
|
+
position?: 'before' | 'after';
|
|
864
|
+
expectedMatches?: number;
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* Delete operation that removes occurrences of target text.
|
|
868
|
+
*
|
|
869
|
+
* @example
|
|
870
|
+
* ```ts
|
|
871
|
+
* const op: SkillPatchDeleteOperation = { type: "delete", before: "obsolete" }
|
|
872
|
+
* ```
|
|
873
|
+
* @see https://agentskills.io/specification
|
|
874
|
+
*/
|
|
875
|
+
interface SkillPatchDeleteOperation {
|
|
876
|
+
type: 'delete';
|
|
877
|
+
before: string;
|
|
878
|
+
expectedMatches?: number;
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Union of all supported patch operations.
|
|
882
|
+
*
|
|
883
|
+
* @example
|
|
884
|
+
* ```ts
|
|
885
|
+
* const op: SkillPatchOperation = { type: "delete", before: "obsolete" }
|
|
886
|
+
* ```
|
|
887
|
+
* @see https://agentskills.io/specification
|
|
888
|
+
*/
|
|
889
|
+
type SkillPatchOperation = SkillPatchReplaceOperation | SkillPatchInsertOperation | SkillPatchDeleteOperation;
|
|
890
|
+
/**
|
|
891
|
+
* Top-level patch payload accepted by `applySkillPatch`.
|
|
892
|
+
*
|
|
893
|
+
* @example
|
|
894
|
+
* ```ts
|
|
895
|
+
* const patch: SkillPatch = { version: 1, operations: [] }
|
|
896
|
+
* ```
|
|
897
|
+
* @see https://agentskills.io/specification
|
|
898
|
+
*/
|
|
899
|
+
interface SkillPatch {
|
|
900
|
+
version: 1;
|
|
901
|
+
operations: SkillPatchOperation[];
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* Machine-readable issue codes emitted by patch validation/application.
|
|
905
|
+
*
|
|
906
|
+
* @example
|
|
907
|
+
* ```ts
|
|
908
|
+
* const code: SkillPatchIssueCode = "OPERATION_TARGET_NOT_FOUND"
|
|
909
|
+
* ```
|
|
910
|
+
* @see https://agentskills.io/specification
|
|
911
|
+
*/
|
|
912
|
+
type SkillPatchIssueCode = 'PATCH_NOT_OBJECT' | 'PATCH_INVALID_VERSION' | 'PATCH_MISSING_OPERATIONS' | 'OPERATION_INVALID' | 'OPERATION_TARGET_EMPTY' | 'OPERATION_INVALID_POSITION' | 'OPERATION_INVALID_EXPECTED_MATCHES' | 'OPERATION_TARGET_NOT_FOUND' | 'OPERATION_TARGET_AMBIGUOUS' | 'OPERATION_MATCH_COUNT_MISMATCH' | 'SKILL_INVALID';
|
|
913
|
+
/**
|
|
914
|
+
* Structured issue detail for patch failures.
|
|
915
|
+
*
|
|
916
|
+
* @example
|
|
917
|
+
* ```ts
|
|
918
|
+
* const issue: SkillPatchIssue = {
|
|
919
|
+
* code: "OPERATION_TARGET_NOT_FOUND",
|
|
920
|
+
* message: "Target text not found."
|
|
921
|
+
* }
|
|
922
|
+
* ```
|
|
923
|
+
* @see https://agentskills.io/specification
|
|
924
|
+
*/
|
|
925
|
+
interface SkillPatchIssue {
|
|
926
|
+
code: SkillPatchIssueCode;
|
|
927
|
+
message: string;
|
|
928
|
+
operationIndex?: number;
|
|
929
|
+
operationType?: SkillPatchOperationType;
|
|
930
|
+
field?: string;
|
|
931
|
+
matchCount?: number;
|
|
932
|
+
expectedMatches?: number;
|
|
933
|
+
snippet?: string;
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* Result returned by `validateSkillPatch`.
|
|
937
|
+
*
|
|
938
|
+
* @example
|
|
939
|
+
* ```ts
|
|
940
|
+
* const result: SkillPatchValidationResult = validateSkillPatch(candidate)
|
|
941
|
+
* ```
|
|
942
|
+
* @see https://agentskills.io/specification
|
|
943
|
+
*/
|
|
944
|
+
interface SkillPatchValidationResult {
|
|
945
|
+
ok: boolean;
|
|
946
|
+
patch?: SkillPatch;
|
|
947
|
+
errors?: SkillPatchIssue[];
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* Options for patch application behavior.
|
|
951
|
+
*
|
|
952
|
+
* @example
|
|
953
|
+
* ```ts
|
|
954
|
+
* const options: SkillPatchApplyOptions = { expectedMatches: 1, validate: true }
|
|
955
|
+
* ```
|
|
956
|
+
* @see https://agentskills.io/specification
|
|
957
|
+
*/
|
|
958
|
+
interface SkillPatchApplyOptions {
|
|
959
|
+
expectedMatches?: number;
|
|
960
|
+
validate?: boolean | ValidateSkillPropertiesOptions;
|
|
961
|
+
}
|
|
962
|
+
/**
|
|
963
|
+
* Result returned by `applySkillPatch`.
|
|
964
|
+
*
|
|
965
|
+
* @example
|
|
966
|
+
* ```ts
|
|
967
|
+
* const result: SkillPatchApplyResult = applySkillPatch(content, patch)
|
|
968
|
+
* ```
|
|
969
|
+
* @see https://agentskills.io/specification
|
|
970
|
+
*/
|
|
971
|
+
interface SkillPatchApplyResult {
|
|
972
|
+
ok: boolean;
|
|
973
|
+
content?: SkillContent;
|
|
974
|
+
errors?: SkillPatchIssue[];
|
|
975
|
+
appliedOperations?: number;
|
|
976
|
+
}
|
|
977
|
+
/**
|
|
978
|
+
* Options for `createSkillPatch`.
|
|
979
|
+
*
|
|
980
|
+
* @example
|
|
981
|
+
* ```ts
|
|
982
|
+
* const options: SkillPatchCreateOptions = { contextLines: 2 }
|
|
983
|
+
* ```
|
|
984
|
+
* @see https://agentskills.io/specification
|
|
985
|
+
*/
|
|
986
|
+
interface SkillPatchCreateOptions {
|
|
987
|
+
contextLines?: number;
|
|
988
|
+
}
|
|
989
|
+
/**
|
|
990
|
+
* Diff segment type.
|
|
991
|
+
*
|
|
992
|
+
* @example
|
|
993
|
+
* ```ts
|
|
994
|
+
* const type: SkillDiffSegmentType = "insert"
|
|
995
|
+
* ```
|
|
996
|
+
* @see https://agentskills.io/specification
|
|
997
|
+
*/
|
|
998
|
+
type SkillDiffSegmentType = 'equal' | 'insert' | 'delete';
|
|
999
|
+
/**
|
|
1000
|
+
* Consecutive lines sharing the same diff operation type.
|
|
1001
|
+
*
|
|
1002
|
+
* @example
|
|
1003
|
+
* ```ts
|
|
1004
|
+
* const segment: SkillDiffSegment = { type: "equal", lines: ["line"] }
|
|
1005
|
+
* ```
|
|
1006
|
+
* @see https://agentskills.io/specification
|
|
1007
|
+
*/
|
|
1008
|
+
interface SkillDiffSegment {
|
|
1009
|
+
type: SkillDiffSegmentType;
|
|
1010
|
+
lines: string[];
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* Line-oriented diff output.
|
|
1014
|
+
*
|
|
1015
|
+
* @example
|
|
1016
|
+
* ```ts
|
|
1017
|
+
* const diff: SkillLineDiff = diffSkillContent("a", "b")
|
|
1018
|
+
* ```
|
|
1019
|
+
* @see https://agentskills.io/specification
|
|
1020
|
+
*/
|
|
1021
|
+
interface SkillLineDiff {
|
|
1022
|
+
baseLineCount: number;
|
|
1023
|
+
updatedLineCount: number;
|
|
1024
|
+
segments: SkillDiffSegment[];
|
|
1025
|
+
}
|
|
1026
|
+
/**
|
|
1027
|
+
* Validates and normalizes a candidate patch payload.
|
|
1028
|
+
*
|
|
1029
|
+
* @param patch - Unknown candidate patch object.
|
|
1030
|
+
* @returns Normalized patch when valid, otherwise structured issues.
|
|
1031
|
+
* @example
|
|
1032
|
+
* ```ts
|
|
1033
|
+
* const result = validateSkillPatch({
|
|
1034
|
+
* version: 1,
|
|
1035
|
+
* operations: [{ type: "replace", before: "old", after: "new" }]
|
|
1036
|
+
* })
|
|
1037
|
+
* ```
|
|
1038
|
+
* @see https://agentskills.io/specification
|
|
1039
|
+
*/
|
|
1040
|
+
declare function validateSkillPatch(patch: unknown): SkillPatchValidationResult;
|
|
1041
|
+
/**
|
|
1042
|
+
* Applies a patch to SKILL.md content with optional post-validation.
|
|
1043
|
+
*
|
|
1044
|
+
* @param content - Existing SKILL.md content.
|
|
1045
|
+
* @param patch - Candidate patch payload (typed or untyped).
|
|
1046
|
+
* @param options - Apply options for validation and expected match counts.
|
|
1047
|
+
* @returns Structured apply result with updated content or issues.
|
|
1048
|
+
* @example
|
|
1049
|
+
* ```ts
|
|
1050
|
+
* const result = applySkillPatch(content, {
|
|
1051
|
+
* version: 1,
|
|
1052
|
+
* operations: [{ type: "replace", before: "old", after: "new" }]
|
|
1053
|
+
* })
|
|
1054
|
+
* ```
|
|
1055
|
+
* @see https://agentskills.io/specification
|
|
1056
|
+
*/
|
|
1057
|
+
declare function applySkillPatch(content: SkillContent, patch: unknown, options?: SkillPatchApplyOptions): SkillPatchApplyResult;
|
|
1058
|
+
/**
|
|
1059
|
+
* Computes a line-based diff between two SKILL.md contents.
|
|
1060
|
+
*
|
|
1061
|
+
* @param base - Original SKILL.md content.
|
|
1062
|
+
* @param updated - Updated SKILL.md content.
|
|
1063
|
+
* @returns Grouped line diff segments.
|
|
1064
|
+
* @example
|
|
1065
|
+
* ```ts
|
|
1066
|
+
* const diff = diffSkillContent(baseContent, updatedContent)
|
|
1067
|
+
* ```
|
|
1068
|
+
* @see https://agentskills.io/specification
|
|
1069
|
+
*/
|
|
1070
|
+
declare function diffSkillContent(base: SkillContent, updated: SkillContent): SkillLineDiff;
|
|
1071
|
+
/**
|
|
1072
|
+
* Creates a contextual replace patch from base and updated content.
|
|
1073
|
+
*
|
|
1074
|
+
* @param base - Original SKILL.md content.
|
|
1075
|
+
* @param updated - Updated SKILL.md content.
|
|
1076
|
+
* @param options - Patch generation options.
|
|
1077
|
+
* @returns Patch payload containing replace operations.
|
|
1078
|
+
* @example
|
|
1079
|
+
* ```ts
|
|
1080
|
+
* const patch = createSkillPatch(baseContent, updatedContent, { contextLines: 2 })
|
|
1081
|
+
* ```
|
|
1082
|
+
* @see https://agentskills.io/specification
|
|
1083
|
+
*/
|
|
1084
|
+
declare function createSkillPatch(base: SkillContent, updated: SkillContent, options?: SkillPatchCreateOptions): SkillPatch;
|
|
1085
|
+
//#endregion
|
|
1086
|
+
//#region src/prompt.d.ts
|
|
1087
|
+
/**
|
|
1088
|
+
* Prompt-ready skill metadata.
|
|
1089
|
+
*
|
|
1090
|
+
* This shape is storage-agnostic and works for both filesystem hosts
|
|
1091
|
+
* (with `location`) and tool-only hosts (without `location`).
|
|
1092
|
+
*
|
|
1093
|
+
* @see https://agentskills.io/specification
|
|
1094
|
+
* @see https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/prompt.py
|
|
1095
|
+
*/
|
|
1096
|
+
interface SkillPromptEntry extends Pick<ResolvedSkill, 'name' | 'description' | 'location'> {}
|
|
1097
|
+
/**
|
|
1098
|
+
* SKILL.md source data for prompt generation.
|
|
1099
|
+
*
|
|
1100
|
+
* @see https://agentskills.io/specification
|
|
1101
|
+
* @see https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/prompt.py
|
|
1102
|
+
*/
|
|
1103
|
+
interface SkillPromptSource {
|
|
1104
|
+
/** Raw SKILL.md content to parse for prompt metadata. */
|
|
1105
|
+
content: SkillContent;
|
|
1106
|
+
/** Optional source location label for prompt output. */
|
|
1107
|
+
location?: SkillPromptEntry['location'];
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* Prompt entry for resource-aware progressive disclosure hosts.
|
|
1111
|
+
*/
|
|
1112
|
+
interface DisclosurePromptEntry extends SkillPromptEntry {
|
|
1113
|
+
/** Optional tier-3 resource names exposed as prompt hints. */
|
|
1114
|
+
resources?: Array<SkillResource['name']>;
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Options for disclosure protocol instruction text generation.
|
|
1118
|
+
*/
|
|
1119
|
+
interface DisclosureInstructionOptions {
|
|
1120
|
+
/** Tool name override used in generated instruction text. */
|
|
1121
|
+
toolName?: string;
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
* Generates the `<available_skills>` XML block for system prompts.
|
|
1125
|
+
*
|
|
1126
|
+
* The base output mirrors the reference XML shape and omits host-specific
|
|
1127
|
+
* protocol instructions.
|
|
1128
|
+
*
|
|
1129
|
+
* @param entries - Prompt entries or raw SKILL.md sources.
|
|
1130
|
+
* @returns XML block describing available skills.
|
|
1131
|
+
*/
|
|
1132
|
+
declare function toPrompt(entries: SkillPromptEntry[]): string;
|
|
1133
|
+
declare function toPrompt(entries: SkillPromptSource[]): string;
|
|
1134
|
+
/**
|
|
1135
|
+
* Generates `<available_skills>` XML including optional tier-3 resource hints.
|
|
1136
|
+
*
|
|
1137
|
+
* This is a host extension for progressive disclosure workflows and does not
|
|
1138
|
+
* replace the base `toPrompt` output contract.
|
|
1139
|
+
*
|
|
1140
|
+
* @param entries - Prompt entries with optional resource names.
|
|
1141
|
+
* @returns XML block describing skills and available resources.
|
|
1142
|
+
*/
|
|
1143
|
+
declare function toDisclosurePrompt(entries: DisclosurePromptEntry[]): string;
|
|
1144
|
+
/**
|
|
1145
|
+
* Generates canonical system-instruction text for progressive disclosure reads.
|
|
1146
|
+
*
|
|
1147
|
+
* @param options - Optional tool naming override.
|
|
1148
|
+
* @returns Multi-line guidance text for model system prompts.
|
|
1149
|
+
*/
|
|
1150
|
+
declare function toDisclosureInstructions(options?: DisclosureInstructionOptions): string;
|
|
1151
|
+
//#endregion
|
|
1152
|
+
//#region src/utils/token-estimator.d.ts
|
|
1153
|
+
/**
|
|
1154
|
+
* Token estimation utilities
|
|
1155
|
+
*
|
|
1156
|
+
* Provides rough token count estimates for context management.
|
|
1157
|
+
*/
|
|
1158
|
+
/**
|
|
1159
|
+
* Estimate token count for text.
|
|
1160
|
+
* Uses rough approximation: ~1 token per 4 characters.
|
|
1161
|
+
*
|
|
1162
|
+
* This is intentionally simple and conservative. For production,
|
|
1163
|
+
* consider using a proper tokenizer like tiktoken or @anthropic-ai/tokenizer.
|
|
1164
|
+
*
|
|
1165
|
+
* The 4-character heuristic tends to overestimate slightly, which is safer
|
|
1166
|
+
* for context limits than underestimating.
|
|
1167
|
+
*
|
|
1168
|
+
* @param text - Text to estimate tokens for
|
|
1169
|
+
* @returns Estimated token count
|
|
1170
|
+
* @example
|
|
1171
|
+
* ```ts
|
|
1172
|
+
* const tokens = estimateTokens("Hello world")
|
|
1173
|
+
* ```
|
|
1174
|
+
* @see https://agentskills.io/specification
|
|
1175
|
+
*/
|
|
1176
|
+
declare function estimateTokens(text: string): number;
|
|
1177
|
+
//#endregion
|
|
1178
|
+
//#region src/utils/unicode.d.ts
|
|
1179
|
+
/**
|
|
1180
|
+
* Unicode utilities for Agent Skills
|
|
1181
|
+
*
|
|
1182
|
+
* Reference: https://agentskills.io/specification
|
|
1183
|
+
* Reference Implementation: https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/validator.py
|
|
1184
|
+
*/
|
|
1185
|
+
/**
|
|
1186
|
+
* Normalize string using NFKC (Normalization Form Compatibility Composition).
|
|
1187
|
+
* Matches Python's unicodedata.normalize("NFKC", str) behavior.
|
|
1188
|
+
*
|
|
1189
|
+
* NFKC normalization:
|
|
1190
|
+
* - Decomposes characters into their base form
|
|
1191
|
+
* - Then recomposes them into the composed form
|
|
1192
|
+
* - Example: "café" with combining accent becomes "café" with precomposed é
|
|
1193
|
+
*
|
|
1194
|
+
* This is critical for i18n support and consistent validation across platforms.
|
|
1195
|
+
*
|
|
1196
|
+
* @param str - Input string to normalize.
|
|
1197
|
+
* @returns NFKC-normalized string.
|
|
1198
|
+
* @example
|
|
1199
|
+
* ```ts
|
|
1200
|
+
* const normalized = normalizeNFKC("cafe\u0301")
|
|
1201
|
+
* ```
|
|
1202
|
+
* @see https://agentskills.io/specification
|
|
1203
|
+
* @see https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/validator.py
|
|
1204
|
+
*/
|
|
1205
|
+
declare function normalizeNFKC(str: string): string;
|
|
1206
|
+
//#endregion
|
|
1207
|
+
export { ALLOWED_FIELDS, type ByteCount, type DisclosureInstructionOptions, type DisclosurePromptEntry, MAX_COMPATIBILITY_LENGTH, MAX_DESCRIPTION_LENGTH, MAX_SKILL_NAME_LENGTH, ParseError, type ParseFrontmatterInputMode, type ParseFrontmatterOptions, type ReadSkillPropertiesOptions, type ReadToolSchema, type ReadToolSchemaOptions, type ResolvedSkill, type ResourceLink, SKILL_FRONTMATTER_KEYS, type SkillAllowedTools, type SkillBody, type SkillContent, type SkillContentEntry, type SkillDiffSegment, type SkillDiffSegmentType, type SkillFile, type SkillFrontmatter, type SkillFrontmatterKey, type SkillFrontmatterParseResult, type SkillId, type SkillLineDiff, type SkillMetadata, type SkillMetadataMap, type SkillParseResult, type SkillPatch, type SkillPatchApplyOptions, type SkillPatchApplyResult, type SkillPatchCreateOptions, type SkillPatchIssue, type SkillPatchIssueCode, type SkillPatchOperation, type SkillPatchOperationType, type SkillPatchValidationResult, type SkillPromptEntry, type SkillPromptSource, type SkillProperties, type SkillReadArgs, type SkillReadError, type SkillReadErrorCode, type SkillReadResult, type SkillResource, type SkillTokenCount, type SkillValidationOptions, type UnixMillis, type ValidateSkillPropertiesOptions, ValidationError, applySkillPatch, createSkillPatch, diffSkillContent, estimateTokens, extractBody, extractResourceLinks, findSkillMdFile, frontmatterToProperties, handleSkillRead, normalizeNFKC, parseFrontmatter, parseSkillContent, readSkillProperties, skillPropertiesToDict, toDisclosureInstructions, toDisclosurePrompt, toPrompt, toReadToolSchema, validateSkillContent, validateSkillEntries, validateSkillPatch, validateSkillProperties };
|
|
1208
|
+
//# sourceMappingURL=index.d.ts.map
|