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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 mcp-b contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# agent-skills-ts-sdk
|
|
2
|
+
|
|
3
|
+
TypeScript implementation of the [AgentSkills specification](https://agentskills.io/specification).
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides parser and validator for Agent Skills, following the official specification at https://agentskills.io/specification.
|
|
8
|
+
|
|
9
|
+
Agent Skills are folders of instructions, scripts, and resources that agents can discover and use. Skills are defined in `SKILL.md` files with YAML frontmatter.
|
|
10
|
+
|
|
11
|
+
## References
|
|
12
|
+
|
|
13
|
+
- **Specification**: https://agentskills.io/specification
|
|
14
|
+
- **Reference Implementation**: [agentskills/skills-ref](https://github.com/agentskills/agentskills/tree/main/skills-ref) (Python)
|
|
15
|
+
- **Example Skills**: https://github.com/anthropics/skills
|
|
16
|
+
- **Reference Repository**: https://github.com/agentskills/agentskills/tree/main/skills-ref
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pnpm add agent-skills-ts-sdk
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### Parsing SKILL.md
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { parseSkillContent, validateSkillContent } from "agent-skills-ts-sdk"
|
|
30
|
+
|
|
31
|
+
const content = `---
|
|
32
|
+
name: my-skill
|
|
33
|
+
description: A test skill
|
|
34
|
+
---
|
|
35
|
+
# My Skill
|
|
36
|
+
|
|
37
|
+
Instructions here.`
|
|
38
|
+
|
|
39
|
+
const { properties, body } = parseSkillContent(content)
|
|
40
|
+
|
|
41
|
+
const errors = validateSkillContent(content)
|
|
42
|
+
if (errors.length > 0) {
|
|
43
|
+
console.error("Validation errors:", errors)
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
For embedded/web-extracted content (for example `<script>` text with a leading
|
|
48
|
+
newline), opt in explicitly:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
const { properties, body } = parseSkillContent(contentFromDom, {
|
|
52
|
+
inputMode: "embedded"
|
|
53
|
+
})
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Validation
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { validateSkillProperties } from "agent-skills-ts-sdk"
|
|
60
|
+
|
|
61
|
+
const properties = {
|
|
62
|
+
name: "my-skill",
|
|
63
|
+
description: "A test skill"
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const errors = validateSkillProperties(properties)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### In-memory file lists (Durable Objects or other non-filesystem hosts)
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import {
|
|
73
|
+
findSkillMdFile,
|
|
74
|
+
readSkillProperties,
|
|
75
|
+
validateSkillEntries
|
|
76
|
+
} from "agent-skills-ts-sdk"
|
|
77
|
+
|
|
78
|
+
const files = [
|
|
79
|
+
{ name: "SKILL.md", content: skillMarkdown }
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
const entry = findSkillMdFile(files)
|
|
83
|
+
const properties = readSkillProperties(files)
|
|
84
|
+
const errors = validateSkillEntries(files, { expectedName: properties.name })
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Prompt generation
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { toPrompt } from "agent-skills-ts-sdk"
|
|
91
|
+
|
|
92
|
+
const promptBlock = toPrompt([
|
|
93
|
+
{ content: skillMarkdown, location: "skills/my-skill/SKILL.md" }
|
|
94
|
+
])
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Progressive disclosure helpers
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import {
|
|
101
|
+
handleSkillRead,
|
|
102
|
+
toDisclosureInstructions,
|
|
103
|
+
toDisclosurePrompt,
|
|
104
|
+
toReadToolSchema
|
|
105
|
+
} from "agent-skills-ts-sdk"
|
|
106
|
+
|
|
107
|
+
const instructions = toDisclosureInstructions({ toolName: "read_site_context" })
|
|
108
|
+
const skillsXml = toDisclosurePrompt([
|
|
109
|
+
{ name: "pizza-maker", description: "Interactive pizza builder", resources: ["build-pizza"] }
|
|
110
|
+
])
|
|
111
|
+
const readTool = toReadToolSchema([{ name: "pizza-maker" }], {
|
|
112
|
+
toolName: "read_site_context"
|
|
113
|
+
})
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Diff + patch
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { createSkillPatch, applySkillPatch } from "agent-skills-ts-sdk"
|
|
120
|
+
|
|
121
|
+
const patch = createSkillPatch(oldContent, newContent)
|
|
122
|
+
const result = applySkillPatch(oldContent, patch)
|
|
123
|
+
|
|
124
|
+
if (!result.ok) {
|
|
125
|
+
console.error(result.errors)
|
|
126
|
+
} else {
|
|
127
|
+
console.log(result.content)
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Library Guide
|
|
132
|
+
|
|
133
|
+
### Parsing
|
|
134
|
+
- `parseFrontmatter` parses YAML frontmatter into the spec’s hyphenated keys, trims required fields, and preserves metadata scalars as strings.
|
|
135
|
+
- `parseSkillContent` returns both the markdown body and a JS-friendly `SkillProperties` shape.
|
|
136
|
+
- `frontmatterToProperties` converts `SkillFrontmatter` to `SkillProperties` without re-parsing.
|
|
137
|
+
- `extractBody` strips frontmatter and returns the markdown body.
|
|
138
|
+
- `findSkillMdFile` and `readSkillProperties` mirror the reference library’s file lookup without assuming a filesystem.
|
|
139
|
+
|
|
140
|
+
### Validation
|
|
141
|
+
- `validateSkillProperties` enforces the name/description/compatibility rules and optionally checks an expected name.
|
|
142
|
+
- `validateSkillContent` validates a single SKILL.md string, including unknown frontmatter fields.
|
|
143
|
+
- `validateSkillEntries` mirrors `skills-ref validate` for in-memory file lists while letting the host surface path and directory state.
|
|
144
|
+
|
|
145
|
+
### Prompt utilities
|
|
146
|
+
- `toPrompt` builds the `<available_skills>` XML block from parsed entries or raw SKILL.md content.
|
|
147
|
+
- `toDisclosurePrompt` optionally includes resource names for tier-3 hints.
|
|
148
|
+
- `toDisclosureInstructions` generates canonical read-protocol instruction text.
|
|
149
|
+
- `toReadToolSchema` builds a strict JSON-schema declaration for a read tool.
|
|
150
|
+
- `handleSkillRead` handles 2-level read requests in memory (overview vs specific resource).
|
|
151
|
+
|
|
152
|
+
### Diff + patch
|
|
153
|
+
- `diffSkillContent` returns a line-based diff for display or patch construction.
|
|
154
|
+
- `createSkillPatch` builds a contextual patch from two SKILL.md strings.
|
|
155
|
+
- `applySkillPatch` applies patch operations and returns structured errors when a patch cannot be applied or yields invalid SKILL.md.
|
|
156
|
+
- `validateSkillPatch` performs runtime validation for model-provided patch payloads.
|
|
157
|
+
|
|
158
|
+
### Utilities
|
|
159
|
+
- `normalizeNFKC` matches Python’s `unicodedata.normalize("NFKC", ...)` for name validation.
|
|
160
|
+
- `estimateTokens` provides a conservative heuristic for context budgeting.
|
|
161
|
+
|
|
162
|
+
### Types
|
|
163
|
+
- `SkillFrontmatter` matches spec keys (`allowed-tools`), `SkillProperties` is the camel-cased JS view.
|
|
164
|
+
- `SkillFile` and `SkillMetadata` are storage-friendly wrappers used by hosts that persist skills.
|
|
165
|
+
|
|
166
|
+
## Specification Compliance
|
|
167
|
+
|
|
168
|
+
This package mirrors the Agent Skills specification for content parsing and
|
|
169
|
+
validation, and aligns with the Python `skills-ref` reference behavior.
|
|
170
|
+
Directory-level checks (missing paths, non-directories, name-to-location match)
|
|
171
|
+
are surfaced through `validateSkillEntries` so hosts can supply their own storage model.
|
|
172
|
+
|
|
173
|
+
### Required Fields
|
|
174
|
+
- `name` (max 64 chars, lowercase, hyphens only)
|
|
175
|
+
- `description` (max 1024 chars)
|
|
176
|
+
|
|
177
|
+
### Optional Fields
|
|
178
|
+
- `license`
|
|
179
|
+
- `compatibility` (max 500 chars)
|
|
180
|
+
- `metadata` (key-value pairs)
|
|
181
|
+
- `allowed-tools` (experimental)
|
|
182
|
+
|
|
183
|
+
### Validation Rules
|
|
184
|
+
- Name must be lowercase
|
|
185
|
+
- Name cannot start/end with hyphen
|
|
186
|
+
- Name cannot contain consecutive hyphens
|
|
187
|
+
- Unicode normalization (NFKC)
|
|
188
|
+
- i18n support (Chinese, Russian, etc.)
|
|
189
|
+
|
|
190
|
+
## Testing
|
|
191
|
+
|
|
192
|
+
This package follows Test-Driven Development with comprehensive test coverage:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
# Run tests
|
|
196
|
+
pnpm test
|
|
197
|
+
|
|
198
|
+
# Run tests in watch mode
|
|
199
|
+
pnpm test:watch
|
|
200
|
+
|
|
201
|
+
# Generate coverage report
|
|
202
|
+
pnpm test:coverage
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**Coverage goals:**
|
|
206
|
+
- Line coverage: >95%
|
|
207
|
+
- Branch coverage: >90%
|
|
208
|
+
- Function coverage: >95%
|
|
209
|
+
|
|
210
|
+
## API Reference
|
|
211
|
+
|
|
212
|
+
See [API.md](./API.md) for full module and function details.
|
|
213
|
+
|
|
214
|
+
## License
|
|
215
|
+
|
|
216
|
+
MIT
|