@aiready/core 0.24.22 → 0.24.25

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.
Files changed (59) hide show
  1. package/dist/chunk-3GCIM6XG.mjs +904 -0
  2. package/dist/chunk-3S5WU6KX.mjs +552 -0
  3. package/dist/chunk-4OMXBYX7.mjs +167 -0
  4. package/dist/chunk-6YWGFKZG.mjs +250 -0
  5. package/dist/chunk-A3BIROBZ.mjs +902 -0
  6. package/dist/chunk-BYMQDORS.mjs +256 -0
  7. package/dist/chunk-CBZNRNEF.mjs +309 -0
  8. package/dist/chunk-ET2WRQSM.mjs +262 -0
  9. package/dist/chunk-F4FTHFHK.mjs +552 -0
  10. package/dist/chunk-G737F72Q.mjs +256 -0
  11. package/dist/chunk-GVFUAIWU.mjs +864 -0
  12. package/dist/chunk-KSEA5XDH.mjs +894 -0
  13. package/dist/chunk-LMIZRJFV.mjs +256 -0
  14. package/dist/chunk-LRPBPWBM.mjs +170 -0
  15. package/dist/chunk-MOTBXU6W.mjs +902 -0
  16. package/dist/chunk-OAH6FVVF.mjs +919 -0
  17. package/dist/chunk-OCM6HLBM.mjs +262 -0
  18. package/dist/chunk-OFBRNGKT.mjs +893 -0
  19. package/dist/chunk-P3KYGPO4.mjs +262 -0
  20. package/dist/chunk-PNWSO6XQ.mjs +250 -0
  21. package/dist/chunk-SO6UKAPR.mjs +164 -0
  22. package/dist/chunk-T2FW6AAF.mjs +552 -0
  23. package/dist/chunk-TQX77RIC.mjs +250 -0
  24. package/dist/chunk-X64EJ3ZO.mjs +314 -0
  25. package/dist/client/index.d.mts +1 -1
  26. package/dist/client/index.d.ts +1 -1
  27. package/dist/client/index.js +32 -5
  28. package/dist/client/index.mjs +1 -1
  29. package/dist/csharp-parser-3CGM6FKB.mjs +9 -0
  30. package/dist/csharp-parser-UWRUYHUH.mjs +9 -0
  31. package/dist/csharp-parser-WIAIE3DD.mjs +9 -0
  32. package/dist/go-parser-AH5QNS4O.mjs +9 -0
  33. package/dist/go-parser-CSAB23BL.mjs +9 -0
  34. package/dist/go-parser-Q3HI32B7.mjs +9 -0
  35. package/dist/index-CL_0jxiJ.d.mts +1315 -0
  36. package/dist/index-CL_0jxiJ.d.ts +1315 -0
  37. package/dist/index-ClwnZa_Y.d.mts +1333 -0
  38. package/dist/index-ClwnZa_Y.d.ts +1333 -0
  39. package/dist/index-DC0cdf0g.d.mts +1321 -0
  40. package/dist/index-DC0cdf0g.d.ts +1321 -0
  41. package/dist/index-DKqKGhcJ.d.mts +1309 -0
  42. package/dist/index-DKqKGhcJ.d.ts +1309 -0
  43. package/dist/index-DNnlhdk0.d.mts +1318 -0
  44. package/dist/index-DNnlhdk0.d.ts +1318 -0
  45. package/dist/index-De2xy_k5.d.mts +1326 -0
  46. package/dist/index-De2xy_k5.d.ts +1326 -0
  47. package/dist/index.d.mts +104 -20
  48. package/dist/index.d.ts +104 -20
  49. package/dist/index.js +581 -147
  50. package/dist/index.mjs +507 -134
  51. package/dist/java-parser-GUKWCEYS.mjs +9 -0
  52. package/dist/java-parser-XTWT5Y5I.mjs +9 -0
  53. package/dist/java-parser-YP5XWLQK.mjs +9 -0
  54. package/dist/python-parser-AOPXUEIV.mjs +8 -0
  55. package/dist/python-parser-FB55P6UA.mjs +8 -0
  56. package/dist/python-parser-WIJPSRKC.mjs +8 -0
  57. package/dist/typescript-parser-5ZWLLMWJ.mjs +7 -0
  58. package/dist/typescript-parser-TWPRLYK6.mjs +7 -0
  59. package/package.json +5 -1
