@aiready/core 0.24.3 → 0.24.4
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/chunk-AZRUQG5T.mjs +537 -0
- package/dist/chunk-LEITCMH3.mjs +535 -0
- package/dist/chunk-MPWWAAHQ.mjs +548 -0
- package/dist/chunk-WH4ZGRVF.mjs +549 -0
- package/dist/chunk-XQSEJ7WN.mjs +547 -0
- package/dist/index.d.mts +1 -19
- package/dist/index.d.ts +1 -19
- package/dist/index.js +106 -70
- package/dist/index.mjs +2 -2
- package/dist/python-parser-7QISP7LK.mjs +8 -0
- package/dist/python-parser-PDCO35VN.mjs +8 -0
- package/dist/python-parser-QAAL56MC.mjs +8 -0
- package/dist/python-parser-R7HLPNZK.mjs +8 -0
- package/dist/python-parser-UFLCDT6L.mjs +8 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -666,13 +666,65 @@ var python_parser_exports = {};
|
|
|
666
666
|
__export(python_parser_exports, {
|
|
667
667
|
PythonParser: () => PythonParser
|
|
668
668
|
});
|
|
669
|
-
var PythonParser;
|
|
669
|
+
var PYTHON_CONSTANTS, PythonParser;
|
|
670
670
|
var init_python_parser = __esm({
|
|
671
671
|
"src/parsers/python-parser.ts"() {
|
|
672
672
|
"use strict";
|
|
673
673
|
init_language();
|
|
674
674
|
init_metadata_utils();
|
|
675
675
|
init_base_parser();
|
|
676
|
+
PYTHON_CONSTANTS = {
|
|
677
|
+
NODES: {
|
|
678
|
+
IMPORT_STATEMENT: "import_statement",
|
|
679
|
+
IMPORT_FROM_STATEMENT: "import_from_statement",
|
|
680
|
+
DOTTED_NAME: "dotted_name",
|
|
681
|
+
ALIASED_IMPORT: "aliased_import",
|
|
682
|
+
WILDCARD_IMPORT: "wildcard_import",
|
|
683
|
+
FUNCTION_DEFINITION: "function_definition",
|
|
684
|
+
CLASS_DEFINITION: "class_definition",
|
|
685
|
+
EXPRESSION_STATEMENT: "expression_statement",
|
|
686
|
+
ASSIGNMENT: "assignment",
|
|
687
|
+
IDENTIFIER: "identifier",
|
|
688
|
+
TYPED_PARAMETER: "typed_parameter",
|
|
689
|
+
DEFAULT_PARAMETER: "default_parameter"
|
|
690
|
+
},
|
|
691
|
+
FIELDS: {
|
|
692
|
+
NAME: "name",
|
|
693
|
+
MODULE_NAME: "module_name",
|
|
694
|
+
LEFT: "left",
|
|
695
|
+
PARAMETERS: "parameters"
|
|
696
|
+
},
|
|
697
|
+
SPECIAL: {
|
|
698
|
+
WILDCARD: "*",
|
|
699
|
+
DUNDER_ALL: "__all__",
|
|
700
|
+
DUNDER_VERSION: "__version__",
|
|
701
|
+
DUNDER_AUTHOR: "__author__",
|
|
702
|
+
DUNDER_INIT: "__init__",
|
|
703
|
+
DUNDER_STR: "__str__",
|
|
704
|
+
DUNDER_REPR: "__repr__",
|
|
705
|
+
DUNDER_NAME: "__name__",
|
|
706
|
+
DUNDER_MAIN: "__main__",
|
|
707
|
+
DUNDER_FILE: "__file__",
|
|
708
|
+
DUNDER_DOC: "__doc__",
|
|
709
|
+
DUNDER_DICT: "__dict__",
|
|
710
|
+
DUNDER_CLASS: "__class__",
|
|
711
|
+
DUNDER_MODULE: "__module__",
|
|
712
|
+
DUNDER_BASES: "__bases__",
|
|
713
|
+
MAIN_VAL: "__main__"
|
|
714
|
+
},
|
|
715
|
+
BUILTINS: {
|
|
716
|
+
PRINT: "print(",
|
|
717
|
+
INPUT: "input(",
|
|
718
|
+
OPEN: "open("
|
|
719
|
+
},
|
|
720
|
+
TYPES: {
|
|
721
|
+
FUNCTION: "function",
|
|
722
|
+
CLASS: "class",
|
|
723
|
+
VARIABLE: "variable",
|
|
724
|
+
CONST: "const",
|
|
725
|
+
DOCSTRING: "docstring"
|
|
726
|
+
}
|
|
727
|
+
};
|
|
676
728
|
PythonParser = class extends BaseLanguageParser {
|
|
677
729
|
constructor() {
|
|
678
730
|
super(...arguments);
|
|
@@ -684,28 +736,25 @@ var init_python_parser = __esm({
|
|
|
684
736
|
}
|
|
685
737
|
/**
|
|
686
738
|
* Analyze metadata for a Python node (purity, side effects).
|
|
687
|
-
*
|
|
688
|
-
* @param node - Tree-sitter node to analyze.
|
|
689
|
-
* @param code - Source code for context.
|
|
690
|
-
* @returns Partial ExportInfo containing discovered metadata.
|
|
691
739
|
*/
|
|
692
740
|
analyzeMetadata(node, code) {
|
|
693
741
|
return analyzeNodeMetadata(node, code, {
|
|
694
|
-
sideEffectSignatures: [
|
|
742
|
+
sideEffectSignatures: [
|
|
743
|
+
PYTHON_CONSTANTS.BUILTINS.PRINT,
|
|
744
|
+
PYTHON_CONSTANTS.BUILTINS.INPUT,
|
|
745
|
+
PYTHON_CONSTANTS.BUILTINS.OPEN
|
|
746
|
+
]
|
|
695
747
|
});
|
|
696
748
|
}
|
|
697
749
|
/**
|
|
698
750
|
* Extract import information using AST walk.
|
|
699
|
-
*
|
|
700
|
-
* @param rootNode - Root node of the Python AST.
|
|
701
|
-
* @returns Array of discovered FileImport objects.
|
|
702
751
|
*/
|
|
703
752
|
extractImportsAST(rootNode) {
|
|
704
753
|
const imports = [];
|
|
705
754
|
const processImportNode = (node) => {
|
|
706
|
-
if (node.type ===
|
|
755
|
+
if (node.type === PYTHON_CONSTANTS.NODES.IMPORT_STATEMENT) {
|
|
707
756
|
for (const child of node.children) {
|
|
708
|
-
if (child.type ===
|
|
757
|
+
if (child.type === PYTHON_CONSTANTS.NODES.DOTTED_NAME) {
|
|
709
758
|
const source = child.text;
|
|
710
759
|
imports.push({
|
|
711
760
|
source,
|
|
@@ -721,8 +770,8 @@ var init_python_parser = __esm({
|
|
|
721
770
|
}
|
|
722
771
|
}
|
|
723
772
|
});
|
|
724
|
-
} else if (child.type ===
|
|
725
|
-
const nameNode = child.childForFieldName(
|
|
773
|
+
} else if (child.type === PYTHON_CONSTANTS.NODES.ALIASED_IMPORT) {
|
|
774
|
+
const nameNode = child.childForFieldName(PYTHON_CONSTANTS.FIELDS.NAME);
|
|
726
775
|
if (nameNode) {
|
|
727
776
|
const source = nameNode.text;
|
|
728
777
|
imports.push({
|
|
@@ -742,19 +791,19 @@ var init_python_parser = __esm({
|
|
|
742
791
|
}
|
|
743
792
|
}
|
|
744
793
|
}
|
|
745
|
-
} else if (node.type ===
|
|
746
|
-
const moduleNameNode = node.childForFieldName(
|
|
794
|
+
} else if (node.type === PYTHON_CONSTANTS.NODES.IMPORT_FROM_STATEMENT) {
|
|
795
|
+
const moduleNameNode = node.childForFieldName(PYTHON_CONSTANTS.FIELDS.MODULE_NAME);
|
|
747
796
|
if (moduleNameNode) {
|
|
748
797
|
const source = moduleNameNode.text;
|
|
749
798
|
const specifiers = [];
|
|
750
799
|
for (const child of node.children) {
|
|
751
|
-
if (child.type ===
|
|
800
|
+
if (child.type === PYTHON_CONSTANTS.NODES.DOTTED_NAME && child !== moduleNameNode) {
|
|
752
801
|
specifiers.push(child.text);
|
|
753
|
-
} else if (child.type ===
|
|
754
|
-
const nameNode = child.childForFieldName(
|
|
802
|
+
} else if (child.type === PYTHON_CONSTANTS.NODES.ALIASED_IMPORT) {
|
|
803
|
+
const nameNode = child.childForFieldName(PYTHON_CONSTANTS.FIELDS.NAME);
|
|
755
804
|
if (nameNode) specifiers.push(nameNode.text);
|
|
756
|
-
} else if (child.type ===
|
|
757
|
-
specifiers.push(
|
|
805
|
+
} else if (child.type === PYTHON_CONSTANTS.NODES.WILDCARD_IMPORT) {
|
|
806
|
+
specifiers.push(PYTHON_CONSTANTS.SPECIAL.WILDCARD);
|
|
758
807
|
}
|
|
759
808
|
}
|
|
760
809
|
if (specifiers.length > 0) {
|
|
@@ -783,16 +832,12 @@ var init_python_parser = __esm({
|
|
|
783
832
|
}
|
|
784
833
|
/**
|
|
785
834
|
* Extract export information using AST walk.
|
|
786
|
-
*
|
|
787
|
-
* @param rootNode - Root node of the Python AST.
|
|
788
|
-
* @param code - Source code for documentation extraction.
|
|
789
|
-
* @returns Array of discovered ExportInfo objects.
|
|
790
835
|
*/
|
|
791
836
|
extractExportsAST(rootNode, code) {
|
|
792
837
|
const exports2 = [];
|
|
793
838
|
for (const node of rootNode.children) {
|
|
794
|
-
if (node.type ===
|
|
795
|
-
const nameNode = node.childForFieldName(
|
|
839
|
+
if (node.type === PYTHON_CONSTANTS.NODES.FUNCTION_DEFINITION) {
|
|
840
|
+
const nameNode = node.childForFieldName(PYTHON_CONSTANTS.FIELDS.NAME);
|
|
796
841
|
if (nameNode) {
|
|
797
842
|
const name = nameNode.text;
|
|
798
843
|
const isPrivate = name.startsWith("_") && !name.startsWith("__");
|
|
@@ -800,7 +845,7 @@ var init_python_parser = __esm({
|
|
|
800
845
|
const metadata = this.analyzeMetadata(node, code);
|
|
801
846
|
exports2.push({
|
|
802
847
|
name,
|
|
803
|
-
type:
|
|
848
|
+
type: PYTHON_CONSTANTS.TYPES.FUNCTION,
|
|
804
849
|
loc: {
|
|
805
850
|
start: {
|
|
806
851
|
line: node.startPosition.row + 1,
|
|
@@ -816,13 +861,13 @@ var init_python_parser = __esm({
|
|
|
816
861
|
});
|
|
817
862
|
}
|
|
818
863
|
}
|
|
819
|
-
} else if (node.type ===
|
|
820
|
-
const nameNode = node.childForFieldName(
|
|
864
|
+
} else if (node.type === PYTHON_CONSTANTS.NODES.CLASS_DEFINITION) {
|
|
865
|
+
const nameNode = node.childForFieldName(PYTHON_CONSTANTS.FIELDS.NAME);
|
|
821
866
|
if (nameNode) {
|
|
822
867
|
const metadata = this.analyzeMetadata(node, code);
|
|
823
868
|
exports2.push({
|
|
824
869
|
name: nameNode.text,
|
|
825
|
-
type:
|
|
870
|
+
type: PYTHON_CONSTANTS.TYPES.CLASS,
|
|
826
871
|
loc: {
|
|
827
872
|
start: {
|
|
828
873
|
line: node.startPosition.row + 1,
|
|
@@ -836,18 +881,18 @@ var init_python_parser = __esm({
|
|
|
836
881
|
...metadata
|
|
837
882
|
});
|
|
838
883
|
}
|
|
839
|
-
} else if (node.type ===
|
|
884
|
+
} else if (node.type === PYTHON_CONSTANTS.NODES.EXPRESSION_STATEMENT) {
|
|
840
885
|
const assignment = node.firstChild;
|
|
841
|
-
if (assignment && assignment.type ===
|
|
842
|
-
const left = assignment.childForFieldName(
|
|
843
|
-
if (left && left.type ===
|
|
886
|
+
if (assignment && assignment.type === PYTHON_CONSTANTS.NODES.ASSIGNMENT) {
|
|
887
|
+
const left = assignment.childForFieldName(PYTHON_CONSTANTS.FIELDS.LEFT);
|
|
888
|
+
if (left && left.type === PYTHON_CONSTANTS.NODES.IDENTIFIER) {
|
|
844
889
|
const name = left.text;
|
|
845
|
-
const isInternal = name ===
|
|
890
|
+
const isInternal = name === PYTHON_CONSTANTS.SPECIAL.DUNDER_ALL || name === PYTHON_CONSTANTS.SPECIAL.DUNDER_VERSION || name === PYTHON_CONSTANTS.SPECIAL.DUNDER_AUTHOR;
|
|
846
891
|
const isPrivate = name.startsWith("_") && !name.startsWith("__");
|
|
847
892
|
if (!isInternal && !isPrivate) {
|
|
848
893
|
exports2.push({
|
|
849
894
|
name,
|
|
850
|
-
type: name === name.toUpperCase() ?
|
|
895
|
+
type: name === name.toUpperCase() ? PYTHON_CONSTANTS.TYPES.CONST : PYTHON_CONSTANTS.TYPES.VARIABLE,
|
|
851
896
|
loc: {
|
|
852
897
|
start: {
|
|
853
898
|
line: node.startPosition.row + 1,
|
|
@@ -868,18 +913,15 @@ var init_python_parser = __esm({
|
|
|
868
913
|
}
|
|
869
914
|
/**
|
|
870
915
|
* Extract parameter names from a function definition node.
|
|
871
|
-
*
|
|
872
|
-
* @param node - Function definition node.
|
|
873
|
-
* @returns Array of parameter name strings.
|
|
874
916
|
*/
|
|
875
917
|
extractParameters(node) {
|
|
876
|
-
const paramsNode = node.childForFieldName(
|
|
918
|
+
const paramsNode = node.childForFieldName(PYTHON_CONSTANTS.FIELDS.PARAMETERS);
|
|
877
919
|
if (!paramsNode) return [];
|
|
878
920
|
return paramsNode.children.filter(
|
|
879
|
-
(c) => c.type ===
|
|
921
|
+
(c) => c.type === PYTHON_CONSTANTS.NODES.IDENTIFIER || c.type === PYTHON_CONSTANTS.NODES.TYPED_PARAMETER || c.type === PYTHON_CONSTANTS.NODES.DEFAULT_PARAMETER
|
|
880
922
|
).map((c) => {
|
|
881
|
-
if (c.type ===
|
|
882
|
-
if (c.type ===
|
|
923
|
+
if (c.type === PYTHON_CONSTANTS.NODES.IDENTIFIER) return c.text;
|
|
924
|
+
if (c.type === PYTHON_CONSTANTS.NODES.TYPED_PARAMETER || c.type === PYTHON_CONSTANTS.NODES.DEFAULT_PARAMETER) {
|
|
883
925
|
return c.firstChild?.text || "unknown";
|
|
884
926
|
}
|
|
885
927
|
return "unknown";
|
|
@@ -887,10 +929,6 @@ var init_python_parser = __esm({
|
|
|
887
929
|
}
|
|
888
930
|
/**
|
|
889
931
|
* Fallback regex-based parsing when tree-sitter is unavailable.
|
|
890
|
-
*
|
|
891
|
-
* @param code - Source code content.
|
|
892
|
-
* @param filePath - Path to the file being parsed.
|
|
893
|
-
* @returns Consolidated ParseResult.
|
|
894
932
|
*/
|
|
895
933
|
parseRegex(code, filePath) {
|
|
896
934
|
try {
|
|
@@ -905,9 +943,7 @@ var init_python_parser = __esm({
|
|
|
905
943
|
]
|
|
906
944
|
};
|
|
907
945
|
} catch (error) {
|
|
908
|
-
const wrapper = new Error(
|
|
909
|
-
`Failed to parse Python file ${filePath}: ${error.message}`
|
|
910
|
-
);
|
|
946
|
+
const wrapper = new Error(`Failed to parse Python file ${filePath}: ${error.message}`);
|
|
911
947
|
wrapper.cause = error;
|
|
912
948
|
throw wrapper;
|
|
913
949
|
}
|
|
@@ -919,20 +955,20 @@ var init_python_parser = __esm({
|
|
|
919
955
|
classPattern: /^[A-Z][a-zA-Z0-9]*$/,
|
|
920
956
|
constantPattern: /^[A-Z][A-Z0-9_]*$/,
|
|
921
957
|
exceptions: [
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
958
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_INIT,
|
|
959
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_STR,
|
|
960
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_REPR,
|
|
961
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_NAME,
|
|
962
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_MAIN,
|
|
963
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_FILE,
|
|
964
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_DOC,
|
|
965
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_ALL,
|
|
966
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_VERSION,
|
|
967
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_AUTHOR,
|
|
968
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_DICT,
|
|
969
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_CLASS,
|
|
970
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_MODULE,
|
|
971
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_BASES
|
|
936
972
|
]
|
|
937
973
|
};
|
|
938
974
|
}
|
|
@@ -966,10 +1002,10 @@ var init_python_parser = __esm({
|
|
|
966
1002
|
if (fromMatch) {
|
|
967
1003
|
const module2 = fromMatch[1];
|
|
968
1004
|
const importsStr = fromMatch[2];
|
|
969
|
-
if (importsStr.trim() ===
|
|
1005
|
+
if (importsStr.trim() === PYTHON_CONSTANTS.SPECIAL.WILDCARD) {
|
|
970
1006
|
imports.push({
|
|
971
1007
|
source: module2,
|
|
972
|
-
specifiers: [
|
|
1008
|
+
specifiers: [PYTHON_CONSTANTS.SPECIAL.WILDCARD],
|
|
973
1009
|
loc: {
|
|
974
1010
|
start: { line: idx + 1, column: 0 },
|
|
975
1011
|
end: { line: idx + 1, column: line.length }
|
|
@@ -1003,7 +1039,7 @@ var init_python_parser = __esm({
|
|
|
1003
1039
|
if (classMatch) {
|
|
1004
1040
|
exports2.push({
|
|
1005
1041
|
name: classMatch[1],
|
|
1006
|
-
type:
|
|
1042
|
+
type: PYTHON_CONSTANTS.TYPES.CLASS,
|
|
1007
1043
|
visibility: "public",
|
|
1008
1044
|
isPure: true,
|
|
1009
1045
|
hasSideEffects: false,
|
|
@@ -1029,14 +1065,14 @@ var init_python_parser = __esm({
|
|
|
1029
1065
|
if (nextLine.trim() && !nextLine.trim().startsWith('"""') && !nextLine.trim().startsWith("'''"))
|
|
1030
1066
|
break;
|
|
1031
1067
|
}
|
|
1032
|
-
const isImpure = name.toLowerCase().includes("impure") || line.includes(
|
|
1068
|
+
const isImpure = name.toLowerCase().includes("impure") || line.includes(PYTHON_CONSTANTS.BUILTINS.PRINT) || idx + 1 < lines.length && lines[idx + 1].includes(PYTHON_CONSTANTS.BUILTINS.PRINT);
|
|
1033
1069
|
exports2.push({
|
|
1034
1070
|
name,
|
|
1035
|
-
type:
|
|
1071
|
+
type: PYTHON_CONSTANTS.TYPES.FUNCTION,
|
|
1036
1072
|
visibility: "public",
|
|
1037
1073
|
isPure: !isImpure,
|
|
1038
1074
|
hasSideEffects: isImpure,
|
|
1039
|
-
documentation: docContent ? { content: docContent, type:
|
|
1075
|
+
documentation: docContent ? { content: docContent, type: PYTHON_CONSTANTS.TYPES.DOCSTRING } : void 0,
|
|
1040
1076
|
loc: {
|
|
1041
1077
|
start: { line: idx + 1, column: 0 },
|
|
1042
1078
|
end: { line: idx + 1, column: line.length }
|
package/dist/index.mjs
CHANGED
|
@@ -58,7 +58,7 @@ import {
|
|
|
58
58
|
} from "./chunk-UTCRW3N7.mjs";
|
|
59
59
|
import {
|
|
60
60
|
PythonParser
|
|
61
|
-
} from "./chunk-
|
|
61
|
+
} from "./chunk-AZRUQG5T.mjs";
|
|
62
62
|
import {
|
|
63
63
|
JavaParser
|
|
64
64
|
} from "./chunk-SWZOT67M.mjs";
|
|
@@ -912,7 +912,7 @@ var ParserFactory = class _ParserFactory {
|
|
|
912
912
|
return new TypeScriptParser2();
|
|
913
913
|
});
|
|
914
914
|
this.registerLazyParser("python" /* Python */, async () => {
|
|
915
|
-
const { PythonParser: PythonParser2 } = await import("./python-parser-
|
|
915
|
+
const { PythonParser: PythonParser2 } = await import("./python-parser-UFLCDT6L.mjs");
|
|
916
916
|
return new PythonParser2();
|
|
917
917
|
});
|
|
918
918
|
this.registerLazyParser("java" /* Java */, async () => {
|