@cencori/scan 0.4.3 → 0.4.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/cli.js CHANGED
@@ -906,24 +906,6 @@ Generate a secure fix.`
906
906
  }
907
907
  return results;
908
908
  }
909
- async function applyFixes(fixes, fileContents) {
910
- for (const fix of fixes) {
911
- if (fix.fixedCode === fix.originalCode) {
912
- continue;
913
- }
914
- const content = fileContents.get(fix.issue.file);
915
- if (!content) {
916
- continue;
917
- }
918
- const newContent = content.replace(fix.originalCode, fix.fixedCode);
919
- if (newContent !== content) {
920
- const filePath = path2.resolve(fix.issue.file);
921
- fs2.writeFileSync(filePath, newContent, "utf-8");
922
- fix.applied = true;
923
- }
924
- }
925
- return fixes;
926
- }
927
909
 
928
910
  // src/telemetry.ts
929
911
  var TELEMETRY_URL = "https://api.cencori.com/v1/telemetry/scan";
@@ -1176,7 +1158,7 @@ No commits found in the specified period.
1176
1158
  // src/cli.ts
1177
1159
  var fs3 = __toESM(require("fs"));
1178
1160
  var path3 = __toESM(require("path"));
1179
- var VERSION = "0.4.2";
1161
+ var VERSION = "0.4.5";
1180
1162
  var scoreStyles = {
1181
1163
  A: { color: import_chalk.default.green },
1182
1164
  B: { color: import_chalk.default.blue },
@@ -1411,23 +1393,135 @@ async function handleAutoFix(result, targetPath) {
1411
1393
  fileContents
1412
1394
  );
1413
1395
  fixSpinner.succeed(`Generated ${fixes.length} fixes`);
1414
- const applySpinner = (0, import_ora.default)({
1415
- text: "Applying fixes...",
1416
- color: "cyan"
1417
- }).start();
1418
- const appliedFixes = await applyFixes(fixes, fileContents);
1419
- const appliedCount = appliedFixes.filter((f) => f.applied).length;
1420
- applySpinner.succeed(`Applied ${appliedCount}/${fixes.length} fixes`);
1421
1396
  console.log();
1422
- console.log(` ${import_chalk.default.bold("Applied fixes:")}`);
1423
- for (const fix of appliedFixes.filter((f) => f.applied)) {
1424
- console.log(import_chalk.default.green(` \u2714 ${fix.issue.file}:${fix.issue.line}`));
1425
- console.log(import_chalk.default.gray(` ${fix.explanation}`));
1397
+ const acceptedFixes = [];
1398
+ const skippedFixes = [];
1399
+ let applyAll = false;
1400
+ let skipRest = false;
1401
+ for (let i = 0; i < fixes.length; i++) {
1402
+ const fix = fixes[i];
1403
+ if (skipRest) {
1404
+ skippedFixes.push(fix);
1405
+ continue;
1406
+ }
1407
+ if (applyAll) {
1408
+ acceptedFixes.push(fix);
1409
+ continue;
1410
+ }
1411
+ console.log(import_chalk.default.cyan(` \u2500\u2500\u2500 Fix ${i + 1}/${fixes.length}: ${fix.issue.file}:${fix.issue.line} \u2500\u2500\u2500`));
1412
+ console.log(import_chalk.default.gray(` Issue: ${fix.issue.name} (${fix.issue.severity})`));
1413
+ console.log();
1414
+ const origLines = fix.originalCode.split("\n");
1415
+ console.log(import_chalk.default.red(" - Original:"));
1416
+ origLines.slice(0, 8).forEach((line) => console.log(import_chalk.default.red(` ${line}`)));
1417
+ if (origLines.length > 8) {
1418
+ console.log(import_chalk.default.gray(` ... (${origLines.length - 8} more lines)`));
1419
+ }
1420
+ console.log();
1421
+ const fixLines = fix.fixedCode.split("\n");
1422
+ console.log(import_chalk.default.green(" + Suggested fix:"));
1423
+ fixLines.slice(0, 8).forEach((line) => console.log(import_chalk.default.green(` ${line}`)));
1424
+ if (fixLines.length > 8) {
1425
+ console.log(import_chalk.default.gray(` ... (${fixLines.length - 8} more lines)`));
1426
+ }
1427
+ console.log();
1428
+ console.log(import_chalk.default.gray(` Explanation: ${fix.explanation}`));
1429
+ console.log();
1430
+ const action = await (0, import_prompts.select)({
1431
+ message: "Apply this fix?",
1432
+ choices: [
1433
+ { name: "Yes - apply this fix", value: "y" },
1434
+ { name: "No - skip this fix", value: "n" },
1435
+ { name: "All - apply all remaining fixes", value: "a" },
1436
+ { name: "Skip rest - save remaining to file", value: "s" },
1437
+ { name: "Quit - stop reviewing", value: "q" }
1438
+ ]
1439
+ });
1440
+ if (action === "y") {
1441
+ acceptedFixes.push(fix);
1442
+ console.log(import_chalk.default.green(" \u2714 Fix accepted"));
1443
+ } else if (action === "n") {
1444
+ skippedFixes.push(fix);
1445
+ console.log(import_chalk.default.yellow(" \u2298 Fix skipped"));
1446
+ } else if (action === "a") {
1447
+ applyAll = true;
1448
+ acceptedFixes.push(fix);
1449
+ for (let j = i + 1; j < fixes.length; j++) {
1450
+ acceptedFixes.push(fixes[j]);
1451
+ }
1452
+ console.log(import_chalk.default.green(` \u2714 Applying all ${fixes.length - i} remaining fixes`));
1453
+ break;
1454
+ } else if (action === "s") {
1455
+ skipRest = true;
1456
+ skippedFixes.push(fix);
1457
+ for (let j = i + 1; j < fixes.length; j++) {
1458
+ skippedFixes.push(fixes[j]);
1459
+ }
1460
+ console.log(import_chalk.default.yellow(` \u2298 Skipping ${fixes.length - i} remaining fixes`));
1461
+ break;
1462
+ } else if (action === "q") {
1463
+ skippedFixes.push(fix);
1464
+ for (let j = i + 1; j < fixes.length; j++) {
1465
+ skippedFixes.push(fixes[j]);
1466
+ }
1467
+ console.log(import_chalk.default.gray(" Stopped reviewing"));
1468
+ break;
1469
+ }
1470
+ console.log();
1471
+ }
1472
+ if (acceptedFixes.length > 0) {
1473
+ console.log();
1474
+ const applySpinner = (0, import_ora.default)({
1475
+ text: `Applying ${acceptedFixes.length} fixes...`,
1476
+ color: "cyan"
1477
+ }).start();
1478
+ let appliedCount = 0;
1479
+ for (const fix of acceptedFixes) {
1480
+ const content = fileContents.get(fix.issue.file);
1481
+ if (!content) continue;
1482
+ const newContent = content.replace(fix.originalCode, fix.fixedCode);
1483
+ if (newContent !== content) {
1484
+ const filePath = path3.resolve(targetPath, fix.issue.file);
1485
+ fs3.writeFileSync(filePath, newContent, "utf-8");
1486
+ fileContents.set(fix.issue.file, newContent);
1487
+ appliedCount++;
1488
+ }
1489
+ }
1490
+ applySpinner.succeed(`Applied ${appliedCount}/${acceptedFixes.length} fixes to your codebase`);
1491
+ }
1492
+ if (skippedFixes.length > 0) {
1493
+ const fixesFile = ".cencori-fixes.json";
1494
+ const fixesData = {
1495
+ generated_at: (/* @__PURE__ */ new Date()).toISOString(),
1496
+ total_fixes: skippedFixes.length,
1497
+ fixes: skippedFixes.map((f) => ({
1498
+ file: f.issue.file,
1499
+ line: f.issue.line,
1500
+ issue_type: f.issue.type,
1501
+ issue_name: f.issue.name,
1502
+ severity: f.issue.severity,
1503
+ original_code: f.originalCode,
1504
+ suggested_fix: f.fixedCode,
1505
+ explanation: f.explanation
1506
+ }))
1507
+ };
1508
+ fs3.writeFileSync(fixesFile, JSON.stringify(fixesData, null, 2));
1509
+ console.log();
1510
+ console.log(import_chalk.default.yellow(` ${skippedFixes.length} skipped fixes saved to ${import_chalk.default.bold(fixesFile)}`));
1511
+ }
1512
+ console.log();
1513
+ console.log(import_chalk.default.gray(" \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\u2500\u2500\u2500\u2500"));
1514
+ console.log();
1515
+ console.log(` ${import_chalk.default.bold("Summary:")}`);
1516
+ if (acceptedFixes.length > 0) {
1517
+ console.log(import_chalk.default.green(` \u2714 ${acceptedFixes.length} fixes applied`));
1518
+ }
1519
+ if (skippedFixes.length > 0) {
1520
+ console.log(import_chalk.default.yellow(` \u2298 ${skippedFixes.length} fixes skipped (saved to .cencori-fixes.json)`));
1426
1521
  }
1427
- const notApplied = appliedFixes.filter((f) => !f.applied);
1428
- if (notApplied.length > 0) {
1522
+ if (acceptedFixes.length > 0) {
1429
1523
  console.log();
1430
- console.log(` ${import_chalk.default.yellow(`${notApplied.length} issues require manual review`)}`);
1524
+ console.log(import_chalk.default.cyan(` Run ${import_chalk.default.bold("npx @cencori/scan")} again to verify your fixes!`));
1431
1525
  }
1432
1526
  console.log();
1433
1527
  } catch (error) {