@idea404/repocontext 0.1.0

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/parser.js ADDED
@@ -0,0 +1,562 @@
1
+ import Parser from 'tree-sitter';
2
+ import fs from 'node:fs';
3
+ import { createRequire } from 'node:module';
4
+ import { makeAllowedPath } from './roots.js';
5
+ import { DEFAULT_MAX_FILE_BYTES, DEFAULT_PARSER_CACHE_SIZE, log } from './utils.js';
6
+ const require = createRequire(import.meta.url);
7
+ const cjs = (pkg) => () => require(pkg);
8
+ const cjsNamed = (pkg, name) => () => require(pkg)[name];
9
+ const esmDefault = (pkg) => async () => {
10
+ const { default: mod } = (await import(pkg));
11
+ return mod;
12
+ };
13
+ const esmNamed = (pkg, name) => async () => {
14
+ const { default: mod } = (await import(pkg));
15
+ return mod[name];
16
+ };
17
+ const languagePackages = {
18
+ typescript: cjsNamed('tree-sitter-typescript', 'typescript'),
19
+ tsx: cjsNamed('tree-sitter-typescript', 'tsx'),
20
+ javascript: cjs('tree-sitter-javascript'),
21
+ python: cjs('tree-sitter-python'),
22
+ go: cjs('tree-sitter-go'),
23
+ rust: cjs('tree-sitter-rust'),
24
+ java: cjs('tree-sitter-java'),
25
+ c: cjs('tree-sitter-c'),
26
+ cpp: cjs('tree-sitter-cpp'),
27
+ bash: cjs('tree-sitter-bash'),
28
+ ruby: cjs('tree-sitter-ruby'),
29
+ swift: cjs('tree-sitter-swift'),
30
+ kotlin: cjs('tree-sitter-kotlin'),
31
+ elixir: cjs('tree-sitter-elixir'),
32
+ haskell: cjs('tree-sitter-haskell'),
33
+ scala: cjs('tree-sitter-scala'),
34
+ json: cjs('tree-sitter-json'),
35
+ html: cjs('tree-sitter-html'),
36
+ php: esmNamed('tree-sitter-php', 'php'),
37
+ ocaml: esmNamed('tree-sitter-ocaml', 'ocaml'),
38
+ csharp: esmDefault('tree-sitter-c-sharp'),
39
+ css: esmDefault('tree-sitter-css'),
40
+ perl: esmDefault('tree-sitter-perl'),
41
+ };
42
+ const extensionToLanguage = {
43
+ ts: 'typescript',
44
+ tsx: 'tsx',
45
+ js: 'javascript',
46
+ jsx: 'javascript',
47
+ mjs: 'javascript',
48
+ cjs: 'javascript',
49
+ py: 'python',
50
+ go: 'go',
51
+ rs: 'rust',
52
+ java: 'java',
53
+ c: 'c',
54
+ h: 'c',
55
+ cpp: 'cpp',
56
+ cc: 'cpp',
57
+ hpp: 'cpp',
58
+ cxx: 'cpp',
59
+ sh: 'bash',
60
+ bash: 'bash',
61
+ rb: 'ruby',
62
+ swift: 'swift',
63
+ kt: 'kotlin',
64
+ kts: 'kotlin',
65
+ ex: 'elixir',
66
+ exs: 'elixir',
67
+ hs: 'haskell',
68
+ lhs: 'haskell',
69
+ scala: 'scala',
70
+ sc: 'scala',
71
+ json: 'json',
72
+ html: 'html',
73
+ htm: 'html',
74
+ php: 'php',
75
+ ml: 'ocaml',
76
+ mli: 'ocaml',
77
+ cs: 'csharp',
78
+ css: 'css',
79
+ pl: 'perl',
80
+ pm: 'perl',
81
+ };
82
+ const cache = new Map();
83
+ const parsers = new Map();
84
+ const languageObjects = new Map();
85
+ function getLanguageSync(language) {
86
+ return languageObjects.get(language) ?? null;
87
+ }
88
+ async function getLanguage(language) {
89
+ const cached = languageObjects.get(language);
90
+ if (cached)
91
+ return cached;
92
+ const loader = languagePackages[language];
93
+ if (!loader)
94
+ return null;
95
+ try {
96
+ const lang = await loader();
97
+ if (lang)
98
+ languageObjects.set(language, lang);
99
+ return lang ?? null;
100
+ }
101
+ catch (err) {
102
+ log('warning', `Failed to load language ${language}: ${err}`);
103
+ return null;
104
+ }
105
+ }
106
+ async function getParser(language) {
107
+ const existing = parsers.get(language);
108
+ if (existing)
109
+ return existing;
110
+ const lang = await getLanguage(language);
111
+ if (!lang)
112
+ return null;
113
+ const parser = new Parser();
114
+ parser.setLanguage(lang);
115
+ parsers.set(language, parser);
116
+ return parser;
117
+ }
118
+ function evictIfNeeded() {
119
+ while (cache.size > DEFAULT_PARSER_CACHE_SIZE) {
120
+ const firstKey = cache.keys().next().value;
121
+ if (firstKey) {
122
+ cache.delete(firstKey);
123
+ }
124
+ }
125
+ }
126
+ export function detectLanguageForPath(filePath) {
127
+ const ext = filePath.split('.').pop()?.toLowerCase();
128
+ if (!ext)
129
+ return null;
130
+ return extensionToLanguage[ext] ?? null;
131
+ }
132
+ export async function parseFile(filePath) {
133
+ const allowed = makeAllowedPath(filePath);
134
+ if (!allowed)
135
+ return null;
136
+ let stat;
137
+ try {
138
+ stat = await fs.promises.stat(allowed);
139
+ }
140
+ catch {
141
+ return null;
142
+ }
143
+ if (!stat.isFile())
144
+ return null;
145
+ if (stat.size > DEFAULT_MAX_FILE_BYTES) {
146
+ log('warning', `Skipping ${allowed}: exceeds ${DEFAULT_MAX_FILE_BYTES} bytes`);
147
+ return null;
148
+ }
149
+ const language = detectLanguageForPath(allowed);
150
+ if (!language)
151
+ return null;
152
+ const cacheKey = `${allowed}|${stat.mtimeMs}|${stat.size}`;
153
+ const cached = cache.get(cacheKey);
154
+ if (cached)
155
+ return cached.result;
156
+ let source;
157
+ try {
158
+ source = await fs.promises.readFile(allowed, 'utf-8');
159
+ }
160
+ catch {
161
+ return null;
162
+ }
163
+ const parser = await getParser(language);
164
+ if (!parser)
165
+ return null;
166
+ const langObj = getLanguageSync(language);
167
+ try {
168
+ const tree = parser.parse(source);
169
+ const result = extractResult(tree, language, source, stat.size, langObj);
170
+ evictIfNeeded();
171
+ cache.set(cacheKey, { result, mtimeMs: stat.mtimeMs, size: stat.size });
172
+ return result;
173
+ }
174
+ catch (err) {
175
+ log('warning', `Failed to parse ${allowed}: ${err}`);
176
+ return null;
177
+ }
178
+ }
179
+ function extractResult(tree, language, fileSource, totalBytes, langObj) {
180
+ const lines = fileSource.split('\n');
181
+ const totalLines = lines.length;
182
+ const blankLines = lines.filter((l) => l.trim().length === 0).length;
183
+ const commentLines = 0;
184
+ const codeLines = totalLines - blankLines - commentLines;
185
+ const structure = extractStructure(tree, language, fileSource, langObj);
186
+ const imports = extractImports(tree, language, langObj);
187
+ const exports = extractExports(tree, language, structure, langObj);
188
+ return {
189
+ language,
190
+ metrics: {
191
+ totalLines,
192
+ codeLines,
193
+ commentLines,
194
+ blankLines,
195
+ totalBytes,
196
+ nodeCount: countNodes(tree.rootNode),
197
+ errorCount: countErrors(tree.rootNode),
198
+ maxDepth: maxDepth(tree.rootNode),
199
+ },
200
+ structure,
201
+ imports,
202
+ exports,
203
+ };
204
+ }
205
+ function extractStructure(tree, language, fileSource, langObj) {
206
+ const result = [];
207
+ const queries = {
208
+ typescript: `
209
+ [
210
+ (function_declaration name: (identifier) @name) @decl
211
+ (class_declaration name: (type_identifier) @name) @decl
212
+ (method_definition name: (property_identifier) @name) @decl
213
+ (interface_declaration name: (type_identifier) @name) @decl
214
+ (type_alias_declaration name: (type_identifier) @name) @decl
215
+ ]
216
+ `,
217
+ tsx: `
218
+ [
219
+ (function_declaration name: (identifier) @name) @decl
220
+ (class_declaration name: (type_identifier) @name) @decl
221
+ (method_definition name: (property_identifier) @name) @decl
222
+ (interface_declaration name: (type_identifier) @name) @decl
223
+ ]
224
+ `,
225
+ javascript: `
226
+ [
227
+ (function_declaration name: (identifier) @name) @decl
228
+ (class_declaration name: (identifier) @name) @decl
229
+ (method_definition name: (property_identifier) @name) @decl
230
+ ]
231
+ `,
232
+ python: `
233
+ [
234
+ (function_definition name: (identifier) @name) @decl
235
+ (class_definition name: (identifier) @name) @decl
236
+ ]
237
+ `,
238
+ go: `
239
+ [
240
+ (function_declaration name: (identifier) @name) @decl
241
+ (method_declaration name: (field_identifier) @name) @decl
242
+ (type_declaration (type_spec name: (type_identifier) @name)) @decl
243
+ ]
244
+ `,
245
+ rust: `
246
+ [
247
+ (function_item name: (identifier) @name) @decl
248
+ (struct_item name: (type_identifier) @name) @decl
249
+ (impl_item type: (type_identifier) @name) @decl
250
+ (trait_item name: (type_identifier) @name) @decl
251
+ ]
252
+ `,
253
+ java: `
254
+ [
255
+ (method_declaration name: (identifier) @name) @decl
256
+ (class_declaration name: (identifier) @name) @decl
257
+ (interface_declaration name: (identifier) @name) @decl
258
+ ]
259
+ `,
260
+ c: `
261
+ [
262
+ (function_definition declarator: (function_declarator declarator: (identifier) @name)) @decl
263
+ (struct_specifier name: (type_identifier) @name) @decl
264
+ ]
265
+ `,
266
+ cpp: `
267
+ [
268
+ (function_definition declarator: (function_declarator declarator: (identifier) @name)) @decl
269
+ (class_specifier name: (type_identifier) @name) @decl
270
+ (struct_specifier name: (type_identifier) @name) @decl
271
+ ]
272
+ `,
273
+ bash: `
274
+ (function_definition name: (word) @name) @decl
275
+ `,
276
+ ruby: `
277
+ [
278
+ (method name: (identifier) @name) @decl
279
+ (class name: (constant) @name) @decl
280
+ (module name: (constant) @name) @decl
281
+ ]
282
+ `,
283
+ swift: `
284
+ [
285
+ (class_declaration name: (type_identifier) @name) @decl
286
+ (struct_declaration name: (type_identifier) @name) @decl
287
+ (enum_declaration name: (type_identifier) @name) @decl
288
+ (protocol_declaration name: (type_identifier) @name) @decl
289
+ (function_declaration name: (simple_identifier) @name) @decl
290
+ ]
291
+ `,
292
+ kotlin: `
293
+ [
294
+ (class_declaration name: (simple_identifier) @name) @decl
295
+ (function_declaration name: (simple_identifier) @name) @decl
296
+ (object_declaration name: (simple_identifier) @name) @decl
297
+ ]
298
+ `,
299
+ scala: `
300
+ [
301
+ (class_definition name: (identifier) @name) @decl
302
+ (trait_definition name: (identifier) @name) @decl
303
+ (object_definition name: (identifier) @name) @decl
304
+ (function_definition name: (identifier) @name) @decl
305
+ ]
306
+ `,
307
+ haskell: `
308
+ [
309
+ (function name: (variable) @name) @decl
310
+ (data_declaration name: (type) @name) @decl
311
+ (class_declaration name: (type) @name) @decl
312
+ (instance_declaration name: (type) @name) @decl
313
+ ]
314
+ `,
315
+ elixir: `
316
+ [
317
+ (call
318
+ function: (identifier) @name
319
+ arguments: (arguments (call target: (identifier) @name)))
320
+ ]
321
+ `,
322
+ csharp: `
323
+ [
324
+ (class_declaration name: (identifier) @name) @decl
325
+ (struct_declaration name: (identifier) @name) @decl
326
+ (interface_declaration name: (identifier) @name) @decl
327
+ (method_declaration name: (identifier) @name) @decl
328
+ ]
329
+ `,
330
+ php: `
331
+ [
332
+ (function_definition name: (name) @name) @decl
333
+ (class_declaration name: (name) @name) @decl
334
+ (interface_declaration name: (name) @name) @decl
335
+ (trait_declaration name: (name) @name) @decl
336
+ ]
337
+ `,
338
+ ocaml: `
339
+ [
340
+ (value_definition name: (value_name) @name) @decl
341
+ (let_binding name: (value_name) @name) @decl
342
+ ]
343
+ `,
344
+ perl: `
345
+ [
346
+ (subroutine_declaration name: (identifier) @name) @decl
347
+ (package_declaration name: (identifier) @name) @decl
348
+ ]
349
+ `,
350
+ css: '',
351
+ html: '',
352
+ json: '',
353
+ };
354
+ const queryText = queries[language];
355
+ if (!queryText || !langObj)
356
+ return result;
357
+ try {
358
+ const query = new Parser.Query(langObj, queryText);
359
+ const matches = query.matches(tree.rootNode);
360
+ for (const match of matches) {
361
+ const declCapture = match.captures.find((c) => c.name === 'decl');
362
+ const nameCapture = match.captures.find((c) => c.name === 'name');
363
+ if (!declCapture || !nameCapture)
364
+ continue;
365
+ const node = declCapture.node;
366
+ const name = nameCapture.node.text;
367
+ const kind = kindFromNode(node.type, language);
368
+ result.push({
369
+ kind,
370
+ name,
371
+ startLine: node.startPosition.row + 1,
372
+ endLine: node.endPosition.row + 1,
373
+ signature: fileSource.slice(node.startIndex, Math.min(node.endIndex, node.startIndex + 200)),
374
+ });
375
+ }
376
+ }
377
+ catch (err) {
378
+ log('warning', `Structure query failed for ${language}: ${err}`);
379
+ }
380
+ return result;
381
+ }
382
+ function kindFromNode(type, _language) {
383
+ if (type.includes('class'))
384
+ return 'class';
385
+ if (type.includes('interface'))
386
+ return 'interface';
387
+ if (type.includes('function'))
388
+ return 'function';
389
+ if (type.includes('method'))
390
+ return 'method';
391
+ if (type.includes('struct'))
392
+ return 'struct';
393
+ if (type.includes('trait'))
394
+ return 'trait';
395
+ if (type.includes('impl'))
396
+ return 'impl';
397
+ if (type.includes('type'))
398
+ return 'type_alias';
399
+ if (type.includes('module'))
400
+ return 'module';
401
+ if (type.includes('package'))
402
+ return 'package';
403
+ if (type.includes('protocol'))
404
+ return 'protocol';
405
+ if (type.includes('enum'))
406
+ return 'enum';
407
+ if (type.includes('object'))
408
+ return 'object';
409
+ if (type.includes('data'))
410
+ return 'data';
411
+ if (type.includes('instance'))
412
+ return 'instance';
413
+ if (type.includes('subroutine'))
414
+ return 'function';
415
+ if (type.includes('value'))
416
+ return 'value';
417
+ if (type.includes('let'))
418
+ return 'value';
419
+ return type;
420
+ }
421
+ function extractImports(tree, language, langObj) {
422
+ const result = [];
423
+ const queries = {
424
+ typescript: '(import_statement source: (string) @source) @import',
425
+ tsx: '(import_statement source: (string) @source) @import',
426
+ javascript: '(import_statement source: (string) @source) @import',
427
+ python: `
428
+ [
429
+ (import_statement name: (dotted_name) @source) @import
430
+ (import_from_statement module_name: (dotted_name) @source) @import
431
+ ]
432
+ `,
433
+ go: '(import_spec path: (interpreted_string_literal) @source) @import',
434
+ rust: '(use_declaration argument: (_) @source) @import',
435
+ java: '(import_declaration (_) @source) @import',
436
+ ruby: `
437
+ [
438
+ (call method: (identifier) @source) @import
439
+ ]
440
+ `,
441
+ php: `
442
+ [
443
+ (include_expression (string) @source) @import
444
+ (include_once_expression (string) @source) @import
445
+ (require_expression (string) @source) @import
446
+ (require_once_expression (string) @source) @import
447
+ ]
448
+ `,
449
+ haskell: '(import_declaration module: (module) @source) @import',
450
+ scala: '(import_export_path path: (identifier) @source) @import',
451
+ swift: '(import_declaration path: (identifier) @source) @import',
452
+ csharp: '(using_directive name: (identifier) @source) @import',
453
+ bash: '',
454
+ c: '',
455
+ cpp: '',
456
+ kotlin: '',
457
+ elixir: '',
458
+ ocaml: '',
459
+ perl: '',
460
+ css: '',
461
+ html: '',
462
+ json: '',
463
+ };
464
+ const queryText = queries[language];
465
+ if (!queryText || !langObj)
466
+ return result;
467
+ try {
468
+ const query = new Parser.Query(langObj, queryText);
469
+ const matches = query.matches(tree.rootNode);
470
+ for (const match of matches) {
471
+ const decl = match.captures.find((c) => c.name === 'import')?.node;
472
+ const sourceNode = match.captures.find((c) => c.name === 'source')?.node;
473
+ if (!decl || !sourceNode)
474
+ continue;
475
+ let source = sourceNode.text;
476
+ source = source.replace(/^["']|["']$/g, '');
477
+ const items = [];
478
+ let isWildcard = false;
479
+ if (language === 'python') {
480
+ isWildcard = decl.text.includes('*');
481
+ }
482
+ else if (['typescript', 'tsx', 'javascript'].includes(language)) {
483
+ const specifierQuery = new Parser.Query(langObj, '(import_specifier name: (identifier) @item)');
484
+ const specMatches = specifierQuery.matches(decl);
485
+ for (const sm of specMatches) {
486
+ const item = sm.captures.find((c) => c.name === 'item')?.node.text;
487
+ if (item)
488
+ items.push(item);
489
+ }
490
+ isWildcard = decl.text.includes('*');
491
+ }
492
+ result.push({ source, items, isWildcard });
493
+ }
494
+ }
495
+ catch (err) {
496
+ log('warning', `Import query failed for ${language}: ${err}`);
497
+ }
498
+ return result;
499
+ }
500
+ function extractExports(tree, language, structure, langObj) {
501
+ if (!['typescript', 'tsx', 'javascript', 'python', 'rust', 'go', 'swift', 'elixir', 'php'].includes(language)) {
502
+ return [];
503
+ }
504
+ const result = [];
505
+ const queries = {
506
+ typescript: '(export_statement (function_declaration name: (identifier) @name)) @export',
507
+ tsx: '(export_statement (function_declaration name: (identifier) @name)) @export',
508
+ javascript: '(export_statement (function_declaration name: (identifier) @name)) @export',
509
+ python: '(expression_statement (assignment left: (identifier) @name)) @export',
510
+ rust: '(visibility_modifier) @export',
511
+ go: '(function_declaration name: (identifier) @name) @export',
512
+ swift: '(function_declaration name: (simple_identifier) @name) @export',
513
+ php: '(function_definition name: (name) @name) @export',
514
+ };
515
+ const queryText = queries[language];
516
+ if (!queryText || !langObj)
517
+ return result;
518
+ try {
519
+ const query = new Parser.Query(langObj, queryText);
520
+ const matches = query.matches(tree.rootNode);
521
+ for (const match of matches) {
522
+ const name = match.captures.find((c) => c.name === 'name')?.node.text;
523
+ if (!name)
524
+ continue;
525
+ result.push({ name, kind: 'export' });
526
+ }
527
+ }
528
+ catch (err) {
529
+ log('warning', `Export query failed for ${language}: ${err}`);
530
+ }
531
+ for (const s of structure) {
532
+ if (!result.some((e) => e.name === s.name)) {
533
+ result.push({ name: s.name, kind: s.kind });
534
+ }
535
+ }
536
+ return result;
537
+ }
538
+ function countNodes(node) {
539
+ let count = 1;
540
+ for (const child of node.children) {
541
+ count += countNodes(child);
542
+ }
543
+ return count;
544
+ }
545
+ function countErrors(node) {
546
+ let count = node.type === 'ERROR' ? 1 : 0;
547
+ for (const child of node.children) {
548
+ count += countErrors(child);
549
+ }
550
+ return count;
551
+ }
552
+ function maxDepth(node, current = 0) {
553
+ let max = current;
554
+ for (const child of node.children) {
555
+ max = Math.max(max, maxDepth(child, current + 1));
556
+ }
557
+ return max;
558
+ }
559
+ export function clearParserCache() {
560
+ cache.clear();
561
+ }
562
+ //# sourceMappingURL=parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAGpF,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAI/C,MAAM,GAAG,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,GAAY,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AACzD,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,IAAY,EAAE,EAAE,C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K,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,KAAK,CAAC,KAAK,EAAE,CAAC;AAChB,CAAC"}
@@ -0,0 +1,15 @@
1
+ export interface Root {
2
+ uri: string;
3
+ name?: string;
4
+ path: string;
5
+ }
6
+ export declare function setRoots(roots: Root[]): void;
7
+ export declare function getRoots(): Root[];
8
+ export declare function initializeFallbackRoot(): void;
9
+ export declare function isPathAllowed(targetPath: string): boolean;
10
+ export declare function makeAllowedPath(inputPath: string): string | null;
11
+ export declare function relativizeToRoot(targetPath: string): {
12
+ root: Root;
13
+ relative: string;
14
+ } | null;
15
+ //# sourceMappingURL=roots.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roots.d.ts","sourceRoot":"","sources":["../src/roots.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,IAAI;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAID,wBAAgB,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAM5C;AAED,wBAAgB,QAAQ,IAAI,IAAI,EAAE,CAEjC;AAED,wBAAgB,sBAAsB,IAAI,IAAI,CAM7C;AASD,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAOzD;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAIhE;AAED,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAS5F"}
package/dist/roots.js ADDED
@@ -0,0 +1,53 @@
1
+ import { fileURLToPath } from 'node:url';
2
+ import path from 'node:path';
3
+ import { log } from './utils.js';
4
+ let allowedRoots = [];
5
+ export function setRoots(roots) {
6
+ allowedRoots = roots.map((r) => ({
7
+ ...r,
8
+ path: normalizeRootPath(r.uri),
9
+ }));
10
+ log('info', `Roots updated: ${allowedRoots.map((r) => r.path).join(', ')}`);
11
+ }
12
+ export function getRoots() {
13
+ return allowedRoots;
14
+ }
15
+ export function initializeFallbackRoot() {
16
+ if (allowedRoots.length === 0) {
17
+ const cwd = process.cwd();
18
+ allowedRoots = [{ uri: `file://${cwd}`, name: 'cwd', path: cwd }];
19
+ log('info', `No roots provided; falling back to cwd: ${cwd}`);
20
+ }
21
+ }
22
+ function normalizeRootPath(uri) {
23
+ if (uri.startsWith('file://')) {
24
+ return fileURLToPath(uri);
25
+ }
26
+ return path.resolve(uri);
27
+ }
28
+ export function isPathAllowed(targetPath) {
29
+ const resolved = path.resolve(targetPath);
30
+ if (allowedRoots.length === 0)
31
+ return false;
32
+ return allowedRoots.some((root) => {
33
+ const relative = path.relative(root.path, resolved);
34
+ return relative && !relative.startsWith('..') && !path.isAbsolute(relative);
35
+ });
36
+ }
37
+ export function makeAllowedPath(inputPath) {
38
+ const resolved = path.resolve(inputPath);
39
+ if (!isPathAllowed(resolved))
40
+ return null;
41
+ return resolved;
42
+ }
43
+ export function relativizeToRoot(targetPath) {
44
+ const resolved = path.resolve(targetPath);
45
+ for (const root of allowedRoots) {
46
+ const relative = path.relative(root.path, resolved);
47
+ if (relative && !relative.startsWith('..') && !path.isAbsolute(relative)) {
48
+ return { root, relative };
49
+ }
50
+ }
51
+ return null;
52
+ }
53
+ //# sourceMappingURL=roots.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roots.js","sourceRoot":"","sources":["../src/roots.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAQjC,IAAI,YAAY,GAAW,EAAE,CAAC;A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