agent-skills-ts-sdk 2.3.1 → 2.3.3

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/API.md ADDED
@@ -0,0 +1,217 @@
1
+ # agent-skills-ts-sdk API
2
+
3
+ This package is a TypeScript implementation of the Agent Skills specification.
4
+ It follows the public spec and mirrors the Python reference library behavior
5
+ with a storage-agnostic, in-memory API surface.
6
+
7
+ References:
8
+
9
+ - Spec: https://agentskills.io/specification
10
+ - Reference implementation: https://github.com/agentskills/agentskills/tree/main/skills-ref
11
+ - Parser reference: https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/parser.py
12
+ - Validator reference: https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/validator.py
13
+ - Models reference: https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/models.py
14
+ - Prompt reference: https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/prompt.py
15
+
16
+ ## Module map (TypeScript → Python reference)
17
+
18
+ - `src/models.ts` → [`skills_ref/models.py`](https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/models.py)
19
+ - `src/parser.ts` → [`skills_ref/parser.py`](https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/parser.py)
20
+ - `src/validator.ts` → [`skills_ref/validator.py`](https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/validator.py)
21
+ - `src/prompt.ts` → [`skills_ref/prompt.py`](https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/prompt.py)
22
+ - `src/patch.ts` → patch/diff utilities (no Python reference module)
23
+ - `src/errors.ts` → [`skills_ref/errors.py`](https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/errors.py)
24
+ - `src/utils/*` → helper logic used by parsing and validation
25
+
26
+ ## Core types
27
+
28
+ ### SkillFrontmatter
29
+
30
+ Spec-accurate YAML frontmatter shape. Keys are exactly as they appear in
31
+ `SKILL.md` (`allowed-tools` stays hyphenated). Required fields are
32
+ `name` and `description`.
33
+
34
+ ### SkillProperties
35
+
36
+ JavaScript-friendly representation of frontmatter. `allowed-tools` becomes
37
+ `allowedTools`, and `metadata` is normalized to string values.
38
+
39
+ ### SkillFile
40
+
41
+ Full record that a host can store in its own persistence layer. Contains the
42
+ raw content, parsed properties, size, and timestamps.
43
+
44
+ ### SkillMetadata
45
+
46
+ Lightweight list view for progressive disclosure with token estimates.
47
+
48
+ ### SkillResource / ResolvedSkill
49
+
50
+ Tier-3 resource models for progressive disclosure hosts:
51
+
52
+ - `SkillResource`: `{ name, path, content }`
53
+ - `ResolvedSkill`: parsed skill body plus associated resources used by
54
+ read handlers and tool schema generation.
55
+
56
+ ## Parsing
57
+
58
+ ### parseFrontmatter(content, options?)
59
+
60
+ Parses YAML frontmatter and returns `{ metadata, body }`.
61
+ Behavior matches the reference parser:
62
+
63
+ - Requires frontmatter, validates name/description presence and non-empty strings.
64
+ - Preserves metadata scalar formatting by reading YAML source tokens where possible.
65
+ - Returns hyphenated keys in `metadata`.
66
+
67
+ `options.inputMode`:
68
+
69
+ - `strict` (default): no preprocessing; requires content to start with `---`.
70
+ - `embedded`: explicit host opt-in for web/embed extraction contexts;
71
+ strips UTF-8 BOM and leading whitespace before strict parsing.
72
+
73
+ ### parseSkillContent(content, options?)
74
+
75
+ Returns `{ properties, body }` where `properties` is the camel-cased
76
+ `SkillProperties` representation of the frontmatter.
77
+ Accepts the same optional `ParseFrontmatterOptions` as `parseFrontmatter`.
78
+
79
+ ### extractResourceLinks(body)
80
+
81
+ Extracts tier-3 resource references from Markdown links and bare relative paths.
82
+
83
+ - Includes paths under observed skill-local resource directories such as
84
+ `scripts/*`, `references/*`, `assets/*`, `lib/*`, `rules/*`, or `templates/*`.
85
+ - Includes root-level files when referenced as Markdown links.
86
+ - Ignores URLs, anchors, and traversal-style paths.
87
+ - Accepts and normalizes leading `./`.
88
+ - Returns deduplicated `{ name, path }` pairs.
89
+
90
+ ### extractBody(content)
91
+
92
+ Strips frontmatter and returns the markdown body.
93
+
94
+ ### frontmatterToProperties(metadata)
95
+
96
+ Converts `SkillFrontmatter` to `SkillProperties` without re-parsing.
97
+
98
+ ### findSkillMdFile(files)
99
+
100
+ Finds `SKILL.md` from an in-memory list of files, preferring uppercase and
101
+ falling back to `skill.md`.
102
+
103
+ ### readSkillProperties(files, options)
104
+
105
+ Reads `SKILL.md` from an in-memory list and returns `SkillProperties`.
106
+ This is the filesystem-free analog of `skills_ref.read_properties`.
107
+
108
+ ## Validation
109
+
110
+ ### validateSkillProperties(properties, options)
111
+
112
+ Validates name, description, compatibility, and optional frontmatter field
113
+ types. Provide `expectedName` to enforce a name match against a host-provided
114
+ value (e.g., directory slug).
115
+
116
+ ### validateSkillContent(content)
117
+
118
+ Parses and validates a single `SKILL.md` content string, including unknown
119
+ frontmatter keys.
120
+
121
+ ### validateSkillEntries(entries, options)
122
+
123
+ Validates a skill represented as an in-memory file list. The host supplies
124
+ storage context via:
125
+
126
+ - `exists` (missing path),
127
+ - `isDirectory` (path is not a directory),
128
+ - `expectedName` (name-to-location match),
129
+ - `location` (user-facing label in error messages).
130
+
131
+ This mirrors the reference `validate()` without assuming a filesystem.
132
+
133
+ ## Prompt generation
134
+
135
+ ### toPrompt(entries)
136
+
137
+ Builds the `<available_skills>` XML block. Accepts either:
138
+
139
+ - `SkillPromptEntry` objects with `name`, `description`, and optional `location`, or
140
+ - `SkillPromptSource` objects with raw `SKILL.md` content + optional `location`.
141
+
142
+ ### toDisclosurePrompt(entries)
143
+
144
+ Builds `<available_skills>` XML with optional `<resources>` hints for
145
+ progressive disclosure hosts.
146
+
147
+ ### toDisclosureInstructions(options?)
148
+
149
+ Generates canonical system-instruction text for the progressive disclosure
150
+ read protocol with configurable tool name.
151
+
152
+ ### handleSkillRead(skills, args)
153
+
154
+ Pure in-memory 2-level read handler:
155
+
156
+ - no `resource`: returns skill body (tier 2)
157
+ - with `resource`: returns resource content (tier 3)
158
+ - validates tool-call argument shape at runtime
159
+ - returns structured errors with machine-readable `code`
160
+ (`INVALID_ARGUMENT`, `SKILL_NOT_FOUND`, `RESOURCE_NOT_FOUND`)
161
+
162
+ ### toReadToolSchema(skills, options?)
163
+
164
+ Builds strict JSON-schema declaration for a read tool:
165
+
166
+ - `name` enum derived from runtime skills
167
+ - optional `resource` string
168
+ - `additionalProperties: false`
169
+
170
+ XML is escaped to preserve safe system prompt formatting.
171
+
172
+ ## Diff + patch
173
+
174
+ ### diffSkillContent(base, updated)
175
+
176
+ Returns a line-based diff with `equal`, `insert`, and `delete` segments.
177
+ This is suitable for UI diff rendering or model feedback loops.
178
+
179
+ ### createSkillPatch(base, updated, options)
180
+
181
+ Generates a contextual patch for the delta between two `SKILL.md` strings.
182
+ Each operation is a `replace` hunk that includes a small amount of context
183
+ to keep patches stable across minor edits.
184
+
185
+ ### validateSkillPatch(patch)
186
+
187
+ Runtime patch validation for model-provided payloads. Returns structured,
188
+ model-friendly errors when a patch is malformed or unsupported.
189
+
190
+ ### applySkillPatch(content, patch, options)
191
+
192
+ Applies patch operations sequentially and returns a structured result:
193
+
194
+ - `ok: true` with `content` when the patch applies cleanly.
195
+ - `ok: false` with `errors` when a target cannot be found, is ambiguous,
196
+ or the resulting content violates the Agent Skills spec.
197
+
198
+ By default, the resulting `SKILL.md` is validated with `validateSkillContent`
199
+ and can optionally enforce an `expectedName`. `options.expectedMatches` must be
200
+ a positive integer when provided.
201
+
202
+ ## Utilities
203
+
204
+ ### normalizeNFKC(str)
205
+
206
+ Unicode normalization used by name validation to match Python’s
207
+ `unicodedata.normalize("NFKC", ...)`.
208
+
209
+ ### estimateTokens(text)
210
+
211
+ Conservative token estimator (~1 token per 4 characters) for context budgeting.
212
+
213
+ ## Error types
214
+
215
+ - `ParseError`: malformed frontmatter, invalid YAML, missing `SKILL.md`.
216
+ - `ValidationError`: invalid or missing required fields, length violations,
217
+ unexpected frontmatter keys.
package/CHANGELOG.md ADDED
@@ -0,0 +1,29 @@
1
+ # agent-skills-ts-sdk
2
+
3
+ ## 2.3.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Add an AgentSkills reference lock and CI drift check for the upstream specification and Python `skills-ref` package.
8
+ - Align parser, validator, disclosure, and patch behavior with the pinned AgentSkills reference.
9
+ - Document intentional conformance divergences for stricter SDK validation behavior.
10
+
11
+ ## 2.3.1
12
+
13
+ ## 2.3.0
14
+
15
+ ## 2.2.0
16
+
17
+ ## 2.1.0
18
+
19
+ ## 2.0.13
20
+
21
+ ## 2.0.12
22
+
23
+ ## 2.0.11
24
+
25
+ ## 2.0.10
26
+
27
+ ### Patch Changes
28
+
29
+ - Remove noisy console.warn from toTransportSchema for empty schemas and schemas without root type. The normalization behavior is correct — no need to warn consumers.
@@ -0,0 +1,25 @@
1
+ # Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We are committed to a respectful, harassment-free project environment for everyone.
6
+
7
+ ## Expected Behavior
8
+
9
+ - Be direct, constructive, and kind.
10
+ - Respect differing experience levels and viewpoints.
11
+ - Focus criticism on ideas, code, and project outcomes.
12
+ - Accept responsibility for mistakes and correct them when possible.
13
+
14
+ ## Unacceptable Behavior
15
+
16
+ - Harassment, threats, or personal attacks.
17
+ - Sexualized language or attention.
18
+ - Publishing private information without permission.
19
+ - Sustained disruption of project discussions.
20
+
21
+ ## Enforcement
22
+
23
+ Maintainers may remove comments, close issues, block participants, or take other reasonable action to protect the project community.
24
+
25
+ Report security-sensitive issues through `SECURITY.md`. For conduct issues, contact a project maintainer through GitHub Issues or the maintainer profile listed in `CODEOWNERS`.
@@ -0,0 +1,34 @@
1
+ # Contributing
2
+
3
+ Thanks for helping improve `agent-skills-ts-sdk`.
4
+
5
+ ## Development
6
+
7
+ Install dependencies with Vite+:
8
+
9
+ ```bash
10
+ vp install
11
+ ```
12
+
13
+ Run the main checks before opening a pull request:
14
+
15
+ ```bash
16
+ vp check
17
+ vp test run
18
+ vp run validate:package
19
+ ```
20
+
21
+ ## Implementation Notes
22
+
23
+ - Keep the public package shape compatible with the published package:
24
+ `dist/index.js` and `dist/index.d.ts`.
25
+ - Keep parser and validator behavior aligned with the AgentSkills
26
+ specification and the Python reference implementation where applicable.
27
+ - Add focused tests for parser, validator, prompt, disclosure, and patch
28
+ behavior instead of broad snapshot tests.
29
+
30
+ ## Releases
31
+
32
+ The release workflow validates the package, versions through Changesets, and
33
+ publishes through npm trusted publishing from
34
+ `WebMCP-org/agent-skills-ts-sdk`. See `docs/release.md`.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 mcp-b contributors
3
+ Copyright (c) 2026 agent-skills-ts-sdk contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
package/PRIVACY.md ADDED
@@ -0,0 +1,15 @@
1
+ # Privacy
2
+
3
+ `agent-skills-ts-sdk` is an open-source TypeScript library. The library itself
4
+ does not operate a hosted service, collect analytics, or transmit data to the
5
+ package maintainers.
6
+
7
+ At runtime, the library parses and validates skill content supplied by the
8
+ consuming application. Applications that use this package control where skill
9
+ content is loaded from, how validation results are stored, and whether any
10
+ parsed data is sent to another service.
11
+
12
+ This repository uses development tools such as package managers and CI
13
+ services. Those tools may have their own telemetry or logs when contributors
14
+ run them or when maintainers run CI. That behavior is outside the runtime
15
+ behavior of the published library.
package/README.md CHANGED
@@ -21,12 +21,27 @@ Agent Skills are folders of instructions, scripts, and resources that agents can
21
21
  pnpm add agent-skills-ts-sdk
