@aiready/core 0.23.2 → 0.23.3
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/__tests__/parser-factory.test.d.ts +1 -1
- package/dist/__tests__/parser-factory.test.js +62 -50
- package/dist/__tests__/python-parser.test.d.ts +1 -1
- package/dist/__tests__/python-parser.test.js +111 -109
- package/dist/__tests__/scoring.test.d.ts +1 -1
- package/dist/__tests__/scoring.test.js +193 -176
- package/dist/chunk-3YI4IS3D.mjs +191 -173
- package/dist/chunk-5HIXDC3X.mjs +273 -251
- package/dist/chunk-5V3L53AE.mjs +805 -0
- package/dist/chunk-CKVKHN3G.mjs +228 -211
- package/dist/chunk-COHIBX3Q.mjs +213 -195
- package/dist/chunk-CWRCDSKZ.mjs +91 -82
- package/dist/chunk-D3D3NCRR.mjs +147 -129
- package/dist/chunk-HCFYP7UD.mjs +805 -0
- package/dist/chunk-HFLFBA6F.mjs +79 -72
- package/dist/chunk-HKSARRCD.mjs +66 -58
- package/dist/chunk-JJ5JL5FX.mjs +91 -82
- package/dist/chunk-KDSTXVLQ.mjs +724 -0
- package/dist/chunk-KI7XORTN.mjs +91 -82
- package/dist/chunk-LTMHFNFK.mjs +690 -0
- package/dist/chunk-LTNXTXRI.mjs +228 -211
- package/dist/chunk-M22BXHBR.mjs +805 -0
- package/dist/chunk-MH3A3LX6.mjs +200 -182
- package/dist/chunk-NGHT7JOG.mjs +697 -0
- package/dist/chunk-OQ6IGDXG.mjs +147 -129
- package/dist/chunk-QAFB3HXQ.mjs +181 -165
- package/dist/chunk-QQBKXHLU.mjs +678 -0
- package/dist/chunk-RDHYGES7.mjs +678 -0
- package/dist/chunk-SWTDBVYJ.mjs +228 -213
- package/dist/chunk-UIWL5JQB.mjs +79 -72
- package/dist/chunk-UQGI67WR.mjs +79 -72
- package/dist/chunk-UTZOO4XO.mjs +147 -131
- package/dist/chunk-X4F46I5L.mjs +213 -195
- package/dist/chunk-XKK7YHPX.mjs +204 -186
- package/dist/chunk-YCA4FTEK.mjs +190 -172
- package/dist/chunk-ZSZRRTJM.mjs +719 -0
- package/dist/client-BgmiMoil.d.mts +1344 -0
- package/dist/client-BgmiMoil.d.ts +1344 -0
- package/dist/client-BxGrPuuN.d.mts +1191 -0
- package/dist/client-BxGrPuuN.d.ts +1191 -0
- package/dist/client-D-cn9ydj.d.mts +1136 -0
- package/dist/client-D-cn9ydj.d.ts +1136 -0
- package/dist/client-D9seCH4K.d.mts +1334 -0
- package/dist/client-D9seCH4K.d.ts +1334 -0
- package/dist/client-DIXIh7rw.d.mts +1193 -0
- package/dist/client-DIXIh7rw.d.ts +1193 -0
- package/dist/client-DVHXWOHw.d.mts +1245 -0
- package/dist/client-DVHXWOHw.d.ts +1245 -0
- package/dist/client.d.mts +2 -1098
- package/dist/client.d.ts +2 -1098
- package/dist/client.js +23 -43
- package/dist/client.mjs +3 -25
- package/dist/index.d.mts +325 -103
- package/dist/index.d.ts +325 -103
- package/dist/index.js +307 -324
- package/dist/index.mjs +283 -306
- package/dist/parsers/parser-factory.d.ts +45 -45
- package/dist/parsers/parser-factory.js +86 -84
- package/dist/parsers/python-parser.d.ts +33 -28
- package/dist/parsers/python-parser.js +224 -222
- package/dist/parsers/typescript-parser.d.ts +15 -10
- package/dist/parsers/typescript-parser.js +223 -197
- package/dist/scoring.d.ts +59 -49
- package/dist/scoring.js +129 -127
- package/dist/types/language.d.ts +104 -93
- package/dist/types/language.js +23 -23
- package/dist/types.d.ts +105 -87
- package/dist/types.js +1 -1
- package/dist/utils/ast-parser.d.ts +42 -33
- package/dist/utils/ast-parser.js +159 -162
- package/dist/utils/cli-helpers.d.ts +27 -10
- package/dist/utils/cli-helpers.js +45 -43
- package/dist/utils/config.d.ts +8 -3
- package/dist/utils/config.js +67 -69
- package/dist/utils/file-scanner.d.ts +1 -1
- package/dist/utils/file-scanner.js +80 -76
- package/dist/utils/metrics.d.ts +1 -1
- package/dist/utils/metrics.js +2 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -38,12 +38,13 @@ import {
|
|
|
38
38
|
getProjectSizeTier,
|
|
39
39
|
getRating,
|
|
40
40
|
getRatingDisplay,
|
|
41
|
+
getRatingSlug,
|
|
41
42
|
getRatingWithContext,
|
|
42
43
|
getRecommendedThreshold,
|
|
43
44
|
getToolWeight,
|
|
44
45
|
normalizeToolName,
|
|
45
46
|
parseWeightString
|
|
46
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-NGHT7JOG.mjs";
|
|
47
48
|
|
|
48
49
|
// src/types/contract.ts
|
|
49
50
|
function validateSpokeOutput(toolName, output) {
|
|
@@ -447,6 +448,7 @@ import {
|
|
|
447
448
|
statSync
|
|
448
449
|
} from "fs";
|
|
449
450
|
import { join as join2, dirname as dirname2, resolve as resolvePath } from "path";
|
|
451
|
+
import chalk from "chalk";
|
|
450
452
|
function resolveOutputPath(userPath, defaultFilename, workingDir = process.cwd()) {
|
|
451
453
|
let outputPath;
|
|
452
454
|
if (userPath) {
|
|
@@ -514,22 +516,72 @@ function emitProgress(processed, total, toolId, message, onProgress, throttleCou
|
|
|
514
516
|
onProgress(processed, total, `${message} (${processed}/${total})`);
|
|
515
517
|
}
|
|
516
518
|
}
|
|
517
|
-
function getSeverityColor(severity, chalk) {
|
|
519
|
+
function getSeverityColor(severity, chalkInstance = chalk) {
|
|
518
520
|
switch (severity.toLowerCase()) {
|
|
519
521
|
case "critical":
|
|
520
522
|
case "high-risk":
|
|
521
523
|
case "blind-risk":
|
|
522
|
-
return
|
|
524
|
+
return chalkInstance.red;
|
|
523
525
|
case "major":
|
|
524
526
|
case "moderate-risk":
|
|
525
|
-
return
|
|
527
|
+
return chalkInstance.yellow;
|
|
526
528
|
case "minor":
|
|
527
529
|
case "safe":
|
|
528
|
-
return
|
|
530
|
+
return chalkInstance.green;
|
|
529
531
|
case "info":
|
|
530
|
-
return
|
|
532
|
+
return chalkInstance.blue;
|
|
531
533
|
default:
|
|
532
|
-
return
|
|
534
|
+
return chalkInstance.white;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
function getSeverityValue(s) {
|
|
538
|
+
if (!s) return 0;
|
|
539
|
+
switch (s.toLowerCase()) {
|
|
540
|
+
case "critical":
|
|
541
|
+
return 4;
|
|
542
|
+
case "major":
|
|
543
|
+
return 3;
|
|
544
|
+
case "minor":
|
|
545
|
+
return 2;
|
|
546
|
+
case "info":
|
|
547
|
+
return 1;
|
|
548
|
+
default:
|
|
549
|
+
return 0;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
function getSeverityLevel(s) {
|
|
553
|
+
return getSeverityValue(s);
|
|
554
|
+
}
|
|
555
|
+
function getSeverityBadge(severity, chalkInstance = chalk) {
|
|
556
|
+
const val = getSeverityValue(
|
|
557
|
+
typeof severity === "string" ? severity : severity
|
|
558
|
+
);
|
|
559
|
+
switch (val) {
|
|
560
|
+
case 4:
|
|
561
|
+
return chalkInstance.bgRed.white.bold(" CRITICAL ");
|
|
562
|
+
case 3:
|
|
563
|
+
return chalkInstance.bgYellow.black.bold(" MAJOR ");
|
|
564
|
+
case 2:
|
|
565
|
+
return chalkInstance.bgBlue.white.bold(" MINOR ");
|
|
566
|
+
case 1:
|
|
567
|
+
return chalkInstance.bgCyan.black(" INFO ");
|
|
568
|
+
default:
|
|
569
|
+
return chalkInstance.bgCyan.black(" INFO ");
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
function getSeverityEnum(s) {
|
|
573
|
+
const level = getSeverityLevel(s);
|
|
574
|
+
switch (level) {
|
|
575
|
+
case 4:
|
|
576
|
+
return "critical";
|
|
577
|
+
case 3:
|
|
578
|
+
return "major";
|
|
579
|
+
case 2:
|
|
580
|
+
return "minor";
|
|
581
|
+
case 1:
|
|
582
|
+
return "info";
|
|
583
|
+
default:
|
|
584
|
+
return "info";
|
|
533
585
|
}
|
|
534
586
|
}
|
|
535
587
|
function findLatestReport(dirPath) {
|
|
@@ -978,94 +1030,6 @@ var TypeScriptParser = class {
|
|
|
978
1030
|
}
|
|
979
1031
|
};
|
|
980
1032
|
|
|
981
|
-
// src/parsers/tree-sitter-utils.ts
|
|
982
|
-
import * as Parser from "web-tree-sitter";
|
|
983
|
-
import * as path from "path";
|
|
984
|
-
import * as fs from "fs";
|
|
985
|
-
var isTreeSitterInitialized = false;
|
|
986
|
-
async function initTreeSitter() {
|
|
987
|
-
if (isTreeSitterInitialized) return;
|
|
988
|
-
try {
|
|
989
|
-
const wasmPath = getWasmPath("web-tree-sitter");
|
|
990
|
-
await Parser.Parser.init({
|
|
991
|
-
locateFile() {
|
|
992
|
-
return wasmPath || "web-tree-sitter.wasm";
|
|
993
|
-
}
|
|
994
|
-
});
|
|
995
|
-
isTreeSitterInitialized = true;
|
|
996
|
-
} catch (error) {
|
|
997
|
-
console.error("Failed to initialize web-tree-sitter:", error);
|
|
998
|
-
isTreeSitterInitialized = true;
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
function findInPnpmStore(startDir, fileName, depth = 0) {
|
|
1002
|
-
if (depth > 8) return null;
|
|
1003
|
-
const pnpmDir = path.join(startDir, "node_modules", ".pnpm");
|
|
1004
|
-
if (fs.existsSync(pnpmDir)) {
|
|
1005
|
-
return findFileRecursively(pnpmDir, fileName, 0);
|
|
1006
|
-
}
|
|
1007
|
-
const parent = path.dirname(startDir);
|
|
1008
|
-
if (parent === startDir) return null;
|
|
1009
|
-
return findInPnpmStore(parent, fileName, depth + 1);
|
|
1010
|
-
}
|
|
1011
|
-
function findFileRecursively(dir, fileName, depth) {
|
|
1012
|
-
if (depth > 6) return null;
|
|
1013
|
-
try {
|
|
1014
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
1015
|
-
for (const entry of entries) {
|
|
1016
|
-
if (entry.isFile() && entry.name === fileName) {
|
|
1017
|
-
return path.join(dir, entry.name);
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
for (const entry of entries) {
|
|
1021
|
-
if (entry.isDirectory()) {
|
|
1022
|
-
const found = findFileRecursively(
|
|
1023
|
-
path.join(dir, entry.name),
|
|
1024
|
-
fileName,
|
|
1025
|
-
depth + 1
|
|
1026
|
-
);
|
|
1027
|
-
if (found) return found;
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
} catch (err) {
|
|
1031
|
-
}
|
|
1032
|
-
return null;
|
|
1033
|
-
}
|
|
1034
|
-
function getWasmPath(language) {
|
|
1035
|
-
const wasmFileName = language === "web-tree-sitter" ? "web-tree-sitter.wasm" : `tree-sitter-${language}.wasm`;
|
|
1036
|
-
const immediatePaths = [
|
|
1037
|
-
path.join(process.cwd(), wasmFileName),
|
|
1038
|
-
path.join(__dirname, wasmFileName),
|
|
1039
|
-
path.join(__dirname, "assets", wasmFileName)
|
|
1040
|
-
];
|
|
1041
|
-
for (const p of immediatePaths) {
|
|
1042
|
-
if (fs.existsSync(p)) return p;
|
|
1043
|
-
}
|
|
1044
|
-
const pnpmPath = findInPnpmStore(__dirname, wasmFileName);
|
|
1045
|
-
if (pnpmPath) return pnpmPath;
|
|
1046
|
-
const pnpmPathCwd = findInPnpmStore(process.cwd(), wasmFileName);
|
|
1047
|
-
if (pnpmPathCwd) return pnpmPathCwd;
|
|
1048
|
-
console.warn(
|
|
1049
|
-
`[Parser] WASM file for ${language} not found. CWD: ${process.cwd()}, DIR: ${__dirname}`
|
|
1050
|
-
);
|
|
1051
|
-
return null;
|
|
1052
|
-
}
|
|
1053
|
-
async function setupParser(language) {
|
|
1054
|
-
await initTreeSitter();
|
|
1055
|
-
const wasmPath = getWasmPath(language);
|
|
1056
|
-
if (!wasmPath) {
|
|
1057
|
-
return null;
|
|
1058
|
-
}
|
|
1059
|
-
try {
|
|
1060
|
-
const parser = new Parser.Parser();
|
|
1061
|
-
const Lang = await Parser.Language.load(wasmPath);
|
|
1062
|
-
parser.setLanguage(Lang);
|
|
1063
|
-
return parser;
|
|
1064
|
-
} catch (error) {
|
|
1065
|
-
return null;
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
1033
|
// src/parsers/metadata-utils.ts
|
|
1070
1034
|
function analyzeNodeMetadata(node, code, options) {
|
|
1071
1035
|
const metadata = {
|
|
@@ -1161,11 +1125,97 @@ function analyzeNodeMetadata(node, code, options) {
|
|
|
1161
1125
|
return metadata;
|
|
1162
1126
|
}
|
|
1163
1127
|
|
|
1164
|
-
// src/parsers/
|
|
1165
|
-
|
|
1128
|
+
// src/parsers/tree-sitter-utils.ts
|
|
1129
|
+
import * as Parser from "web-tree-sitter";
|
|
1130
|
+
import * as path from "path";
|
|
1131
|
+
import * as fs from "fs";
|
|
1132
|
+
var isTreeSitterInitialized = false;
|
|
1133
|
+
async function initTreeSitter() {
|
|
1134
|
+
if (isTreeSitterInitialized) return;
|
|
1135
|
+
try {
|
|
1136
|
+
const wasmPath = getWasmPath("web-tree-sitter");
|
|
1137
|
+
await Parser.Parser.init({
|
|
1138
|
+
locateFile() {
|
|
1139
|
+
return wasmPath || "web-tree-sitter.wasm";
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1142
|
+
isTreeSitterInitialized = true;
|
|
1143
|
+
} catch (error) {
|
|
1144
|
+
console.error("Failed to initialize web-tree-sitter:", error);
|
|
1145
|
+
isTreeSitterInitialized = true;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
function findInPnpmStore(startDir, fileName, depth = 0) {
|
|
1149
|
+
if (depth > 8) return null;
|
|
1150
|
+
const pnpmDir = path.join(startDir, "node_modules", ".pnpm");
|
|
1151
|
+
if (fs.existsSync(pnpmDir)) {
|
|
1152
|
+
return findFileRecursively(pnpmDir, fileName, 0);
|
|
1153
|
+
}
|
|
1154
|
+
const parent = path.dirname(startDir);
|
|
1155
|
+
if (parent === startDir) return null;
|
|
1156
|
+
return findInPnpmStore(parent, fileName, depth + 1);
|
|
1157
|
+
}
|
|
1158
|
+
function findFileRecursively(dir, fileName, depth) {
|
|
1159
|
+
if (depth > 6) return null;
|
|
1160
|
+
try {
|
|
1161
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
1162
|
+
for (const entry of entries) {
|
|
1163
|
+
if (entry.isFile() && entry.name === fileName) {
|
|
1164
|
+
return path.join(dir, entry.name);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
for (const entry of entries) {
|
|
1168
|
+
if (entry.isDirectory()) {
|
|
1169
|
+
const found = findFileRecursively(
|
|
1170
|
+
path.join(dir, entry.name),
|
|
1171
|
+
fileName,
|
|
1172
|
+
depth + 1
|
|
1173
|
+
);
|
|
1174
|
+
if (found) return found;
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
} catch (err) {
|
|
1178
|
+
}
|
|
1179
|
+
return null;
|
|
1180
|
+
}
|
|
1181
|
+
function getWasmPath(language) {
|
|
1182
|
+
const wasmFileName = language === "web-tree-sitter" ? "web-tree-sitter.wasm" : `tree-sitter-${language}.wasm`;
|
|
1183
|
+
const immediatePaths = [
|
|
1184
|
+
path.join(process.cwd(), wasmFileName),
|
|
1185
|
+
path.join(__dirname, wasmFileName),
|
|
1186
|
+
path.join(__dirname, "assets", wasmFileName)
|
|
1187
|
+
];
|
|
1188
|
+
for (const p of immediatePaths) {
|
|
1189
|
+
if (fs.existsSync(p)) return p;
|
|
1190
|
+
}
|
|
1191
|
+
const pnpmPath = findInPnpmStore(__dirname, wasmFileName);
|
|
1192
|
+
if (pnpmPath) return pnpmPath;
|
|
1193
|
+
const pnpmPathCwd = findInPnpmStore(process.cwd(), wasmFileName);
|
|
1194
|
+
if (pnpmPathCwd) return pnpmPathCwd;
|
|
1195
|
+
console.warn(
|
|
1196
|
+
`[Parser] WASM file for ${language} not found. CWD: ${process.cwd()}, DIR: ${__dirname}`
|
|
1197
|
+
);
|
|
1198
|
+
return null;
|
|
1199
|
+
}
|
|
1200
|
+
async function setupParser(language) {
|
|
1201
|
+
await initTreeSitter();
|
|
1202
|
+
const wasmPath = getWasmPath(language);
|
|
1203
|
+
if (!wasmPath) {
|
|
1204
|
+
return null;
|
|
1205
|
+
}
|
|
1206
|
+
try {
|
|
1207
|
+
const parser = new Parser.Parser();
|
|
1208
|
+
const Lang = await Parser.Language.load(wasmPath);
|
|
1209
|
+
parser.setLanguage(Lang);
|
|
1210
|
+
return parser;
|
|
1211
|
+
} catch (error) {
|
|
1212
|
+
return null;
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
// src/parsers/base-parser.ts
|
|
1217
|
+
var BaseLanguageParser = class {
|
|
1166
1218
|
constructor() {
|
|
1167
|
-
this.language = "python" /* Python */;
|
|
1168
|
-
this.extensions = [".py"];
|
|
1169
1219
|
this.parser = null;
|
|
1170
1220
|
this.initialized = false;
|
|
1171
1221
|
}
|
|
@@ -1174,19 +1224,18 @@ var PythonParser = class {
|
|
|
1174
1224
|
*/
|
|
1175
1225
|
async initialize() {
|
|
1176
1226
|
if (this.initialized) return;
|
|
1177
|
-
|
|
1178
|
-
|
|
1227
|
+
try {
|
|
1228
|
+
this.parser = await setupParser(this.getParserName());
|
|
1229
|
+
this.initialized = true;
|
|
1230
|
+
} catch (error) {
|
|
1231
|
+
console.warn(`Failed to initialize ${this.language} parser:`, error);
|
|
1232
|
+
}
|
|
1179
1233
|
}
|
|
1180
1234
|
async getAST(code, filePath) {
|
|
1181
1235
|
if (!this.initialized) await this.initialize();
|
|
1182
1236
|
if (!this.parser) return null;
|
|
1183
1237
|
return this.parser.parse(code);
|
|
1184
1238
|
}
|
|
1185
|
-
analyzeMetadata(node, code) {
|
|
1186
|
-
return analyzeNodeMetadata(node, code, {
|
|
1187
|
-
sideEffectSignatures: ["print(", "input(", "open("]
|
|
1188
|
-
});
|
|
1189
|
-
}
|
|
1190
1239
|
parse(code, filePath) {
|
|
1191
1240
|
if (!this.initialized || !this.parser) {
|
|
1192
1241
|
return this.parseRegex(code, filePath);
|
|
@@ -1196,19 +1245,42 @@ var PythonParser = class {
|
|
|
1196
1245
|
if (!tree || tree.rootNode.type === "ERROR" || tree.rootNode.hasError) {
|
|
1197
1246
|
return this.parseRegex(code, filePath);
|
|
1198
1247
|
}
|
|
1199
|
-
const
|
|
1200
|
-
const
|
|
1201
|
-
const exports = this.extractExportsAST(rootNode, code);
|
|
1248
|
+
const imports = this.extractImportsAST(tree.rootNode);
|
|
1249
|
+
const exports = this.extractExportsAST(tree.rootNode, code);
|
|
1202
1250
|
return {
|
|
1203
1251
|
exports,
|
|
1204
1252
|
imports,
|
|
1205
|
-
language:
|
|
1253
|
+
language: this.language,
|
|
1206
1254
|
warnings: []
|
|
1207
1255
|
};
|
|
1208
1256
|
} catch (error) {
|
|
1257
|
+
console.warn(
|
|
1258
|
+
`AST parsing failed for ${filePath}, falling back to regex: ${error.message}`
|
|
1259
|
+
);
|
|
1209
1260
|
return this.parseRegex(code, filePath);
|
|
1210
1261
|
}
|
|
1211
1262
|
}
|
|
1263
|
+
canHandle(filePath) {
|
|
1264
|
+
const lowerPath = filePath.toLowerCase();
|
|
1265
|
+
return this.extensions.some((ext) => lowerPath.endsWith(ext));
|
|
1266
|
+
}
|
|
1267
|
+
};
|
|
1268
|
+
|
|
1269
|
+
// src/parsers/python-parser.ts
|
|
1270
|
+
var PythonParser = class extends BaseLanguageParser {
|
|
1271
|
+
constructor() {
|
|
1272
|
+
super(...arguments);
|
|
1273
|
+
this.language = "python" /* Python */;
|
|
1274
|
+
this.extensions = [".py"];
|
|
1275
|
+
}
|
|
1276
|
+
getParserName() {
|
|
1277
|
+
return "python";
|
|
1278
|
+
}
|
|
1279
|
+
analyzeMetadata(node, code) {
|
|
1280
|
+
return analyzeNodeMetadata(node, code, {
|
|
1281
|
+
sideEffectSignatures: ["print(", "input(", "open("]
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1212
1284
|
extractImportsAST(rootNode) {
|
|
1213
1285
|
const imports = [];
|
|
1214
1286
|
const processImportNode = (node) => {
|
|
@@ -1642,25 +1714,14 @@ function extractParameterNames(node) {
|
|
|
1642
1714
|
}
|
|
1643
1715
|
|
|
1644
1716
|
// src/parsers/java-parser.ts
|
|
1645
|
-
var JavaParser = class {
|
|
1717
|
+
var JavaParser = class extends BaseLanguageParser {
|
|
1646
1718
|
constructor() {
|
|
1719
|
+
super(...arguments);
|
|
1647
1720
|
this.language = "java" /* Java */;
|
|
1648
1721
|
this.extensions = [".java"];
|
|
1649
|
-
this.parser = null;
|
|
1650
|
-
this.initialized = false;
|
|
1651
1722
|
}
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
*/
|
|
1655
|
-
async initialize() {
|
|
1656
|
-
if (this.initialized) return;
|
|
1657
|
-
this.parser = await setupParser("java");
|
|
1658
|
-
this.initialized = true;
|
|
1659
|
-
}
|
|
1660
|
-
async getAST(code, filePath) {
|
|
1661
|
-
if (!this.initialized) await this.initialize();
|
|
1662
|
-
if (!this.parser) return null;
|
|
1663
|
-
return this.parser.parse(code);
|
|
1723
|
+
getParserName() {
|
|
1724
|
+
return "java";
|
|
1664
1725
|
}
|
|
1665
1726
|
analyzeMetadata(node, code) {
|
|
1666
1727
|
return analyzeGeneralMetadata(node, code, {
|
|
@@ -1672,31 +1733,6 @@ var JavaParser = class {
|
|
|
1672
1733
|
]
|
|
1673
1734
|
});
|
|
1674
1735
|
}
|
|
1675
|
-
parse(code, filePath) {
|
|
1676
|
-
if (!this.initialized || !this.parser) {
|
|
1677
|
-
return this.parseRegex(code, filePath);
|
|
1678
|
-
}
|
|
1679
|
-
try {
|
|
1680
|
-
const tree = this.parser.parse(code);
|
|
1681
|
-
if (!tree || tree.rootNode.type === "ERROR" || tree.rootNode.hasError) {
|
|
1682
|
-
return this.parseRegex(code, filePath);
|
|
1683
|
-
}
|
|
1684
|
-
const rootNode = tree.rootNode;
|
|
1685
|
-
const imports = this.extractImportsAST(rootNode);
|
|
1686
|
-
const exports = this.extractExportsAST(rootNode, code);
|
|
1687
|
-
return {
|
|
1688
|
-
exports,
|
|
1689
|
-
imports,
|
|
1690
|
-
language: "java" /* Java */,
|
|
1691
|
-
warnings: []
|
|
1692
|
-
};
|
|
1693
|
-
} catch (error) {
|
|
1694
|
-
console.warn(
|
|
1695
|
-
`AST parsing failed for ${filePath}, falling back to regex: ${error.message}`
|
|
1696
|
-
);
|
|
1697
|
-
return this.parseRegex(code, filePath);
|
|
1698
|
-
}
|
|
1699
|
-
}
|
|
1700
1736
|
parseRegex(code, filePath) {
|
|
1701
1737
|
const lines = code.split("\n");
|
|
1702
1738
|
const exports = [];
|
|
@@ -1885,54 +1921,20 @@ var JavaParser = class {
|
|
|
1885
1921
|
};
|
|
1886
1922
|
|
|
1887
1923
|
// src/parsers/csharp-parser.ts
|
|
1888
|
-
var CSharpParser = class {
|
|
1924
|
+
var CSharpParser = class extends BaseLanguageParser {
|
|
1889
1925
|
constructor() {
|
|
1926
|
+
super(...arguments);
|
|
1890
1927
|
this.language = "csharp" /* CSharp */;
|
|
1891
1928
|
this.extensions = [".cs"];
|
|
1892
|
-
this.parser = null;
|
|
1893
|
-
this.initialized = false;
|
|
1894
1929
|
}
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
*/
|
|
1898
|
-
async initialize() {
|
|
1899
|
-
if (this.initialized) return;
|
|
1900
|
-
this.parser = await setupParser("c_sharp");
|
|
1901
|
-
this.initialized = true;
|
|
1902
|
-
}
|
|
1903
|
-
async getAST(code, filePath) {
|
|
1904
|
-
if (!this.initialized) await this.initialize();
|
|
1905
|
-
if (!this.parser) return null;
|
|
1906
|
-
return this.parser.parse(code);
|
|
1930
|
+
getParserName() {
|
|
1931
|
+
return "c_sharp";
|
|
1907
1932
|
}
|
|
1908
1933
|
analyzeMetadata(node, code) {
|
|
1909
1934
|
return analyzeGeneralMetadata(node, code, {
|
|
1910
1935
|
sideEffectSignatures: ["Console.Write", "File.Write", "Logging."]
|
|
1911
1936
|
});
|
|
1912
1937
|
}
|
|
1913
|
-
parse(code, filePath) {
|
|
1914
|
-
if (!this.initialized || !this.parser) {
|
|
1915
|
-
return this.parseRegex(code, filePath);
|
|
1916
|
-
}
|
|
1917
|
-
try {
|
|
1918
|
-
const tree = this.parser.parse(code);
|
|
1919
|
-
if (!tree) throw new Error("Parser.parse(code) returned null");
|
|
1920
|
-
const rootNode = tree.rootNode;
|
|
1921
|
-
const imports = this.extractImportsAST(rootNode);
|
|
1922
|
-
const exports = this.extractExportsAST(rootNode, code);
|
|
1923
|
-
return {
|
|
1924
|
-
exports,
|
|
1925
|
-
imports,
|
|
1926
|
-
language: "csharp" /* CSharp */,
|
|
1927
|
-
warnings: []
|
|
1928
|
-
};
|
|
1929
|
-
} catch (error) {
|
|
1930
|
-
console.warn(
|
|
1931
|
-
`AST parsing failed for ${filePath}, falling back to regex: ${error.message}`
|
|
1932
|
-
);
|
|
1933
|
-
return this.parseRegex(code, filePath);
|
|
1934
|
-
}
|
|
1935
|
-
}
|
|
1936
1938
|
parseRegex(code, filePath) {
|
|
1937
1939
|
const lines = code.split("\n");
|
|
1938
1940
|
const exports = [];
|
|
@@ -2129,56 +2131,20 @@ var CSharpParser = class {
|
|
|
2129
2131
|
};
|
|
2130
2132
|
|
|
2131
2133
|
// src/parsers/go-parser.ts
|
|
2132
|
-
var GoParser = class {
|
|
2134
|
+
var GoParser = class extends BaseLanguageParser {
|
|
2133
2135
|
constructor() {
|
|
2136
|
+
super(...arguments);
|
|
2134
2137
|
this.language = "go" /* Go */;
|
|
2135
2138
|
this.extensions = [".go"];
|
|
2136
|
-
this.parser = null;
|
|
2137
|
-
this.initialized = false;
|
|
2138
2139
|
}
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
*/
|
|
2142
|
-
async initialize() {
|
|
2143
|
-
if (this.initialized) return;
|
|
2144
|
-
this.parser = await setupParser("go");
|
|
2145
|
-
this.initialized = true;
|
|
2146
|
-
}
|
|
2147
|
-
async getAST(code, filePath) {
|
|
2148
|
-
if (!this.initialized) await this.initialize();
|
|
2149
|
-
if (!this.parser) return null;
|
|
2150
|
-
return this.parser.parse(code);
|
|
2140
|
+
getParserName() {
|
|
2141
|
+
return "go";
|
|
2151
2142
|
}
|
|
2152
2143
|
analyzeMetadata(node, code) {
|
|
2153
2144
|
return analyzeGeneralMetadata(node, code, {
|
|
2154
2145
|
sideEffectSignatures: ["<-", "fmt.Print", "fmt.Fprintf", "os.Exit"]
|
|
2155
2146
|
});
|
|
2156
2147
|
}
|
|
2157
|
-
parse(code, filePath) {
|
|
2158
|
-
if (!this.initialized || !this.parser) {
|
|
2159
|
-
return this.parseRegex(code, filePath);
|
|
2160
|
-
}
|
|
2161
|
-
try {
|
|
2162
|
-
const tree = this.parser.parse(code);
|
|
2163
|
-
if (!tree || tree.rootNode.type === "ERROR" || tree.rootNode.hasError) {
|
|
2164
|
-
return this.parseRegex(code, filePath);
|
|
2165
|
-
}
|
|
2166
|
-
const rootNode = tree.rootNode;
|
|
2167
|
-
const imports = this.extractImportsAST(rootNode);
|
|
2168
|
-
const exports = this.extractExportsAST(rootNode, code);
|
|
2169
|
-
return {
|
|
2170
|
-
exports,
|
|
2171
|
-
imports,
|
|
2172
|
-
language: "go" /* Go */,
|
|
2173
|
-
warnings: []
|
|
2174
|
-
};
|
|
2175
|
-
} catch (error) {
|
|
2176
|
-
console.warn(
|
|
2177
|
-
`AST parsing failed for ${filePath}, falling back to regex: ${error.message}`
|
|
2178
|
-
);
|
|
2179
|
-
return this.parseRegex(code, filePath);
|
|
2180
|
-
}
|
|
2181
|
-
}
|
|
2182
2148
|
parseRegex(code, filePath) {
|
|
2183
2149
|
const lines = code.split("\n");
|
|
2184
2150
|
const exports = [];
|
|
@@ -2505,48 +2471,7 @@ function getSupportedLanguages() {
|
|
|
2505
2471
|
return ParserFactory.getInstance().getSupportedLanguages();
|
|
2506
2472
|
}
|
|
2507
2473
|
|
|
2508
|
-
// src/utils/ast-
|
|
2509
|
-
function parseFileExports(code, filePath) {
|
|
2510
|
-
const parser = getParser(filePath);
|
|
2511
|
-
if (parser && parser.language !== "typescript" /* TypeScript */ && parser.language !== "javascript" /* JavaScript */) {
|
|
2512
|
-
try {
|
|
2513
|
-
const result = parser.parse(code, filePath);
|
|
2514
|
-
return {
|
|
2515
|
-
exports: result.exports.map((e) => ({
|
|
2516
|
-
name: e.name,
|
|
2517
|
-
type: e.type,
|
|
2518
|
-
imports: e.imports || [],
|
|
2519
|
-
dependencies: e.dependencies || [],
|
|
2520
|
-
typeReferences: e.typeReferences || [],
|
|
2521
|
-
loc: e.loc ? {
|
|
2522
|
-
start: { line: e.loc.start.line, column: e.loc.start.column },
|
|
2523
|
-
end: { line: e.loc.end.line, column: e.loc.end.column }
|
|
2524
|
-
} : void 0
|
|
2525
|
-
})),
|
|
2526
|
-
imports: result.imports.map((i) => ({
|
|
2527
|
-
source: i.source,
|
|
2528
|
-
specifiers: i.specifiers,
|
|
2529
|
-
isTypeOnly: i.isTypeOnly || false
|
|
2530
|
-
}))
|
|
2531
|
-
};
|
|
2532
|
-
} catch (e) {
|
|
2533
|
-
return { exports: [], imports: [] };
|
|
2534
|
-
}
|
|
2535
|
-
}
|
|
2536
|
-
try {
|
|
2537
|
-
const ast = parse2(code, {
|
|
2538
|
-
loc: true,
|
|
2539
|
-
range: true,
|
|
2540
|
-
jsx: filePath.endsWith(".tsx") || filePath.endsWith(".jsx"),
|
|
2541
|
-
filePath
|
|
2542
|
-
});
|
|
2543
|
-
const imports = extractFileImports(ast);
|
|
2544
|
-
const exports = extractExportsWithDependencies(ast, imports);
|
|
2545
|
-
return { exports, imports };
|
|
2546
|
-
} catch (error) {
|
|
2547
|
-
return { exports: [], imports: [] };
|
|
2548
|
-
}
|
|
2549
|
-
}
|
|
2474
|
+
// src/utils/ast-visitor.ts
|
|
2550
2475
|
function extractFileImports(ast) {
|
|
2551
2476
|
const imports = [];
|
|
2552
2477
|
for (const node of ast.body) {
|
|
@@ -2604,22 +2529,23 @@ function extractExportsWithDependencies(ast, fileImports) {
|
|
|
2604
2529
|
}
|
|
2605
2530
|
return exports;
|
|
2606
2531
|
}
|
|
2607
|
-
function extractFromDeclaration(
|
|
2532
|
+
function extractFromDeclaration(node) {
|
|
2533
|
+
if (!node) return [];
|
|
2608
2534
|
const results = [];
|
|
2609
|
-
if (
|
|
2610
|
-
results.push({ name:
|
|
2611
|
-
} else if (
|
|
2612
|
-
results.push({ name:
|
|
2613
|
-
} else if (
|
|
2614
|
-
for (const
|
|
2615
|
-
if (
|
|
2616
|
-
results.push({ name:
|
|
2535
|
+
if (node.type === "FunctionDeclaration" && node.id) {
|
|
2536
|
+
results.push({ name: node.id.name, type: "function" });
|
|
2537
|
+
} else if (node.type === "ClassDeclaration" && node.id) {
|
|
2538
|
+
results.push({ name: node.id.name, type: "class" });
|
|
2539
|
+
} else if (node.type === "VariableDeclaration") {
|
|
2540
|
+
for (const decl of node.declarations) {
|
|
2541
|
+
if (decl.id.type === "Identifier") {
|
|
2542
|
+
results.push({ name: decl.id.name, type: "const" });
|
|
2617
2543
|
}
|
|
2618
2544
|
}
|
|
2619
|
-
} else if (
|
|
2620
|
-
results.push({ name:
|
|
2621
|
-
} else if (
|
|
2622
|
-
results.push({ name:
|
|
2545
|
+
} else if (node.type === "TSInterfaceDeclaration" && node.id) {
|
|
2546
|
+
results.push({ name: node.id.name, type: "interface" });
|
|
2547
|
+
} else if (node.type === "TSTypeAliasDeclaration" && node.id) {
|
|
2548
|
+
results.push({ name: node.id.name, type: "type" });
|
|
2623
2549
|
}
|
|
2624
2550
|
return results;
|
|
2625
2551
|
}
|
|
@@ -2647,16 +2573,6 @@ function findUsedImports(node, importedNames) {
|
|
|
2647
2573
|
visit(node);
|
|
2648
2574
|
return Array.from(usedImports);
|
|
2649
2575
|
}
|
|
2650
|
-
function calculateImportSimilarity(export1, export2) {
|
|
2651
|
-
if (export1.imports.length === 0 && export2.imports.length === 0) {
|
|
2652
|
-
return 1;
|
|
2653
|
-
}
|
|
2654
|
-
const set1 = new Set(export1.imports);
|
|
2655
|
-
const set2 = new Set(export2.imports);
|
|
2656
|
-
const intersection = new Set([...set1].filter((x) => set2.has(x)));
|
|
2657
|
-
const union = /* @__PURE__ */ new Set([...set1, ...set2]);
|
|
2658
|
-
return intersection.size / union.size;
|
|
2659
|
-
}
|
|
2660
2576
|
function extractTypeReferences(node) {
|
|
2661
2577
|
const types = /* @__PURE__ */ new Set();
|
|
2662
2578
|
function visit(n) {
|
|
@@ -2694,6 +2610,59 @@ function extractTypeReferences(node) {
|
|
|
2694
2610
|
visit(node);
|
|
2695
2611
|
return Array.from(types);
|
|
2696
2612
|
}
|
|
2613
|
+
|
|
2614
|
+
// src/utils/ast-parser.ts
|
|
2615
|
+
function parseFileExports(code, filePath) {
|
|
2616
|
+
const parser = getParser(filePath);
|
|
2617
|
+
if (parser && parser.language !== "typescript" /* TypeScript */ && parser.language !== "javascript" /* JavaScript */) {
|
|
2618
|
+
try {
|
|
2619
|
+
const result = parser.parse(code, filePath);
|
|
2620
|
+
return {
|
|
2621
|
+
exports: result.exports.map((e) => ({
|
|
2622
|
+
name: e.name,
|
|
2623
|
+
type: e.type,
|
|
2624
|
+
imports: e.imports || [],
|
|
2625
|
+
dependencies: e.dependencies || [],
|
|
2626
|
+
typeReferences: e.typeReferences || [],
|
|
2627
|
+
loc: e.loc ? {
|
|
2628
|
+
start: { line: e.loc.start.line, column: e.loc.start.column },
|
|
2629
|
+
end: { line: e.loc.end.line, column: e.loc.end.column }
|
|
2630
|
+
} : void 0
|
|
2631
|
+
})),
|
|
2632
|
+
imports: result.imports.map((i) => ({
|
|
2633
|
+
source: i.source,
|
|
2634
|
+
specifiers: i.specifiers,
|
|
2635
|
+
isTypeOnly: i.isTypeOnly || false
|
|
2636
|
+
}))
|
|
2637
|
+
};
|
|
2638
|
+
} catch (e) {
|
|
2639
|
+
return { exports: [], imports: [] };
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
try {
|
|
2643
|
+
const ast = parse2(code, {
|
|
2644
|
+
loc: true,
|
|
2645
|
+
range: true,
|
|
2646
|
+
jsx: filePath.endsWith(".tsx") || filePath.endsWith(".jsx"),
|
|
2647
|
+
filePath
|
|
2648
|
+
});
|
|
2649
|
+
const imports = extractFileImports(ast);
|
|
2650
|
+
const exports = extractExportsWithDependencies(ast, imports);
|
|
2651
|
+
return { exports, imports };
|
|
2652
|
+
} catch (error) {
|
|
2653
|
+
return { exports: [], imports: [] };
|
|
2654
|
+
}
|
|
2655
|
+
}
|
|
2656
|
+
function calculateImportSimilarity(export1, export2) {
|
|
2657
|
+
if (export1.imports.length === 0 && export2.imports.length === 0) {
|
|
2658
|
+
return 1;
|
|
2659
|
+
}
|
|
2660
|
+
const set1 = new Set(export1.imports);
|
|
2661
|
+
const set2 = new Set(export2.imports);
|
|
2662
|
+
const intersection = new Set([...set1].filter((x) => set2.has(x)));
|
|
2663
|
+
const union = /* @__PURE__ */ new Set([...set1, ...set2]);
|
|
2664
|
+
return intersection.size / union.size;
|
|
2665
|
+
}
|
|
2697
2666
|
function parseCode(code, language) {
|
|
2698
2667
|
return null;
|
|
2699
2668
|
}
|
|
@@ -2757,14 +2726,14 @@ async function loadConfig(rootDir) {
|
|
|
2757
2726
|
return config;
|
|
2758
2727
|
} catch (error) {
|
|
2759
2728
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
2760
|
-
const
|
|
2729
|
+
const configError = new Error(
|
|
2761
2730
|
`Failed to load config from ${configPath}: ${errorMessage}`
|
|
2762
2731
|
);
|
|
2763
2732
|
try {
|
|
2764
|
-
|
|
2733
|
+
configError.cause = error instanceof Error ? error : void 0;
|
|
2765
2734
|
} catch {
|
|
2766
2735
|
}
|
|
2767
|
-
throw
|
|
2736
|
+
throw configError;
|
|
2768
2737
|
}
|
|
2769
2738
|
}
|
|
2770
2739
|
const parent = dirname4(currentDir);
|
|
@@ -2777,28 +2746,28 @@ async function loadConfig(rootDir) {
|
|
|
2777
2746
|
}
|
|
2778
2747
|
function mergeConfigWithDefaults(userConfig, defaults) {
|
|
2779
2748
|
if (!userConfig) return defaults;
|
|
2780
|
-
const
|
|
2749
|
+
const mergedConfig = { ...defaults };
|
|
2781
2750
|
if (userConfig.scan) {
|
|
2782
|
-
if (userConfig.scan.include)
|
|
2783
|
-
if (userConfig.scan.exclude)
|
|
2751
|
+
if (userConfig.scan.include) mergedConfig.include = userConfig.scan.include;
|
|
2752
|
+
if (userConfig.scan.exclude) mergedConfig.exclude = userConfig.scan.exclude;
|
|
2784
2753
|
}
|
|
2785
2754
|
const toolOverrides = userConfig.tools && !Array.isArray(userConfig.tools) && typeof userConfig.tools === "object" ? userConfig.tools : userConfig.toolConfigs;
|
|
2786
2755
|
if (toolOverrides) {
|
|
2787
|
-
if (!
|
|
2756
|
+
if (!mergedConfig.toolConfigs) mergedConfig.toolConfigs = {};
|
|
2788
2757
|
for (const [toolName, toolConfig] of Object.entries(toolOverrides)) {
|
|
2789
2758
|
if (typeof toolConfig === "object" && toolConfig !== null) {
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
...
|
|
2759
|
+
mergedConfig[toolName] = { ...mergedConfig[toolName], ...toolConfig };
|
|
2760
|
+
mergedConfig.toolConfigs[toolName] = {
|
|
2761
|
+
...mergedConfig.toolConfigs[toolName],
|
|
2793
2762
|
...toolConfig
|
|
2794
2763
|
};
|
|
2795
2764
|
}
|
|
2796
2765
|
}
|
|
2797
2766
|
}
|
|
2798
2767
|
if (userConfig.output) {
|
|
2799
|
-
|
|
2768
|
+
mergedConfig.output = { ...mergedConfig.output, ...userConfig.output };
|
|
2800
2769
|
}
|
|
2801
|
-
return
|
|
2770
|
+
return mergedConfig;
|
|
2802
2771
|
}
|
|
2803
2772
|
|
|
2804
2773
|
// src/business/pricing-models.ts
|
|
@@ -3011,7 +2980,10 @@ function predictAcceptanceRate(toolOutputs) {
|
|
|
3011
2980
|
impact: Math.round((50 - aiSignalClarity.score) * 2e-3 * 100)
|
|
3012
2981
|
});
|
|
3013
2982
|
}
|
|
3014
|
-
const totalImpact = factors.reduce(
|
|
2983
|
+
const totalImpact = factors.reduce(
|
|
2984
|
+
(sum, f) => sum + f.impact / 100,
|
|
2985
|
+
0
|
|
2986
|
+
);
|
|
3015
2987
|
const rate = Math.max(0.05, Math.min(0.8, baseRate + totalImpact));
|
|
3016
2988
|
let confidence = 0.35;
|
|
3017
2989
|
if (toolOutputs.size >= 4) confidence = 0.75;
|
|
@@ -4350,12 +4322,17 @@ export {
|
|
|
4350
4322
|
getProjectSizeTier,
|
|
4351
4323
|
getRating,
|
|
4352
4324
|
getRatingDisplay,
|
|
4325
|
+
getRatingSlug,
|
|
4353
4326
|
getRatingWithContext,
|
|
4354
4327
|
getRecommendedThreshold,
|
|
4355
4328
|
getRepoMetadata,
|
|
4356
4329
|
getSafetyIcon,
|
|
4357
4330
|
getScoreBar,
|
|
4331
|
+
getSeverityBadge,
|
|
4358
4332
|
getSeverityColor,
|
|
4333
|
+
getSeverityEnum,
|
|
4334
|
+
getSeverityLevel,
|
|
4335
|
+
getSeverityValue,
|
|
4359
4336
|
getSupportedLanguages,
|
|
4360
4337
|
getToolWeight,
|
|
4361
4338
|
getWasmPath,
|