@agentforge/skills 0.16.59 → 0.16.61

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentforge/skills",
3
- "version": "0.16.59",
3
+ "version": "0.16.61",
4
4
  "description": "Composable skill system for building modular TypeScript AI agents: author skills, register capabilities, and compose behaviors.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,7 +18,7 @@
18
18
  "README.md"
19
19
  ],
20
20
  "dependencies": {
21
- "@agentforge/core": "0.16.59",
21
+ "@agentforge/core": "0.16.61",
22
22
  "gray-matter": "^4.0.3",
23
23
  "zod": "^3.24.1"
24
24
  },
package/dist/index.d.cts DELETED
@@ -1,460 +0,0 @@
1
- import { Tool } from '@agentforge/core';
2
- import { z } from 'zod';
3
-
4
- /**
5
- * Skill System Types
6
- *
7
- * Core type definitions for the AgentForge Agent Skills system.
8
- * These types align with the Agent Skills specification (https://agentskills.io/specification).
9
- */
10
- /**
11
- * Trust level for a skill root directory.
12
- *
13
- * - `workspace` — Skills from the project workspace (highest trust, scripts allowed)
14
- * - `trusted` — Explicitly trusted skill roots (scripts allowed)
15
- * - `untrusted` — Untrusted roots like community packs (scripts blocked by default)
16
- */
17
- type TrustLevel = 'workspace' | 'trusted' | 'untrusted';
18
- /**
19
- * Configuration for a skill root with an explicit trust level.
20
- *
21
- * @example
22
- * ```ts
23
- * const roots: SkillRootConfig[] = [
24
- * { path: '.agentskills', trust: 'workspace' },
25
- * { path: '~/.agentskills', trust: 'trusted' },
26
- * { path: '/shared/community-skills', trust: 'untrusted' },
27
- * ];
28
- * ```
29
- */
30
- interface SkillRootConfig {
31
- /** Directory path to scan for skills */
32
- path: string;
33
- /** Trust level assigned to all skills discovered from this root */
34
- trust: TrustLevel;
35
- }
36
- /**
37
- * Policy decision returned by trust enforcement checks.
38
- */
39
- interface TrustPolicyDecision {
40
- /** Whether the action is allowed */
41
- allowed: boolean;
42
- /** Machine-readable reason code for auditing */
43
- reason: TrustPolicyReason;
44
- /** Human-readable explanation */
45
- message: string;
46
- }
47
- /**
48
- * Reason codes for trust policy decisions.
49
- *
50
- * Used for structured logging and auditing of guardrail behavior.
51
- */
52
- declare enum TrustPolicyReason {
53
- /** Resource is not a script — no trust check needed */
54
- NOT_SCRIPT = "not-script",
55
- /** Skill root has workspace trust — scripts allowed */
56
- WORKSPACE_TRUST = "workspace-trust",
57
- /** Skill root has explicit trusted status — scripts allowed */
58
- TRUSTED_ROOT = "trusted-root",
59
- /** Skill root is untrusted — scripts denied by default */
60
- UNTRUSTED_SCRIPT_DENIED = "untrusted-script-denied",
61
- /** Untrusted script access was explicitly allowed via config override */
62
- UNTRUSTED_SCRIPT_ALLOWED = "untrusted-script-allowed-override",
63
- /** Trust level is unknown — treated as untrusted for security */
64
- UNKNOWN_TRUST_LEVEL = "unknown-trust-level"
65
- }
66
- /**
67
- * Parsed metadata from a SKILL.md frontmatter block.
68
- *
69
- * Required fields: `name`, `description`.
70
- * All other fields are optional per the Agent Skills spec.
71
- */
72
- interface SkillMetadata {
73
- /** Skill name (1-64 chars, lowercase alphanumeric + hyphens, must match parent dir name) */
74
- name: string;
75
- /** Human-readable description (1-1024 chars) */
76
- description: string;
77
- /** SPDX license identifier */
78
- license?: string;
79
- /** List of compatible agent frameworks / tool hosts */
80
- compatibility?: string[];
81
- /** Arbitrary key-value metadata (author, version, etc.) */
82
- metadata?: Record<string, unknown>;
83
- /** Tools that this skill is allowed to use */
84
- allowedTools?: string[];
85
- }
86
- /**
87
- * A fully resolved skill entry in the registry.
88
- *
89
- * Contains parsed metadata plus internal tracking fields
90
- * that are not part of the SKILL.md frontmatter.
91
- */
92
- interface Skill {
93
- /** Parsed frontmatter metadata */
94
- metadata: SkillMetadata;
95
- /** Absolute path to the skill directory */
96
- skillPath: string;
97
- /** Which configured skill root this was discovered from */
98
- rootPath: string;
99
- /** Trust level assigned to this skill (inherited from root config) */
100
- trustLevel: TrustLevel;
101
- }
102
- /**
103
- * Configuration for the SkillRegistry.
104
- */
105
- interface SkillRegistryConfig {
106
- /**
107
- * Array of directory paths to scan for skills.
108
- *
109
- * Each entry can be a plain string (defaults to `'untrusted'` trust level)
110
- * or a `SkillRootConfig` object with an explicit trust level.
111
- *
112
- * Paths may be absolute or relative (resolved against `cwd`).
113
- * The `~` prefix is expanded to `$HOME`.
114
- *
115
- * @example
116
- * ```ts
117
- * // Simple string roots (default to 'untrusted')
118
- * skillRoots: ['.agentskills', '~/.agentskills']
119
- *
120
- * // Trust-aware roots
121
- * skillRoots: [
122
- * { path: '.agentskills', trust: 'workspace' },
123
- * { path: '~/.agentskills', trust: 'trusted' },
124
- * { path: '/shared/community', trust: 'untrusted' },
125
- * ]
126
- * ```
127
- */
128
- skillRoots: Array<string | SkillRootConfig>;
129
- /**
130
- * Feature flag to enable Agent Skills in system prompts.
131
- *
132
- * When `false` (default), `generatePrompt()` returns an empty string
133
- * so agents operate with unmodified system prompts.
134
- *
135
- * @default false
136
- */
137
- enabled?: boolean;
138
- /**
139
- * Maximum number of skills to include in generated prompts.
140
- *
141
- * Caps prompt token usage when many skills are discovered.
142
- * Skills are included in discovery order (first root first).
143
- * When undefined, all discovered skills are included.
144
- */
145
- maxDiscoveredSkills?: number;
146
- /**
147
- * Allow script resources from untrusted roots.
148
- *
149
- * When `true`, scripts from `scripts/` directories in untrusted
150
- * skill roots are returned instead of being denied. This disables
151
- * the default-deny policy for untrusted scripts.
152
- *
153
- * **Security warning:** Only enable when you have reviewed all
154
- * skill packs from untrusted roots.
155
- *
156
- * @default false
157
- */
158
- allowUntrustedScripts?: boolean;
159
- }
160
- /**
161
- * Options for `SkillRegistry.generatePrompt()`.
162
- */
163
- interface SkillPromptOptions {
164
- /**
165
- * Subset of skill names to include in the generated prompt.
166
- *
167
- * When provided, only skills matching these names appear in the
168
- * `<available_skills>` XML block. This enables creating focused
169
- * agents with different skill sets from the same registry.
170
- *
171
- * When omitted or empty, all discovered skills are included.
172
- *
173
- * @example ['code-review', 'testing-strategy']
174
- */
175
- skills?: string[];
176
- }
177
- /**
178
- * Events emitted by the SkillRegistry during discovery and usage.
179
- */
180
- declare enum SkillRegistryEvent {
181
- /** Emitted when a valid skill is discovered during scanning */
182
- SKILL_DISCOVERED = "skill:discovered",
183
- /** Emitted when a skill parse or validation issue is encountered */
184
- SKILL_WARNING = "skill:warning",
185
- /** Emitted when a skill is activated (full body loaded) */
186
- SKILL_ACTIVATED = "skill:activated",
187
- /** Emitted when a skill resource file is loaded */
188
- SKILL_RESOURCE_LOADED = "skill:resource-loaded",
189
- /** Emitted when a trust policy denies access to a resource */
190
- TRUST_POLICY_DENIED = "trust:policy-denied",
191
- /** Emitted when a trust policy allows access (for auditing) */
192
- TRUST_POLICY_ALLOWED = "trust:policy-allowed"
193
- }
194
- /**
195
- * Event handler type for skill registry events.
196
- */
197
- type SkillEventHandler = (data: unknown) => void;
198
- /**
199
- * Result of parsing a single SKILL.md file.
200
- */
201
- interface SkillParseResult {
202
- /** Whether parsing and validation succeeded */
203
- success: boolean;
204
- /** Parsed metadata (present when success is true) */
205
- metadata?: SkillMetadata;
206
- /** The raw markdown body below the frontmatter (present when success is true) */
207
- body?: string;
208
- /** Error description (present when success is false) */
209
- error?: string;
210
- }
211
- /**
212
- * Validation error detail.
213
- */
214
- interface SkillValidationError {
215
- /** Which field failed validation */
216
- field: string;
217
- /** Human-readable error message */
218
- message: string;
219
- }
220
-
221
- /**
222
- * SKILL.md Frontmatter Parser
223
- *
224
- * Parses YAML frontmatter from SKILL.md files and validates
225
- * against the Agent Skills specification constraints.
226
- *
227
- * @see https://agentskills.io/specification
228
- */
229
-
230
- /**
231
- * Validate the `name` field per the Agent Skills spec.
232
- *
233
- * @param name - The name value from frontmatter
234
- * @returns Array of validation errors (empty = valid)
235
- */
236
- declare function validateSkillName(name: unknown): SkillValidationError[];
237
- /**
238
- * Validate the `description` field per the Agent Skills spec.
239
- *
240
- * @param description - The description value from frontmatter
241
- * @returns Array of validation errors (empty = valid)
242
- */
243
- declare function validateSkillDescription(description: unknown): SkillValidationError[];
244
- /**
245
- * Validate that the skill name matches its parent directory name (per spec).
246
- *
247
- * @param name - The name from frontmatter
248
- * @param dirName - The parent directory name
249
- * @returns Array of validation errors (empty = valid)
250
- */
251
- declare function validateSkillNameMatchesDir(name: string, dirName: string): SkillValidationError[];
252
- /**
253
- * Parse and validate a SKILL.md file's raw content.
254
- *
255
- * Extracts YAML frontmatter using gray-matter, then validates
256
- * required and optional fields against spec constraints.
257
- *
258
- * @param content - Raw file content of the SKILL.md
259
- * @param dirName - Parent directory name for name-match validation
260
- * @returns Parse result with metadata or error
261
- */
262
- declare function parseSkillContent(content: string, dirName: string): SkillParseResult;
263
-
264
- /**
265
- * Skill Directory Scanner
266
- *
267
- * Scans configured skill roots for directories containing valid SKILL.md files.
268
- * Returns a list of candidate skill paths for the parser to process.
269
- */
270
- /**
271
- * Discovered skill candidate — a directory containing a SKILL.md file.
272
- */
273
- interface SkillCandidate {
274
- /** Absolute path to the skill directory */
275
- skillPath: string;
276
- /** The parent directory name (expected to match the skill name) */
277
- dirName: string;
278
- /** Raw content of the SKILL.md file */
279
- content: string;
280
- /** Which configured root this came from */
281
- rootPath: string;
282
- }
283
- /**
284
- * Expand `~` prefix to the user's home directory.
285
- */
286
- declare function expandHome(p: string): string;
287
- /**
288
- * Scan a single skill root for directories containing SKILL.md.
289
- *
290
- * @param rootPath - The root directory to scan (may not exist)
291
- * @returns Array of valid skill candidates found under this root
292
- */
293
- declare function scanSkillRoot(rootPath: string): SkillCandidate[];
294
- /**
295
- * Scan multiple skill roots for directories containing SKILL.md.
296
- *
297
- * @param skillRoots - Array of root paths to scan
298
- * @returns Array of all skill candidates found across all roots
299
- */
300
- declare function scanAllSkillRoots(skillRoots: string[]): SkillCandidate[];
301
-
302
- declare const activateSkillSchema: z.ZodObject<{
303
- name: z.ZodString;
304
- }, "strip", z.ZodTypeAny, {
305
- name: string;
306
- }, {
307
- name: string;
308
- }>;
309
- declare const readSkillResourceSchema: z.ZodObject<{
310
- name: z.ZodString;
311
- path: z.ZodString;
312
- }, "strip", z.ZodTypeAny, {
313
- name: string;
314
- path: string;
315
- }, {
316
- name: string;
317
- path: string;
318
- }>;
319
-
320
- /**
321
- * Create the `activate-skill` tool bound to a registry instance.
322
- *
323
- * Resolves the skill by name, reads the full SKILL.md file, and returns
324
- * the body content (below frontmatter).
325
- *
326
- * @param registry - The SkillRegistry to resolve skills from
327
- * @returns An AgentForge Tool
328
- */
329
- declare function createActivateSkillTool(registry: SkillRegistry): Tool<z.infer<typeof activateSkillSchema>, string>;
330
-
331
- /**
332
- * Resolve a resource path within a skill root, blocking path traversal.
333
- *
334
- * @param skillPath - Absolute path to the skill directory
335
- * @param resourcePath - Relative path to the resource file
336
- * @returns Absolute path to the resource, or an error string
337
- */
338
- declare function resolveResourcePath(skillPath: string, resourcePath: string): {
339
- success: true;
340
- resolvedPath: string;
341
- } | {
342
- success: false;
343
- error: string;
344
- };
345
-
346
- /**
347
- * Create the `read-skill-resource` tool bound to a registry instance.
348
- *
349
- * Resolves the skill by name, validates the resource path (blocking
350
- * traversal), and returns the file content.
351
- *
352
- * @param registry - The SkillRegistry to resolve skills from
353
- * @returns An AgentForge Tool
354
- */
355
- declare function createReadSkillResourceTool(registry: SkillRegistry): Tool<z.infer<typeof readSkillResourceSchema>, string>;
356
-
357
- /**
358
- * Skill Activation Tools
359
- *
360
- * Provides `activate-skill` and `read-skill-resource` tools built with
361
- * the AgentForge tool builder API. These tools enable agents to load
362
- * skill instructions on demand and access skill resources at runtime.
363
- *
364
- * @see https://agentskills.io/specification
365
- *
366
- * @example
367
- * ```ts
368
- * const [activateSkill, readSkillResource] = createSkillActivationTools(registry);
369
- * // activateSkill — load full SKILL.md body
370
- * // readSkillResource — load a resource file from a skill
371
- *
372
- * // Or use the convenience method:
373
- * const [activateSkill, readSkillResource] = registry.toActivationTools();
374
- * ```
375
- */
376
-
377
- /**
378
- * Create both skill activation tools bound to a registry instance.
379
- *
380
- * @param registry - The SkillRegistry to bind tools to
381
- * @returns Array of both tools [activate-skill, read-skill-resource]
382
- */
383
- declare function createSkillActivationTools(registry: SkillRegistry): [Tool<z.infer<typeof activateSkillSchema>, string>, Tool<z.infer<typeof readSkillResourceSchema>, string>];
384
-
385
- declare class SkillRegistry {
386
- private skills;
387
- private eventHandlers;
388
- private readonly config;
389
- private scanErrors;
390
- private rootTrustMap;
391
- constructor(config: SkillRegistryConfig);
392
- discover(): void;
393
- get(name: string): Skill | undefined;
394
- getAll(): Skill[];
395
- has(name: string): boolean;
396
- size(): number;
397
- getNames(): string[];
398
- getScanErrors(): ReadonlyArray<{
399
- path: string;
400
- error: string;
401
- }>;
402
- getAllowUntrustedScripts(): boolean;
403
- getAllowedTools(name: string): string[] | undefined;
404
- generatePrompt(options?: SkillPromptOptions): string;
405
- on(event: SkillRegistryEvent, handler: SkillEventHandler): void;
406
- off(event: SkillRegistryEvent, handler: SkillEventHandler): void;
407
- emitEvent(event: SkillRegistryEvent, data: unknown): void;
408
- toActivationTools(): ReturnType<typeof createSkillActivationTools>;
409
- private emit;
410
- }
411
-
412
- /**
413
- * Skill Trust Policy Engine
414
- *
415
- * Enforces trust-level-based access control for skill resources.
416
- * Scripts from untrusted roots are denied by default unless explicitly allowed.
417
- *
418
- * Trust levels:
419
- * - `workspace` — Project-local skills, highest trust. Scripts always allowed.
420
- * - `trusted` — Explicitly trusted roots. Scripts allowed.
421
- * - `untrusted` — Community or third-party skills. Scripts denied by default.
422
- *
423
- * @see https://agentskills.io/specification
424
- */
425
-
426
- /**
427
- * Normalize a skill root config entry.
428
- *
429
- * String entries default to `'untrusted'` trust level for safe defaults.
430
- *
431
- * @param root - A string path or SkillRootConfig object
432
- * @returns Normalized SkillRootConfig with explicit trust level
433
- */
434
- declare function normalizeRootConfig(root: string | SkillRootConfig): SkillRootConfig;
435
- /**
436
- * Check whether a resource path refers to a script.
437
- *
438
- * A resource is considered a script if its relative path starts with
439
- * `scripts/` or is exactly `scripts`, after normalizing path separators,
440
- * stripping leading "./" segments, and ignoring case.
441
- *
442
- * @param resourcePath - Relative path within the skill directory
443
- * @returns True if the resource is in the scripts/ directory
444
- */
445
- declare function isScriptResource(resourcePath: string): boolean;
446
- /**
447
- * Evaluate the trust policy for a resource access request.
448
- *
449
- * Non-script resources are always allowed regardless of trust level.
450
- * Script resources require `workspace` or `trusted` trust, or the
451
- * `allowUntrustedScripts` override to be enabled.
452
- *
453
- * @param resourcePath - Relative path to the resource within the skill directory
454
- * @param trustLevel - Trust level of the skill's root directory
455
- * @param allowUntrustedScripts - Override flag to permit untrusted scripts
456
- * @returns Policy decision with allow/deny, reason code, and message
457
- */
458
- declare function evaluateTrustPolicy(resourcePath: string, trustLevel: TrustLevel, allowUntrustedScripts?: boolean): TrustPolicyDecision;
459
-
460
- export { type Skill, type SkillCandidate, type SkillEventHandler, type SkillMetadata, type SkillParseResult, type SkillPromptOptions, SkillRegistry, type SkillRegistryConfig, SkillRegistryEvent, type SkillRootConfig, type SkillValidationError, type TrustLevel, type TrustPolicyDecision, TrustPolicyReason, createActivateSkillTool, createReadSkillResourceTool, createSkillActivationTools, evaluateTrustPolicy, expandHome, isScriptResource, normalizeRootConfig, parseSkillContent, resolveResourcePath, scanAllSkillRoots, scanSkillRoot, validateSkillDescription, validateSkillName, validateSkillNameMatchesDir };
package/dist/index.d.ts DELETED
@@ -1,460 +0,0 @@
1
- import { Tool } from '@agentforge/core';
2
- import { z } from 'zod';
3
-
4
- /**
5
- * Skill System Types
6
- *
7
- * Core type definitions for the AgentForge Agent Skills system.
8
- * These types align with the Agent Skills specification (https://agentskills.io/specification).
9
- */
10
- /**
11
- * Trust level for a skill root directory.
12
- *
13
- * - `workspace` — Skills from the project workspace (highest trust, scripts allowed)
14
- * - `trusted` — Explicitly trusted skill roots (scripts allowed)
15
- * - `untrusted` — Untrusted roots like community packs (scripts blocked by default)
16
- */
17
- type TrustLevel = 'workspace' | 'trusted' | 'untrusted';
18
- /**
19
- * Configuration for a skill root with an explicit trust level.
20
- *
21
- * @example
22
- * ```ts
23
- * const roots: SkillRootConfig[] = [
24
- * { path: '.agentskills', trust: 'workspace' },
25
- * { path: '~/.agentskills', trust: 'trusted' },
26
- * { path: '/shared/community-skills', trust: 'untrusted' },
27
- * ];
28
- * ```
29
- */
30
- interface SkillRootConfig {
31
- /** Directory path to scan for skills */
32
- path: string;
33
- /** Trust level assigned to all skills discovered from this root */
34
- trust: TrustLevel;
35
- }
36
- /**
37
- * Policy decision returned by trust enforcement checks.
38
- */
39
- interface TrustPolicyDecision {
40
- /** Whether the action is allowed */
41
- allowed: boolean;
42
- /** Machine-readable reason code for auditing */
43
- reason: TrustPolicyReason;
44
- /** Human-readable explanation */
45
- message: string;
46
- }
47
- /**
48
- * Reason codes for trust policy decisions.
49
- *
50
- * Used for structured logging and auditing of guardrail behavior.
51
- */
52
- declare enum TrustPolicyReason {
53
- /** Resource is not a script — no trust check needed */
54
- NOT_SCRIPT = "not-script",
55
- /** Skill root has workspace trust — scripts allowed */
56
- WORKSPACE_TRUST = "workspace-trust",
57
- /** Skill root has explicit trusted status — scripts allowed */
58
- TRUSTED_ROOT = "trusted-root",
59
- /** Skill root is untrusted — scripts denied by default */
60
- UNTRUSTED_SCRIPT_DENIED = "untrusted-script-denied",
61
- /** Untrusted script access was explicitly allowed via config override */
62
- UNTRUSTED_SCRIPT_ALLOWED = "untrusted-script-allowed-override",
63
- /** Trust level is unknown — treated as untrusted for security */
64
- UNKNOWN_TRUST_LEVEL = "unknown-trust-level"
65
- }
66
- /**
67
- * Parsed metadata from a SKILL.md frontmatter block.
68
- *
69
- * Required fields: `name`, `description`.
70
- * All other fields are optional per the Agent Skills spec.
71
- */
72
- interface SkillMetadata {
73
- /** Skill name (1-64 chars, lowercase alphanumeric + hyphens, must match parent dir name) */
74
- name: string;
75
- /** Human-readable description (1-1024 chars) */
76
- description: string;
77
- /** SPDX license identifier */
78
- license?: string;
79
- /** List of compatible agent frameworks / tool hosts */
80
- compatibility?: string[];
81
- /** Arbitrary key-value metadata (author, version, etc.) */
82
- metadata?: Record<string, unknown>;
83
- /** Tools that this skill is allowed to use */
84
- allowedTools?: string[];
85
- }
86
- /**
87
- * A fully resolved skill entry in the registry.
88
- *
89
- * Contains parsed metadata plus internal tracking fields
90
- * that are not part of the SKILL.md frontmatter.
91
- */
92
- interface Skill {
93
- /** Parsed frontmatter metadata */
94
- metadata: SkillMetadata;
95
- /** Absolute path to the skill directory */
96
- skillPath: string;
97
- /** Which configured skill root this was discovered from */
98
- rootPath: string;
99
- /** Trust level assigned to this skill (inherited from root config) */
100
- trustLevel: TrustLevel;
101
- }
102
- /**
103
- * Configuration for the SkillRegistry.
104
- */
105
- interface SkillRegistryConfig {
106
- /**
107
- * Array of directory paths to scan for skills.
108
- *
109
- * Each entry can be a plain string (defaults to `'untrusted'` trust level)
110
- * or a `SkillRootConfig` object with an explicit trust level.
111
- *
112
- * Paths may be absolute or relative (resolved against `cwd`).
113
- * The `~` prefix is expanded to `$HOME`.
114
- *
115
- * @example
116
- * ```ts
117
- * // Simple string roots (default to 'untrusted')
118
- * skillRoots: ['.agentskills', '~/.agentskills']
119
- *
120
- * // Trust-aware roots
121
- * skillRoots: [
122
- * { path: '.agentskills', trust: 'workspace' },
123
- * { path: '~/.agentskills', trust: 'trusted' },
124
- * { path: '/shared/community', trust: 'untrusted' },
125
- * ]
126
- * ```
127
- */
128
- skillRoots: Array<string | SkillRootConfig>;
129
- /**
130
- * Feature flag to enable Agent Skills in system prompts.
131
- *
132
- * When `false` (default), `generatePrompt()` returns an empty string
133
- * so agents operate with unmodified system prompts.
134
- *
135
- * @default false
136
- */
137
- enabled?: boolean;
138
- /**
139
- * Maximum number of skills to include in generated prompts.
140
- *
141
- * Caps prompt token usage when many skills are discovered.
142
- * Skills are included in discovery order (first root first).
143
- * When undefined, all discovered skills are included.
144
- */
145
- maxDiscoveredSkills?: number;
146
- /**
147
- * Allow script resources from untrusted roots.
148
- *
149
- * When `true`, scripts from `scripts/` directories in untrusted
150
- * skill roots are returned instead of being denied. This disables
151
- * the default-deny policy for untrusted scripts.
152
- *
153
- * **Security warning:** Only enable when you have reviewed all
154
- * skill packs from untrusted roots.
155
- *
156
- * @default false
157
- */
158
- allowUntrustedScripts?: boolean;
159
- }
160
- /**
161
- * Options for `SkillRegistry.generatePrompt()`.
162
- */
163
- interface SkillPromptOptions {
164
- /**
165
- * Subset of skill names to include in the generated prompt.
166
- *
167
- * When provided, only skills matching these names appear in the
168
- * `<available_skills>` XML block. This enables creating focused
169
- * agents with different skill sets from the same registry.
170
- *
171
- * When omitted or empty, all discovered skills are included.
172
- *
173
- * @example ['code-review', 'testing-strategy']
174
- */
175
- skills?: string[];
176
- }
177
- /**
178
- * Events emitted by the SkillRegistry during discovery and usage.
179
- */
180
- declare enum SkillRegistryEvent {
181
- /** Emitted when a valid skill is discovered during scanning */
182
- SKILL_DISCOVERED = "skill:discovered",
183
- /** Emitted when a skill parse or validation issue is encountered */
184
- SKILL_WARNING = "skill:warning",
185
- /** Emitted when a skill is activated (full body loaded) */
186
- SKILL_ACTIVATED = "skill:activated",
187
- /** Emitted when a skill resource file is loaded */
188
- SKILL_RESOURCE_LOADED = "skill:resource-loaded",
189
- /** Emitted when a trust policy denies access to a resource */
190
- TRUST_POLICY_DENIED = "trust:policy-denied",
191
- /** Emitted when a trust policy allows access (for auditing) */
192
- TRUST_POLICY_ALLOWED = "trust:policy-allowed"
193
- }
194
- /**
195
- * Event handler type for skill registry events.
196
- */
197
- type SkillEventHandler = (data: unknown) => void;
198
- /**
199
- * Result of parsing a single SKILL.md file.
200
- */
201
- interface SkillParseResult {
202
- /** Whether parsing and validation succeeded */
203
- success: boolean;
204
- /** Parsed metadata (present when success is true) */
205
- metadata?: SkillMetadata;
206
- /** The raw markdown body below the frontmatter (present when success is true) */
207
- body?: string;
208
- /** Error description (present when success is false) */
209
- error?: string;
210
- }
211
- /**
212
- * Validation error detail.
213
- */
214
- interface SkillValidationError {
215
- /** Which field failed validation */
216
- field: string;
217
- /** Human-readable error message */
218
- message: string;
219
- }
220
-
221
- /**
222
- * SKILL.md Frontmatter Parser
223
- *
224
- * Parses YAML frontmatter from SKILL.md files and validates
225
- * against the Agent Skills specification constraints.
226
- *
227
- * @see https://agentskills.io/specification
228
- */
229
-
230
- /**
231
- * Validate the `name` field per the Agent Skills spec.
232
- *
233
- * @param name - The name value from frontmatter
234
- * @returns Array of validation errors (empty = valid)
235
- */
236
- declare function validateSkillName(name: unknown): SkillValidationError[];
237
- /**
238
- * Validate the `description` field per the Agent Skills spec.
239
- *
240
- * @param description - The description value from frontmatter
241
- * @returns Array of validation errors (empty = valid)
242
- */
243
- declare function validateSkillDescription(description: unknown): SkillValidationError[];
244
- /**
245
- * Validate that the skill name matches its parent directory name (per spec).
246
- *
247
- * @param name - The name from frontmatter
248
- * @param dirName - The parent directory name
249
- * @returns Array of validation errors (empty = valid)
250
- */
251
- declare function validateSkillNameMatchesDir(name: string, dirName: string): SkillValidationError[];
252
- /**
253
- * Parse and validate a SKILL.md file's raw content.
254
- *
255
- * Extracts YAML frontmatter using gray-matter, then validates
256
- * required and optional fields against spec constraints.
257
- *
258
- * @param content - Raw file content of the SKILL.md
259
- * @param dirName - Parent directory name for name-match validation
260
- * @returns Parse result with metadata or error
261
- */
262
- declare function parseSkillContent(content: string, dirName: string): SkillParseResult;
263
-
264
- /**
265
- * Skill Directory Scanner
266
- *
267
- * Scans configured skill roots for directories containing valid SKILL.md files.
268
- * Returns a list of candidate skill paths for the parser to process.
269
- */
270
- /**
271
- * Discovered skill candidate — a directory containing a SKILL.md file.
272
- */
273
- interface SkillCandidate {
274
- /** Absolute path to the skill directory */
275
- skillPath: string;
276
- /** The parent directory name (expected to match the skill name) */
277
- dirName: string;
278
- /** Raw content of the SKILL.md file */
279
- content: string;
280
- /** Which configured root this came from */
281
- rootPath: string;
282
- }
283
- /**
284
- * Expand `~` prefix to the user's home directory.
285
- */
286
- declare function expandHome(p: string): string;
287
- /**
288
- * Scan a single skill root for directories containing SKILL.md.
289
- *
290
- * @param rootPath - The root directory to scan (may not exist)
291
- * @returns Array of valid skill candidates found under this root
292
- */
293
- declare function scanSkillRoot(rootPath: string): SkillCandidate[];
294
- /**
295
- * Scan multiple skill roots for directories containing SKILL.md.
296
- *
297
- * @param skillRoots - Array of root paths to scan
298
- * @returns Array of all skill candidates found across all roots
299
- */
300
- declare function scanAllSkillRoots(skillRoots: string[]): SkillCandidate[];
301
-
302
- declare const activateSkillSchema: z.ZodObject<{
303
- name: z.ZodString;
304
- }, "strip", z.ZodTypeAny, {
305
- name: string;
306
- }, {
307
- name: string;
308
- }>;
309
- declare const readSkillResourceSchema: z.ZodObject<{
310
- name: z.ZodString;
311
- path: z.ZodString;
312
- }, "strip", z.ZodTypeAny, {
313
- name: string;
314
- path: string;
315
- }, {
316
- name: string;
317
- path: string;
318
- }>;
319
-
320
- /**
321
- * Create the `activate-skill` tool bound to a registry instance.
322
- *
323
- * Resolves the skill by name, reads the full SKILL.md file, and returns
324
- * the body content (below frontmatter).
325
- *
326
- * @param registry - The SkillRegistry to resolve skills from
327
- * @returns An AgentForge Tool
328
- */
329
- declare function createActivateSkillTool(registry: SkillRegistry): Tool<z.infer<typeof activateSkillSchema>, string>;
330
-
331
- /**
332
- * Resolve a resource path within a skill root, blocking path traversal.
333
- *
334
- * @param skillPath - Absolute path to the skill directory
335
- * @param resourcePath - Relative path to the resource file
336
- * @returns Absolute path to the resource, or an error string
337
- */
338
- declare function resolveResourcePath(skillPath: string, resourcePath: string): {
339
- success: true;
340
- resolvedPath: string;
341
- } | {
342
- success: false;
343
- error: string;
344
- };
345
-
346
- /**
347
- * Create the `read-skill-resource` tool bound to a registry instance.
348
- *
349
- * Resolves the skill by name, validates the resource path (blocking
350
- * traversal), and returns the file content.
351
- *
352
- * @param registry - The SkillRegistry to resolve skills from
353
- * @returns An AgentForge Tool
354
- */
355
- declare function createReadSkillResourceTool(registry: SkillRegistry): Tool<z.infer<typeof readSkillResourceSchema>, string>;
356
-
357
- /**
358
- * Skill Activation Tools
359
- *
360
- * Provides `activate-skill` and `read-skill-resource` tools built with
361
- * the AgentForge tool builder API. These tools enable agents to load
362
- * skill instructions on demand and access skill resources at runtime.
363
- *
364
- * @see https://agentskills.io/specification
365
- *
366
- * @example
367
- * ```ts
368
- * const [activateSkill, readSkillResource] = createSkillActivationTools(registry);
369
- * // activateSkill — load full SKILL.md body
370
- * // readSkillResource — load a resource file from a skill
371
- *
372
- * // Or use the convenience method:
373
- * const [activateSkill, readSkillResource] = registry.toActivationTools();
374
- * ```
375
- */
376
-
377
- /**
378
- * Create both skill activation tools bound to a registry instance.
379
- *
380
- * @param registry - The SkillRegistry to bind tools to
381
- * @returns Array of both tools [activate-skill, read-skill-resource]
382
- */
383
- declare function createSkillActivationTools(registry: SkillRegistry): [Tool<z.infer<typeof activateSkillSchema>, string>, Tool<z.infer<typeof readSkillResourceSchema>, string>];
384
-
385
- declare class SkillRegistry {
386
- private skills;
387
- private eventHandlers;
388
- private readonly config;
389
- private scanErrors;
390
- private rootTrustMap;
391
- constructor(config: SkillRegistryConfig);
392
- discover(): void;
393
- get(name: string): Skill | undefined;
394
- getAll(): Skill[];
395
- has(name: string): boolean;
396
- size(): number;
397
- getNames(): string[];
398
- getScanErrors(): ReadonlyArray<{
399
- path: string;
400
- error: string;
401
- }>;
402
- getAllowUntrustedScripts(): boolean;
403
- getAllowedTools(name: string): string[] | undefined;
404
- generatePrompt(options?: SkillPromptOptions): string;
405
- on(event: SkillRegistryEvent, handler: SkillEventHandler): void;
406
- off(event: SkillRegistryEvent, handler: SkillEventHandler): void;
407
- emitEvent(event: SkillRegistryEvent, data: unknown): void;
408
- toActivationTools(): ReturnType<typeof createSkillActivationTools>;
409
- private emit;
410
- }
411
-
412
- /**
413
- * Skill Trust Policy Engine
414
- *
415
- * Enforces trust-level-based access control for skill resources.
416
- * Scripts from untrusted roots are denied by default unless explicitly allowed.
417
- *
418
- * Trust levels:
419
- * - `workspace` — Project-local skills, highest trust. Scripts always allowed.
420
- * - `trusted` — Explicitly trusted roots. Scripts allowed.
421
- * - `untrusted` — Community or third-party skills. Scripts denied by default.
422
- *
423
- * @see https://agentskills.io/specification
424
- */
425
-
426
- /**
427
- * Normalize a skill root config entry.
428
- *
429
- * String entries default to `'untrusted'` trust level for safe defaults.
430
- *
431
- * @param root - A string path or SkillRootConfig object
432
- * @returns Normalized SkillRootConfig with explicit trust level
433
- */
434
- declare function normalizeRootConfig(root: string | SkillRootConfig): SkillRootConfig;
435
- /**
436
- * Check whether a resource path refers to a script.
437
- *
438
- * A resource is considered a script if its relative path starts with
439
- * `scripts/` or is exactly `scripts`, after normalizing path separators,
440
- * stripping leading "./" segments, and ignoring case.
441
- *
442
- * @param resourcePath - Relative path within the skill directory
443
- * @returns True if the resource is in the scripts/ directory
444
- */
445
- declare function isScriptResource(resourcePath: string): boolean;
446
- /**
447
- * Evaluate the trust policy for a resource access request.
448
- *
449
- * Non-script resources are always allowed regardless of trust level.
450
- * Script resources require `workspace` or `trusted` trust, or the
451
- * `allowUntrustedScripts` override to be enabled.
452
- *
453
- * @param resourcePath - Relative path to the resource within the skill directory
454
- * @param trustLevel - Trust level of the skill's root directory
455
- * @param allowUntrustedScripts - Override flag to permit untrusted scripts
456
- * @returns Policy decision with allow/deny, reason code, and message
457
- */
458
- declare function evaluateTrustPolicy(resourcePath: string, trustLevel: TrustLevel, allowUntrustedScripts?: boolean): TrustPolicyDecision;
459
-
460
- export { type Skill, type SkillCandidate, type SkillEventHandler, type SkillMetadata, type SkillParseResult, type SkillPromptOptions, SkillRegistry, type SkillRegistryConfig, SkillRegistryEvent, type SkillRootConfig, type SkillValidationError, type TrustLevel, type TrustPolicyDecision, TrustPolicyReason, createActivateSkillTool, createReadSkillResourceTool, createSkillActivationTools, evaluateTrustPolicy, expandHome, isScriptResource, normalizeRootConfig, parseSkillContent, resolveResourcePath, scanAllSkillRoots, scanSkillRoot, validateSkillDescription, validateSkillName, validateSkillNameMatchesDir };