22
22
  ```
23
23
 
24
+ ## Playground
25
+
26
+ This repo includes a small browser-run React playground for trying the SDK
27
+ against editable `SKILL.md` content.
28
+
29
+ ```bash
30
+ pnpm playground:dev
31
+ ```
32
+
33
+ The playground shows live browser-side parsing and validation, prompt metadata,
34
+ token estimates, patch generation, IndexedDB storage, and raw/rendered Markdown
35
+ previews using the same SDK entry points. It also includes a CopilotKit-rendered
36
+ mock agent transcript that simulates a model reading and using the active skill
37
+ without any backend LLM call.
38
+
24
39
  ## Usage
25
40
 
26
41
  ### Parsing SKILL.md
27
42
 
28
43
  ```typescript
29
- import { parseSkillContent, validateSkillContent } from 'agent-skills-ts-sdk';
44
+ import { parseSkillContent, validateSkillContent } from "agent-skills-ts-sdk";
30
45
 
31
46
  const content = `---
32
47
  name: my-skill
@@ -40,7 +55,7 @@ const { properties, body } = parseSkillContent(content);
40
55
 
41
56
  const errors = validateSkillContent(content);
42
57
  if (errors.length > 0) {
43
- console.error('Validation errors:', errors);
58
+ console.error("Validation errors:", errors);
44
59
  }
45
60
  ```
