eslint-plugin-ai-guard 1.2.2 → 1.2.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/cli/index.js +152 -52
- package/dist/cli/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -201,14 +201,14 @@ __export(config_manager_exports, {
|
|
|
201
201
|
});
|
|
202
202
|
function backupConfig(configPath) {
|
|
203
203
|
const backupPath = `${configPath}.bak`;
|
|
204
|
-
|
|
204
|
+
import_fs7.default.copyFileSync(configPath, backupPath);
|
|
205
205
|
return backupPath;
|
|
206
206
|
}
|
|
207
207
|
function readConfig(configPath) {
|
|
208
|
-
return
|
|
208
|
+
return import_fs7.default.readFileSync(configPath, "utf-8");
|
|
209
209
|
}
|
|
210
210
|
function writeConfig(configPath, content) {
|
|
211
|
-
|
|
211
|
+
import_fs7.default.writeFileSync(configPath, content, "utf-8");
|
|
212
212
|
}
|
|
213
213
|
function generateFlatConfig(preset) {
|
|
214
214
|
return `import aiGuard from 'eslint-plugin-ai-guard';
|
|
@@ -461,11 +461,11 @@ function validateLegacyConfigText(content) {
|
|
|
461
461
|
}
|
|
462
462
|
return problems;
|
|
463
463
|
}
|
|
464
|
-
var
|
|
464
|
+
var import_fs7, import_path6, AI_GUARD_MARKER, DEFAULT_FLAT_IGNORES, DEFAULT_LEGACY_IGNORES;
|
|
465
465
|
var init_config_manager = __esm({
|
|
466
466
|
"cli/utils/config-manager.ts"() {
|
|
467
467
|
"use strict";
|
|
468
|
-
|
|
468
|
+
import_fs7 = __toESM(require("fs"));
|
|
469
469
|
import_path6 = __toESM(require("path"));
|
|
470
470
|
AI_GUARD_MARKER = "eslint-plugin-ai-guard";
|
|
471
471
|
DEFAULT_FLAT_IGNORES = [
|
|
@@ -489,10 +489,11 @@ var init_config_manager = __esm({
|
|
|
489
489
|
|
|
490
490
|
// cli/index.ts
|
|
491
491
|
var import_commander = require("commander");
|
|
492
|
-
var
|
|
492
|
+
var import_fs12 = __toESM(require("fs"));
|
|
493
493
|
var import_path14 = __toESM(require("path"));
|
|
494
494
|
|
|
495
495
|
// cli/commands/run.ts
|
|
496
|
+
var import_fs4 = __toESM(require("fs"));
|
|
496
497
|
var import_ora = __toESM(require("ora"));
|
|
497
498
|
var import_chalk3 = __toESM(require("chalk"));
|
|
498
499
|
|
|
@@ -1250,6 +1251,50 @@ var RULE_DOCS = {
|
|
|
1250
1251
|
"ai-guard/no-dead-branch": { shortDesc: "Dead code branch that can never execute", tags: ["ai-patterns"] }
|
|
1251
1252
|
};
|
|
1252
1253
|
var BASE_DOCS_URL = "https://github.com/YashJadhav21/eslint-plugin-ai-guard/blob/main/docs/rules";
|
|
1254
|
+
function sanitizeSarifTags(tags) {
|
|
1255
|
+
return Array.from(
|
|
1256
|
+
new Set(
|
|
1257
|
+
tags.filter((t) => typeof t === "string" && t.trim().length > 0).map((t) => t.toLowerCase().trim().replace(/\s+/g, "-"))
|
|
1258
|
+
)
|
|
1259
|
+
);
|
|
1260
|
+
}
|
|
1261
|
+
function sanitizeSarifProperties(props) {
|
|
1262
|
+
return {
|
|
1263
|
+
tags: sanitizeSarifTags(props.tags),
|
|
1264
|
+
confidence: props.confidence ?? "low",
|
|
1265
|
+
category: props.category ?? "AI Patterns",
|
|
1266
|
+
"problem.severity": props.problemSeverity ?? "low"
|
|
1267
|
+
};
|
|
1268
|
+
}
|
|
1269
|
+
function sanitizeSarifRule(rule) {
|
|
1270
|
+
return {
|
|
1271
|
+
...rule,
|
|
1272
|
+
shortDescription: {
|
|
1273
|
+
text: rule.shortDescription.text || `ai-guard rule: ${rule.id}`
|
|
1274
|
+
},
|
|
1275
|
+
fullDescription: rule.fullDescription?.text ? rule.fullDescription : { text: rule.shortDescription.text || `ai-guard rule: ${rule.id}` },
|
|
1276
|
+
properties: rule.properties ? {
|
|
1277
|
+
...rule.properties,
|
|
1278
|
+
// Re-deduplicate tags at the rule level as a final safety net
|
|
1279
|
+
tags: rule.properties.tags ? sanitizeSarifTags(rule.properties.tags) : []
|
|
1280
|
+
} : void 0
|
|
1281
|
+
};
|
|
1282
|
+
}
|
|
1283
|
+
function sanitizeSarifLog(log2) {
|
|
1284
|
+
return {
|
|
1285
|
+
...log2,
|
|
1286
|
+
runs: log2.runs.map((run) => ({
|
|
1287
|
+
...run,
|
|
1288
|
+
tool: {
|
|
1289
|
+
...run.tool,
|
|
1290
|
+
driver: {
|
|
1291
|
+
...run.tool.driver,
|
|
1292
|
+
rules: run.tool.driver.rules.map(sanitizeSarifRule)
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
}))
|
|
1296
|
+
};
|
|
1297
|
+
}
|
|
1253
1298
|
function confidenceToSarifLevel(confidence) {
|
|
1254
1299
|
switch (confidence) {
|
|
1255
1300
|
case "high":
|
|
@@ -1311,6 +1356,8 @@ function buildRuleDescriptors(ruleIds) {
|
|
|
1311
1356
|
const confidence = ISSUE_CONFIDENCE[id];
|
|
1312
1357
|
const category = ISSUE_CATEGORY[id] ?? "AI Patterns";
|
|
1313
1358
|
const remediation = ISSUE_REMEDIATION[id];
|
|
1359
|
+
const categorySlug = category.toLowerCase().replace(/\s+/g, "-");
|
|
1360
|
+
const rawTags = [...meta?.tags ?? ["ai-guard"], categorySlug];
|
|
1314
1361
|
const helpMarkdown = [
|
|
1315
1362
|
`**${meta?.shortDesc ?? shortName}**`,
|
|
1316
1363
|
"",
|
|
@@ -1318,7 +1365,7 @@ function buildRuleDescriptors(ruleIds) {
|
|
|
1318
1365
|
"",
|
|
1319
1366
|
`[View rule documentation](${BASE_DOCS_URL}/${shortName}.md)`
|
|
1320
1367
|
].filter(Boolean).join("\n");
|
|
1321
|
-
return {
|
|
1368
|
+
return sanitizeSarifRule({
|
|
1322
1369
|
id,
|
|
1323
1370
|
shortDescription: {
|
|
1324
1371
|
text: meta?.shortDesc ?? `ai-guard rule: ${shortName}`
|
|
@@ -1334,13 +1381,13 @@ function buildRuleDescriptors(ruleIds) {
|
|
|
1334
1381
|
defaultConfiguration: {
|
|
1335
1382
|
level: confidenceToSarifLevel(confidence)
|
|
1336
1383
|
},
|
|
1337
|
-
properties: {
|
|
1338
|
-
tags:
|
|
1339
|
-
confidence
|
|
1384
|
+
properties: sanitizeSarifProperties({
|
|
1385
|
+
tags: rawTags,
|
|
1386
|
+
confidence,
|
|
1340
1387
|
category,
|
|
1341
|
-
|
|
1342
|
-
}
|
|
1343
|
-
};
|
|
1388
|
+
problemSeverity: confidenceToGitHubSeverity(confidence)
|
|
1389
|
+
})
|
|
1390
|
+
});
|
|
1344
1391
|
});
|
|
1345
1392
|
}
|
|
1346
1393
|
function buildSarifResult(issue, file) {
|
|
@@ -1386,7 +1433,7 @@ function buildSarifLog(result, version = PKG_VERSION) {
|
|
|
1386
1433
|
sarifResults.push(buildSarifResult(issue, file));
|
|
1387
1434
|
}
|
|
1388
1435
|
}
|
|
1389
|
-
|
|
1436
|
+
const log2 = {
|
|
1390
1437
|
$schema: "https://json.schemastore.org/sarif-2.1.0.json",
|
|
1391
1438
|
version: "2.1.0",
|
|
1392
1439
|
runs: [
|
|
@@ -1410,10 +1457,36 @@ function buildSarifLog(result, version = PKG_VERSION) {
|
|
|
1410
1457
|
}
|
|
1411
1458
|
]
|
|
1412
1459
|
};
|
|
1460
|
+
return sanitizeSarifLog(log2);
|
|
1413
1461
|
}
|
|
1414
1462
|
function sarifToJson(log2) {
|
|
1415
1463
|
return JSON.stringify(log2, null, 2);
|
|
1416
1464
|
}
|
|
1465
|
+
function buildSarifDebugInfo(result) {
|
|
1466
|
+
const usedRuleIds = collectUsedRuleIds(result);
|
|
1467
|
+
const rulesEmitted = usedRuleIds.map((id) => {
|
|
1468
|
+
const meta = RULE_DOCS[id];
|
|
1469
|
+
const confidence = ISSUE_CONFIDENCE[id];
|
|
1470
|
+
const category = ISSUE_CATEGORY[id] ?? "AI Patterns";
|
|
1471
|
+
const categorySlug = category.toLowerCase().replace(/\s+/g, "-");
|
|
1472
|
+
const rawTags = [...meta?.tags ?? ["ai-guard"], categorySlug];
|
|
1473
|
+
const sanitizedTags = sanitizeSarifTags(rawTags);
|
|
1474
|
+
return {
|
|
1475
|
+
id,
|
|
1476
|
+
rawTags,
|
|
1477
|
+
sanitizedTags,
|
|
1478
|
+
hasDuplicatesInRaw: rawTags.length !== new Set(rawTags).size,
|
|
1479
|
+
confidence: confidence ?? "low",
|
|
1480
|
+
category,
|
|
1481
|
+
level: confidenceToSarifLevel(confidence)
|
|
1482
|
+
};
|
|
1483
|
+
});
|
|
1484
|
+
return {
|
|
1485
|
+
rulesEmitted,
|
|
1486
|
+
totalResults: result.files.reduce((n, f) => n + f.issues.length, 0),
|
|
1487
|
+
version: PKG_VERSION
|
|
1488
|
+
};
|
|
1489
|
+
}
|
|
1417
1490
|
|
|
1418
1491
|
// cli/utils/github-summary.ts
|
|
1419
1492
|
var import_fs2 = __toESM(require("fs"));
|
|
@@ -1891,7 +1964,7 @@ function registerRunCommand(program2) {
|
|
|
1891
1964
|
"--max-warnings <n>",
|
|
1892
1965
|
"Fail with exit code 1 if warnings exceed this count",
|
|
1893
1966
|
(value) => Number.parseInt(value, 10)
|
|
1894
|
-
).option("--verbose", "Show all issues \u2014 disable grouping of repeated warnings").option("--quiet", "Only show errors \u2014 suppress warnings and informational hints").option("--debug-timing", "Print per-phase timing diagnostics").action(async (opts) => {
|
|
1967
|
+
).option("--verbose", "Show all issues \u2014 disable grouping of repeated warnings").option("--quiet", "Only show errors \u2014 suppress warnings and informational hints").option("--debug-timing", "Print per-phase timing diagnostics").option("--debug-sarif", "Print SARIF tag normalization trace \u2014 diagnose duplicate-tag schema issues").option("--sarif-output <file>", "Write SARIF to this file instead of stdout").action(async (opts) => {
|
|
1895
1968
|
if (opts.maxWarnings !== void 0 && (!Number.isInteger(opts.maxWarnings) || opts.maxWarnings < 0)) {
|
|
1896
1969
|
log.blank();
|
|
1897
1970
|
log.error("--max-warnings must be a non-negative integer.");
|
|
@@ -1943,9 +2016,36 @@ function registerRunCommand(program2) {
|
|
|
1943
2016
|
writeGitHubSummary(result, { preset, scanMode: "full" });
|
|
1944
2017
|
writeGitHubOutputs(result);
|
|
1945
2018
|
}
|
|
1946
|
-
if (opts.sarif) {
|
|
2019
|
+
if (opts.sarif || opts.sarifOutput) {
|
|
1947
2020
|
const sarifLog = buildSarifLog(result);
|
|
1948
|
-
|
|
2021
|
+
const sarifJson = sarifToJson(sarifLog);
|
|
2022
|
+
if (opts.debugSarif) {
|
|
2023
|
+
const debugInfo = buildSarifDebugInfo(result);
|
|
2024
|
+
process.stderr.write("\n[debug-sarif] SARIF Tag Normalization Trace\n");
|
|
2025
|
+
process.stderr.write("[debug-sarif] \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n");
|
|
2026
|
+
for (const r of debugInfo.rulesEmitted) {
|
|
2027
|
+
process.stderr.write(`[debug-sarif] ${r.id}
|
|
2028
|
+
`);
|
|
2029
|
+
process.stderr.write(`[debug-sarif] raw: ${JSON.stringify(r.rawTags)}
|
|
2030
|
+
`);
|
|
2031
|
+
process.stderr.write(`[debug-sarif] sanitized: ${JSON.stringify(r.sanitizedTags)}
|
|
2032
|
+
`);
|
|
2033
|
+
if (r.hasDuplicatesInRaw) {
|
|
2034
|
+
process.stderr.write(`[debug-sarif] \u26A0 had duplicates \u2014 deduplicated
|
|
2035
|
+
`);
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
process.stderr.write("\n");
|
|
2039
|
+
}
|
|
2040
|
+
if (opts.sarifOutput) {
|
|
2041
|
+
import_fs4.default.writeFileSync(opts.sarifOutput, sarifJson, "utf-8");
|
|
2042
|
+
if (opts.debugSarif) {
|
|
2043
|
+
process.stderr.write(`[debug-sarif] SARIF written to: ${opts.sarifOutput}
|
|
2044
|
+
`);
|
|
2045
|
+
}
|
|
2046
|
+
} else {
|
|
2047
|
+
console.log(sarifJson);
|
|
2048
|
+
}
|
|
1949
2049
|
process.exit(resolveExitCode(result, opts.failOn ?? "errors", opts.maxWarnings));
|
|
1950
2050
|
return;
|
|
1951
2051
|
}
|
|
@@ -2280,7 +2380,7 @@ function resolveExitCode(result, failOn, maxWarnings) {
|
|
|
2280
2380
|
|
|
2281
2381
|
// cli/commands/changed.ts
|
|
2282
2382
|
var import_path4 = __toESM(require("path"));
|
|
2283
|
-
var
|
|
2383
|
+
var import_fs5 = __toESM(require("fs"));
|
|
2284
2384
|
var import_ora2 = __toESM(require("ora"));
|
|
2285
2385
|
var import_chalk5 = __toESM(require("chalk"));
|
|
2286
2386
|
function registerChangedCommand(program2) {
|
|
@@ -2401,7 +2501,7 @@ function handleResults(result, opts, preset, scanMode, changedFilesCount, inCI,
|
|
|
2401
2501
|
const sarifLog = buildSarifLog(result);
|
|
2402
2502
|
const sarifJson = sarifToJson(sarifLog);
|
|
2403
2503
|
if (resolvedSarifPath) {
|
|
2404
|
-
|
|
2504
|
+
import_fs5.default.writeFileSync(resolvedSarifPath, sarifJson, "utf-8");
|
|
2405
2505
|
} else {
|
|
2406
2506
|
console.log(sarifJson);
|
|
2407
2507
|
}
|
|
@@ -2532,10 +2632,10 @@ function getFailOnExitCode(result, failOn, maxWarnings) {
|
|
|
2532
2632
|
// cli/commands/init.ts
|
|
2533
2633
|
var import_chalk6 = __toESM(require("chalk"));
|
|
2534
2634
|
var import_path7 = __toESM(require("path"));
|
|
2535
|
-
var
|
|
2635
|
+
var import_fs8 = __toESM(require("fs"));
|
|
2536
2636
|
|
|
2537
2637
|
// cli/utils/detector.ts
|
|
2538
|
-
var
|
|
2638
|
+
var import_fs6 = __toESM(require("fs"));
|
|
2539
2639
|
var import_path5 = __toESM(require("path"));
|
|
2540
2640
|
var import_module2 = require("module");
|
|
2541
2641
|
var FLAT_CONFIG_FILES = [
|
|
@@ -2554,7 +2654,7 @@ var ALL_CONFIG_FILES = [...FLAT_CONFIG_FILES, ...LEGACY_CONFIG_FILES];
|
|
|
2554
2654
|
function isPackageInstalled(pkgName, cwd = process.cwd()) {
|
|
2555
2655
|
try {
|
|
2556
2656
|
const pkgPath = import_path5.default.join(cwd, "node_modules", pkgName, "package.json");
|
|
2557
|
-
if (
|
|
2657
|
+
if (import_fs6.default.existsSync(pkgPath)) {
|
|
2558
2658
|
return true;
|
|
2559
2659
|
}
|
|
2560
2660
|
const req = (0, import_module2.createRequire)(import_path5.default.join(cwd, "package.json"));
|
|
@@ -2567,8 +2667,8 @@ function isPackageInstalled(pkgName, cwd = process.cwd()) {
|
|
|
2567
2667
|
function getPackageVersion(pkgName, cwd = process.cwd()) {
|
|
2568
2668
|
try {
|
|
2569
2669
|
const pkgPath = import_path5.default.join(cwd, "node_modules", pkgName, "package.json");
|
|
2570
|
-
const resolvedPath =
|
|
2571
|
-
const raw =
|
|
2670
|
+
const resolvedPath = import_fs6.default.existsSync(pkgPath) ? pkgPath : (0, import_module2.createRequire)(import_path5.default.join(cwd, "package.json")).resolve(`${pkgName}/package.json`);
|
|
2671
|
+
const raw = import_fs6.default.readFileSync(resolvedPath, "utf-8");
|
|
2572
2672
|
const json = JSON.parse(raw);
|
|
2573
2673
|
return json.version ?? null;
|
|
2574
2674
|
} catch {
|
|
@@ -2585,7 +2685,7 @@ function detectConfigType(cwd = process.cwd()) {
|
|
|
2585
2685
|
let first = null;
|
|
2586
2686
|
for (const { file, type } of ALL_CONFIG_FILES) {
|
|
2587
2687
|
const fullPath = import_path5.default.join(cwd, file);
|
|
2588
|
-
if (
|
|
2688
|
+
if (import_fs6.default.existsSync(fullPath)) {
|
|
2589
2689
|
found.push(fullPath);
|
|
2590
2690
|
if (!first) first = { type, path: fullPath };
|
|
2591
2691
|
}
|
|
@@ -2608,7 +2708,7 @@ function requiresFlatConfig(eslintMajor) {
|
|
|
2608
2708
|
function detectNukeIgnore(configPath) {
|
|
2609
2709
|
if (!configPath) return false;
|
|
2610
2710
|
try {
|
|
2611
|
-
const content =
|
|
2711
|
+
const content = import_fs6.default.readFileSync(configPath, "utf-8");
|
|
2612
2712
|
return content.includes('"**/*"') || content.includes("'**/*'");
|
|
2613
2713
|
} catch {
|
|
2614
2714
|
return false;
|
|
@@ -2843,10 +2943,10 @@ function registerInitCommand(program2) {
|
|
|
2843
2943
|
const legacyConfigs = env.allConfigPaths.filter((p) => !p.includes("eslint.config."));
|
|
2844
2944
|
let cleanedUp = false;
|
|
2845
2945
|
for (const p of legacyConfigs) {
|
|
2846
|
-
if (
|
|
2946
|
+
if (import_fs8.default.existsSync(p)) {
|
|
2847
2947
|
if (!isDryRun) {
|
|
2848
2948
|
try {
|
|
2849
|
-
|
|
2949
|
+
import_fs8.default.renameSync(p, `${p}.bak`);
|
|
2850
2950
|
cleanedUp = true;
|
|
2851
2951
|
} catch (err) {
|
|
2852
2952
|
const reason = err instanceof Error ? err.message : String(err);
|
|
@@ -2872,7 +2972,7 @@ function registerInitCommand(program2) {
|
|
|
2872
2972
|
}
|
|
2873
2973
|
log.blank();
|
|
2874
2974
|
log.section("Validation");
|
|
2875
|
-
if (!
|
|
2975
|
+
if (!import_fs8.default.existsSync(finalConfigPath)) {
|
|
2876
2976
|
log.error(`Config file not found after write: ${import_path7.default.relative(cwd, finalConfigPath)}`);
|
|
2877
2977
|
log.blank();
|
|
2878
2978
|
log.print(` ${import_chalk6.default.bold("Problem:")} File write may have failed.`);
|
|
@@ -2929,7 +3029,7 @@ function registerInitCommand(program2) {
|
|
|
2929
3029
|
let cleanedUpInfo = false;
|
|
2930
3030
|
if (eslintNeedsFlat) {
|
|
2931
3031
|
const legacyConfigs = env.allConfigPaths.filter((p) => !p.includes("eslint.config."));
|
|
2932
|
-
cleanedUpInfo = legacyConfigs.some((p) =>
|
|
3032
|
+
cleanedUpInfo = legacyConfigs.some((p) => import_fs8.default.existsSync(`${p}.bak`) && !import_fs8.default.existsSync(p));
|
|
2933
3033
|
}
|
|
2934
3034
|
const lingeringConflicts = env.hasConflictingConfigs && !eslintNeedsFlat && !cleanedUpInfo;
|
|
2935
3035
|
if (loadError === null && !lingeringConflicts) {
|
|
@@ -3319,7 +3419,7 @@ function registerIgnoreCommand(program2) {
|
|
|
3319
3419
|
}
|
|
3320
3420
|
|
|
3321
3421
|
// cli/commands/baseline.ts
|
|
3322
|
-
var
|
|
3422
|
+
var import_fs9 = __toESM(require("fs"));
|
|
3323
3423
|
var import_path11 = __toESM(require("path"));
|
|
3324
3424
|
var import_chalk10 = __toESM(require("chalk"));
|
|
3325
3425
|
var import_ora3 = __toESM(require("ora"));
|
|
@@ -3342,14 +3442,14 @@ function saveBaseline(result, preset, mode, cwd) {
|
|
|
3342
3442
|
entries
|
|
3343
3443
|
};
|
|
3344
3444
|
const baselinePath = import_path11.default.join(cwd, BASELINE_FILE);
|
|
3345
|
-
|
|
3445
|
+
import_fs9.default.writeFileSync(baselinePath, JSON.stringify(baseline, null, 2), "utf-8");
|
|
3346
3446
|
return baselinePath;
|
|
3347
3447
|
}
|
|
3348
3448
|
function loadBaseline(cwd) {
|
|
3349
3449
|
const baselinePath = import_path11.default.join(cwd, BASELINE_FILE);
|
|
3350
|
-
if (!
|
|
3450
|
+
if (!import_fs9.default.existsSync(baselinePath)) return null;
|
|
3351
3451
|
try {
|
|
3352
|
-
const raw =
|
|
3452
|
+
const raw = import_fs9.default.readFileSync(baselinePath, "utf-8");
|
|
3353
3453
|
return JSON.parse(raw);
|
|
3354
3454
|
} catch {
|
|
3355
3455
|
return null;
|
|
@@ -3516,7 +3616,7 @@ function registerBaselineCommand(program2) {
|
|
|
3516
3616
|
}
|
|
3517
3617
|
|
|
3518
3618
|
// cli/commands/init-context.ts
|
|
3519
|
-
var
|
|
3619
|
+
var import_fs10 = __toESM(require("fs"));
|
|
3520
3620
|
var import_path12 = __toESM(require("path"));
|
|
3521
3621
|
var import_chalk11 = __toESM(require("chalk"));
|
|
3522
3622
|
var import_prompts2 = require("@inquirer/prompts");
|
|
@@ -3888,16 +3988,16 @@ var AGENTS = [
|
|
|
3888
3988
|
function getPackageVersion2(cwd) {
|
|
3889
3989
|
try {
|
|
3890
3990
|
const pkgPath = import_path12.default.join(cwd, "node_modules", "eslint-plugin-ai-guard", "package.json");
|
|
3891
|
-
if (
|
|
3892
|
-
const pkg = JSON.parse(
|
|
3991
|
+
if (import_fs10.default.existsSync(pkgPath)) {
|
|
3992
|
+
const pkg = JSON.parse(import_fs10.default.readFileSync(pkgPath, "utf-8"));
|
|
3893
3993
|
if (pkg.version) return pkg.version;
|
|
3894
3994
|
}
|
|
3895
3995
|
} catch {
|
|
3896
3996
|
}
|
|
3897
3997
|
try {
|
|
3898
3998
|
const pkgPath = import_path12.default.join(cwd, "package.json");
|
|
3899
|
-
if (
|
|
3900
|
-
const pkg = JSON.parse(
|
|
3999
|
+
if (import_fs10.default.existsSync(pkgPath)) {
|
|
4000
|
+
const pkg = JSON.parse(import_fs10.default.readFileSync(pkgPath, "utf-8"));
|
|
3901
4001
|
if (pkg.version) return pkg.version;
|
|
3902
4002
|
}
|
|
3903
4003
|
} catch {
|
|
@@ -3965,7 +4065,7 @@ function registerInitContextCommand(program2) {
|
|
|
3965
4065
|
const results = [];
|
|
3966
4066
|
for (const agent of selectedAgents) {
|
|
3967
4067
|
const fullPath = import_path12.default.join(cwd, agent.filePath);
|
|
3968
|
-
const exists =
|
|
4068
|
+
const exists = import_fs10.default.existsSync(fullPath);
|
|
3969
4069
|
if (exists && !isForce && !isDryRun) {
|
|
3970
4070
|
const overwrite = await (0, import_prompts2.confirm)({
|
|
3971
4071
|
message: `${agent.filePath} already exists. Overwrite?`,
|
|
@@ -3990,10 +4090,10 @@ function registerInitContextCommand(program2) {
|
|
|
3990
4090
|
continue;
|
|
3991
4091
|
}
|
|
3992
4092
|
const parentDir = import_path12.default.dirname(fullPath);
|
|
3993
|
-
if (!
|
|
3994
|
-
|
|
4093
|
+
if (!import_fs10.default.existsSync(parentDir)) {
|
|
4094
|
+
import_fs10.default.mkdirSync(parentDir, { recursive: true });
|
|
3995
4095
|
}
|
|
3996
|
-
|
|
4096
|
+
import_fs10.default.writeFileSync(fullPath, content, "utf-8");
|
|
3997
4097
|
results.push({ file: agent.filePath, status: "created" });
|
|
3998
4098
|
}
|
|
3999
4099
|
log.section("Summary");
|
|
@@ -4027,7 +4127,7 @@ function registerInitContextCommand(program2) {
|
|
|
4027
4127
|
}
|
|
4028
4128
|
|
|
4029
4129
|
// cli/commands/report.ts
|
|
4030
|
-
var
|
|
4130
|
+
var import_fs11 = __toESM(require("fs"));
|
|
4031
4131
|
var import_path13 = __toESM(require("path"));
|
|
4032
4132
|
var import_ora4 = __toESM(require("ora"));
|
|
4033
4133
|
var RULE_META = {
|
|
@@ -4053,8 +4153,8 @@ var RULE_META = {
|
|
|
4053
4153
|
function getProjectName(cwd) {
|
|
4054
4154
|
try {
|
|
4055
4155
|
const pkgPath = import_path13.default.join(cwd, "package.json");
|
|
4056
|
-
if (
|
|
4057
|
-
const pkg = JSON.parse(
|
|
4156
|
+
if (import_fs11.default.existsSync(pkgPath)) {
|
|
4157
|
+
const pkg = JSON.parse(import_fs11.default.readFileSync(pkgPath, "utf-8"));
|
|
4058
4158
|
if (pkg.name) return pkg.name;
|
|
4059
4159
|
}
|
|
4060
4160
|
} catch {
|
|
@@ -4064,16 +4164,16 @@ function getProjectName(cwd) {
|
|
|
4064
4164
|
function getPluginVersion(cwd) {
|
|
4065
4165
|
try {
|
|
4066
4166
|
const pkgPath = import_path13.default.resolve(__dirname, "../../package.json");
|
|
4067
|
-
if (
|
|
4068
|
-
const pkg = JSON.parse(
|
|
4167
|
+
if (import_fs11.default.existsSync(pkgPath)) {
|
|
4168
|
+
const pkg = JSON.parse(import_fs11.default.readFileSync(pkgPath, "utf-8"));
|
|
4069
4169
|
if (pkg.version) return pkg.version;
|
|
4070
4170
|
}
|
|
4071
4171
|
} catch {
|
|
4072
4172
|
}
|
|
4073
4173
|
try {
|
|
4074
4174
|
const pkgPath = import_path13.default.join(cwd, "node_modules", "eslint-plugin-ai-guard", "package.json");
|
|
4075
|
-
if (
|
|
4076
|
-
const pkg = JSON.parse(
|
|
4175
|
+
if (import_fs11.default.existsSync(pkgPath)) {
|
|
4176
|
+
const pkg = JSON.parse(import_fs11.default.readFileSync(pkgPath, "utf-8"));
|
|
4077
4177
|
if (pkg.version) return pkg.version;
|
|
4078
4178
|
}
|
|
4079
4179
|
} catch {
|
|
@@ -4451,7 +4551,7 @@ function registerReportCommand(program2) {
|
|
|
4451
4551
|
log.blank();
|
|
4452
4552
|
const html = generateHtml(reportData);
|
|
4453
4553
|
const outputPath = import_path13.default.resolve(cwd, opts.output);
|
|
4454
|
-
|
|
4554
|
+
import_fs11.default.writeFileSync(outputPath, html, "utf-8");
|
|
4455
4555
|
log.success(`Report saved: ${opts.output}`);
|
|
4456
4556
|
log.info(
|
|
4457
4557
|
`Score: ${reportData.score}/100 \xB7 ${reportData.totalErrors} errors \xB7 ${reportData.totalWarnings} warnings`
|
|
@@ -4485,7 +4585,7 @@ function registerReportCommand(program2) {
|
|
|
4485
4585
|
function getVersion() {
|
|
4486
4586
|
try {
|
|
4487
4587
|
const pkgPath = import_path14.default.resolve(__dirname, "../../package.json");
|
|
4488
|
-
const raw =
|
|
4588
|
+
const raw = import_fs12.default.readFileSync(pkgPath, "utf-8");
|
|
4489
4589
|
const pkg = JSON.parse(raw);
|
|
4490
4590
|
return typeof pkg.version === "string" ? pkg.version : "0.0.0";
|
|
4491
4591
|
} catch {
|