@gulu9527/code-trust 0.2.1 → 0.3.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.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  type Severity = 'high' | 'medium' | 'low' | 'info';
2
2
  type RuleCategory = 'security' | 'logic' | 'structure' | 'style' | 'coverage';
3
3
  type TrustGrade = 'HIGH_TRUST' | 'REVIEW' | 'LOW_TRUST' | 'UNTRUSTED';
4
+ type ScanMode = 'staged' | 'diff' | 'files' | 'changed';
5
+ type ScanErrorType = 'rule-failure' | 'deleted-file' | 'unreadable-file' | 'missing-file-content' | 'unsupported-file-type';
4
6
  interface Issue {
5
7
  ruleId: string;
6
8
  severity: Severity;
@@ -12,20 +14,75 @@ interface Issue {
12
14
  suggestion?: string;
13
15
  codeSnippet?: string;
14
16
  }
17
+ type IssueLifecycleStatus = 'new' | 'existing';
18
+ interface ReportIssue extends Issue {
19
+ fingerprint: string;
20
+ fingerprintVersion: string;
21
+ lifecycle?: IssueLifecycleStatus;
22
+ }
23
+ interface FixedIssue {
24
+ ruleId: string;
25
+ severity: Severity;
26
+ category: RuleCategory;
27
+ file: string;
28
+ startLine: number;
29
+ endLine: number;
30
+ message: string;
31
+ fingerprint: string;
32
+ fingerprintVersion?: string;
33
+ }
34
+ interface LifecycleSummary {
35
+ newIssues: number;
36
+ existingIssues: number;
37
+ fixedIssues: number;
38
+ baselineUsed: boolean;
39
+ baselineCommit?: string;
40
+ baselineTimestamp?: string;
41
+ }
15
42
  interface DimensionScore {
16
43
  score: number;
44
+ issues: ReportIssue[];
45
+ }
46
+ interface RuleFailure {
47
+ ruleId: string;
48
+ file: string;
49
+ message: string;
50
+ }
51
+ interface RuleRunResult {
17
52
  issues: Issue[];
53
+ rulesExecuted: number;
54
+ rulesFailed: number;
55
+ ruleFailures: RuleFailure[];
56
+ }
57
+ interface ScanError {
58
+ type: ScanErrorType;
59
+ message: string;
60
+ file?: string;
61
+ ruleId?: string;
62
+ }
63
+ interface ToolHealth {
64
+ rulesExecuted: number;
65
+ rulesFailed: number;
66
+ filesConsidered: number;
67
+ filesScanned: number;
68
+ filesExcluded: number;
69
+ filesSkipped: number;
70
+ scanErrors: ScanError[];
71
+ ruleFailures: RuleFailure[];
18
72
  }
19
73
  interface TrustReport {
74
+ schemaVersion: string;
20
75
  version: string;
21
76
  timestamp: string;
22
77
  commit?: string;
78
+ scanMode: ScanMode;
23
79
  overall: {
24
80
  score: number;
25
81
  grade: TrustGrade;
26
82
  filesScanned: number;
27
83
  issuesFound: number;
28
84
  };
85
+ toolHealth: ToolHealth;
29
86
  dimensions: {
30
87
  security: DimensionScore;
31
88
  logic: DimensionScore;
@@ -33,7 +90,9 @@ interface TrustReport {
33
90
  style: DimensionScore;
34
91
  coverage: DimensionScore;
35
92
  };
36
- issues: Issue[];
93
+ issues: ReportIssue[];
94
+ lifecycle?: LifecycleSummary;
95
+ fixedIssues?: FixedIssue[];
37
96
  }
38
97
  interface DiffFile {
39
98
  filePath: string;
@@ -55,6 +114,7 @@ interface ScanOptions {
55
114
  diff?: string;
56
115
  files?: string[];
57
116
  minScore?: number;
117
+ baseline?: string;
58
118
  format?: 'terminal' | 'json' | 'html';
59
119
  }
60
120
 
@@ -97,8 +157,29 @@ declare class ScanEngine {
97
157
  private ruleEngine;
98
158
  constructor(config: CodeTrustConfig, workDir?: string);
99
159
  scan(options: ScanOptions): Promise<TrustReport>;
160
+ private scanFile;
161
+ private createSkippedResult;
162
+ private createErrorResult;
163
+ private readFileContent;
164
+ private extractAddedLines;
165
+ private runStructureAnalysis;
166
+ private getScanCandidates;
167
+ private getScanMode;
100
168
  private getDiffFiles;
169
+ private shouldIncludeFile;
170
+ private matchesPattern;
101
171
  private isTsJsFile;
172
+ private attachFingerprints;
173
+ private normalizeRelativePath;
174
+ private loadBaseline;
175
+ private parseBaselineIssues;
176
+ private parseBaselineIssue;
177
+ private isValidBaselineIssue;
178
+ private attachLifecycle;
179
+ private getFixedIssues;
180
+ private buildLifecycleSummary;
181
+ private isSeverity;
182
+ private isRuleCategory;
102
183
  private groupByDimension;
103
184
  }
104
185
 
@@ -137,6 +218,7 @@ declare class RuleEngine {
137
218
  private rules;
138
219
  constructor(config: CodeTrustConfig);
139
220
  run(context: RuleContext): Issue[];
221
+ runWithDiagnostics(context: RuleContext): RuleRunResult;
140
222
  getRules(): Rule[];
141
223
  listRules(): Array<{
142
224
  id: string;
@@ -152,6 +234,11 @@ declare class DiffParser {
152
234
  getStagedFiles(): Promise<DiffFile[]>;
153
235
  getDiffFromRef(ref: string): Promise<DiffFile[]>;
154
236
  getChangedFiles(): Promise<DiffFile[]>;
237
+ /**
238
+ * Merge two sets of diff files, deduplicating by file path.
239
+ * When a file appears in both, merge their hunks and combine stats.
240
+ */
241
+ private mergeDiffFiles;
155
242
  getLastCommitDiff(): Promise<DiffFile[]>;
156
243
  getCurrentCommitHash(): Promise<string | undefined>;
157
244
  getFileContent(filePath: string): Promise<string | undefined>;
@@ -160,7 +247,7 @@ declare class DiffParser {
160
247
  private parseHunks;
161
248
  }
162
249
 
163
- declare function calculateDimensionScore(issues: Issue[]): DimensionScore;
250
+ declare function calculateDimensionScore(issues: ReportIssue[]): DimensionScore;
164
251
  declare function calculateOverallScore(dimensions: Record<RuleCategory, DimensionScore>, weights: DimensionWeights): number;
165
252
  declare function getGrade(score: number): TrustGrade;
166
253
  declare function getGradeEmoji(grade: TrustGrade): string;