46
61
 
@@ -49,18 +64,18 @@ newline), opt in explicitly:
49
64
 
50
65
  ```typescript
51
66
  const { properties, body } = parseSkillContent(contentFromDom, {
52
- inputMode: 'embedded',
67
+ inputMode: "embedded",
53
68
  });
54
69
  ```
55
70
 
56
71
  ### Validation
57
72
 
58
73
  ```typescript
59
- import { validateSkillProperties } from 'agent-skills-ts-sdk';
74
+ import { validateSkillProperties } from "agent-skills-ts-sdk";
60
75
 
61
76
  const properties = {
62
- name: 'my-skill',
63
- description: 'A test skill',
77
+ name: "my-skill",
78
+ description: "A test skill",
64
79
  };
65
80
 
66
81
  const errors = validateSkillProperties(properties);
@@ -69,9 +84,9 @@ const errors = validateSkillProperties(properties);
69
84
  ### In-memory file lists (Durable Objects or other non-filesystem hosts)
70
85
 
71
86
  ```typescript
72
- import { findSkillMdFile, readSkillProperties, validateSkillEntries } from 'agent-skills-ts-sdk';
87
+ import { findSkillMdFile, readSkillProperties, validateSkillEntries } from "agent-skills-ts-sdk";
73
88
 
