@aiready/core 0.24.3 → 0.24.5
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 +115 -67
- 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,10 @@ 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(
|
|
775
|
+
PYTHON_CONSTANTS.FIELDS.NAME
|
|
776
|
+
);
|
|
726
777
|
if (nameNode) {
|
|
727
778
|
const source = nameNode.text;
|
|
728
779
|
imports.push({
|
|
@@ -742,19 +793,23 @@ var init_python_parser = __esm({
|
|
|
742
793
|
}
|
|
743
794
|
}
|
|
744
795
|
}
|
|
745
|
-
} else if (node.type ===
|
|
746
|
-
const moduleNameNode = node.childForFieldName(
|
|
796
|
+
} else if (node.type === PYTHON_CONSTANTS.NODES.IMPORT_FROM_STATEMENT) {
|
|
797
|
+
const moduleNameNode = node.childForFieldName(
|
|
798
|
+
PYTHON_CONSTANTS.FIELDS.MODULE_NAME
|
|
799
|
+
);
|
|
747
800
|
if (moduleNameNode) {
|
|
748
801
|
const source = moduleNameNode.text;
|
|
749
802
|
const specifiers = [];
|
|
750
803
|
for (const child of node.children) {
|
|
751
|
-
if (child.type ===
|
|
804
|
+
if (child.type === PYTHON_CONSTANTS.NODES.DOTTED_NAME && child !== moduleNameNode) {
|
|
752
805
|
specifiers.push(child.text);
|
|
753
|
-
} else if (child.type ===
|
|
754
|
-
const nameNode = child.childForFieldName(
|
|
806
|
+
} else if (child.type === PYTHON_CONSTANTS.NODES.ALIASED_IMPORT) {
|
|
807
|
+
const nameNode = child.childForFieldName(
|
|
808
|
+
PYTHON_CONSTANTS.FIELDS.NAME
|
|
809
|
+
);
|
|
755
810
|
if (nameNode) specifiers.push(nameNode.text);
|
|
756
|
-
} else if (child.type ===
|
|
757
|
-
specifiers.push(
|
|
811
|
+
} else if (child.type === PYTHON_CONSTANTS.NODES.WILDCARD_IMPORT) {
|
|
812
|
+
specifiers.push(PYTHON_CONSTANTS.SPECIAL.WILDCARD);
|
|
758
813
|
}
|
|
759
814
|
}
|
|
760
815
|
if (specifiers.length > 0) {
|
|
@@ -783,16 +838,12 @@ var init_python_parser = __esm({
|
|
|
783
838
|
}
|
|
784
839
|
/**
|
|
785
840
|
* 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
841
|
*/
|
|
791
842
|
extractExportsAST(rootNode, code) {
|
|
792
843
|
const exports2 = [];
|
|
793
844
|
for (const node of rootNode.children) {
|
|
794
|
-
if (node.type ===
|
|
795
|
-
const nameNode = node.childForFieldName(
|
|
845
|
+
if (node.type === PYTHON_CONSTANTS.NODES.FUNCTION_DEFINITION) {
|
|
846
|
+
const nameNode = node.childForFieldName(PYTHON_CONSTANTS.FIELDS.NAME);
|
|
796
847
|
if (nameNode) {
|
|
797
848
|
const name = nameNode.text;
|
|
798
849
|
const isPrivate = name.startsWith("_") && !name.startsWith("__");
|
|
@@ -800,7 +851,7 @@ var init_python_parser = __esm({
|
|
|
800
851
|
const metadata = this.analyzeMetadata(node, code);
|
|
801
852
|
exports2.push({
|
|
802
853
|
name,
|
|
803
|
-
type:
|
|
854
|
+
type: PYTHON_CONSTANTS.TYPES.FUNCTION,
|
|
804
855
|
loc: {
|
|
805
856
|
start: {
|
|
806
857
|
line: node.startPosition.row + 1,
|
|
@@ -816,13 +867,13 @@ var init_python_parser = __esm({
|
|
|
816
867
|
});
|
|
817
868
|
}
|
|
818
869
|
}
|
|
819
|
-
} else if (node.type ===
|
|
820
|
-
const nameNode = node.childForFieldName(
|
|
870
|
+
} else if (node.type === PYTHON_CONSTANTS.NODES.CLASS_DEFINITION) {
|
|
871
|
+
const nameNode = node.childForFieldName(PYTHON_CONSTANTS.FIELDS.NAME);
|
|
821
872
|
if (nameNode) {
|
|
822
873
|
const metadata = this.analyzeMetadata(node, code);
|
|
823
874
|
exports2.push({
|
|
824
875
|
name: nameNode.text,
|
|
825
|
-
type:
|
|
876
|
+
type: PYTHON_CONSTANTS.TYPES.CLASS,
|
|
826
877
|
loc: {
|
|
827
878
|
start: {
|
|
828
879
|
line: node.startPosition.row + 1,
|
|
@@ -836,18 +887,20 @@ var init_python_parser = __esm({
|
|
|
836
887
|
...metadata
|
|
837
888
|
});
|
|
838
889
|
}
|
|
839
|
-
} else if (node.type ===
|
|
890
|
+
} else if (node.type === PYTHON_CONSTANTS.NODES.EXPRESSION_STATEMENT) {
|
|
840
891
|
const assignment = node.firstChild;
|
|
841
|
-
if (assignment && assignment.type ===
|
|
842
|
-
const left = assignment.childForFieldName(
|
|
843
|
-
|
|
892
|
+
if (assignment && assignment.type === PYTHON_CONSTANTS.NODES.ASSIGNMENT) {
|
|
893
|
+
const left = assignment.childForFieldName(
|
|
894
|
+
PYTHON_CONSTANTS.FIELDS.LEFT
|
|
895
|
+
);
|
|
896
|
+
if (left && left.type === PYTHON_CONSTANTS.NODES.IDENTIFIER) {
|
|
844
897
|
const name = left.text;
|
|
845
|
-
const isInternal = name ===
|
|
898
|
+
const isInternal = name === PYTHON_CONSTANTS.SPECIAL.DUNDER_ALL || name === PYTHON_CONSTANTS.SPECIAL.DUNDER_VERSION || name === PYTHON_CONSTANTS.SPECIAL.DUNDER_AUTHOR;
|
|
846
899
|
const isPrivate = name.startsWith("_") && !name.startsWith("__");
|
|
847
900
|
if (!isInternal && !isPrivate) {
|
|
848
901
|
exports2.push({
|
|
849
902
|
name,
|
|
850
|
-
type: name === name.toUpperCase() ?
|
|
903
|
+
type: name === name.toUpperCase() ? PYTHON_CONSTANTS.TYPES.CONST : PYTHON_CONSTANTS.TYPES.VARIABLE,
|
|
851
904
|
loc: {
|
|
852
905
|
start: {
|
|
853
906
|
line: node.startPosition.row + 1,
|
|
@@ -868,18 +921,17 @@ var init_python_parser = __esm({
|
|
|
868
921
|
}
|
|
869
922
|
/**
|
|
870
923
|
* Extract parameter names from a function definition node.
|
|
871
|
-
*
|
|
872
|
-
* @param node - Function definition node.
|
|
873
|
-
* @returns Array of parameter name strings.
|
|
874
924
|
*/
|
|
875
925
|
extractParameters(node) {
|
|
876
|
-
const paramsNode = node.childForFieldName(
|
|
926
|
+
const paramsNode = node.childForFieldName(
|
|
927
|
+
PYTHON_CONSTANTS.FIELDS.PARAMETERS
|
|
928
|
+
);
|
|
877
929
|
if (!paramsNode) return [];
|
|
878
930
|
return paramsNode.children.filter(
|
|
879
|
-
(c) => c.type ===
|
|
931
|
+
(c) => c.type === PYTHON_CONSTANTS.NODES.IDENTIFIER || c.type === PYTHON_CONSTANTS.NODES.TYPED_PARAMETER || c.type === PYTHON_CONSTANTS.NODES.DEFAULT_PARAMETER
|
|
880
932
|
).map((c) => {
|
|
881
|
-
if (c.type ===
|
|
882
|
-
if (c.type ===
|
|
933
|
+
if (c.type === PYTHON_CONSTANTS.NODES.IDENTIFIER) return c.text;
|
|
934
|
+
if (c.type === PYTHON_CONSTANTS.NODES.TYPED_PARAMETER || c.type === PYTHON_CONSTANTS.NODES.DEFAULT_PARAMETER) {
|
|
883
935
|
return c.firstChild?.text || "unknown";
|
|
884
936
|
}
|
|
885
937
|
return "unknown";
|
|
@@ -887,10 +939,6 @@ var init_python_parser = __esm({
|
|
|
887
939
|
}
|
|
888
940
|
/**
|
|
889
941
|
* 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
942
|
*/
|
|
895
943
|
parseRegex(code, filePath) {
|
|
896
944
|
try {
|
|
@@ -919,20 +967,20 @@ var init_python_parser = __esm({
|
|
|
919
967
|
classPattern: /^[A-Z][a-zA-Z0-9]*$/,
|
|
920
968
|
constantPattern: /^[A-Z][A-Z0-9_]*$/,
|
|
921
969
|
exceptions: [
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
970
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_INIT,
|
|
971
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_STR,
|
|
972
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_REPR,
|
|
973
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_NAME,
|
|
974
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_MAIN,
|
|
975
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_FILE,
|
|
976
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_DOC,
|
|
977
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_ALL,
|
|
978
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_VERSION,
|
|
979
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_AUTHOR,
|
|
980
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_DICT,
|
|
981
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_CLASS,
|
|
982
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_MODULE,
|
|
983
|
+
PYTHON_CONSTANTS.SPECIAL.DUNDER_BASES
|
|
936
984
|
]
|
|
937
985
|
};
|
|
938
986
|
}
|
|
@@ -966,10 +1014,10 @@ var init_python_parser = __esm({
|
|
|
966
1014
|
if (fromMatch) {
|
|
967
1015
|
const module2 = fromMatch[1];
|
|
968
1016
|
const importsStr = fromMatch[2];
|
|
969
|
-
if (importsStr.trim() ===
|
|
1017
|
+
if (importsStr.trim() === PYTHON_CONSTANTS.SPECIAL.WILDCARD) {
|
|
970
1018
|
imports.push({
|
|
971
1019
|
source: module2,
|
|
972
|
-
specifiers: [
|
|
1020
|
+
specifiers: [PYTHON_CONSTANTS.SPECIAL.WILDCARD],
|
|
973
1021
|
loc: {
|
|
974
1022
|
start: { line: idx + 1, column: 0 },
|
|
975
1023
|
end: { line: idx + 1, column: line.length }
|
|
@@ -1003,7 +1051,7 @@ var init_python_parser = __esm({
|
|
|
1003
1051
|
if (classMatch) {
|
|
1004
1052
|
exports2.push({
|
|
1005
1053
|
name: classMatch[1],
|
|
1006
|
-
type:
|
|
1054
|
+
type: PYTHON_CONSTANTS.TYPES.CLASS,
|
|
1007
1055
|
visibility: "public",
|
|
1008
1056
|
isPure: true,
|
|
1009
1057
|
hasSideEffects: false,
|
|
@@ -1029,14 +1077,14 @@ var init_python_parser = __esm({
|
|
|
1029
1077
|
if (nextLine.trim() && !nextLine.trim().startsWith('"""') && !nextLine.trim().startsWith("'''"))
|
|
1030
1078
|
break;
|
|
1031
1079
|
}
|
|
1032
|
-
const isImpure = name.toLowerCase().includes("impure") || line.includes(
|
|
1080
|
+
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
1081
|
exports2.push({
|
|
1034
1082
|
name,
|
|
1035
|
-
type:
|
|
1083
|
+
type: PYTHON_CONSTANTS.TYPES.FUNCTION,
|
|
1036
1084
|
visibility: "public",
|
|
1037
1085
|
isPure: !isImpure,
|
|
1038
1086
|
hasSideEffects: isImpure,
|
|
1039
|
-
documentation: docContent ? { content: docContent, type:
|
|
1087
|
+
documentation: docContent ? { content: docContent, type: PYTHON_CONSTANTS.TYPES.DOCSTRING } : void 0,
|
|
1040
1088
|
loc: {
|
|
1041
1089
|
start: { line: idx + 1, column: 0 },
|
|
1042
1090
|
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-WH4ZGRVF.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-7QISP7LK.mjs");
|
|
916
916
|
return new PythonParser2();
|
|
917
917
|
});
|
|
918
918
|
this.registerLazyParser("java" /* Java */, async () => {
|