@@ -0,0 +1,552 @@
1
+ import {
2
+ BaseLanguageParser
3
+ } from "./chunk-SO6UKAPR.mjs";
4
+
5
+ // src/parsers/metadata-utils.ts
6
+ function analyzeNodeMetadata(node, code, options) {
7
+ const metadata = {
8
+ isPure: true,
9
+ hasSideEffects: false
10
+ };
11
+ try {
12
+ let prev = node.previousSibling;
13
+ while (prev && /comment/i.test(prev.type)) {
14
+ const text = prev.text || "";
15
+ const loc = {
16
+ start: {
17
+ line: prev.startPosition.row + 1,
18
+ column: prev.startPosition.column
19
+ },
20
+ end: {
21
+ line: prev.endPosition.row + 1,
22
+ column: prev.endPosition.column
23
+ }
24
+ };
25
+ if (text.trim().startsWith("/**") || text.trim().startsWith("/*")) {
26
+ metadata.documentation = {
27
+ content: text.replace(/^[/*]+|[/*]+$/g, "").trim(),
28
+ type: "comment",
29
+ loc
30
+ };
31
+ break;
32
+ }
33
+ if (text.trim().startsWith("///")) {
34
+ metadata.documentation = {
35
+ content: text.replace(/^\/\/\//, "").trim(),
36
+ type: "xml-doc",
37
+ loc
38
+ };
39
+ break;
40
+ }
41
+ if (text.trim().startsWith("//")) {
42
+ metadata.documentation = {
43
+ content: text.replace(/^\/\//, "").trim(),
44
+ type: "comment",
45
+ loc
46
+ };
47
+ break;
48
+ }
49
+ prev = prev.previousSibling;
50
+ }
51
+ if (node.type === "function_definition" || node.type === "class_definition") {
52
+ const body2 = node.childForFieldName("body") || node.children.find((c) => c.type === "block");
53
+ if (body2 && body2.children.length > 0) {
54
+ const firstStmt = body2.children[0];
55
+ if (firstStmt.type === "expression_statement" && firstStmt.firstChild?.type === "string") {
56
+ metadata.documentation = {
57
+ content: firstStmt.firstChild.text.replace(/['"`]/g, "").trim(),
58
+ type: "docstring",
59
+ loc: {
60
+ start: {
61
+ line: firstStmt.startPosition.row + 1,
62
+ column: firstStmt.startPosition.column
63
+ },
64
+ end: {
65
+ line: firstStmt.endPosition.row + 1,
66
+ column: firstStmt.endPosition.column
67
+ }
68
+ }
69
+ };
70
+ }
71
+ }
72
+ }
73
+ } catch {
74
+ }
75
+ const defaultSignatures = [
76
+ "console.",
77
+ "fmt.",
78
+ "panic(",
79
+ "os.Exit",
80
+ "log.",
81
+ "Console.Write",
82
+ "File.Write",
83
+ "System.out",
84
+ "System.err",
85
+ "Files.write",
86
+ "process.exit",
87
+ "exit("
88
+ ];
89
+ const signatures = Array.from(
90
+ /* @__PURE__ */ new Set([...options?.sideEffectSignatures || [], ...defaultSignatures])
91
+ );
92
+ const walk = (n) => {
93
+ try {
94
+ const t = n.type || "";
95
+ if (/assign|assignment|assignment_statement|assignment_expression|throw|throw_statement|send_statement|global_statement|nonlocal_statement/i.test(
96
+ t
97
+ )) {
98
+ metadata.isPure = false;
99
+ metadata.hasSideEffects = true;
100
+ }
101
+ const text = n.text || "";
102
+ for (const s of signatures) {
103
+ if (text.includes(s)) {
104
+ metadata.isPure = false;
105
+ metadata.hasSideEffects = true;
106
+ break;
107
+ }
108
+ }
109
+ for (let i = 0; i < n.childCount; i++) {
110
+ const c = n.child(i);
111
+ if (c) walk(c);
112
+ }
113
+ } catch {
114
+ }
115
+ };
116
+ const body = node.childForFieldName("body") || node.children.find(
117
+ (c) => /body|block|class_body|declaration_list|function_body/.test(c.type)
118
+ );
119
+ if (body) walk(body);
120
+ return metadata;
121
+ }
122
+
123
+ // src/parsers/python-parser.ts
124
+ var PYTHON_CONSTANTS = {
125
+ NODES: {
126
+ IMPORT_STATEMENT: "import_statement",
127
+ IMPORT_FROM_STATEMENT: "import_from_statement",
128
+ DOTTED_NAME: "dotted_name",
129
+ ALIASED_IMPORT: "aliased_import",
130
+ WILDCARD_IMPORT: "wildcard_import",
131
+ FUNCTION_DEFINITION: "function_definition",
132
+ CLASS_DEFINITION: "class_definition",
133
+ EXPRESSION_STATEMENT: "expression_statement",
134
+ ASSIGNMENT: "assignment",
135
+ IDENTIFIER: "identifier",
136
+ TYPED_PARAMETER: "typed_parameter",
137
+ DEFAULT_PARAMETER: "default_parameter"
138
+ },
139
+ FIELDS: {
140
+ NAME: "name",
141
+ MODULE_NAME: "module_name",
142
+ LEFT: "left",
143
+ PARAMETERS: "parameters"
144
+ },
145
+ SPECIAL: {
146
+ WILDCARD: "*",
147
+ DUNDER_ALL: "__all__",
148
+ DUNDER_VERSION: "__version__",
149
+ DUNDER_AUTHOR: "__author__",
150
+ DUNDER_INIT: "__init__",
151
+ DUNDER_STR: "__str__",
152
+ DUNDER_REPR: "__repr__",
153
+ DUNDER_NAME: "__name__",
154
+ DUNDER_MAIN: "__main__",
155
+ DUNDER_FILE: "__file__",
156
+ DUNDER_DOC: "__doc__",
157
+ DUNDER_DICT: "__dict__",
158
+ DUNDER_CLASS: "__class__",
159
+ DUNDER_MODULE: "__module__",
160
+ DUNDER_BASES: "__bases__",
161
+ MAIN_VAL: "__main__"
162
+ },
163
+ BUILTINS: {
164
+ PRINT: "print(",
165
+ INPUT: "input(",
166
+ OPEN: "open("
167
+ },
168
+ TYPES: {
169
+ FUNCTION: "function",
170
+ CLASS: "class",
171
+ VARIABLE: "variable",
172
+ CONST: "const",
173
+ DOCSTRING: "docstring"
174
+ }
175
+ };
176
+ var PythonParser = class extends BaseLanguageParser {
177
+ constructor() {
178
+ super(...arguments);
179
+ this.language = "python" /* Python */;
180
+ this.extensions = [".py"];
181
+ }
182
+ /**
183
+ * Returns the canonical name of this parser.
184
+ */
185
+ getParserName() {
186
+ return "python";
187
+ }
188
+ /**
189
+ * Analyze metadata for a Python node (purity, side effects).
190
+ */
191
+ analyzeMetadata(node, code) {
192
+ return analyzeNodeMetadata(node, code, {
193
+ sideEffectSignatures: [
194
+ PYTHON_CONSTANTS.BUILTINS.PRINT,
195
+ PYTHON_CONSTANTS.BUILTINS.INPUT,
196
+ PYTHON_CONSTANTS.BUILTINS.OPEN
197
+ ]
198
+ });
199
+ }
200
+ /**
201
+ * Extract import information using AST walk.
202
+ */
203
+ extractImportsAST(rootNode) {
204
+ const imports = [];
205
+ const processImportNode = (node) => {
206
+ if (node.type === PYTHON_CONSTANTS.NODES.IMPORT_STATEMENT) {
207
+ for (const child of node.children) {
208
+ if (child.type === PYTHON_CONSTANTS.NODES.DOTTED_NAME) {
209
+ const source = child.text;
210
+ imports.push({
211
+ source,
212
+ specifiers: [source],
213
+ loc: {
214
+ start: {
215
+ line: child.startPosition.row + 1,
216
+ column: child.startPosition.column
217
+ },
218
+ end: {
219
+ line: child.endPosition.row + 1,
220
+ column: child.endPosition.column
221
+ }
222
+ }
223
+ });
224
+ } else if (child.type === PYTHON_CONSTANTS.NODES.ALIASED_IMPORT) {
225
+ const nameNode = child.childForFieldName(
226
+ PYTHON_CONSTANTS.FIELDS.NAME
227
+ );
228
+ if (nameNode) {
229
+ const source = nameNode.text;
230
+ imports.push({
231
+ source,
232
+ specifiers: [source],
233
+ loc: {
234
+ start: {
235
+ line: child.startPosition.row + 1,
236
+ column: child.startPosition.column
237
+ },
238
+ end: {
239
+ line: child.endPosition.row + 1,
240
+ column: child.endPosition.column
241
+ }
242
+ }
243
+ });
244
+ }
245
+ }
246
+ }
247
+ } else if (node.type === PYTHON_CONSTANTS.NODES.IMPORT_FROM_STATEMENT) {
248
+ const moduleNameNode = node.childForFieldName(
249
+ PYTHON_CONSTANTS.FIELDS.MODULE_NAME
250
+ );
251
+ if (moduleNameNode) {
252
+ const source = moduleNameNode.text;
253
+ const specifiers = [];
254
+ for (const child of node.children) {
255
+ if (child.type === PYTHON_CONSTANTS.NODES.DOTTED_NAME && child !== moduleNameNode) {
256
+ specifiers.push(child.text);
257
+ } else if (child.type === PYTHON_CONSTANTS.NODES.ALIASED_IMPORT) {
258
+ const nameNode = child.childForFieldName(
259
+ PYTHON_CONSTANTS.FIELDS.NAME
260
+ );
261
+ if (nameNode) specifiers.push(nameNode.text);
262
+ } else if (child.type === PYTHON_CONSTANTS.NODES.WILDCARD_IMPORT) {
263
+ specifiers.push(PYTHON_CONSTANTS.SPECIAL.WILDCARD);
264
+ }
265
+ }
266
+ if (specifiers.length > 0) {
267
+ imports.push({
268
+ source,
269
+ specifiers,
270
+ loc: {
271
+ start: {
272
+ line: node.startPosition.row + 1,
273
+ column: node.startPosition.column
274
+ },
275
+ end: {
276
+ line: node.endPosition.row + 1,
277
+ column: node.endPosition.column
278
+ }
279
+ }
280
+ });
281
+ }
282
+ }
283
+ }
284
+ };
285
+ for (const node of rootNode.children) {
286
+ processImportNode(node);
287
+ }
288
+ return imports;
289
+ }
290
+ /**
291
+ * Extract export information using AST walk.
292
+ */
293
+ extractExportsAST(rootNode, code) {
294
+ const exports = [];
295
+ for (const node of rootNode.children) {
296
+ if (node.type === PYTHON_CONSTANTS.NODES.FUNCTION_DEFINITION) {
297
+ const nameNode = node.childForFieldName(PYTHON_CONSTANTS.FIELDS.NAME);
298
+ if (nameNode) {
299
+ const name = nameNode.text;
300
+ const isPrivate = name.startsWith("_") && !name.startsWith("__");
301
+ if (!isPrivate) {
302
+ const metadata = this.analyzeMetadata(node, code);
303
+ exports.push({
304
+ name,
305
+ type: PYTHON_CONSTANTS.TYPES.FUNCTION,
306
+ loc: {
307
+ start: {
308
+ line: node.startPosition.row + 1,
309
+ column: node.startPosition.column
310
+ },
311
+ end: {
312
+ line: node.endPosition.row + 1,
313
+ column: node.endPosition.column
314
+ }
315
+ },
316
+ parameters: this.extractParameters(node),
317
+ ...metadata
318
+ });
319
+ }
320
+ }
321
+ } else if (node.type === PYTHON_CONSTANTS.NODES.CLASS_DEFINITION) {
322
+ const nameNode = node.childForFieldName(PYTHON_CONSTANTS.FIELDS.NAME);
323
+ if (nameNode) {
324
+ const metadata = this.analyzeMetadata(node, code);
325
+ exports.push({
326
+ name: nameNode.text,
327
+ type: PYTHON_CONSTANTS.TYPES.CLASS,
328
+ loc: {
329
+ start: {
330
+ line: node.startPosition.row + 1,
331
+ column: node.startPosition.column
332
+ },
333
+ end: {
334
+ line: node.endPosition.row + 1,
335
+ column: node.endPosition.column
336
+ }
337
+ },
338
+ ...metadata
339
+ });
340
+ }
341
+ } else if (node.type === PYTHON_CONSTANTS.NODES.EXPRESSION_STATEMENT) {
342
+ const assignment = node.firstChild;
343
+ if (assignment && assignment.type === PYTHON_CONSTANTS.NODES.ASSIGNMENT) {
344
+ const left = assignment.childForFieldName(
345
+ PYTHON_CONSTANTS.FIELDS.LEFT
346
+ );
347
+ if (left && left.type === PYTHON_CONSTANTS.NODES.IDENTIFIER) {
348
+ const name = left.text;
349
+ const isInternal = name === PYTHON_CONSTANTS.SPECIAL.DUNDER_ALL || name === PYTHON_CONSTANTS.SPECIAL.DUNDER_VERSION || name === PYTHON_CONSTANTS.SPECIAL.DUNDER_AUTHOR;
350
+ const isPrivate = name.startsWith("_") && !name.startsWith("__");
351
+ if (!isInternal && !isPrivate) {
352
+ exports.push({
353
+ name,
354
+ type: name === name.toUpperCase() ? PYTHON_CONSTANTS.TYPES.CONST : PYTHON_CONSTANTS.TYPES.VARIABLE,
355
+ loc: {
356
+ start: {
357
+ line: node.startPosition.row + 1,
358
+ column: node.startPosition.column
359
+ },
360
+ end: {
361
+ line: node.endPosition.row + 1,
362
+ column: node.endPosition.column
363
+ }
364
+ }
365
+ });
366
+ }
367
+ }
368
+ }
369
+ }
370
+ }
371
+ return exports;
372
+ }
373
+ /**
374
+ * Extract parameter names from a function definition node.
375
+ */
376
+ extractParameters(node) {
377
+ const paramsNode = node.childForFieldName(
378
+ PYTHON_CONSTANTS.FIELDS.PARAMETERS
379
+ );
380
+ if (!paramsNode) return [];
381
+ return paramsNode.children.filter(
382
+ (c) => c.type === PYTHON_CONSTANTS.NODES.IDENTIFIER || c.type === PYTHON_CONSTANTS.NODES.TYPED_PARAMETER || c.type === PYTHON_CONSTANTS.NODES.DEFAULT_PARAMETER
383
+ ).map((c) => {
384
+ if (c.type === PYTHON_CONSTANTS.NODES.IDENTIFIER) return c.text;
385
+ return c.firstChild?.text || "unknown";
386
+ });
387
+ }
388
+ /**
389
+ * Fallback regex-based parsing when tree-sitter is unavailable.
390
+ */
391
+ parseRegex(code, filePath) {
392
+ try {
393
+ const imports = this.extractImportsRegex(code, filePath);
394
+ const exports = this.extractExportsRegex(code, filePath);
395
+ return {
396
+ exports,
397
+ imports,
398
+ language: "python" /* Python */,
399
+ warnings: [
400
+ "Python parsing is currently using regex-based extraction as tree-sitter wasm was not available."
401
+ ]
402
+ };
403
+ } catch (error) {
404
+ const message = error instanceof Error ? error.message : String(error);
405
+ const wrapper = new Error(
406
+ `Failed to parse Python file ${filePath}: ${message}`
407
+ );
408
+ if (error instanceof Error) {
409
+ wrapper.cause = error;
410
+ }
411
+ throw wrapper;
412
+ }
413
+ }
414
+ getNamingConventions() {
415
+ return {
416
+ variablePattern: /^[a-z_][a-z0-9_]*$/,
417
+ functionPattern: /^[a-z_][a-z0-9_]*$/,
418
+ classPattern: /^[A-Z][a-zA-Z0-9]*$/,
419
+ constantPattern: /^[A-Z][A-Z0-9_]*$/,
420
+ exceptions: [
421
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_INIT,
422
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_STR,
423
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_REPR,
424
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_NAME,
425
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_MAIN,
426
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_FILE,
427
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_DOC,
428
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_ALL,
429
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_VERSION,
430
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_AUTHOR,
431
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_DICT,
432
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_CLASS,
433
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_MODULE,
434
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_BASES
435
+ ]
436
+ };
437
+ }
438
+ canHandle(filePath) {
439
+ return filePath.toLowerCase().endsWith(".py");
440
+ }
441
+ extractImportsRegex(code, _filePath) {
442
+ void _filePath;
443
+ const imports = [];
444
+ const lines = code.split("\n");
445
+ const importRegex = /^\s*import\s+([a-zA-Z0-9_., ]+)/;
446
+ const fromImportRegex = /^\s*from\s+([a-zA-Z0-9_.]+)\s+import\s+(.+)/;
447
+ lines.forEach((line, idx) => {
448
+ if (line.trim().startsWith("#")) return;
449
+ const importMatch = line.match(importRegex);
450
+ if (importMatch) {
451
+ const modules = importMatch[1].split(",").map((m) => m.trim().split(" as ")[0]);
452
+ modules.forEach((module) => {
453
+ imports.push({
454
+ source: module,
455
+ specifiers: [module],
456
+ loc: {
457
+ start: { line: idx + 1, column: 0 },
458
+ end: { line: idx + 1, column: line.length }
459
+ }
460
+ });
461
+ });
462
+ return;
463
+ }
464
+ const fromMatch = line.match(fromImportRegex);
465
+ if (fromMatch) {
466
+ const module = fromMatch[1];
467
+ const importsStr = fromMatch[2];
468
+ if (importsStr.trim() === PYTHON_CONSTANTS.SPECIAL.WILDCARD) {
469
+ imports.push({
470
+ source: module,
471
+ specifiers: [PYTHON_CONSTANTS.SPECIAL.WILDCARD],
472
+ loc: {
473
+ start: { line: idx + 1, column: 0 },
474
+ end: { line: idx + 1, column: line.length }
475
+ }
476
+ });
477
+ return;
478
+ }
479
+ const specifiers = importsStr.split(",").map((s) => s.trim().split(" as ")[0]);
480
+ imports.push({
481
+ source: module,
482
+ specifiers,
483
+ loc: {
484
+ start: { line: idx + 1, column: 0 },
485
+ end: { line: idx + 1, column: line.length }
486
+ }
487
+ });
488
+ }
489
+ });
490
+ return imports;
491
+ }
492
+ extractExportsRegex(code, _filePath) {
493
+ void _filePath;
494
+ const exports = [];
495
+ const lines = code.split("\n");
496
+ const funcRegex = /^def\s+([a-zA-Z0-9_]+)\s*\(/;
497
+ const classRegex = /^class\s+([a-zA-Z0-9_]+)/;
498
+ lines.forEach((line, idx) => {
499
+ const indent = line.search(/\S/);
500
+ if (indent !== 0) return;
501
+ const classMatch = line.match(classRegex);
502
+ if (classMatch) {
503
+ exports.push({
504
+ name: classMatch[1],
505
+ type: PYTHON_CONSTANTS.TYPES.CLASS,
506
+ visibility: "public",
507
+ isPure: true,
508
+ hasSideEffects: false,
509
+ loc: {
510
+ start: { line: idx + 1, column: 0 },
511
+ end: { line: idx + 1, column: line.length }
512
+ }
513
+ });
514
+ return;
515
+ }
516
+ const funcMatch = line.match(funcRegex);
517
+ if (funcMatch) {
518
+ const name = funcMatch[1];
519
+ if (name.startsWith("_") && !name.startsWith("__")) return;
520
+ let docContent;
521
+ const nextLines = lines.slice(idx + 1, idx + 4);
522
+ for (const nextLine of nextLines) {
523
+ const docMatch = nextLine.match(/^\s*"""([\s\S]*?)"""/) || nextLine.match(/^\s*'''([\s\S]*?)'''/);
524
+ if (docMatch) {
525
+ docContent = docMatch[1].trim();
526
+ break;
527
+ }
528
+ if (nextLine.trim() && !nextLine.trim().startsWith('"""') && !nextLine.trim().startsWith("'''"))
529
+ break;
530
+ }
531
+ const isImpure = name.toLowerCase().includes("impure") || line.includes(PYTHON_CONSTANTS.BUILTINS.PRINT) || idx + 1 < lines.length && lines[idx + 1].includes(PYTHON_CONSTANTS.BUILTINS.PRINT);
532
+ exports.push({
533
+ name,
534
+ type: PYTHON_CONSTANTS.TYPES.FUNCTION,
535
+ visibility: "public",
536
+ isPure: !isImpure,
537
+ hasSideEffects: isImpure,
538
+ documentation: docContent ? { content: docContent, type: PYTHON_CONSTANTS.TYPES.DOCSTRING } : void 0,
539
+ loc: {
540
+ start: { line: idx + 1, column: 0 },
541
+ end: { line: idx + 1, column: line.length }
542
+ }
543
+ });
544
+ }
545
+ });
546
+ return exports;
547
+ }
548
+ };
549
+
550
+ export {
551
+ PythonParser
552
+ };
@@ -0,0 +1,167 @@
1
+ // src/utils/path-utils.ts
2
+ import { dirname } from "path";
3
+ import { fileURLToPath } from "url";
4
+ function getDirname(importMetaUrl) {
5
+ if (typeof __dirname !== "undefined") {
6
+ return __dirname;
7
+ }
8
+ return dirname(fileURLToPath(importMetaUrl));
9
+ }
10
+
11
+ // src/parsers/tree-sitter-utils.ts
12
+ import * as Parser from "web-tree-sitter";
13
+ import * as path from "path";
14
+ import * as fs from "fs";
15
+ var getDirname2 = () => {
16
+ try {
17
+ return getDirname(import.meta.url);
18
+ } catch {
19
+ return process.cwd();
20
+ }
21
+ };
22
+ var __dirname2 = getDirname2();
23
+ var isTreeSitterInitialized = false;
24
+ async function initTreeSitter() {
25
+ if (isTreeSitterInitialized) return;
26
+ try {
27
+ const wasmPath = getWasmPath("web-tree-sitter");
28
+ await Parser.Parser.init({
29
+ locateFile() {
30
+ return wasmPath || "web-tree-sitter.wasm";
31
+ }
32
+ });
33
+ isTreeSitterInitialized = true;
34
+ } catch (error) {
35
+ console.error("Failed to initialize web-tree-sitter:", error);
36
+ isTreeSitterInitialized = true;
37
+ }
38
+ }
39
+ function findInPnpmStore(startDir, fileName, depth = 0) {
40
+ if (depth > 8) return null;
41
+ const pnpmDir = path.join(startDir, "node_modules", ".pnpm");
42
+ if (fs.existsSync(pnpmDir)) {
43
+ return findFileRecursively(pnpmDir, fileName, 0);
44
+ }
45
+ const parent = path.dirname(startDir);
46
+ if (parent === startDir) return null;
47
+ return findInPnpmStore(parent, fileName, depth + 1);
48
+ }
49
+ function findFileRecursively(dir, fileName, depth) {
50
+ if (depth > 6) return null;
51
+ try {
52
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
53
+ for (const entry of entries) {
54
+ if (entry.isFile() && entry.name === fileName) {
55
+ return path.join(dir, entry.name);
56
+ }
57
+ }
58
+ for (const entry of entries) {
59
+ if (entry.isDirectory()) {
60
+ const found = findFileRecursively(
61
+ path.join(dir, entry.name),
62
+ fileName,
63
+ depth + 1
64
+ );
65
+ if (found) return found;
66
+ }
67
+ }
68
+ } catch {
69
+ }
70
+ return null;
71
+ }
72
+ function getWasmPath(language) {
73
+ const wasmFileName = language === "web-tree-sitter" ? "web-tree-sitter.wasm" : `tree-sitter-${language}.wasm`;
74
+ const immediatePaths = [
75
+ path.join(process.cwd(), wasmFileName),
76
+ path.join(__dirname2, wasmFileName),
77
+ path.join(__dirname2, "assets", wasmFileName)
78
+ ];
79
+ for (const p of immediatePaths) {
80
+ if (fs.existsSync(p)) return p;
81
+ }
82
+ const pnpmPath = findInPnpmStore(__dirname2, wasmFileName);
83
+ if (pnpmPath) return pnpmPath;
84
+ const pnpmPathCwd = findInPnpmStore(process.cwd(), wasmFileName);
85
+ if (pnpmPathCwd) return pnpmPathCwd;
86
+ console.warn(
87
+ `[Parser] WASM file for ${language} not found. CWD: ${process.cwd()}, DIR: ${__dirname2}`
88
+ );
89
+ return null;
90
+ }
91
+ async function setupParser(language) {
92
+ await initTreeSitter();
93
+ const wasmPath = getWasmPath(language);
94
+ if (!wasmPath) {
95
+ return null;
96
+ }
97
+ try {
98
+ const parser = new Parser.Parser();
99
+ const Lang = await Parser.Language.load(wasmPath);
100
+ parser.setLanguage(Lang);
101
+ return parser;
102
+ } catch {
103
+ return null;
104
+ }
105
+ }
106
+
107
+ // src/parsers/base-parser.ts
108
+ var BaseLanguageParser = class {
109
+ constructor() {
110
+ this.parser = null;
111
+ this.initialized = false;
112
+ }
113
+ /**
114
+ * Initialize the tree-sitter parser
115
+ */
116
+ async initialize() {
117
+ if (this.initialized) return;
118
+ try {
119
+ this.parser = await setupParser(this.getParserName());
120
+ this.initialized = true;
121
+ } catch (error) {
122
+ console.warn(`Failed to initialize ${this.language} parser:`, error);
123
+ }
124
+ }
125
+ async getAST(code, _filePath) {
126
+ void _filePath;
127
+ if (!this.initialized) await this.initialize();
128
+ if (!this.parser) return null;
129
+ return this.parser.parse(code);
130
+ }
131
+ parse(code, filePath) {
132
+ if (!this.initialized || !this.parser) {
133
+ return this.parseRegex(code, filePath);
134
+ }
135
+ try {
136
+ const tree = this.parser.parse(code);
137
+ if (!tree || tree.rootNode.type === "ERROR" || tree.rootNode.hasError) {
138
+ return this.parseRegex(code, filePath);
139
+ }
140
+ const imports = this.extractImportsAST(tree.rootNode);
141
+ const exports = this.extractExportsAST(tree.rootNode, code);
142
+ return {
143
+ exports,
144
+ imports,
145
+ language: this.language,
146
+ warnings: []
147
+ };
148
+ } catch (error) {
149
+ console.warn(
150
+ `AST parsing failed for ${filePath}, falling back to regex: ${error.message}`
151
+ );
152
+ return this.parseRegex(code, filePath);
153
+ }
154
+ }
155
+ canHandle(filePath) {
156
+ const lowerPath = filePath.toLowerCase();
157
+ return this.extensions.some((ext) => lowerPath.endsWith(ext));
158
+ }
159
+ };
160
+
161
+ export {
162
+ getDirname,
163
+ initTreeSitter,
164
+ getWasmPath,
165
+ setupParser,
166
+ BaseLanguageParser
167
+ };