74
- const files = [{ name: 'SKILL.md', content: skillMarkdown }];
89
+ const files = [{ name: "SKILL.md", content: skillMarkdown }];
75
90
 
76
91
  const entry = findSkillMdFile(files);
77
92
  const properties = readSkillProperties(files);
@@ -81,9 +96,9 @@ const errors = validateSkillEntries(files, { expectedName: properties.name });
81
96
  ### Prompt generation
82
97
 
83
98
  ```typescript
84
- import { toPrompt } from 'agent-skills-ts-sdk';
99
+ import { toPrompt } from "agent-skills-ts-sdk";
85
100
 
86
- const promptBlock = toPrompt([{ content: skillMarkdown, location: 'skills/my-skill/SKILL.md' }]);
101
+ const promptBlock = toPrompt([{ content: skillMarkdown, location: "skills/my-skill/SKILL.md" }]);
87
102
  ```
88
103
 
89
104
  ### Progressive disclosure helpers
@@ -94,21 +109,21 @@ import {
94
109
  toDisclosureInstructions,
95
110
  toDisclosurePrompt,
96
111
  toReadToolSchema,
97
- } from 'agent-skills-ts-sdk';
112
+ } from "agent-skills-ts-sdk";
98
113
 
99
- const instructions = toDisclosureInstructions({ toolName: 'read_site_context' });
114
+ const instructions = toDisclosureInstructions({ toolName: "read_site_context" });
100
115
  const skillsXml = toDisclosurePrompt([
101
- { name: 'pizza-maker', description: 'Interactive pizza builder', resources: ['build-pizza'] },
116
+ { name: "pizza-maker", description: "Interactive pizza builder", resources: ["build-pizza"] },
102
117
  ]);
