@vibe-agent-toolkit/resources 0.1.0-rc.10
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/README.md +646 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/link-parser.d.ts +37 -0
- package/dist/link-parser.d.ts.map +1 -0
- package/dist/link-parser.js +327 -0
- package/dist/link-parser.js.map +1 -0
- package/dist/link-validator.d.ts +30 -0
- package/dist/link-validator.d.ts.map +1 -0
- package/dist/link-validator.js +217 -0
- package/dist/link-validator.js.map +1 -0
- package/dist/resource-registry.d.ts +278 -0
- package/dist/resource-registry.d.ts.map +1 -0
- package/dist/resource-registry.js +468 -0
- package/dist/resource-registry.js.map +1 -0
- package/dist/schemas/resource-metadata.d.ts +137 -0
- package/dist/schemas/resource-metadata.d.ts.map +1 -0
- package/dist/schemas/resource-metadata.js +61 -0
- package/dist/schemas/resource-metadata.js.map +1 -0
- package/dist/schemas/validation-result.d.ts +124 -0
- package/dist/schemas/validation-result.d.ts.map +1 -0
- package/dist/schemas/validation-result.js +47 -0
- package/dist/schemas/validation-result.js.map +1 -0
- package/dist/types.d.ts +15 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +18 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +26 -0
- package/dist/utils.js.map +1 -0
- package/package.json +60 -0
- package/src/index.ts +66 -0
- package/src/link-parser.ts +371 -0
- package/src/link-validator.ts +275 -0
- package/src/resource-registry.ts +559 -0
- package/src/schemas/resource-metadata.ts +86 -0
- package/src/schemas/validation-result.ts +55 -0
- package/src/types.ts +27 -0
- package/src/utils.ts +27 -0
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resource registry for managing collections of markdown resources.
|
|
3
|
+
*
|
|
4
|
+
* The registry maintains a collection of parsed markdown resources and provides:
|
|
5
|
+
* - Resource addition and crawling
|
|
6
|
+
* - Link validation across the registry
|
|
7
|
+
* - Link resolution (setting resolvedId for local_file links)
|
|
8
|
+
* - Query capabilities (by path, ID, or glob pattern)
|
|
9
|
+
*/
|
|
10
|
+
import type { ResourceMetadata } from './schemas/resource-metadata.js';
|
|
11
|
+
import type { ValidationResult } from './schemas/validation-result.js';
|
|
12
|
+
/**
|
|
13
|
+
* Options for crawling directories to add resources.
|
|
14
|
+
*/
|
|
15
|
+
export interface CrawlOptions {
|
|
16
|
+
/** Base directory to crawl */
|
|
17
|
+
baseDir: string;
|
|
18
|
+
/** Include patterns (default: all .md files) */
|
|
19
|
+
include?: string[];
|
|
20
|
+
/** Exclude patterns (default: node_modules, .git, dist) */
|
|
21
|
+
exclude?: string[];
|
|
22
|
+
/** Follow symbolic links (default: false) */
|
|
23
|
+
followSymlinks?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Options for ResourceRegistry constructor.
|
|
27
|
+
*/
|
|
28
|
+
export interface ResourceRegistryOptions {
|
|
29
|
+
/** Validate resources when they are added (default: false) */
|
|
30
|
+
validateOnAdd?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Statistics about resources in the registry.
|
|
34
|
+
*/
|
|
35
|
+
export interface RegistryStats {
|
|
36
|
+
totalResources: number;
|
|
37
|
+
totalLinks: number;
|
|
38
|
+
linksByType: Record<string, number>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Resource registry for managing collections of markdown resources.
|
|
42
|
+
*
|
|
43
|
+
* Provides centralized management of markdown resources with:
|
|
44
|
+
* - Automatic parsing and ID generation
|
|
45
|
+
* - Link validation across the registry
|
|
46
|
+
* - Link resolution between resources
|
|
47
|
+
* - Query capabilities
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const registry = new ResourceRegistry();
|
|
52
|
+
*
|
|
53
|
+
* // Add resources
|
|
54
|
+
* await registry.addResource('/project/README.md');
|
|
55
|
+
* await registry.crawl({ baseDir: '/project/docs' });
|
|
56
|
+
*
|
|
57
|
+
* // Validate all links
|
|
58
|
+
* const result = await registry.validate();
|
|
59
|
+
* console.log(`Found ${result.errorCount} errors`);
|
|
60
|
+
*
|
|
61
|
+
* // Resolve links between resources
|
|
62
|
+
* registry.resolveLinks();
|
|
63
|
+
*
|
|
64
|
+
* // Query resources
|
|
65
|
+
* const readme = registry.getResourceById('readme');
|
|
66
|
+
* const docs = registry.getResourcesByPattern('docs/**');
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare class ResourceRegistry {
|
|
70
|
+
private readonly resourcesByPath;
|
|
71
|
+
private readonly resourcesById;
|
|
72
|
+
private readonly validateOnAdd;
|
|
73
|
+
constructor(options?: ResourceRegistryOptions);
|
|
74
|
+
/**
|
|
75
|
+
* Add a single resource to the registry.
|
|
76
|
+
*
|
|
77
|
+
* Parses the markdown file, generates a unique ID, and stores the resource.
|
|
78
|
+
* If validateOnAdd is true, validates the resource immediately.
|
|
79
|
+
*
|
|
80
|
+
* @param filePath - Path to the markdown file (will be normalized to absolute)
|
|
81
|
+
* @returns The parsed resource metadata
|
|
82
|
+
* @throws Error if file cannot be read or parsed
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* const resource = await registry.addResource('./docs/README.md');
|
|
87
|
+
* console.log(`Added ${resource.id} with ${resource.links.length} links`);
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
addResource(filePath: string): Promise<ResourceMetadata>;
|
|
91
|
+
/**
|
|
92
|
+
* Add multiple resources to the registry in parallel.
|
|
93
|
+
*
|
|
94
|
+
* @param filePaths - Array of file paths to add
|
|
95
|
+
* @returns Array of parsed resource metadata
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const resources = await registry.addResources([
|
|
100
|
+
* './README.md',
|
|
101
|
+
* './docs/guide.md',
|
|
102
|
+
* './docs/api.md'
|
|
103
|
+
* ]);
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
addResources(filePaths: string[]): Promise<ResourceMetadata[]>;
|
|
107
|
+
/**
|
|
108
|
+
* Crawl a directory and add all matching markdown files.
|
|
109
|
+
*
|
|
110
|
+
* @param options - Crawl options (baseDir, include, exclude patterns)
|
|
111
|
+
* @returns Array of all added resources
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* // Crawl docs directory, excluding node_modules
|
|
116
|
+
* const resources = await registry.crawl({
|
|
117
|
+
* baseDir: './docs',
|
|
118
|
+
* include: ['**\/*.md'],
|
|
119
|
+
* exclude: ['**\/node_modules/**']
|
|
120
|
+
* });
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
crawl(options: CrawlOptions): Promise<ResourceMetadata[]>;
|
|
124
|
+
/**
|
|
125
|
+
* Validate all links in all resources in the registry.
|
|
126
|
+
*
|
|
127
|
+
* Checks:
|
|
128
|
+
* - local_file links: file exists, anchor valid if present
|
|
129
|
+
* - anchor links: heading exists in current file
|
|
130
|
+
* - external links: returns info (not errors)
|
|
131
|
+
* - email links: valid by default
|
|
132
|
+
* - unknown links: returns warning
|
|
133
|
+
*
|
|
134
|
+
* @returns Validation result with all issues and statistics
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const result = await registry.validate();
|
|
139
|
+
* console.log(`Passed: ${result.passed}`);
|
|
140
|
+
* console.log(`Errors: ${result.errorCount}`);
|
|
141
|
+
* console.log(`Warnings: ${result.warningCount}`);
|
|
142
|
+
* console.log(`Total resources: ${result.totalResources}`);
|
|
143
|
+
* for (const issue of result.issues) {
|
|
144
|
+
* console.log(`${issue.severity}: ${issue.message}`);
|
|
145
|
+
* }
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
validate(): Promise<ValidationResult>;
|
|
149
|
+
/**
|
|
150
|
+
* Resolve links between resources in the registry.
|
|
151
|
+
*
|
|
152
|
+
* For each local_file link, sets the resolvedId property to the ID
|
|
153
|
+
* of the target resource if it exists in the registry.
|
|
154
|
+
*
|
|
155
|
+
* Mutates the ResourceLink objects in place.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* registry.resolveLinks();
|
|
160
|
+
*
|
|
161
|
+
* // Now local_file links have resolvedId set
|
|
162
|
+
* const resource = registry.getResource('/project/README.md');
|
|
163
|
+
* for (const link of resource.links) {
|
|
164
|
+
* if (link.type === 'local_file' && link.resolvedId) {
|
|
165
|
+
* console.log(`Link resolves to: ${link.resolvedId}`);
|
|
166
|
+
* }
|
|
167
|
+
* }
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
resolveLinks(): void;
|
|
171
|
+
/**
|
|
172
|
+
* Get a resource by its file path.
|
|
173
|
+
*
|
|
174
|
+
* @param filePath - Path to the resource (will be normalized to absolute)
|
|
175
|
+
* @returns Resource metadata or undefined if not found
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* const resource = registry.getResource('./docs/README.md');
|
|
180
|
+
* if (resource) {
|
|
181
|
+
* console.log(`Found: ${resource.id}`);
|
|
182
|
+
* }
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
getResource(filePath: string): ResourceMetadata | undefined;
|
|
186
|
+
/**
|
|
187
|
+
* Get a resource by its ID.
|
|
188
|
+
*
|
|
189
|
+
* @param id - Resource ID
|
|
190
|
+
* @returns Resource metadata or undefined if not found
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* const resource = registry.getResourceById('readme');
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
getResourceById(id: string): ResourceMetadata | undefined;
|
|
198
|
+
/**
|
|
199
|
+
* Get all resources in the registry.
|
|
200
|
+
*
|
|
201
|
+
* @returns Array of all resource metadata
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* const allResources = registry.getAllResources();
|
|
206
|
+
* console.log(`Total: ${allResources.length}`);
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
getAllResources(): ResourceMetadata[];
|
|
210
|
+
/**
|
|
211
|
+
* Get resources matching a glob pattern.
|
|
212
|
+
*
|
|
213
|
+
* Normalizes paths to Unix-style (forward slashes) before matching
|
|
214
|
+
* to ensure consistent behavior across platforms. On Windows,
|
|
215
|
+
* path.resolve() returns backslashes but glob patterns expect forward slashes.
|
|
216
|
+
*
|
|
217
|
+
* @param pattern - Glob pattern (e.g., 'docs/**', '**\/README.md')
|
|
218
|
+
* @returns Array of matching resources
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```typescript
|
|
222
|
+
* const docs = registry.getResourcesByPattern('docs/**');
|
|
223
|
+
* const readmes = registry.getResourcesByPattern('**\/README.md');
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
getResourcesByPattern(pattern: string): ResourceMetadata[];
|
|
227
|
+
/**
|
|
228
|
+
* Clear all resources from the registry.
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```typescript
|
|
232
|
+
* registry.clear();
|
|
233
|
+
* console.log(registry.getAllResources().length); // 0
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
clear(): void;
|
|
237
|
+
/**
|
|
238
|
+
* Get statistics about the resources in the registry.
|
|
239
|
+
*
|
|
240
|
+
* @returns Statistics object with counts
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const stats = registry.getStats();
|
|
245
|
+
* console.log(`Resources: ${stats.totalResources}`);
|
|
246
|
+
* console.log(`Links: ${stats.totalLinks}`);
|
|
247
|
+
* console.log(`Local file links: ${stats.linksByType.local_file}`);
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
getStats(): RegistryStats;
|
|
251
|
+
/**
|
|
252
|
+
* Generate a unique ID from a file path.
|
|
253
|
+
*
|
|
254
|
+
* Process:
|
|
255
|
+
* 1. Get basename without extension
|
|
256
|
+
* 2. Convert to kebab-case
|
|
257
|
+
* 3. Handle collisions by appending suffix (-2, -3, etc.)
|
|
258
|
+
*
|
|
259
|
+
* @param filePath - Absolute file path
|
|
260
|
+
* @returns Unique ID
|
|
261
|
+
*/
|
|
262
|
+
private generateUniqueId;
|
|
263
|
+
/**
|
|
264
|
+
* Build a map of file paths to their heading trees.
|
|
265
|
+
*
|
|
266
|
+
* Used for link validation.
|
|
267
|
+
*/
|
|
268
|
+
private buildHeadingsByFileMap;
|
|
269
|
+
/**
|
|
270
|
+
* Resolve a relative link href to an absolute file path.
|
|
271
|
+
*
|
|
272
|
+
* @param linkHref - The href from the link (e.g., './file.md', '../dir/file.md#anchor')
|
|
273
|
+
* @param sourceFilePath - Absolute path to the source file
|
|
274
|
+
* @returns Absolute path to the target file
|
|
275
|
+
*/
|
|
276
|
+
private resolveRelativeLinkPath;
|
|
277
|
+
}
|
|
278
|
+
//# sourceMappingURL=resource-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-registry.d.ts","sourceRoot":"","sources":["../src/resource-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH,OAAO,KAAK,EAAe,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AACpF,OAAO,KAAK,EAAmB,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAGxF;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,2DAA2D;IAC3D,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,6CAA6C;IAC7C,c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