@gulu9527/code-trust 0.2.0 → 0.3.0

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,54 @@ interface Issue {
12
14
  suggestion?: string;
13
15
  codeSnippet?: string;
14
16
  }
17
+ interface ReportIssue extends Issue {
18
+ fingerprint: string;
19
+ fingerprintVersion: string;
20
+ }
15
21
  interface DimensionScore {
16
22
  score: number;
23
+ issues: ReportIssue[];
24
+ }
25
+ interface RuleFailure {
26
+ ruleId: string;
27
+ file: string;
28
+ message: string;
29
+ }
30
+ interface RuleRunResult {
17
31
  issues: Issue[];
32
+ rulesExecuted: number;
33
+ rulesFailed: number;
34
+ ruleFailures: RuleFailure[];
35
+ }
36
+ interface ScanError {
37
+ type: ScanErrorType;
38
+ message: string;
39
+ file?: string;
40
+ ruleId?: string;
41
+ }
42
+ interface ToolHealth {
43
+ rulesExecuted: number;
44
+ rulesFailed: number;
45
+ filesConsidered: number;
46
+ filesScanned: number;
47
+ filesExcluded: number;
48
+ filesSkipped: number;
49
+ scanErrors: ScanError[];
50
+ ruleFailures: RuleFailure[];
18
51
  }
19
52
  interface TrustReport {
53
+ schemaVersion: string;
20
54
  version: string;
21
55
  timestamp: string;
22
56
  commit?: string;
57
+ scanMode: ScanMode;
23
58
  overall: {
24
59
  score: number;
25
60
  grade: TrustGrade;
26
61
  filesScanned: number;
27
62
  issuesFound: number;
28
63
  };
64
+ toolHealth: ToolHealth;
29
65
  dimensions: {
30
66
  security: DimensionScore;
31
67
  logic: DimensionScore;
@@ -33,7 +69,7 @@ interface TrustReport {
33
69
  style: DimensionScore;
34
70
  coverage: DimensionScore;
35
71
  };
36
- issues: Issue[];
72
+ issues: ReportIssue[];
37
73
  }
38
74
  interface DiffFile {
39
75
  filePath: string;
@@ -97,14 +133,27 @@ declare class ScanEngine {
97
133
  private ruleEngine;
98
134
  constructor(config: CodeTrustConfig, workDir?: string);
99
135
  scan(options: ScanOptions): Promise<TrustReport>;
136
+ private scanFile;
137
+ private getScanCandidates;
138
+ private getScanMode;
100
139
  private getDiffFiles;
140
+ private shouldIncludeFile;
141
+ private matchesPattern;
101
142
  private isTsJsFile;
143
+ private attachFingerprints;
144
+ private normalizeRelativePath;
102
145
  private groupByDimension;
103
146
  }
104
147
 
105
148
  declare function loadConfig(searchFrom?: string): Promise<CodeTrustConfig>;
106
149
  declare function generateDefaultConfig(): string;
107
150
 
151
+ interface Fix {
152
+ /** Byte range in the original file content [startOffset, endOffset) */
153
+ range: [number, number];
154
+ /** Replacement text (empty string = delete) */
155
+ text: string;
156
+ }
108
157
  interface Rule {
109
158
  id: string;
110
159
  category: RuleCategory;
@@ -112,6 +161,10 @@ interface Rule {
112
161
  title: string;
113
162
  description: string;
114
163
  check: (context: RuleContext) => Issue[];
164
+ /** Whether this rule supports auto-fix */
165
+ fixable?: boolean;
166
+ /** Generate a fix for a given issue. Returns null if unfixable. */
167
+ fix?: (context: RuleContext, issue: Issue) => Fix | null;
115
168
  }
116
169
  interface RuleContext {
117
170
  filePath: string;
@@ -127,6 +180,7 @@ declare class RuleEngine {
127
180
  private rules;
128
181
  constructor(config: CodeTrustConfig);
129
182
  run(context: RuleContext): Issue[];
183
+ runWithDiagnostics(context: RuleContext): RuleRunResult;
130
184
  getRules(): Rule[];
131
185
  listRules(): Array<{
132
186
  id: string;
@@ -150,7 +204,7 @@ declare class DiffParser {
150
204
  private parseHunks;
151
205
  }
152
206
 
153
- declare function calculateDimensionScore(issues: Issue[]): DimensionScore;
207
+ declare function calculateDimensionScore(issues: ReportIssue[]): DimensionScore;
154
208
  declare function calculateOverallScore(dimensions: Record<RuleCategory, DimensionScore>, weights: DimensionWeights): number;
155
209
  declare function getGrade(score: number): TrustGrade;
156
210
  declare function getGradeEmoji(grade: TrustGrade): string;