@vibe-agent-toolkit/resources 0.1.12 → 0.1.14
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/dist/content-transform.d.ts +142 -0
- package/dist/content-transform.d.ts.map +1 -0
- package/dist/content-transform.js +252 -0
- package/dist/content-transform.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/resource-registry.d.ts +50 -20
- package/dist/resource-registry.d.ts.map +1 -1
- package/dist/resource-registry.js +88 -53
- package/dist/resource-registry.js.map +1 -1
- package/package.json +2 -2
- package/src/content-transform.ts +395 -0
- package/src/index.ts +11 -1
- package/src/resource-registry.ts +102 -59
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content transform engine for rewriting markdown links.
|
|
3
|
+
*
|
|
4
|
+
* Provides a pure function for transforming markdown link references
|
|
5
|
+
* based on configurable rules. Used by both RAG (rewriting links before
|
|
6
|
+
* persistence) and agent-skills (rewriting links during skill packaging).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { transformContent, type LinkRewriteRule } from '@vibe-agent-toolkit/resources';
|
|
11
|
+
*
|
|
12
|
+
* const rules: LinkRewriteRule[] = [
|
|
13
|
+
* {
|
|
14
|
+
* match: { type: 'local_file' },
|
|
15
|
+
* template: '{{link.text}} (see: {{link.resource.id}})',
|
|
16
|
+
* },
|
|
17
|
+
* ];
|
|
18
|
+
*
|
|
19
|
+
* const result = transformContent(content, links, { linkRewriteRules: rules, resourceRegistry: registry });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import type { LinkType, ResourceLink, ResourceMetadata } from './schemas/resource-metadata.js';
|
|
23
|
+
/**
|
|
24
|
+
* Interface for looking up resources by ID.
|
|
25
|
+
*
|
|
26
|
+
* Intentionally minimal to avoid tight coupling to ResourceRegistry.
|
|
27
|
+
* Any object providing `getResourceById` satisfies this contract.
|
|
28
|
+
*/
|
|
29
|
+
export interface ResourceLookup {
|
|
30
|
+
/** Look up a resource by its unique ID */
|
|
31
|
+
getResourceById(id: string): ResourceMetadata | undefined;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Match criteria for a link rewrite rule.
|
|
35
|
+
*
|
|
36
|
+
* A rule matches a link when ALL specified criteria are satisfied:
|
|
37
|
+
* - `type`: Link type matches (if specified)
|
|
38
|
+
* - `pattern`: Target resource's filePath matches a glob pattern (if specified)
|
|
39
|
+
* - `excludeResourceIds`: Target resource's ID is NOT in the exclusion list
|
|
40
|
+
*/
|
|
41
|
+
export interface LinkRewriteMatch {
|
|
42
|
+
/**
|
|
43
|
+
* Link type(s) to match. If omitted, matches any type.
|
|
44
|
+
* Can be a single LinkType or an array of LinkType values.
|
|
45
|
+
*/
|
|
46
|
+
type?: LinkType | LinkType[];
|
|
47
|
+
/**
|
|
48
|
+
* Glob pattern(s) to match against the target resource's filePath.
|
|
49
|
+
* If omitted, matches any path. Requires the link to have a resolvedId
|
|
50
|
+
* so the target resource can be looked up.
|
|
51
|
+
* Can be a single glob string or an array of glob strings.
|
|
52
|
+
*/
|
|
53
|
+
pattern?: string | string[];
|
|
54
|
+
/**
|
|
55
|
+
* Resource IDs to exclude from matching.
|
|
56
|
+
* If the link's resolvedId is in this list, the rule does not match.
|
|
57
|
+
*/
|
|
58
|
+
excludeResourceIds?: string[];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A rule for rewriting markdown links in content.
|
|
62
|
+
*
|
|
63
|
+
* Rules are evaluated in order; the first matching rule wins.
|
|
64
|
+
* Links that match no rule are left untouched.
|
|
65
|
+
*/
|
|
66
|
+
export interface LinkRewriteRule {
|
|
67
|
+
/**
|
|
68
|
+
* Match criteria. All specified criteria must be satisfied for the rule to match.
|
|
69
|
+
*/
|
|
70
|
+
match: LinkRewriteMatch;
|
|
71
|
+
/**
|
|
72
|
+
* Handlebars template for the replacement text.
|
|
73
|
+
*
|
|
74
|
+
* Available template variables:
|
|
75
|
+
* - `link.text` - Link display text
|
|
76
|
+
* - `link.href` - Original href (without fragment)
|
|
77
|
+
* - `link.fragment` - Fragment portion including `#` prefix (or empty string)
|
|
78
|
+
* - `link.type` - Link type (local_file, anchor, external, email, unknown)
|
|
79
|
+
* - `link.resource.id` - Target resource ID (if resolved)
|
|
80
|
+
* - `link.resource.filePath` - Target resource file path (if resolved)
|
|
81
|
+
* - `link.resource.extension` - Target resource file extension (if resolved)
|
|
82
|
+
* - `link.resource.mimeType` - Inferred MIME type (if resolved)
|
|
83
|
+
* - `link.resource.frontmatter.*` - Target resource frontmatter fields (if resolved)
|
|
84
|
+
* - `link.resource.sizeBytes` - Target resource size in bytes (if resolved)
|
|
85
|
+
* - `link.resource.estimatedTokenCount` - Target resource estimated token count (if resolved)
|
|
86
|
+
* - Plus any variables from `context`
|
|
87
|
+
*/
|
|
88
|
+
template: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Options for the `transformContent` function.
|
|
92
|
+
*/
|
|
93
|
+
export interface ContentTransformOptions {
|
|
94
|
+
/** Ordered list of link rewrite rules. First matching rule wins. */
|
|
95
|
+
linkRewriteRules: LinkRewriteRule[];
|
|
96
|
+
/**
|
|
97
|
+
* Resource lookup for resolving `link.resource.*` template variables.
|
|
98
|
+
* If not provided, `link.resource.*` variables will be undefined in templates.
|
|
99
|
+
*/
|
|
100
|
+
resourceRegistry?: ResourceLookup;
|
|
101
|
+
/**
|
|
102
|
+
* Additional context variables available in all templates.
|
|
103
|
+
* These are merged at the top level of the template context.
|
|
104
|
+
*/
|
|
105
|
+
context?: Record<string, unknown>;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Transform markdown content by rewriting links according to rules.
|
|
109
|
+
*
|
|
110
|
+
* This is a pure function that takes content, its parsed links, and transform options,
|
|
111
|
+
* and returns the content with matching links rewritten according to the first matching rule.
|
|
112
|
+
*
|
|
113
|
+
* Links are matched by their original markdown syntax `[text](href)`. For each link found
|
|
114
|
+
* in the content, the function checks the provided rules in order. The first matching rule
|
|
115
|
+
* determines the replacement. Links matching no rule are left untouched.
|
|
116
|
+
*
|
|
117
|
+
* @param content - The markdown content to transform
|
|
118
|
+
* @param links - Parsed links from the content (from ResourceMetadata.links)
|
|
119
|
+
* @param options - Transform options including rules, registry, and context
|
|
120
|
+
* @returns The transformed content with rewritten links
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const rules: LinkRewriteRule[] = [
|
|
125
|
+
* {
|
|
126
|
+
* match: { type: 'local_file' },
|
|
127
|
+
* template: '{{link.text}} (ref: {{link.resource.id}})',
|
|
128
|
+
* },
|
|
129
|
+
* {
|
|
130
|
+
* match: { type: 'external' },
|
|
131
|
+
* template: '[{{link.text}}]({{link.href}})',
|
|
132
|
+
* },
|
|
133
|
+
* ];
|
|
134
|
+
*
|
|
135
|
+
* const result = transformContent(content, resource.links, {
|
|
136
|
+
* linkRewriteRules: rules,
|
|
137
|
+
* resourceRegistry: registry,
|
|
138
|
+
* });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export declare function transformContent(content: string, links: ResourceLink[], options: ContentTransformOptions): string;
|
|
142
|
+
//# sourceMappingURL=content-transform.d.ts.map
|
|
@@ -0,0 +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;IAC1C,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAAC;CAC3D;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,IAAI,CAAC,EAAE,QAAQ,GAAG,QAAQ,EAAE,CAAC;IAE7B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE5B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC/B;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,KAAK,EAAE,gBAAgB,CAAC;IAExB;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,oEAAoE;IACpE,gBAAgB,EAAE,eAAe,EAAE,CAAC;IAEpC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,cAAc,CAAC;IAElC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAyJD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,YAAY,EAAE,EACrB,OAAO,EAAE,uBAAuB,GAC/B,MAAM,CAmDR"}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content transform engine for rewriting markdown links.
|
|
3
|
+
*
|
|
4
|
+
* Provides a pure function for transforming markdown link references
|
|
5
|
+
* based on configurable rules. Used by both RAG (rewriting links before
|
|
6
|
+
* persistence) and agent-skills (rewriting links during skill packaging).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { transformContent, type LinkRewriteRule } from '@vibe-agent-toolkit/resources';
|
|
11
|
+
*
|
|
12
|
+
* const rules: LinkRewriteRule[] = [
|
|
13
|
+
* {
|
|
14
|
+
* match: { type: 'local_file' },
|
|
15
|
+
* template: '{{link.text}} (see: {{link.resource.id}})',
|
|
16
|
+
* },
|
|
17
|
+
* ];
|
|
18
|
+
*
|
|
19
|
+
* const result = transformContent(content, links, { linkRewriteRules: rules, resourceRegistry: registry });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import path from 'node:path';
|
|
23
|
+
import { renderTemplate } from '@vibe-agent-toolkit/utils';
|
|
24
|
+
import { matchesGlobPattern, splitHrefAnchor } from './utils.js';
|
|
25
|
+
/**
|
|
26
|
+
* Extension-to-MIME-type mapping for common resource file types.
|
|
27
|
+
*/
|
|
28
|
+
const EXTENSION_MIME_MAP = {
|
|
29
|
+
'.md': 'text/markdown',
|
|
30
|
+
'.ts': 'text/typescript',
|
|
31
|
+
'.js': 'text/javascript',
|
|
32
|
+
'.json': 'application/json',
|
|
33
|
+
'.yaml': 'text/yaml',
|
|
34
|
+
'.yml': 'text/yaml',
|
|
35
|
+
'.xml': 'application/xml',
|
|
36
|
+
'.html': 'text/html',
|
|
37
|
+
'.css': 'text/css',
|
|
38
|
+
'.txt': 'text/plain',
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Default MIME type when the file extension is unknown.
|
|
42
|
+
*/
|
|
43
|
+
const DEFAULT_MIME_TYPE = 'application/octet-stream';
|
|
44
|
+
/**
|
|
45
|
+
* Infer MIME type from a file extension.
|
|
46
|
+
*
|
|
47
|
+
* @param filePath - File path to extract extension from
|
|
48
|
+
* @returns Inferred MIME type string
|
|
49
|
+
*/
|
|
50
|
+
function inferMimeType(filePath) {
|
|
51
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
52
|
+
return EXTENSION_MIME_MAP[ext] ?? DEFAULT_MIME_TYPE;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Build the template context for a matched link.
|
|
56
|
+
*
|
|
57
|
+
* @param link - The ResourceLink being transformed
|
|
58
|
+
* @param hrefWithoutFragment - The href with fragment stripped
|
|
59
|
+
* @param fragment - The fragment string including '#' prefix, or empty string
|
|
60
|
+
* @param resource - The resolved target resource (if available)
|
|
61
|
+
* @param extraContext - Additional context variables
|
|
62
|
+
* @returns Template context object
|
|
63
|
+
*/
|
|
64
|
+
function buildTemplateContext(link, hrefWithoutFragment, fragment, resource, extraContext) {
|
|
65
|
+
const resourceContext = resource === undefined
|
|
66
|
+
? undefined
|
|
67
|
+
: {
|
|
68
|
+
id: resource.id,
|
|
69
|
+
filePath: resource.filePath,
|
|
70
|
+
extension: path.extname(resource.filePath),
|
|
71
|
+
mimeType: inferMimeType(resource.filePath),
|
|
72
|
+
frontmatter: resource.frontmatter,
|
|
73
|
+
sizeBytes: resource.sizeBytes,
|
|
74
|
+
estimatedTokenCount: resource.estimatedTokenCount,
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
...extraContext,
|
|
78
|
+
link: {
|
|
79
|
+
text: link.text,
|
|
80
|
+
href: hrefWithoutFragment,
|
|
81
|
+
fragment,
|
|
82
|
+
type: link.type,
|
|
83
|
+
resource: resourceContext,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Check if a link's type matches the rule's type criteria.
|
|
89
|
+
*
|
|
90
|
+
* @param linkType - The link's type
|
|
91
|
+
* @param matchType - The rule's type criteria (single or array, or undefined = match all)
|
|
92
|
+
* @returns True if the type matches
|
|
93
|
+
*/
|
|
94
|
+
function matchesType(linkType, matchType) {
|
|
95
|
+
if (matchType === undefined) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
if (Array.isArray(matchType)) {
|
|
99
|
+
return matchType.includes(linkType);
|
|
100
|
+
}
|
|
101
|
+
return linkType === matchType;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Check if a link's target resource matches the rule's pattern criteria.
|
|
105
|
+
*
|
|
106
|
+
* @param resource - The target resource (if resolved)
|
|
107
|
+
* @param patterns - The pattern(s) to match against (or undefined = match all)
|
|
108
|
+
* @returns True if the pattern matches or no pattern is specified
|
|
109
|
+
*/
|
|
110
|
+
function matchesPattern(resource, patterns) {
|
|
111
|
+
if (patterns === undefined) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
// Pattern matching requires a resolved resource
|
|
115
|
+
if (resource === undefined) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
const patternArray = Array.isArray(patterns) ? patterns : [patterns];
|
|
119
|
+
return patternArray.some((pattern) => matchesGlobPattern(resource.filePath, pattern));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Check if a link's resolvedId is excluded by the rule.
|
|
123
|
+
*
|
|
124
|
+
* @param resolvedId - The link's resolved resource ID (if any)
|
|
125
|
+
* @param excludeResourceIds - IDs to exclude (if any)
|
|
126
|
+
* @returns True if the link is excluded (should NOT match)
|
|
127
|
+
*/
|
|
128
|
+
function isExcluded(resolvedId, excludeResourceIds) {
|
|
129
|
+
if (excludeResourceIds === undefined || excludeResourceIds.length === 0) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
if (resolvedId === undefined) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
return excludeResourceIds.includes(resolvedId);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Find the first matching rule for a given link.
|
|
139
|
+
*
|
|
140
|
+
* @param link - The ResourceLink to match
|
|
141
|
+
* @param resource - The resolved target resource (if available)
|
|
142
|
+
* @param rules - Ordered list of rules
|
|
143
|
+
* @returns The first matching rule, or undefined if no rule matches
|
|
144
|
+
*/
|
|
145
|
+
function findMatchingRule(link, resource, rules) {
|
|
146
|
+
for (const rule of rules) {
|
|
147
|
+
const { match } = rule;
|
|
148
|
+
if (!matchesType(link.type, match.type)) {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (!matchesPattern(resource, match.pattern)) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (isExcluded(link.resolvedId, match.excludeResourceIds)) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
return rule;
|
|
158
|
+
}
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Regex pattern matching markdown links: `[text](href)`
|
|
163
|
+
*
|
|
164
|
+
* Captures:
|
|
165
|
+
* - Group 0: Full match including brackets and parentheses
|
|
166
|
+
* - Group 1: Link text
|
|
167
|
+
* - Group 2: Link href
|
|
168
|
+
*
|
|
169
|
+
* Does NOT handle nested brackets in link text — the negated character class
|
|
170
|
+
* `[^\]]*` excludes `]` characters, so `[text [with] brackets](href)` would
|
|
171
|
+
* not be matched as a single link.
|
|
172
|
+
*/
|
|
173
|
+
// eslint-disable-next-line sonarjs/slow-regex -- negated character classes [^\]] and [^)] are inherently non-backtracking
|
|
174
|
+
const MARKDOWN_LINK_REGEX = /\[([^\]]*)\]\(([^)]*)\)/g;
|
|
175
|
+
/**
|
|
176
|
+
* Transform markdown content by rewriting links according to rules.
|
|
177
|
+
*
|
|
178
|
+
* This is a pure function that takes content, its parsed links, and transform options,
|
|
179
|
+
* and returns the content with matching links rewritten according to the first matching rule.
|
|
180
|
+
*
|
|
181
|
+
* Links are matched by their original markdown syntax `[text](href)`. For each link found
|
|
182
|
+
* in the content, the function checks the provided rules in order. The first matching rule
|
|
183
|
+
* determines the replacement. Links matching no rule are left untouched.
|
|
184
|
+
*
|
|
185
|
+
* @param content - The markdown content to transform
|
|
186
|
+
* @param links - Parsed links from the content (from ResourceMetadata.links)
|
|
187
|
+
* @param options - Transform options including rules, registry, and context
|
|
188
|
+
* @returns The transformed content with rewritten links
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* const rules: LinkRewriteRule[] = [
|
|
193
|
+
* {
|
|
194
|
+
* match: { type: 'local_file' },
|
|
195
|
+
* template: '{{link.text}} (ref: {{link.resource.id}})',
|
|
196
|
+
* },
|
|
197
|
+
* {
|
|
198
|
+
* match: { type: 'external' },
|
|
199
|
+
* template: '[{{link.text}}]({{link.href}})',
|
|
200
|
+
* },
|
|
201
|
+
* ];
|
|
202
|
+
*
|
|
203
|
+
* const result = transformContent(content, resource.links, {
|
|
204
|
+
* linkRewriteRules: rules,
|
|
205
|
+
* resourceRegistry: registry,
|
|
206
|
+
* });
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
export function transformContent(content, links, options) {
|
|
210
|
+
const { linkRewriteRules, resourceRegistry, context } = options;
|
|
211
|
+
// If there are no rules or no links, return content unchanged
|
|
212
|
+
if (linkRewriteRules.length === 0 || links.length === 0) {
|
|
213
|
+
return content;
|
|
214
|
+
}
|
|
215
|
+
// Build a lookup map from "[text](href)" to the corresponding ResourceLink.
|
|
216
|
+
// Multiple links can share the same text+href combination; we process them all
|
|
217
|
+
// with the first matching ResourceLink (they are identical in terms of match criteria).
|
|
218
|
+
const linkBySignature = new Map();
|
|
219
|
+
for (const link of links) {
|
|
220
|
+
const signature = `[${link.text}](${link.href})`;
|
|
221
|
+
if (!linkBySignature.has(signature)) {
|
|
222
|
+
linkBySignature.set(signature, link);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// Replace markdown links in content
|
|
226
|
+
return content.replaceAll(MARKDOWN_LINK_REGEX, (fullMatch, text, href) => {
|
|
227
|
+
// Find the corresponding ResourceLink
|
|
228
|
+
const signature = `[${text}](${href})`;
|
|
229
|
+
const link = linkBySignature.get(signature);
|
|
230
|
+
if (!link) {
|
|
231
|
+
// Link not in the parsed links array - leave untouched
|
|
232
|
+
return fullMatch;
|
|
233
|
+
}
|
|
234
|
+
// Resolve the target resource if available
|
|
235
|
+
const resource = link.resolvedId === undefined || resourceRegistry === undefined
|
|
236
|
+
? undefined
|
|
237
|
+
: resourceRegistry.getResourceById(link.resolvedId);
|
|
238
|
+
// Find the first matching rule
|
|
239
|
+
const rule = findMatchingRule(link, resource, linkRewriteRules);
|
|
240
|
+
if (!rule) {
|
|
241
|
+
// No rule matches - leave untouched
|
|
242
|
+
return fullMatch;
|
|
243
|
+
}
|
|
244
|
+
// Parse fragment from href
|
|
245
|
+
const [hrefWithoutFragment, anchor] = splitHrefAnchor(href);
|
|
246
|
+
const fragment = anchor === undefined ? '' : `#${anchor}`;
|
|
247
|
+
// Build template context and render
|
|
248
|
+
const templateContext = buildTemplateContext(link, hrefWithoutFragment, fragment, resource, context);
|
|
249
|
+
return renderTemplate(rule.template, templateContext);
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=content-transform.js.map
|
|
@@ -0,0 +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,MAAM,2BAA2B,CAAC;AAG3D,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;AA+FD;;;;;;;;;GASG;AACH,SAAS,oBAAoB,CAC3B,IAAkB,EAClB,mBAA2B,EAC3B,QAAgB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AAC;QAEtD,+BAA+B;QAC/B,MAAM,IAAI,GAAG,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC;QAEhE,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,oCAAoC;YACpC,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,2BAA2B;QAC3B,MAAM,CAAC,mBAAmB,EAAE,MAAM,CAAC,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;QAC5D,MAAM,QAAQ,GAAG,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC;QAE1D,oCAAoC;QACpC,MAAM,eAAe,GAAG,oBAAoB,CAAC,IAAI,EAAE,mBAAmB,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QACrG,OAAO,cAAc,CAAC,IAAI,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* }
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
export { ResourceRegistry, type CrawlOptions, type ResourceRegistryOptions, type RegistryStats, type CollectionStats, type CollectionStat, } from './resource-registry.js';
|
|
28
|
+
export { ResourceRegistry, generateIdFromPath, type CrawlOptions, type ResourceRegistryOptions, type RegistryStats, type CollectionStats, type CollectionStat, } from './resource-registry.js';
|
|
29
29
|
export { ResourceQuery } from './resource-query.js';
|
|
30
30
|
export { ResourceCollection } from './resource-collection.js';
|
|
31
31
|
export type { ResourceCollectionInterface } from './resource-collection-interface.js';
|
|
@@ -34,4 +34,5 @@ export { LinkTypeSchema, HeadingNodeSchema, ResourceLinkSchema, ResourceMetadata
|
|
|
34
34
|
export { ValidationIssueSchema, ValidationResultSchema, } from './schemas/validation-result.js';
|
|
35
35
|
export { parseMarkdown, type ParseResult } from './link-parser.js';
|
|
36
36
|
export { validateFrontmatter } from './frontmatter-validator.js';
|
|
37
|
+
export { transformContent, type ContentTransformOptions, type LinkRewriteMatch, type LinkRewriteRule, type ResourceLookup, } from './content-transform.js';
|
|
37
38
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,EACL,gBAAgB,EAChB,KAAK,YAAY,EACjB,KAAK,uBAAuB,EAC5B,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,cAAc,GACpB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAG9D,YAAY,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAGtF,YAAY,EACV,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,GACf,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EAAE,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,YAAY,EACjB,KAAK,uBAAuB,EAC5B,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,cAAc,GACpB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAG9D,YAAY,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAGtF,YAAY,EACV,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,GACf,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EAAE,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGjE,OAAO,EACL,gBAAgB,EAChB,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,cAAc,GACpB,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
* }
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
// Export main ResourceRegistry class
|
|
29
|
-
export { ResourceRegistry, } from './resource-registry.js';
|
|
28
|
+
// Export main ResourceRegistry class and ID generation utility
|
|
29
|
+
export { ResourceRegistry, generateIdFromPath, } from './resource-registry.js';
|
|
30
30
|
// Export ResourceQuery for lazy evaluation and filtering
|
|
31
31
|
export { ResourceQuery } from './resource-query.js';
|
|
32
32
|
// Export ResourceCollection for immutable collections with lazy duplicate detection
|
|
@@ -38,6 +38,8 @@ export { ValidationIssueSchema, ValidationResultSchema, } from './schemas/valida
|
|
|
38
38
|
export { parseMarkdown } from './link-parser.js';
|
|
39
39
|
// Export frontmatter validation
|
|
40
40
|
export { validateFrontmatter } from './frontmatter-validator.js';
|
|
41
|
+
// Export content transform engine for link rewriting
|
|
42
|
+
export { transformContent, } from './content-transform.js';
|
|
41
43
|
// Note: link-parser and link-validator internals are NOT exported
|
|
42
44
|
// They are implementation details. Users should use ResourceRegistry API.
|
|
43
45
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,+DAA+D;AAC/D,OAAO,EACL,gBAAgB,EAChB,kBAAkB,GAMnB,MAAM,wBAAwB,CAAC;AAEhC,yDAAyD;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,oFAAoF;AACpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAoB9D,qFAAqF;AACrF,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,gCAAgC,CAAC;AAExC,iDAAiD;AACjD,OAAO,EAAE,aAAa,EAAoB,MAAM,kBAAkB,CAAC;AAEnE,gCAAgC;AAChC,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,qDAAqD;AACrD,OAAO,EACL,gBAAgB,GAKjB,MAAM,wBAAwB,CAAC;AAEhC,kEAAkE;AAClE,0EAA0E"}
|
|
@@ -30,8 +30,10 @@ export interface CrawlOptions {
|
|
|
30
30
|
* Options for ResourceRegistry constructor.
|
|
31
31
|
*/
|
|
32
32
|
export interface ResourceRegistryOptions {
|
|
33
|
-
/**
|
|
34
|
-
|
|
33
|
+
/** Base directory for resources. Used for relative-path ID generation and schema resolution. */
|
|
34
|
+
baseDir?: string;
|
|
35
|
+
/** Frontmatter field name to use as resource ID (optional). When set, the value of this frontmatter field takes priority over path-based ID generation. */
|
|
36
|
+
idField?: string;
|
|
35
37
|
/** Project configuration (optional, enables collection support) */
|
|
36
38
|
config?: ProjectConfig;
|
|
37
39
|
/** Git tracker for efficient git-ignore checking (optional, improves performance) */
|
|
@@ -112,8 +114,10 @@ export interface CollectionStats {
|
|
|
112
114
|
* ```
|
|
113
115
|
*/
|
|
114
116
|
export declare class ResourceRegistry implements ResourceCollectionInterface {
|
|
115
|
-
/**
|
|
116
|
-
|
|
117
|
+
/** Base directory for resources. Used for relative-path ID generation and schema resolution. Set via constructor or propagated from crawl(). */
|
|
118
|
+
baseDir?: string;
|
|
119
|
+
/** Frontmatter field name to use as resource ID. */
|
|
120
|
+
readonly idField?: string;
|
|
117
121
|
/** Optional project configuration (enables collection support) */
|
|
118
122
|
readonly config?: ProjectConfig;
|
|
119
123
|
/** Optional git tracker for efficient git-ignore checking */
|
|
@@ -124,29 +128,31 @@ export declare class ResourceRegistry implements ResourceCollectionInterface {
|
|
|
124
128
|
private readonly resourcesByChecksum;
|
|
125
129
|
constructor(options?: ResourceRegistryOptions);
|
|
126
130
|
/**
|
|
127
|
-
* Create an empty registry with a
|
|
131
|
+
* Create an empty registry with a base directory.
|
|
128
132
|
*
|
|
129
|
-
* @param
|
|
133
|
+
* @param baseDir - Base directory for resources
|
|
130
134
|
* @param options - Additional options
|
|
131
135
|
* @returns New empty registry
|
|
132
136
|
*
|
|
133
137
|
* @example
|
|
134
138
|
* ```typescript
|
|
135
139
|
* const registry = ResourceRegistry.empty('/project/docs');
|
|
136
|
-
* console.log(registry.
|
|
140
|
+
* console.log(registry.baseDir); // '/project/docs'
|
|
137
141
|
* console.log(registry.size()); // 0
|
|
138
142
|
* ```
|
|
139
143
|
*/
|
|
140
|
-
static empty(
|
|
144
|
+
static empty(baseDir: string, options?: Omit<ResourceRegistryOptions, 'baseDir'>): ResourceRegistry;
|
|
141
145
|
/**
|
|
142
146
|
* Create a registry from an existing array of resources.
|
|
143
147
|
*
|
|
144
148
|
* Initializes all indexes (by path, ID, name, checksum) from the provided resources.
|
|
149
|
+
* Throws if any resources have duplicate IDs.
|
|
145
150
|
*
|
|
146
|
-
* @param
|
|
151
|
+
* @param baseDir - Base directory for resources
|
|
147
152
|
* @param resources - Array of resource metadata
|
|
148
153
|
* @param options - Additional options
|
|
149
154
|
* @returns New registry with resources
|
|
155
|
+
* @throws Error if duplicate resource IDs are found
|
|
150
156
|
*
|
|
151
157
|
* @example
|
|
152
158
|
* ```typescript
|
|
@@ -155,7 +161,7 @@ export declare class ResourceRegistry implements ResourceCollectionInterface {
|
|
|
155
161
|
* console.log(`Created registry with ${registry.size()} resources`);
|
|
156
162
|
* ```
|
|
157
163
|
*/
|
|
158
|
-
static fromResources(
|
|
164
|
+
static fromResources(baseDir: string, resources: ResourceMetadata[], options?: Omit<ResourceRegistryOptions, 'baseDir'>): ResourceRegistry;
|
|
159
165
|
/**
|
|
160
166
|
* Create a registry by crawling a directory.
|
|
161
167
|
*
|
|
@@ -175,7 +181,7 @@ export declare class ResourceRegistry implements ResourceCollectionInterface {
|
|
|
175
181
|
* console.log(`Crawled ${registry.size()} resources`);
|
|
176
182
|
* ```
|
|
177
183
|
*/
|
|
178
|
-
static fromCrawl(crawlOptions: CrawlOptions, registryOptions?: Omit<ResourceRegistryOptions, '
|
|
184
|
+
static fromCrawl(crawlOptions: CrawlOptions, registryOptions?: Omit<ResourceRegistryOptions, 'baseDir'>): Promise<ResourceRegistry>;
|
|
179
185
|
/**
|
|
180
186
|
* Add a single resource to the registry.
|
|
181
187
|
*
|
|
@@ -193,10 +199,13 @@ export declare class ResourceRegistry implements ResourceCollectionInterface {
|
|
|
193
199
|
*/
|
|
194
200
|
addResource(filePath: string): Promise<ResourceMetadata>;
|
|
195
201
|
/**
|
|
196
|
-
* Add multiple resources to the registry
|
|
202
|
+
* Add multiple resources to the registry sequentially.
|
|
203
|
+
*
|
|
204
|
+
* Sequential execution ensures deterministic duplicate ID detection.
|
|
197
205
|
*
|
|
198
206
|
* @param filePaths - Array of file paths to add
|
|
199
207
|
* @returns Array of parsed resource metadata
|
|
208
|
+
* @throws Error if any resource produces a duplicate ID
|
|
200
209
|
*
|
|
201
210
|
* @example
|
|
202
211
|
* ```typescript
|
|
@@ -540,17 +549,16 @@ export declare class ResourceRegistry implements ResourceCollectionInterface {
|
|
|
540
549
|
*/
|
|
541
550
|
getCollectionStats(): CollectionStats | undefined;
|
|
542
551
|
/**
|
|
543
|
-
* Generate a
|
|
544
|
-
*
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
* 2. Convert to kebab-case
|
|
548
|
-
* 3. Handle collisions by appending suffix (-2, -3, etc.)
|
|
552
|
+
* Generate a resource ID using the priority chain:
|
|
553
|
+
* 1. Frontmatter field (if `idField` is configured and field exists)
|
|
554
|
+
* 2. Relative path from `baseDir` (if `baseDir` is set)
|
|
555
|
+
* 3. Filename stem (fallback)
|
|
549
556
|
*
|
|
550
557
|
* @param filePath - Absolute file path
|
|
551
|
-
* @
|
|
558
|
+
* @param frontmatter - Parsed frontmatter (optional)
|
|
559
|
+
* @returns Resource ID
|
|
552
560
|
*/
|
|
553
|
-
private
|
|
561
|
+
private generateId;
|
|
554
562
|
/**
|
|
555
563
|
* Build a map of file paths to their heading trees.
|
|
556
564
|
*
|
|
@@ -578,4 +586,26 @@ export declare class ResourceRegistry implements ResourceCollectionInterface {
|
|
|
578
586
|
*/
|
|
579
587
|
private resolveRelativeLinkPath;
|
|
580
588
|
}
|
|
589
|
+
/**
|
|
590
|
+
* Generate an ID from a file path.
|
|
591
|
+
*
|
|
592
|
+
* When `baseDir` is provided, computes a relative path from baseDir and uses the full
|
|
593
|
+
* directory structure in the ID. When no `baseDir`, uses the filename stem only.
|
|
594
|
+
*
|
|
595
|
+
* @param filePath - Absolute file path
|
|
596
|
+
* @param baseDir - Base directory for relative path computation (optional)
|
|
597
|
+
* @returns Generated ID in kebab-case
|
|
598
|
+
*
|
|
599
|
+
* @example
|
|
600
|
+
* ```typescript
|
|
601
|
+
* // Without baseDir: filename stem only
|
|
602
|
+
* generateIdFromPath('/project/docs/User Guide.md') // 'user-guide'
|
|
603
|
+
* generateIdFromPath('/project/README.md') // 'readme'
|
|
604
|
+
*
|
|
605
|
+
* // With baseDir: relative path
|
|
606
|
+
* generateIdFromPath('/project/docs/concepts/core/overview.md', '/project/docs') // 'concepts-core-overview'
|
|
607
|
+
* generateIdFromPath('/project/docs/guide.md', '/project/docs') // 'guide'
|
|
608
|
+
* ```
|
|
609
|
+
*/
|
|
610
|
+
export declare function generateIdFromPath(filePath: string, baseDir?: string): string;
|
|
581
611
|
//# sourceMappingURL=resource-registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-registry.d.ts","sourceRoot":"","sources":["../src/resource-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,EAA0D,KAAK,UAAU,
|
|
1
|
+
{"version":3,"file":"resource-registry.d.ts","sourceRoot":"","sources":["../src/resource-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,EAA0D,KAAK,UAAU,EAAoC,MAAM,2BAA2B,CAAC;AAQtJ,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AACtF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EAAe,gBAAgB,EAAE,MAAM,gCA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