103
- const readTool = toReadToolSchema([{ name: 'pizza-maker' }], {
104
- toolName: 'read_site_context',
118
+ const readTool = toReadToolSchema([{ name: "pizza-maker" }], {
119
+ toolName: "read_site_context",
105
120
  });
106
121
  ```
107
122
 
108
123
  ### Diff + patch
109
124
 
110
125
  ```typescript
111
- import { createSkillPatch, applySkillPatch } from 'agent-skills-ts-sdk';
126
+ import { createSkillPatch, applySkillPatch } from "agent-skills-ts-sdk";
112
127
 
113
128
  const patch = createSkillPatch(oldContent, newContent);
114
129
  const result = applySkillPatch(oldContent, patch);
@@ -132,7 +147,7 @@ if (!result.ok) {
132
147
 
133
148
  ### Validation
134
149
 
135
- - `validateSkillProperties` enforces the name/description/compatibility rules and optionally checks an expected name.
150
+ - `validateSkillProperties` enforces field types, name/description/compatibility rules, and optionally checks an expected name.
136
151
  - `validateSkillContent` validates a single SKILL.md string, including unknown frontmatter fields.
137
152
  - `validateSkillEntries` mirrors `skills-ref validate` for in-memory file lists while letting the host surface path and directory state.
138
153
 
@@ -176,8 +191,8 @@ are surfaced through `validateSkillEntries` so hosts can supply their own storag
176
191
  ### Optional Fields
177
192
 
178
193
  - `license`
179
- - `compatibility` (max 500 chars)
180
- - `metadata` (key-value pairs)
194
+ - `compatibility` (1-500 chars when present)
195
+ - `metadata` (string key-value pairs)
181
196
  - `allowed-tools` (experimental)
182
197
 
183
198
  ### Validation Rules
@@ -194,13 +209,13 @@ This package follows Test-Driven Development with comprehensive test coverage:
194
209
 
195
210
  ```bash
196
211
  # Run tests
197
- pnpm test
212
+ vp test
198
213
 
199
- # Run tests in watch mode
200
- pnpm test:watch
214
+ # Run formatting, linting, and type checks
215
+ vp check
201
216
 
202
217
  # Generate coverage report
203
- pnpm test:coverage
218
+ vp run test:coverage
204
219
  ```
205
220
 
206
221
  **Coverage goals:**
package/SECURITY.md ADDED
@@ -0,0 +1,13 @@
1
+ # Security Policy
2
+
3
+ ## Reporting a Vulnerability
4
+
5
+ Report suspected vulnerabilities through GitHub private vulnerability reporting for this repository:
6
+
7
+ https://github.com/WebMCP-org/agent-skills-ts-sdk/security/advisories/new
8
+
9
+ Do not open a public issue for a vulnerability report. Include the affected version, reproduction details, expected impact, and any known workaround.
10
+
11
+ ## Supported Versions
12
+
13
+ Security fixes are provided for the latest published major version unless a separate support policy is documented in a release note.