@nikhil_telkar/codeshield 0.0.0-stage → 0.1.1

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.
Files changed (103) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +239 -2
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +237 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/engine/fileWalker.d.ts +15 -0
  8. package/dist/engine/fileWalker.d.ts.map +1 -0
  9. package/dist/engine/fileWalker.js +170 -0
  10. package/dist/engine/fileWalker.js.map +1 -0
  11. package/dist/engine/index.d.ts +4 -0
  12. package/dist/engine/index.d.ts.map +1 -0
  13. package/dist/engine/index.js +4 -0
  14. package/dist/engine/index.js.map +1 -0
  15. package/dist/engine/projectDetector.d.ts +10 -0
  16. package/dist/engine/projectDetector.d.ts.map +1 -0
  17. package/dist/engine/projectDetector.js +44 -0
  18. package/dist/engine/projectDetector.js.map +1 -0
  19. package/dist/engine/runner.d.ts +8 -0
  20. package/dist/engine/runner.d.ts.map +1 -0
  21. package/dist/engine/runner.js +87 -0
  22. package/dist/engine/runner.js.map +1 -0
  23. package/dist/fix/fixer.d.ts +17 -0
  24. package/dist/fix/fixer.d.ts.map +1 -0
  25. package/dist/fix/fixer.js +190 -0
  26. package/dist/fix/fixer.js.map +1 -0
  27. package/dist/fix/history.d.ts +23 -0
  28. package/dist/fix/history.d.ts.map +1 -0
  29. package/dist/fix/history.js +107 -0
  30. package/dist/fix/history.js.map +1 -0
  31. package/dist/fix/index.d.ts +3 -0
  32. package/dist/fix/index.d.ts.map +1 -0
  33. package/dist/fix/index.js +3 -0
  34. package/dist/fix/index.js.map +1 -0
  35. package/dist/index.d.ts +8 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +8 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/report/colors.d.ts +21 -0
  40. package/dist/report/colors.d.ts.map +1 -0
  41. package/dist/report/colors.js +70 -0
  42. package/dist/report/colors.js.map +1 -0
  43. package/dist/report/index.d.ts +15 -0
  44. package/dist/report/index.d.ts.map +1 -0
  45. package/dist/report/index.js +39 -0
  46. package/dist/report/index.js.map +1 -0
  47. package/dist/report/sarif.d.ts +44 -0
  48. package/dist/report/sarif.d.ts.map +1 -0
  49. package/dist/report/sarif.js +69 -0
  50. package/dist/report/sarif.js.map +1 -0
  51. package/dist/report/score.d.ts +14 -0
  52. package/dist/report/score.d.ts.map +1 -0
  53. package/dist/report/score.js +62 -0
  54. package/dist/report/score.js.map +1 -0
  55. package/dist/report/terminal.d.ts +10 -0
  56. package/dist/report/terminal.d.ts.map +1 -0
  57. package/dist/report/terminal.js +77 -0
  58. package/dist/report/terminal.js.map +1 -0
  59. package/dist/scanners/code.d.ts +22 -0
  60. package/dist/scanners/code.d.ts.map +1 -0
  61. package/dist/scanners/code.js +319 -0
  62. package/dist/scanners/code.js.map +1 -0
  63. package/dist/scanners/dependencies.d.ts +10 -0
  64. package/dist/scanners/dependencies.d.ts.map +1 -0
  65. package/dist/scanners/dependencies.js +240 -0
  66. package/dist/scanners/dependencies.js.map +1 -0
  67. package/dist/scanners/env.d.ts +7 -0
  68. package/dist/scanners/env.d.ts.map +1 -0
  69. package/dist/scanners/env.js +195 -0
  70. package/dist/scanners/env.js.map +1 -0
  71. package/dist/scanners/helper.d.ts +27 -0
  72. package/dist/scanners/helper.d.ts.map +1 -0
  73. package/dist/scanners/helper.js +50 -0
  74. package/dist/scanners/helper.js.map +1 -0
  75. package/dist/scanners/index.d.ts +6 -0
  76. package/dist/scanners/index.d.ts.map +1 -0
  77. package/dist/scanners/index.js +6 -0
  78. package/dist/scanners/index.js.map +1 -0
  79. package/dist/scanners/secrets.d.ts +19 -0
  80. package/dist/scanners/secrets.d.ts.map +1 -0
  81. package/dist/scanners/secrets.js +213 -0
  82. package/dist/scanners/secrets.js.map +1 -0
  83. package/dist/types.d.ts +43 -0
  84. package/dist/types.d.ts.map +1 -0
  85. package/dist/types.js +2 -0
  86. package/dist/types.js.map +1 -0
  87. package/dist/utils/constants.d.ts +9 -0
  88. package/dist/utils/constants.d.ts.map +1 -0
  89. package/dist/utils/constants.js +54 -0
  90. package/dist/utils/constants.js.map +1 -0
  91. package/dist/utils/levenshtein.d.ts +2 -0
  92. package/dist/utils/levenshtein.d.ts.map +1 -0
  93. package/dist/utils/levenshtein.js +35 -0
  94. package/dist/utils/levenshtein.js.map +1 -0
  95. package/dist/utils/registry.d.ts +18 -0
  96. package/dist/utils/registry.d.ts.map +1 -0
  97. package/dist/utils/registry.js +106 -0
  98. package/dist/utils/registry.js.map +1 -0
  99. package/dist/utils/sanitize.d.ts +3 -0
  100. package/dist/utils/sanitize.d.ts.map +1 -0
  101. package/dist/utils/sanitize.js +10 -0
  102. package/dist/utils/sanitize.js.map +1 -0
  103. package/package.json +59 -4
