@vibe-agent-toolkit/resources 0.1.29-rc.3 → 0.1.29
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.
|
@@ -35,7 +35,7 @@ export interface ResourceLookup {
|
|
|
35
35
|
*
|
|
36
36
|
* A rule matches a link when ALL specified criteria are satisfied:
|
|
37
37
|
* - `type`: Link type matches (if specified)
|
|
38
|
-
* - `pattern`: Target
|
|
38
|
+
* - `pattern`: Target file path matches a glob pattern (if specified)
|
|
39
39
|
* - `excludeResourceIds`: Target resource's ID is NOT in the exclusion list
|
|
40
40
|
*/
|
|
41
41
|
export interface LinkRewriteMatch {
|
|
@@ -45,9 +45,15 @@ export interface LinkRewriteMatch {
|
|
|
45
45
|
*/
|
|
46
46
|
type?: LinkType | LinkType[];
|
|
47
47
|
/**
|
|
48
|
-
* Glob pattern(s) to match against the target
|
|
49
|
-
*
|
|
50
|
-
*
|
|
48
|
+
* Glob pattern(s) to match against the target file path.
|
|
49
|
+
*
|
|
50
|
+
* For resolved links (target resource found in the registry), patterns match
|
|
51
|
+
* against `resource.filePath`. For unresolved links (e.g., terminal links to
|
|
52
|
+
* non-markdown files not indexed by the registry), patterns fall back to
|
|
53
|
+
* matching against the link's raw href. This allows exclude rules to apply
|
|
54
|
+
* to assets like YAML, JSON, or images that markdown files reference.
|
|
55
|
+
*
|
|
56
|
+
* If omitted, matches any path.
|
|
51
57
|
* Can be a single glob string or an array of glob strings.
|
|
52
58
|
*/
|
|
53
59
|
pattern?: string | string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-transform.d.ts","sourceRoot":"","sources":["../src/content-transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAMH,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAmC/F;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,0CAA0C;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G;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AA0LD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,YAAY,EAAE,EACrB,OAAO,EAAE,uBAAuB,GAC/B,MAAM,CA2HR"}
|
|
@@ -60,9 +60,11 @@ function inferMimeType(filePath) {
|
|
|
60
60
|
* @param resource - The resolved target resource (if available)
|
|
61
61
|
* @param extraContext - Additional context variables
|
|
62
62
|
* @param sourceFilePath - Absolute path of the source document (for relativePath computation)
|
|
63
|
+
* @param rawText - Raw markdown text between the `[` and `]` (with inline formatting preserved).
|
|
64
|
+
* When omitted, `link.rawText` falls back to `link.text`.
|
|
63
65
|
* @returns Template context object
|
|
64
66
|
*/
|
|
65
|
-
function buildTemplateContext(link, hrefWithoutFragment, fragment, resource, extraContext, sourceFilePath) {
|
|
67
|
+
function buildTemplateContext(link, hrefWithoutFragment, fragment, resource, extraContext, sourceFilePath, rawText) {
|
|
66
68
|
const resourceContext = resource === undefined
|
|
67
69
|
? undefined
|
|
68
70
|
: {
|
|
@@ -82,6 +84,7 @@ function buildTemplateContext(link, hrefWithoutFragment, fragment, resource, ext
|
|
|
82
84
|
...extraContext,
|
|
83
85
|
link: {
|
|
84
86
|
text: link.text,
|
|
87
|
+
rawText: rawText ?? link.text,
|
|
85
88
|
href: hrefWithoutFragment,
|
|
86
89
|
fragment,
|
|
87
90
|
type: link.type,
|
|
@@ -106,22 +109,34 @@ function matchesType(linkType, matchType) {
|
|
|
106
109
|
return linkType === matchType;
|
|
107
110
|
}
|
|
108
111
|
/**
|
|
109
|
-
* Check if a link's target
|
|
112
|
+
* Check if a link's target file path matches the rule's pattern criteria.
|
|
110
113
|
*
|
|
114
|
+
* Uses `resource.filePath` when the link is resolved. Falls back to the link's
|
|
115
|
+
* href (anchor stripped) for unresolved links so rules can target terminal
|
|
116
|
+
* assets — YAML, JSON, images — that the registry does not index.
|
|
117
|
+
*
|
|
118
|
+
* @param link - The link being tested
|
|
111
119
|
* @param resource - The target resource (if resolved)
|
|
112
120
|
* @param patterns - The pattern(s) to match against (or undefined = match all)
|
|
113
121
|
* @returns True if the pattern matches or no pattern is specified
|
|
114
122
|
*/
|
|
115
|
-
function matchesPattern(resource, patterns) {
|
|
123
|
+
function matchesPattern(link, resource, patterns) {
|
|
116
124
|
if (patterns === undefined) {
|
|
117
125
|
return true;
|
|
118
126
|
}
|
|
119
|
-
|
|
127
|
+
let pathToMatch;
|
|
120
128
|
if (resource === undefined) {
|
|
121
|
-
|
|
129
|
+
const [hrefWithoutAnchor] = splitHrefAnchor(link.href);
|
|
130
|
+
if (hrefWithoutAnchor === '') {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
pathToMatch = hrefWithoutAnchor;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
pathToMatch = resource.filePath;
|
|
122
137
|
}
|
|
123
138
|
const patternArray = Array.isArray(patterns) ? patterns : [patterns];
|
|
124
|
-
return patternArray.some((pattern) => matchesGlobPattern(
|
|
139
|
+
return patternArray.some((pattern) => matchesGlobPattern(pathToMatch, pattern));
|
|
125
140
|
}
|
|
126
141
|
/**
|
|
127
142
|
* Check if a link's resolvedId is excluded by the rule.
|
|
@@ -153,7 +168,7 @@ function findMatchingRule(link, resource, rules) {
|
|
|
153
168
|
if (!matchesType(link.type, match.type)) {
|
|
154
169
|
continue;
|
|
155
170
|
}
|
|
156
|
-
if (!matchesPattern(resource, match.pattern)) {
|
|
171
|
+
if (!matchesPattern(link, resource, match.pattern)) {
|
|
157
172
|
continue;
|
|
158
173
|
}
|
|
159
174
|
if (isExcluded(link.resolvedId, match.excludeResourceIds)) {
|
|
@@ -231,24 +246,26 @@ export function transformContent(content, links, options) {
|
|
|
231
246
|
return content;
|
|
232
247
|
}
|
|
233
248
|
// === Pass 1: Inline links [text](href) ===
|
|
234
|
-
// Build a lookup map
|
|
235
|
-
//
|
|
236
|
-
//
|
|
237
|
-
|
|
249
|
+
// Build a lookup map keyed by href → ResourceLink. We intentionally key by href
|
|
250
|
+
// rather than "[text](href)" because the regex below captures the RAW markdown
|
|
251
|
+
// text (including backticks, emphasis markers, etc.), while `link.text` is
|
|
252
|
+
// already rendered (formatting stripped). Keying by text causes a signature
|
|
253
|
+
// mismatch for any formatted link text; keying by href avoids that class of
|
|
254
|
+
// bug entirely. When multiple inline links share an href, the first wins —
|
|
255
|
+
// their match criteria (type, resolvedId) are identical for lookup purposes.
|
|
256
|
+
const linkByHref = new Map();
|
|
238
257
|
for (const link of links) {
|
|
239
258
|
if (link.nodeType === 'definition') {
|
|
240
259
|
continue; // Definitions are handled in pass 2
|
|
241
260
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
linkBySignature.set(signature, link);
|
|
261
|
+
if (!linkByHref.has(link.href)) {
|
|
262
|
+
linkByHref.set(link.href, link);
|
|
245
263
|
}
|
|
246
264
|
}
|
|
247
265
|
// Replace inline markdown links in content
|
|
248
|
-
let result = content.replaceAll(MARKDOWN_LINK_REGEX, (fullMatch,
|
|
249
|
-
// Find the corresponding ResourceLink
|
|
250
|
-
const
|
|
251
|
-
const link = linkBySignature.get(signature);
|
|
266
|
+
let result = content.replaceAll(MARKDOWN_LINK_REGEX, (fullMatch, rawText, href) => {
|
|
267
|
+
// Find the corresponding ResourceLink by href
|
|
268
|
+
const link = linkByHref.get(href);
|
|
252
269
|
if (!link) {
|
|
253
270
|
// Link not in the parsed links array - leave untouched
|
|
254
271
|
return fullMatch;
|
|
@@ -268,8 +285,10 @@ export function transformContent(content, links, options) {
|
|
|
268
285
|
// Parse fragment from href
|
|
269
286
|
const [hrefWithoutFragment, anchor] = splitHrefAnchor(href);
|
|
270
287
|
const fragment = anchor === undefined ? '' : `#${anchor}`;
|
|
271
|
-
// Build template context and render
|
|
272
|
-
|
|
288
|
+
// Build template context and render. rawText preserves any inline
|
|
289
|
+
// formatting the author wrote (backticks, bold, italics) so templates
|
|
290
|
+
// targeting bundled links can render the link with original styling.
|
|
291
|
+
const templateContext = buildTemplateContext(link, hrefWithoutFragment, fragment, resource, context, sourceFilePath, rawText);
|
|
273
292
|
return renderTemplate(template, templateContext);
|
|
274
293
|
});
|
|
275
294
|
// === Pass 2: Reference-style definitions [ref]: url ===
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-transform.js","sourceRoot":"","sources":["../src/content-transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAGrF,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEjE;;GAEG;AACH,MAAM,kBAAkB,GAA2B;IACjD,KAAK,EAAE,eAAe;IACtB,KAAK,EAAE,iBAAiB;IACxB,KAAK,EAAE,iBAAiB;IACxB,OAAO,EAAE,kBAAkB;IAC3B,OAAO,EAAE,WAAW;IACpB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,iBAAiB;IACzB,OAAO,EAAE,WAAW;IACpB,MAAM,EAAE,UAAU;IAClB,MAAM,EAAE,YAAY;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,iBAAiB,GAAG,0BAA0B,CAAC;AAErD;;;;;GAKG;AACH,SAAS,aAAa,CAAC,QAAgB;IACrC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;IACjD,OAAO,kBAAkB,CAAC,GAAG,CAAC,IAAI,iBAAiB,CAAC;AACtD,CAAC;
|
|
1
|
+
{"version":3,"file":"content-transform.js","sourceRoot":"","sources":["../src/content-transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqNmD,CAAC;AAExD,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibe-agent-toolkit/resources",
|
|
3
|
-
"version": "0.1.29
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"description": "Markdown resource parsing, validation, and link integrity checking",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"author": "Jeff Dutton",
|
|
34
34
|
"license": "MIT",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@vibe-agent-toolkit/agent-schema": "0.1.29
|
|
37
|
-
"@vibe-agent-toolkit/utils": "0.1.29
|
|
36
|
+
"@vibe-agent-toolkit/agent-schema": "0.1.29",
|
|
37
|
+
"@vibe-agent-toolkit/utils": "0.1.29",
|
|
38
38
|
"ajv": "^8.17.1",
|
|
39
39
|
"github-slugger": "^2.0.0",
|
|
40
40
|
"js-yaml": "^4.1.1",
|
package/src/content-transform.ts
CHANGED
|
@@ -75,7 +75,7 @@ export interface ResourceLookup {
|
|
|
75
75
|
*
|
|
76
76
|
* A rule matches a link when ALL specified criteria are satisfied:
|
|
77
77
|
* - `type`: Link type matches (if specified)
|
|
78
|
-
* - `pattern`: Target
|
|
78
|
+
* - `pattern`: Target file path matches a glob pattern (if specified)
|
|
79
79
|
* - `excludeResourceIds`: Target resource's ID is NOT in the exclusion list
|
|
80
80
|
*/
|
|
81
81
|
export interface LinkRewriteMatch {
|
|
@@ -86,9 +86,15 @@ export interface LinkRewriteMatch {
|
|
|
86
86
|
type?: LinkType | LinkType[];
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
|
-
* Glob pattern(s) to match against the target
|
|
90
|
-
*
|
|
91
|
-
*
|
|
89
|
+
* Glob pattern(s) to match against the target file path.
|
|
90
|
+
*
|
|
91
|
+
* For resolved links (target resource found in the registry), patterns match
|
|
92
|
+
* against `resource.filePath`. For unresolved links (e.g., terminal links to
|
|
93
|
+
* non-markdown files not indexed by the registry), patterns fall back to
|
|
94
|
+
* matching against the link's raw href. This allows exclude rules to apply
|
|
95
|
+
* to assets like YAML, JSON, or images that markdown files reference.
|
|
96
|
+
*
|
|
97
|
+
* If omitted, matches any path.
|
|
92
98
|
* Can be a single glob string or an array of glob strings.
|
|
93
99
|
*/
|
|
94
100
|
pattern?: string | string[];
|
|
@@ -177,6 +183,8 @@ export interface ContentTransformOptions {
|
|
|
177
183
|
* @param resource - The resolved target resource (if available)
|
|
178
184
|
* @param extraContext - Additional context variables
|
|
179
185
|
* @param sourceFilePath - Absolute path of the source document (for relativePath computation)
|
|
186
|
+
* @param rawText - Raw markdown text between the `[` and `]` (with inline formatting preserved).
|
|
187
|
+
* When omitted, `link.rawText` falls back to `link.text`.
|
|
180
188
|
* @returns Template context object
|
|
181
189
|
*/
|
|
182
190
|
function buildTemplateContext(
|
|
@@ -186,6 +194,7 @@ function buildTemplateContext(
|
|
|
186
194
|
resource: ResourceMetadata | undefined,
|
|
187
195
|
extraContext: Record<string, unknown> | undefined,
|
|
188
196
|
sourceFilePath: string | undefined,
|
|
197
|
+
rawText: string | undefined,
|
|
189
198
|
): Record<string, unknown> {
|
|
190
199
|
const resourceContext = resource === undefined
|
|
191
200
|
? undefined
|
|
@@ -207,6 +216,7 @@ function buildTemplateContext(
|
|
|
207
216
|
...extraContext,
|
|
208
217
|
link: {
|
|
209
218
|
text: link.text,
|
|
219
|
+
rawText: rawText ?? link.text,
|
|
210
220
|
href: hrefWithoutFragment,
|
|
211
221
|
fragment,
|
|
212
222
|
type: link.type,
|
|
@@ -233,13 +243,19 @@ function matchesType(linkType: LinkType, matchType: LinkType | LinkType[] | unde
|
|
|
233
243
|
}
|
|
234
244
|
|
|
235
245
|
/**
|
|
236
|
-
* Check if a link's target
|
|
246
|
+
* Check if a link's target file path matches the rule's pattern criteria.
|
|
247
|
+
*
|
|
248
|
+
* Uses `resource.filePath` when the link is resolved. Falls back to the link's
|
|
249
|
+
* href (anchor stripped) for unresolved links so rules can target terminal
|
|
250
|
+
* assets — YAML, JSON, images — that the registry does not index.
|
|
237
251
|
*
|
|
252
|
+
* @param link - The link being tested
|
|
238
253
|
* @param resource - The target resource (if resolved)
|
|
239
254
|
* @param patterns - The pattern(s) to match against (or undefined = match all)
|
|
240
255
|
* @returns True if the pattern matches or no pattern is specified
|
|
241
256
|
*/
|
|
242
257
|
function matchesPattern(
|
|
258
|
+
link: ResourceLink,
|
|
243
259
|
resource: ResourceMetadata | undefined,
|
|
244
260
|
patterns: string | string[] | undefined,
|
|
245
261
|
): boolean {
|
|
@@ -247,13 +263,19 @@ function matchesPattern(
|
|
|
247
263
|
return true;
|
|
248
264
|
}
|
|
249
265
|
|
|
250
|
-
|
|
266
|
+
let pathToMatch: string;
|
|
251
267
|
if (resource === undefined) {
|
|
252
|
-
|
|
268
|
+
const [hrefWithoutAnchor] = splitHrefAnchor(link.href);
|
|
269
|
+
if (hrefWithoutAnchor === '') {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
pathToMatch = hrefWithoutAnchor;
|
|
273
|
+
} else {
|
|
274
|
+
pathToMatch = resource.filePath;
|
|
253
275
|
}
|
|
254
276
|
|
|
255
277
|
const patternArray = Array.isArray(patterns) ? patterns : [patterns];
|
|
256
|
-
return patternArray.some((pattern) => matchesGlobPattern(
|
|
278
|
+
return patternArray.some((pattern) => matchesGlobPattern(pathToMatch, pattern));
|
|
257
279
|
}
|
|
258
280
|
|
|
259
281
|
/**
|
|
@@ -296,7 +318,7 @@ function findMatchingRule(
|
|
|
296
318
|
continue;
|
|
297
319
|
}
|
|
298
320
|
|
|
299
|
-
if (!matchesPattern(resource, match.pattern)) {
|
|
321
|
+
if (!matchesPattern(link, resource, match.pattern)) {
|
|
300
322
|
continue;
|
|
301
323
|
}
|
|
302
324
|
|
|
@@ -387,25 +409,27 @@ export function transformContent(
|
|
|
387
409
|
|
|
388
410
|
// === Pass 1: Inline links [text](href) ===
|
|
389
411
|
|
|
390
|
-
// Build a lookup map
|
|
391
|
-
//
|
|
392
|
-
//
|
|
393
|
-
|
|
412
|
+
// Build a lookup map keyed by href → ResourceLink. We intentionally key by href
|
|
413
|
+
// rather than "[text](href)" because the regex below captures the RAW markdown
|
|
414
|
+
// text (including backticks, emphasis markers, etc.), while `link.text` is
|
|
415
|
+
// already rendered (formatting stripped). Keying by text causes a signature
|
|
416
|
+
// mismatch for any formatted link text; keying by href avoids that class of
|
|
417
|
+
// bug entirely. When multiple inline links share an href, the first wins —
|
|
418
|
+
// their match criteria (type, resolvedId) are identical for lookup purposes.
|
|
419
|
+
const linkByHref = new Map<string, ResourceLink>();
|
|
394
420
|
for (const link of links) {
|
|
395
421
|
if (link.nodeType === 'definition') {
|
|
396
422
|
continue; // Definitions are handled in pass 2
|
|
397
423
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
linkBySignature.set(signature, link);
|
|
424
|
+
if (!linkByHref.has(link.href)) {
|
|
425
|
+
linkByHref.set(link.href, link);
|
|
401
426
|
}
|
|
402
427
|
}
|
|
403
428
|
|
|
404
429
|
// Replace inline markdown links in content
|
|
405
|
-
let result = content.replaceAll(MARKDOWN_LINK_REGEX, (fullMatch,
|
|
406
|
-
// Find the corresponding ResourceLink
|
|
407
|
-
const
|
|
408
|
-
const link = linkBySignature.get(signature);
|
|
430
|
+
let result = content.replaceAll(MARKDOWN_LINK_REGEX, (fullMatch, rawText: string, href: string) => {
|
|
431
|
+
// Find the corresponding ResourceLink by href
|
|
432
|
+
const link = linkByHref.get(href);
|
|
409
433
|
|
|
410
434
|
if (!link) {
|
|
411
435
|
// Link not in the parsed links array - leave untouched
|
|
@@ -431,8 +455,10 @@ export function transformContent(
|
|
|
431
455
|
const [hrefWithoutFragment, anchor] = splitHrefAnchor(href);
|
|
432
456
|
const fragment = anchor === undefined ? '' : `#${anchor}`;
|
|
433
457
|
|
|
434
|
-
// Build template context and render
|
|
435
|
-
|
|
458
|
+
// Build template context and render. rawText preserves any inline
|
|
459
|
+
// formatting the author wrote (backticks, bold, italics) so templates
|
|
460
|
+
// targeting bundled links can render the link with original styling.
|
|
461
|
+
const templateContext = buildTemplateContext(link, hrefWithoutFragment, fragment, resource, context, sourceFilePath, rawText);
|
|
436
462
|
return renderTemplate(template, templateContext);
|
|
437
463
|
});
|
|
438
464
|
|