vite-plugin-ai-code-review 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Your Name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # vite-plugin-ai-code-review
2
+
3
+ AI-powered code review plugin for Vite. Automatically review code quality, security, and best practices.
4
+
5
+ ## ✨ Features
6
+
7
+ - 🔍 **Auto Review** - Automatically review code on build
8
+ - 🤖 **AI Analysis** - Use OpenAI to analyze code quality
9
+ - 🔒 **Security Check** - Detect security vulnerabilities
10
+ - ⚡ **Performance** - Find performance issues
11
+ - 📊 **Reports** - Generate detailed review reports
12
+ - 🎯 **Git Integration** - Review only changed files
13
+
14
+ ## 📦 Installation
15
+
16
+ ::: code-group
17
+
18
+ ```bash [npm]
19
+ npm install -D vite-plugin-ai-code-review
20
+ ```
21
+
22
+ ```bash [yarn]
23
+ yarn add -D vite-plugin-ai-code-review
24
+ ```
25
+
26
+ ```bash [pnpm]
27
+ pnpm add -D vite-plugin-ai-code-review
28
+ ```
29
+
30
+ :::
31
+
32
+ ## 🚀 Quick Start
33
+
34
+ ```typescript
35
+ // vite.config.ts
36
+ import { defineConfig } from "vite";
37
+ import { vitePluginAICodeReview } from "vite-plugin-ai-code-review";
38
+
39
+ export default defineConfig({
40
+ plugins: [
41
+ vitePluginAICodeReview({
42
+ apiKey: process.env.OPENAI_API_KEY,
43
+ mode: "changed", // 'all' | 'changed'
44
+ level: "standard", // 'basic' | 'standard' | 'strict'
45
+ rules: {
46
+ security: "error",
47
+ performance: "warn",
48
+ style: "info",
49
+ },
50
+ output: {
51
+ console: true,
52
+ html: true,
53
+ markdown: true,
54
+ },
55
+ }),
56
+ ],
57
+ });
58
+ ```
59
+
60
+ ## 📚 Documentation
61
+
62
+ Full documentation: https://mo520.github.io/vite-plugin-ai/plugins/ai-code-review
63
+
64
+ ## 📄 License
65
+
66
+ MIT
@@ -0,0 +1,202 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ /**
4
+ * AI 代码审查器
5
+ */
6
+ interface ReviewIssue {
7
+ file: string;
8
+ line?: number;
9
+ category: "security" | "performance" | "style" | "best-practice";
10
+ severity: "error" | "warn" | "info";
11
+ message: string;
12
+ suggestion?: string;
13
+ code?: string;
14
+ }
15
+ interface ReviewerOptions {
16
+ apiKey: string;
17
+ apiUrl: string;
18
+ model: string;
19
+ level: "quick" | "standard" | "thorough";
20
+ rules: {
21
+ security?: string;
22
+ performance?: string;
23
+ style?: string;
24
+ bestPractice?: string;
25
+ };
26
+ cache: boolean;
27
+ }
28
+ declare class CodeReviewer {
29
+ private llm;
30
+ private options;
31
+ private cache;
32
+ constructor(options: ReviewerOptions);
33
+ /**
34
+ * 审查代码
35
+ */
36
+ review(code: string, filePath: string): Promise<ReviewIssue[]>;
37
+ /**
38
+ * 执行审查
39
+ */
40
+ private performReview;
41
+ /**
42
+ * 构建系统提示
43
+ */
44
+ private buildSystemPrompt;
45
+ /**
46
+ * 构建用户提示
47
+ */
48
+ private buildUserPrompt;
49
+ /**
50
+ * 解析问题
51
+ */
52
+ private parseIssues;
53
+ /**
54
+ * 获取语言类型
55
+ */
56
+ private getLanguage;
57
+ /**
58
+ * 生成缓存键
59
+ */
60
+ private getCacheKey;
61
+ /**
62
+ * 清除缓存
63
+ */
64
+ clearCache(): void;
65
+ /**
66
+ * 获取缓存统计
67
+ */
68
+ getCacheStats(): {
69
+ size: number;
70
+ hits: number;
71
+ };
72
+ }
73
+
74
+ /**
75
+ * Git 工具类
76
+ * 用于获取 Git 变更信息
77
+ * 统一策略:对比上一次提交(HEAD~1)
78
+ */
79
+ declare class GitUtils {
80
+ /**
81
+ * 获取 Git 变更的文件列表
82
+ * 统一策略:对比上一次提交(HEAD~1)
83
+ */
84
+ getChangedFiles(): Promise<string[]>;
85
+ /**
86
+ * 检查是否在 Git 仓库中
87
+ */
88
+ private isGitRepository;
89
+ /**
90
+ * 获取与上一次提交的差异文件
91
+ */
92
+ private getCommitDiffFiles;
93
+ /**
94
+ * 获取最近一次提交的所有文件
95
+ */
96
+ private getLastCommitFiles;
97
+ /**
98
+ * 获取未提交的变更文件(降级方案)
99
+ */
100
+ private getUncommittedFiles;
101
+ /**
102
+ * 获取最近 N 次提交的变更文件
103
+ */
104
+ getRecentChangedFiles(commits?: number): Promise<string[]>;
105
+ /**
106
+ * 获取当前分支名
107
+ */
108
+ getCurrentBranch(): string;
109
+ /**
110
+ * 获取文件的 Git 状态
111
+ */
112
+ getFileStatus(filePath: string): string;
113
+ }
114
+
115
+ /**
116
+ * 报告生成器
117
+ */
118
+
119
+ interface ReporterOptions {
120
+ console?: boolean;
121
+ html?: boolean;
122
+ markdown?: boolean;
123
+ json?: boolean;
124
+ failOnError?: boolean;
125
+ }
126
+ declare class Reporter {
127
+ private options;
128
+ constructor(options?: ReporterOptions);
129
+ /**
130
+ * 生成报告
131
+ */
132
+ generate(issues: ReviewIssue[]): Promise<void>;
133
+ /**
134
+ * 生成控制台报告
135
+ */
136
+ private generateConsoleReport;
137
+ /**
138
+ * 生成 HTML 报告
139
+ */
140
+ private generateHTMLReport;
141
+ /**
142
+ * 生成 Markdown 报告
143
+ */
144
+ private generateMarkdownReport;
145
+ /**
146
+ * 生成 JSON 报告
147
+ */
148
+ private generateJSONReport;
149
+ /**
150
+ * 按类别分组
151
+ */
152
+ private groupByCategory;
153
+ /**
154
+ * 获取类别图标
155
+ */
156
+ private getCategoryIcon;
157
+ /**
158
+ * 获取严重程度图标
159
+ */
160
+ private getSeverityIcon;
161
+ }
162
+
163
+ /**
164
+ * AI Code Review Plugin
165
+ *
166
+ * 功能:
167
+ * - 审查代码质量
168
+ * - 检测安全问题
169
+ * - 发现性能问题
170
+ * - 提供改进建议
171
+ */
172
+
173
+ interface CodeReviewOptions {
174
+ apiKey?: string;
175
+ apiUrl?: string;
176
+ model?: string;
177
+ mode?: "changed" | "all" | "manual";
178
+ files?: string[];
179
+ level?: "quick" | "standard" | "thorough";
180
+ rules?: {
181
+ security?: "error" | "warn" | "info" | "off";
182
+ performance?: "error" | "warn" | "info" | "off";
183
+ style?: "error" | "warn" | "info" | "off";
184
+ bestPractice?: "error" | "warn" | "info" | "off";
185
+ };
186
+ include?: string[];
187
+ exclude?: string[];
188
+ output?: {
189
+ console?: boolean;
190
+ html?: boolean;
191
+ markdown?: boolean;
192
+ json?: boolean;
193
+ failOnError?: boolean;
194
+ };
195
+ cache?: boolean;
196
+ batchSize?: number;
197
+ maxConcurrent?: number;
198
+ enabled?: boolean;
199
+ }
200
+ declare function vitePluginAICodeReview(options?: CodeReviewOptions): Plugin;
201
+
202
+ export { type CodeReviewOptions, CodeReviewer, GitUtils, Reporter, vitePluginAICodeReview };
@@ -0,0 +1,202 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ /**
4
+ * AI 代码审查器
5
+ */
6
+ interface ReviewIssue {
7
+ file: string;
8
+ line?: number;
9
+ category: "security" | "performance" | "style" | "best-practice";
10
+ severity: "error" | "warn" | "info";
11
+ message: string;
12
+ suggestion?: string;
13
+ code?: string;
14
+ }
15
+ interface ReviewerOptions {
16
+ apiKey: string;
17
+ apiUrl: string;
18
+ model: string;
19
+ level: "quick" | "standard" | "thorough";
20
+ rules: {
21
+ security?: string;
22
+ performance?: string;
23
+ style?: string;
24
+ bestPractice?: string;
25
+ };
26
+ cache: boolean;
27
+ }
28
+ declare class CodeReviewer {
29
+ private llm;
30
+ private options;
31
+ private cache;
32
+ constructor(options: ReviewerOptions);
33
+ /**
34
+ * 审查代码
35
+ */
36
+ review(code: string, filePath: string): Promise<ReviewIssue[]>;
37
+ /**
38
+ * 执行审查
39
+ */
40
+ private performReview;
41
+ /**
42
+ * 构建系统提示
43
+ */
44
+ private buildSystemPrompt;
45
+ /**
46
+ * 构建用户提示
47
+ */
48
+ private buildUserPrompt;
49
+ /**
50
+ * 解析问题
51
+ */
52
+ private parseIssues;
53
+ /**
54
+ * 获取语言类型
55
+ */
56
+ private getLanguage;
57
+ /**
58
+ * 生成缓存键
59
+ */
60
+ private getCacheKey;
61
+ /**
62
+ * 清除缓存
63
+ */
64
+ clearCache(): void;
65
+ /**
66
+ * 获取缓存统计
67
+ */
68
+ getCacheStats(): {
69
+ size: number;
70
+ hits: number;
71
+ };
72
+ }
73
+
74
+ /**
75
+ * Git 工具类
76
+ * 用于获取 Git 变更信息
77
+ * 统一策略:对比上一次提交(HEAD~1)
78
+ */
79
+ declare class GitUtils {
80
+ /**
81
+ * 获取 Git 变更的文件列表
82
+ * 统一策略:对比上一次提交(HEAD~1)
83
+ */
84
+ getChangedFiles(): Promise<string[]>;
85
+ /**
86
+ * 检查是否在 Git 仓库中
87
+ */
88
+ private isGitRepository;
89
+ /**
90
+ * 获取与上一次提交的差异文件
91
+ */
92
+ private getCommitDiffFiles;
93
+ /**
94
+ * 获取最近一次提交的所有文件
95
+ */
96
+ private getLastCommitFiles;
97
+ /**
98
+ * 获取未提交的变更文件(降级方案)
99
+ */
100
+ private getUncommittedFiles;
101
+ /**
102
+ * 获取最近 N 次提交的变更文件
103
+ */
104
+ getRecentChangedFiles(commits?: number): Promise<string[]>;
105
+ /**
106
+ * 获取当前分支名
107
+ */
108
+ getCurrentBranch(): string;
109
+ /**
110
+ * 获取文件的 Git 状态
111
+ */
112
+ getFileStatus(filePath: string): string;
113
+ }
114
+
115
+ /**
116
+ * 报告生成器
117
+ */
118
+
119
+ interface ReporterOptions {
120
+ console?: boolean;
121
+ html?: boolean;
122
+ markdown?: boolean;
123
+ json?: boolean;
124
+ failOnError?: boolean;
125
+ }
126
+ declare class Reporter {
127
+ private options;
128
+ constructor(options?: ReporterOptions);
129
+ /**
130
+ * 生成报告
131
+ */
132
+ generate(issues: ReviewIssue[]): Promise<void>;
133
+ /**
134
+ * 生成控制台报告
135
+ */
136
+ private generateConsoleReport;
137
+ /**
138
+ * 生成 HTML 报告
139
+ */
140
+ private generateHTMLReport;
141
+ /**
142
+ * 生成 Markdown 报告
143
+ */
144
+ private generateMarkdownReport;
145
+ /**
146
+ * 生成 JSON 报告
147
+ */
148
+ private generateJSONReport;
149
+ /**
150
+ * 按类别分组
151
+ */
152
+ private groupByCategory;
153
+ /**
154
+ * 获取类别图标
155
+ */
156
+ private getCategoryIcon;
157
+ /**
158
+ * 获取严重程度图标
159
+ */
160
+ private getSeverityIcon;
161
+ }
162
+
163
+ /**
164
+ * AI Code Review Plugin
165
+ *
166
+ * 功能:
167
+ * - 审查代码质量
168
+ * - 检测安全问题
169
+ * - 发现性能问题
170
+ * - 提供改进建议
171
+ */
172
+
173
+ interface CodeReviewOptions {
174
+ apiKey?: string;
175
+ apiUrl?: string;
176
+ model?: string;
177
+ mode?: "changed" | "all" | "manual";
178
+ files?: string[];
179
+ level?: "quick" | "standard" | "thorough";
180
+ rules?: {
181
+ security?: "error" | "warn" | "info" | "off";
182
+ performance?: "error" | "warn" | "info" | "off";
183
+ style?: "error" | "warn" | "info" | "off";
184
+ bestPractice?: "error" | "warn" | "info" | "off";
185
+ };
186
+ include?: string[];
187
+ exclude?: string[];
188
+ output?: {
189
+ console?: boolean;
190
+ html?: boolean;
191
+ markdown?: boolean;
192
+ json?: boolean;
193
+ failOnError?: boolean;
194
+ };
195
+ cache?: boolean;
196
+ batchSize?: number;
197
+ maxConcurrent?: number;
198
+ enabled?: boolean;
199
+ }
200
+ declare function vitePluginAICodeReview(options?: CodeReviewOptions): Plugin;
201
+
202
+ export { type CodeReviewOptions, CodeReviewer, GitUtils, Reporter, vitePluginAICodeReview };