@@ -0,0 +1,107 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ export function getFindingFingerprint(f) {
4
+ return `${f.ruleId}:${f.file}:${f.line}`;
5
+ }
6
+ const HISTORY_DIR = '.codeshield';
7
+ const HISTORY_FILE = 'last-scan.json';
8
+ export function getHistoryFilePath(root) {
9
+ return path.join(path.resolve(root), HISTORY_DIR, HISTORY_FILE);
10
+ }
11
+ export function readLastScan(root) {
12
+ try {
13
+ const filePath = getHistoryFilePath(root);
14
+ if (!fs.existsSync(filePath))
15
+ return null;
16
+ const content = fs.readFileSync(filePath, 'utf8');
17
+ const parsed = JSON.parse(content);
18
+ if (typeof parsed.score === 'number' && Array.isArray(parsed.findingFingerprints)) {
19
+ return parsed;
20
+ }
21
+ return null;
22
+ }
23
+ catch {
24
+ return null;
25
+ }
26
+ }
27
+ export function saveLastScan(root, score, grade, findings) {
28
+ try {
29
+ const dirPath = path.join(path.resolve(root), HISTORY_DIR);
30
+ if (!fs.existsSync(dirPath)) {
31
+ fs.mkdirSync(dirPath, { recursive: true });
32
+ }
33
+ const snapshot = {
34
+ timestamp: Date.now(),
35
+ score,
36
+ grade,
37
+ findingsCount: findings.length,
38
+ findingFingerprints: findings.map(getFindingFingerprint),
39
+ };
40
+ const filePath = path.join(dirPath, HISTORY_FILE);
41
+ fs.writeFileSync(filePath, JSON.stringify(snapshot, null, 2), 'utf8');
42
+ ensureCodeshieldInGitignore(root);
43
+ }
44
+ catch {
45
+ // fail silently — history recording should never crash the scan
46
+ }
47
+ }
48
+ export function ensureCodeshieldInGitignore(root) {
49
+ try {
50
+ const gitignorePath = path.join(path.resolve(root), '.gitignore');
51
+ if (!fs.existsSync(gitignorePath))
52
+ return;
53
+ const content = fs.readFileSync(gitignorePath, 'utf8');
54
+ if (content.includes('.codeshield'))
55
+ return;
56
+ const addition = content.endsWith('\n') || content.length === 0
57
+ ? '.codeshield/\n'
58
+ : '\n.codeshield/\n';
59
+ fs.appendFileSync(gitignorePath, addition, 'utf8');
60
+ }
61
+ catch {
62
+ // fail silently
63
+ }
64
+ }
65
+ export function compareWithLastScan(previous, currentScore, currentFindings) {
66
+ const currentFingerprints = new Set(currentFindings.map(getFindingFingerprint));
67
+ const previousFingerprints = new Set(previous.findingFingerprints);
68
+ let fixedCount = 0;
69
+ for (const fp of previousFingerprints) {
70
+ if (!currentFingerprints.has(fp)) {
71
+ fixedCount++;
72
+ }
73
+ }
74
+ let newCount = 0;
75
+ for (const fp of currentFingerprints) {
76
+ if (!previousFingerprints.has(fp)) {
77
+ newCount++;
78
+ }
79
+ }
80
+ const scoreDiff = currentScore - previous.score;
81
+ let summaryText = '';
82
+ const fixedLabel = `${fixedCount} issue${fixedCount === 1 ? '' : 's'} fixed`;
83
+ const newLabel = `${newCount} new issue${newCount === 1 ? '' : 's'}`;
84
+ if (scoreDiff > 0) {
85
+ summaryText = `Score improved ${previous.score} -> ${currentScore}, ${fixedLabel}${newCount > 0 ? `, ${newLabel}` : ''}.`;
86
+ }
87
+ else if (scoreDiff < 0) {
88
+ summaryText = `Score dropped ${previous.score} -> ${currentScore}, ${newLabel}${fixedCount > 0 ? `, ${fixedLabel}` : ''}.`;
89
+ }
90
+ else {
91
+ if (fixedCount > 0 || newCount > 0) {
92
+ summaryText = `Score unchanged at ${currentScore}, ${fixedLabel}, ${newLabel}.`;
93
+ }
94
+ else {
95
+ summaryText = `Score unchanged at ${currentScore}.`;
96
+ }
97
+ }
98
+ return {
99
+ previousScore: previous.score,
100
+ currentScore,
101
+ scoreDiff,
102
+ fixedCount,
103
+ newCount,
104
+ summaryText,
105
+ };
106
+ }
107
+ //# sourceMappingURL=history.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/fix/history.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAoBlC,MAAM,UAAU,qBAAqB,CAAC,CAAU;IAC9C,OAAO,GAAG,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;AAC3C,CAAC;AAED,MAAM,WAAW,GAAG,aAAa,CAAC;AAClC,MAAM,YAAY,GAAG,gBAAgB,CAAC;AAEtC,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;YAAE,OAAO,IAAI,CAAC;QAC1C,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAClD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAiB,CAAC;QACnD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1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fix/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './fixer.js';
2
+ export * from './history.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/fix/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,8 @@
1
+ export * from './types.js';
2
+ export * from './utils/constants.js';
3
+ export * from './utils/sanitize.js';
4
+ export * from './engine/index.js';
5
+ export * from './report/index.js';
6
+ export * from './scanners/index.js';
7
+ export * from './fix/index.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export * from './types.js';
2
+ export * from './utils/constants.js';
3
+ export * from './utils/sanitize.js';
4
+ export * from './engine/index.js';
5
+ export * from './report/index.js';
6
+ export * from './scanners/index.js';
7
+ export * from './fix/index.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { Severity } from '../types.js';
2
+ export interface ColorOptions {
3
+ enabled?: boolean;
4
+ }
5
+ export declare function areColorsEnabled(options?: ColorOptions): boolean;
6
+ export declare class Colorizer {
7
+ private readonly enabled;
8
+ constructor(options?: ColorOptions);
9
+ private style;
10
+ bold(text: string): string;
11
+ dim(text: string): string;
12
+ red(text: string): string;
13
+ green(text: string): string;
14
+ yellow(text: string): string;
15
+ cyan(text: string): string;
16
+ blue(text: string): string;
17
+ magenta(text: string): string;
18
+ severityBadge(sev: Severity): string;
19
+ scoreBadge(score: number, grade: string): string;
20
+ }
21
+ //# sourceMappingURL=colors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../src/report/colors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAQhE;AAED,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;gBAEtB,OAAO,CAAC,EAAE,YAAY;IAIlC,OAAO,CAAC,KAAK;IAIb,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI1B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIzB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIzB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI3B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI5B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI1B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI1B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI7B,aAAa,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM;IAepC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;CAQjD"}
@@ -0,0 +1,70 @@
1
+ import { styleText } from 'node:util';
2
+ export function areColorsEnabled(options) {
3
+ if (options?.enabled !== undefined) {
4
+ return options.enabled;
5
+ }
6
+ if (process.env['NO_COLOR'] !== undefined && process.env['NO_COLOR'] !== '') {
7
+ return false;
8
+ }
9
+ return Boolean(process.stdout && process.stdout.isTTY);
10
+ }
11
+ export class Colorizer {
12
+ enabled;
13
+ constructor(options) {
14
+ this.enabled = areColorsEnabled(options);
15
+ }
16
+ style(format, text) {
17
+ return this.enabled ? styleText(format, text, { validateStream: false }) : text;
18
+ }
19
+ bold(text) {
20
+ return this.style('bold', text);
21
+ }
22
+ dim(text) {
23
+ return this.style('dim', text);
24
+ }
25
+ red(text) {
26
+ return this.style('red', text);
27
+ }
28
+ green(text) {
29
+ return this.style('green', text);
30
+ }
31
+ yellow(text) {
32
+ return this.style('yellow', text);
33
+ }
34
+ cyan(text) {
35
+ return this.style('cyan', text);
36
+ }
37
+ blue(text) {
38
+ return this.style('blue', text);
39
+ }
40
+ magenta(text) {
41
+ return this.style('magenta', text);
42
+ }
43
+ severityBadge(sev) {
44
+ switch (sev) {
45
+ case 'critical':
46
+ return this.bold(this.red('🔴 CRITICAL'));
47
+ case 'high':
48
+ return this.bold(this.yellow('🟠 HIGH'));
49
+ case 'medium':
50
+ return this.yellow('🟡 MEDIUM');
51
+ case 'low':
52
+ return this.blue('🔵 LOW');
53
+ case 'info':
54
+ return this.dim('⚪ INFO');
55
+ }
56
+ }
57
+ scoreBadge(score, grade) {
58
+ const label = `${score}/100 [Grade ${grade}]`;
59
+ if (score >= 90)
60
+ return this.bold(this.green(label));
61
+ if (score >= 75)
62
+ return this.bold(this.cyan(label));
63
+ if (score >= 60)
64
+ return this.bold(this.yellow(label));
65
+ if (score >= 40)
66
+ return this.bold(this.red(label));
67
+ return this.bold(this.red(`⚠️ ${label}`));
68
+ }
69
+ }
70
+ //# sourceMappingURL=colors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colors.js","sourceRoot":"","sources":["../../src/report/colors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAOtC,MAAM,UAAU,gBAAgB,CAAC,OAAsB;IACrD,IAAI,OAAO,EAAE,OAAO,KAAK,SAAS,EAAE,CAAC;QACnC,OAAO,OAAO,CAAC,OAAO,CAAC;IACzB,CAAC;IACD,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,CAAC;QAC5E,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,OAAO,SAAS;IACH,OAAO,CAAU;IAElC,YAAY,OAAsB;QAChC,IAAI,CAAC,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IAEO,KAAK,CAAC,MAAuC,EAAE,IAAY;QACjE,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAClF,CAAC;IAED,IAAI,CAAC,IAAY;QACf,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IAED,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CA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AAC;QACrD,IAAI,KAAK,IAAI,EAAE;YAAE,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QACpD,IAAI,KAAK,IAAI,EAAE;YAAE,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACtD,IAAI,KAAK,IAAI,EAAE;YAAE,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;QACnD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC;IAC7C,CAAC;CACF"}
@@ -0,0 +1,15 @@
1
+ import { ScanResult } from '../types.js';
2
+ import { ScoreDetails } from './score.js';
3
+ import { TerminalReportOptions } from './terminal.js';
4
+ export * from './score.js';
5
+ export * from './colors.js';
6
+ export * from './terminal.js';
7
+ export * from './sarif.js';
8
+ export type ReportMode = 'simple' | 'detailed' | 'json' | 'sarif';
9
+ export interface ReportOptions extends TerminalReportOptions {
10
+ mode?: ReportMode;
11
+ version?: string;
12
+ }
13
+ export declare function formatJsonReport(result: ScanResult, scoreDetails?: ScoreDetails): string;
14
+ export declare function renderReport(result: ScanResult, options?: ReportOptions): string;
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/report/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAkB,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAA4C,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAGhG,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAE3B,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC;AAElE,MAAM,WAAW,aAAc,SAAQ,qBAAqB;IAC1D,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,YAAY,CAAC,EAAE,YAAY,GAAG,MAAM,CAexF;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAepF"}
@@ -0,0 +1,39 @@
1
+ import { calculateScore } from './score.js';
2
+ import { formatSimpleReport, formatDetailedReport } from './terminal.js';
3
+ import { formatSarifReport } from './sarif.js';
4
+ export * from './score.js';
5
+ export * from './colors.js';
6
+ export * from './terminal.js';
7
+ export * from './sarif.js';
8
+ export function formatJsonReport(result, scoreDetails) {
9
+ const details = scoreDetails ?? calculateScore(result.findings);
10
+ const payload = {
11
+ score: details.score,
12
+ grade: details.grade,
13
+ gradeLabel: details.gradeLabel,
14
+ projectType: result.projectType,
15
+ filesScanned: result.filesScanned,
16
+ filesSkipped: result.filesSkipped,
17
+ truncated: result.truncated,
18
+ durationMs: result.durationMs,
19
+ summary: details.countsBySeverity,
20
+ findings: result.findings,
21
+ };
22
+ return JSON.stringify(payload, null, 2);
23
+ }
24
+ export function renderReport(result, options = {}) {
25
+ const mode = options.mode ?? 'simple';
26
+ const scoreDetails = calculateScore(result.findings);
27
+ switch (mode) {
28
+ case 'json':
29
+ return formatJsonReport(result, scoreDetails);
30
+ case 'sarif':
31
+ return formatSarifReport(result, options.version ?? '0.1.0');
32
+ case 'detailed':
33
+ return formatDetailedReport(result, scoreDetails, options);
34
+ case 'simple':
35
+ default:
36
+ return formatSimpleReport(result, scoreDetails, options);
37
+ }
38
+ }
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/report/index.ts"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BAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,CAAC;QAC/D,KAAK,UAAU;YACb,OAAO,oBAAoB,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;QAC7D,KAAK,QAAQ,CAAC;QACd;YACE,OAAO,kBAAkB,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { ScanResult } from '../types.js';
2
+ export interface SarifOutput {
3
+ $schema: string;
4
+ version: string;
5
+ runs: Array<{
6
+ tool: {
7
+ driver: {
8
+ name: string;
9
+ version: string;
10
+ informationUri: string;
11
+ rules: Array<{
12
+ id: string;
13
+ name: string;
14
+ shortDescription: {
15
+ text: string;
16
+ };
17
+ help: {
18
+ text: string;
19
+ };
20
+ properties?: Record<string, unknown>;
21
+ }>;
22
+ };
23
+ };
24
+ results: Array<{
25
+ ruleId: string;
26
+ level: 'error' | 'warning' | 'note' | 'none';
27
+ message: {
28
+ text: string;
29
+ };
30
+ locations: Array<{
31
+ physicalLocation: {
32
+ artifactLocation: {
33
+ uri: string;
34
+ };
35
+ region: {
36
+ startLine: number;
37
+ };
38
+ };
39
+ }>;
40
+ }>;
41
+ }>;
42
+ }
43
+ export declare function formatSarifReport(result: ScanResult, version?: string): string;
44
+ //# sourceMappingURL=sarif.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sarif.d.ts","sourceRoot":"","sources":["../../src/report/sarif.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,UAAU,EAAY,MAAM,aAAa,CAAC;AAG5D,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,KAAK,CAAC;QACV,IAAI,EAAE;YACJ,MAAM,EAAE;gBACN,IAAI,EAAE,MAAM,CAAC;gBACb,OAAO,EAAE,MAAM,CAAC;gBAChB,cAAc,EAAE,MAAM,CAAC;gBACvB,KAAK,EAAE,KAAK,CAAC;oBACX,EAAE,EAAE,MAAM,CAAC;oBACX,IAAI,EAAE,MAAM,CAAC;oBACb,gBAAgB,EAAE;wBAAE,IAAI,EAAE,MAAM,CAAA;qBAAE,CAAC;oBACnC,IAAI,EAAE;wBAAE,IAAI,EAAE,MAAM,CAAA;qBAAE,CAAC;oBACvB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;iBACtC,CAAC,CAAC;aACJ,CAAC;SACH,CAAC;QACF,OAAO,EAAE,KAAK,CAAC;YACb,MAAM,EAAE,MAAM,CAAC;YACf,KAAK,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;YAC7C,OAAO,EAAE;gBAAE,IAAI,EAAE,MAAM,CAAA;aAAE,CAAC;YAC1B,SAAS,EAAE,KAAK,CAAC;gBACf,gBAAgB,EAAE;oBAChB,gBAAgB,EAAE;wBAAE,GAAG,EAAE,MAAM,CAAA;qBAAE,CAAC;oBAClC,MAAM,EAAE;wBAAE,SAAS,EAAE,MAAM,CAAA;qBAAE,CAAC;iBAC/B,CAAC;aACH,CAAC,CAAC;SACJ,CAAC,CAAC;KACJ,CAAC,CAAC;CACJ;AAgBD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,SAAU,GAAG,MAAM,CA0D/E"}
@@ -0,0 +1,69 @@
1
+ import { sanitize } from '../utils/sanitize.js';
2
+ function severityToSarifLevel(sev) {
3
+ switch (sev) {
4
+ case 'critical':
5
+ case 'high':
6
+ return 'error';
7
+ case 'medium':
8
+ return 'warning';
9
+ case 'low':
10
+ return 'note';
11
+ case 'info':
12
+ return 'none';
13
+ }
14
+ }
15
+ export function formatSarifReport(result, version = '0.1.0') {
16
+ const rulesMap = new Map();
17
+ for (const f of result.findings) {
18
+ if (!rulesMap.has(f.ruleId)) {
19
+ rulesMap.set(f.ruleId, {
20
+ id: f.ruleId,
21
+ name: sanitize(f.title),
22
+ description: sanitize(f.plainExplanation),
23
+ fix: sanitize(f.fix),
24
+ ...(f.cwe ? { cwe: f.cwe } : {}),
25
+ });
26
+ }
27
+ }
28
+ const sarifRules = Array.from(rulesMap.values()).map(r => ({
29
+ id: r.id,
30
+ name: r.name,
31
+ shortDescription: { text: r.name },
32
+ help: { text: `${r.description}\n\nFix: ${r.fix}` },
33
+ properties: {
34
+ tags: ['security', ...(r.cwe ? [r.cwe] : [])],
35
+ },
36
+ }));
37
+ const sarifResults = result.findings.map(f => ({
38
+ ruleId: f.ruleId,
39
+ level: severityToSarifLevel(f.severity),
40
+ message: { text: `${sanitize(f.title)}: ${sanitize(f.plainExplanation)}` },
41
+ locations: [
42
+ {
43
+ physicalLocation: {
44
+ artifactLocation: { uri: f.file },
45
+ region: { startLine: Math.max(1, f.line) },
46
+ },
47
+ },
48
+ ],
49
+ }));
50
+ const sarif = {
51
+ $schema: 'https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json',
52
+ version: '2.1.0',
53
+ runs: [
54
+ {
55
+ tool: {
56
+ driver: {
57
+ name: 'CodeShield',
58
+ version,
59
+ informationUri: 'https://github.com/nikhiltelkar2005-glitch/codeshield_npm_package',
60
+ rules: sarifRules,
61
+ },
62
+ },
63
+ results: sarifResults,
64
+ },
65
+ ],
66
+ };
67
+ return JSON.stringify(sarif, null, 2);
68
+ }
69
+ //# sourceMappingURL=sarif.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sarif.js","sourceRoot":"","sources":["../../src/report/sarif.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAkChD,SAAS,oBAAoB,CAAC,GAAa;IACzC,QAAQ,GAAG,EAAE,CAAC;QACZ,KAAK,UAAU,CAAC;QAChB,KAAK,MAAM;YACT,OAAO,OAAO,CAAC;QACjB,KAAK,QAAQ;YACX,OAAO,SAAS,CAAC;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CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SAC9C;KACF,CAAC,CAAC,CAAC;IAEJ,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC7C,MAAM,EAAE,CAAC,CAAC,MAAM;QAChB,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC,QAAQ,CAAC;QACvC,OAAO,EAAE,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,EAAE,EAAE;QAC1E,SAAS,EAAE;YACT;gBACE,gBAAgB,EAAE;oBAChB,gBAAgB,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE;oBACjC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE;iBAC3C;aACF;SACF;KACF,CAAC,CAAC,CAAC;IAEJ,MAAM,KAAK,GAAgB;QACzB,OAAO,EAAE,gGAAgG;QACzG,OAAO,EAAE,OAAO;QAChB,IAAI,EAAE;YACJ;gBACE,IAAI,EAAE;oBACJ,MAAM,EAAE;wBACN,IAAI,EAAE,YAAY;wBAClB,OAAO;wBACP,cAAc,EAAE,mEAAmE;wBACnF,KAAK,EAAE,UAAU;qBAClB;iBACF;gBACD,OAAO,EAAE,YAAY;aACtB;SACF;KACF,CAAC;IAEF,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { Finding, Severity } from '../types.js';
2
+ export declare const SEVERITY_WEIGHTS: Record<Severity, number>;
3
+ export declare const MAX_DEDUCTION_PER_RULE = 35;
4
+ export type LetterGrade = 'A' | 'B' | 'C' | 'D' | 'F';
5
+ export interface ScoreDetails {
6
+ score: number;
7
+ grade: LetterGrade;
8
+ gradeLabel: string;
9
+ totalFindings: number;
10
+ deductionsByRule: Record<string, number>;
11
+ countsBySeverity: Record<Severity, number>;
12
+ }
13
+ export declare function calculateScore(findings: readonly Finding[]): ScoreDetails;
14
+ //# sourceMappingURL=score.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"score.d.ts","sourceRoot":"","sources":["../../src/report/score.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEhD,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAMrD,CAAC;AAEF,eAAO,MAAM,sBAAsB,KAAK,CAAC;AAEzC,MAAM,MAAM,WAAW,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAEtD,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,WAAW,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,gBAAgB,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;CAC5C;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,GAAG,YAAY,CAsDzE"}
@@ -0,0 +1,62 @@
1
+ export const SEVERITY_WEIGHTS = {
2
+ critical: 25,
3
+ high: 15,
4
+ medium: 8,
5
+ low: 3,
6
+ info: 0,
7
+ };
8
+ export const MAX_DEDUCTION_PER_RULE = 35;
9
+ export function calculateScore(findings) {
10
+ const deductionsByRule = {};
11
+ const countsBySeverity = {
12
+ critical: 0,
13
+ high: 0,
14
+ medium: 0,
15
+ low: 0,
16
+ info: 0,
17
+ };
18
+ for (const f of findings) {
19
+ countsBySeverity[f.severity] = (countsBySeverity[f.severity] ?? 0) + 1;
20
+ const penalty = SEVERITY_WEIGHTS[f.severity] ?? 0;
21
+ deductionsByRule[f.ruleId] = (deductionsByRule[f.ruleId] ?? 0) + penalty;
22
+ }
23
+ let totalDeductions = 0;
24
+ for (const ruleId of Object.keys(deductionsByRule)) {
25
+ const rawPenalty = deductionsByRule[ruleId] ?? 0;
26
+ const cappedPenalty = Math.min(rawPenalty, MAX_DEDUCTION_PER_RULE);
27
+ deductionsByRule[ruleId] = cappedPenalty;
28
+ totalDeductions += cappedPenalty;
29
+ }
30
+ const score = Math.max(0, Math.min(100, Math.round(100 - totalDeductions)));
31
+ let grade;
32
+ let gradeLabel;
33
+ if (score >= 90) {
34
+ grade = 'A';
35
+ gradeLabel = 'Excellent';
36
+ }
37
+ else if (score >= 75) {
38
+ grade = 'B';
39
+ gradeLabel = 'Good';
40
+ }
41
+ else if (score >= 60) {
42
+ grade = 'C';
43
+ gradeLabel = 'Needs Improvement';
44
+ }
45
+ else if (score >= 40) {
46
+ grade = 'D';
47
+ gradeLabel = 'Poor';
48
+ }
49
+ else {
50
+ grade = 'F';
51
+ gradeLabel = 'Critical Attention Required';
52
+ }
53
+ return {
54
+ score,
55
+ grade,
56
+ gradeLabel,
57
+ totalFindings: findings.length,
58
+ deductionsByRule,
59
+ countsBySeverity,
60
+ };
61
+ }
62
+ //# sourceMappingURL=score.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"score.js","sourceRoot":"","sources":["../../src/report/score.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gBAAgB,GAA6B;IACxD,QAAQ,EAAE,EAAE;IACZ,IAAI,EAAE,EAAE;IACR,MAAM,EAAE,CAAC;IACT,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC;CACR,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAazC,MAAM,UAAU,cAAc,CAAC,QAA4B;IACzD,MAAM,gBA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QACZ,UAAU,GAAG,WAAW,CAAC;IAC3B,CAAC;SAAM,IAAI,KAAK,IAAI,EAAE,EAAE,CAAC;QACvB,KAAK,GAAG,GAAG,CAAC;QACZ,UAAU,GAAG,MAAM,CAAC;IACtB,CAAC;SAAM,IAAI,KAAK,IAAI,EAAE,EAAE,CAAC;QACvB,KAAK,GAAG,GAAG,CAAC;QACZ,UAAU,GAAG,mBAAmB,CAAC;IACnC,CAAC;SAAM,IAAI,KAAK,IAAI,EAAE,EAAE,CAAC;QACvB,KAAK,GAAG,GAAG,CAAC;QACZ,UAAU,GAAG,MAAM,CAAC;IACtB,CAAC;SAAM,CAAC;QACN,KAAK,GAAG,GAAG,CAAC;QACZ,UAAU,GAAG,6BAA6B,CAAC;IAC7C,CAAC;IAED,OAAO;QACL,KAAK;QACL,KAAK;QACL,UAAU;QACV,aAAa,EAAE,QAAQ,CAAC,MAAM;QAC9B,gBAAgB;QAChB,gBAAgB;KACjB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { ScanResult } from '../types.js';
2
+ import { ColorOptions } from './colors.js';
3
+ import { ScoreDetails } from './score.js';
4
+ export interface TerminalReportOptions extends ColorOptions {
5
+ detailed?: boolean;
6
+ historyText?: string;
7
+ }
8
+ export declare function formatSimpleReport(result: ScanResult, scoreDetails: ScoreDetails, options?: TerminalReportOptions): string;
9
+ export declare function formatDetailedReport(result: ScanResult, scoreDetails: ScoreDetails, options?: TerminalReportOptions): string;
10
+ //# sourceMappingURL=terminal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"terminal.d.ts","sourceRoot":"","sources":["../../src/report/terminal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,UAAU,EAAY,MAAM,aAAa,CAAC;AAG5D,OAAO,EAAa,YAAY,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,WAAW,qBAAsB,SAAQ,YAAY;IACzD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AA4DD,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,UAAU,EAClB,YAAY,EAAE,YAAY,EAC1B,OAAO,CAAC,EAAE,qBAAqB,GAC9B,MAAM,CA6BR;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,UAAU,EAClB,YAAY,EAAE,YAAY,EAC1B,OAAO,CAAC,EAAE,qBAAqB,GAC9B,MAAM,CAmBR"}
@@ -0,0 +1,77 @@
1
+ import { SEVERITIES } from '../utils/constants.js';
2
+ import { sanitize } from '../utils/sanitize.js';
3
+ import { Colorizer } from './colors.js';
4
+ function formatSummaryLine(result, scoreDetails, c, options) {
5
+ const parts = [];
6
+ for (const sev of SEVERITIES) {
7
+ const count = scoreDetails.countsBySeverity[sev] ?? 0;
8
+ if (count > 0) {
9
+ parts.push(`${count} ${sev}`);
10
+ }
11
+ }
12
+ const findingsText = parts.length > 0 ? parts.join(', ') : '0 findings';
13
+ const duration = `${result.durationMs}ms`;
14
+ const scanned = `${result.filesScanned} file${result.filesScanned === 1 ? '' : 's'}${result.truncated ? ' (truncated)' : ''}`;
15
+ const lines = [
16
+ `\n${c.dim('────────────────────────────────────────────────────────────')}`,
17
+ `${c.bold('Security Score')} : ${c.scoreBadge(scoreDetails.score, scoreDetails.grade)} (${scoreDetails.gradeLabel})`,
18
+ ];
19
+ if (options?.historyText) {
20
+ lines.push(`${c.bold('Progress ')} : ${c.cyan(options.historyText)}`);
21
+ }
22
+ lines.push(`${c.bold('Files Scanned ')} : ${scanned}`, `${c.bold('Findings ')} : ${scoreDetails.totalFindings} [${findingsText}]`, `${c.bold('Duration ')} : ${duration}`, c.dim('────────────────────────────────────────────────────────────'));
23
+ return lines.join('\n');
24
+ }
25
+ function formatFindingBlock(f, c, isDetailed = false) {
26
+ const lines = [
27
+ `\n${c.severityBadge(f.severity)} [${c.bold(f.ruleId)}] ${c.bold(sanitize(f.title))}`,
28
+ ` ${c.dim('File ')} : ${c.cyan(sanitize(f.file))}:${c.cyan(String(f.line))}`,
29
+ ];
30
+ if (f.snippet) {
31
+ lines.push(` ${c.dim('Line ')} : ${c.dim(sanitize(f.snippet))}`);
32
+ }
33
+ if (isDetailed && f.cwe) {
34
+ lines.push(` ${c.dim('CWE ')} : ${sanitize(f.cwe)}`);
35
+ }
36
+ lines.push(` ${c.dim('Issue ')} : ${sanitize(f.plainExplanation)}`);
37
+ lines.push(` ${c.dim('Fix ')} : ${c.green(sanitize(f.fix))}`);
38
+ lines.push(` ${c.dim('AI Prompt')} : ${c.bold(sanitize(f.aiPrompt))}`);
39
+ return lines.join('\n');
40
+ }
41
+ export function formatSimpleReport(result, scoreDetails, options) {
42
+ const c = new Colorizer(options);
43
+ const out = [];
44
+ out.push(formatSummaryLine(result, scoreDetails, c, options));
45
+ if (result.findings.length === 0) {
46
+ out.push(`\n${c.bold(c.green('✅ No security issues found. Codebase looks clean!'))}\n`);
47
+ return out.join('\n');
48
+ }
49
+ const topCount = Math.min(5, Math.max(3, Math.min(5, result.findings.length)));
50
+ const topFindings = result.findings.slice(0, topCount);
51
+ out.push(`\n${c.bold('🎯 Fix These First (Top Priorities):')}`);
52
+ for (const f of topFindings) {
53
+ out.push(formatFindingBlock(f, c, false));
54
+ }
55
+ if (result.findings.length > topCount) {
56
+ const remaining = result.findings.length - topCount;
57
+ out.push(`\n${c.dim(`... and ${remaining} more finding${remaining === 1 ? '' : 's'}. Run with --detailed to view all findings.`)}`);
58
+ }
59
+ out.push('');
60
+ return out.join('\n');
61
+ }
62
+ export function formatDetailedReport(result, scoreDetails, options) {
63
+ const c = new Colorizer(options);
64
+ const out = [];
65
+ out.push(formatSummaryLine(result, scoreDetails, c, options));
66
+ if (result.findings.length === 0) {
67
+ out.push(`\n${c.bold(c.green('✅ No security issues found. Codebase looks clean!'))}\n`);
68
+ return out.join('\n');
69
+ }
70
+ out.push(`\n${c.bold(`📋 All Findings (${result.findings.length}):`)}`);
71
+ for (const f of result.findings) {
72
+ out.push(formatFindingBlock(f, c, true));
73
+ }
74
+ out.push('');
75
+ return out.join('\n');
76
+ }
77
+ //# sourceMappingURL=terminal.js.map