kodevu 0.1.34 → 0.1.37
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/package.json +1 -1
- package/src/config.js +2 -2
- package/src/git-client.js +19 -0
- package/src/report-generator.js +113 -58
- package/src/review-runner.js +5 -4
- package/src/vcs-client.js +16 -2
package/package.json
CHANGED
package/src/config.js
CHANGED
|
@@ -266,8 +266,8 @@ Options:
|
|
|
266
266
|
--reviewer, -r Reviewer (codex | gemini | copilot | auto, default: auto)
|
|
267
267
|
--prompt, -p Additional instructions or @file.txt to read from file
|
|
268
268
|
--lang, -l Output language (e.g. zh, en, auto)
|
|
269
|
-
--rev, -v Review
|
|
270
|
-
--last, -n Review the latest N revisions (default: 1)
|
|
269
|
+
--rev, -v Review specific revision(s), hashes, branches or ranges (comma-separated)
|
|
270
|
+
--last, -n Review the latest N revisions (ignored if --rev is provided) (default: 1)
|
|
271
271
|
--output, -o Output directory (default: ~/.kodevu)
|
|
272
272
|
--format, -f Output formats (markdown, json, comma-separated)
|
|
273
273
|
--debug, -d Print extra debug information
|
package/src/git-client.js
CHANGED
|
@@ -105,6 +105,25 @@ export async function isValidCheckpoint(config, targetInfo, checkpointCommit, la
|
|
|
105
105
|
return ancestorResult.code === 0;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
export async function resolveCommits(config, targetInfo, revSpec) {
|
|
109
|
+
const result = await runGit(
|
|
110
|
+
config,
|
|
111
|
+
["rev-list", revSpec],
|
|
112
|
+
{ cwd: targetInfo.repoRootPath, trim: true, allowFailure: true }
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
if (result.code !== 0) {
|
|
116
|
+
// Attempt fallback to a single hash resolution if rev-list fails (e.g. for non-standard specs)
|
|
117
|
+
const single = await runGit(config, ["rev-parse", revSpec], {
|
|
118
|
+
cwd: targetInfo.repoRootPath, trim: true, allowFailure: true
|
|
119
|
+
});
|
|
120
|
+
if (single.code === 0) return [single.stdout.trim()];
|
|
121
|
+
throw new Error(`Failed to resolve Git revision: ${revSpec}`);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return splitLines(result.stdout);
|
|
125
|
+
}
|
|
126
|
+
|
|
108
127
|
export async function getPendingCommits(config, targetInfo, startExclusive, endInclusive, limit) {
|
|
109
128
|
const args = ["rev-list", "--reverse"];
|
|
110
129
|
|
package/src/report-generator.js
CHANGED
|
@@ -2,11 +2,65 @@ export function getCoreReviewInstruction(lang) {
|
|
|
2
2
|
const lowLang = (lang || "").toLowerCase();
|
|
3
3
|
if (lowLang.startsWith("zh")) {
|
|
4
4
|
if (lowLang === "zh-tw" || lowLang === "zh-hk") {
|
|
5
|
-
return
|
|
5
|
+
return `你是一位擁有 10 年以上經驗的高級軟體架構師和代碼審查專家。你的任務是對以下代碼變更進行嚴格且高質量的審查。
|
|
6
|
+
你的目標是:
|
|
7
|
+
1. 發現代碼中的 Bug、邏輯缺陷和潛在的回歸風險。
|
|
8
|
+
2. 識別性能瓶頸、記憶體洩漏或不必要的計算。
|
|
9
|
+
3. 檢查安全漏洞(如注入、越權、敏感信息洩露等)。
|
|
10
|
+
4. 評估代碼的可維護性、可讀性和是否符合最佳實踐。
|
|
11
|
+
5. 檢查是否涵蓋了必要的單元測試和邊界條件。
|
|
12
|
+
|
|
13
|
+
你的輸出格式必須清晰,請使用以下 Markdown 結構:
|
|
14
|
+
### 1. 變更總結 (Summary)
|
|
15
|
+
簡要描述這次提交的主要目的和影響面。
|
|
16
|
+
### 2. 核心缺陷 (Critical Issues)
|
|
17
|
+
列出 Bug、安全隱患或會導致程序崩潰/邏輯錯誤的問題。請註明檔案名和行號。
|
|
18
|
+
### 3. 改進建議 (Suggestions)
|
|
19
|
+
列出關於代碼風格、性能優化或架構設計的改進點。
|
|
20
|
+
### 4. 審查結論 (Conclusion)
|
|
21
|
+
如果發現明顯缺陷,總結修復建議;如果未發現明顯缺陷,請說明「未發現明顯缺陷」並指出可能的殘留風險。
|
|
22
|
+
|
|
23
|
+
注意:你正處於唯讀審查模式,請勿表現出「正在應用補丁」或「準備執行代碼」的行為。只需提供文字審查分析。`;
|
|
6
24
|
}
|
|
7
|
-
return
|
|
25
|
+
return `你是一位拥有 10 年以上经验的高级软件架构师和代码审查专家。你的任务是对以下代码变更进行严格且高质量的审查。
|
|
26
|
+
你的目标是:
|
|
27
|
+
1. 发现代码中的 Bug、逻辑缺陷和潜在的回归风险。
|
|
28
|
+
2. 识别性能瓶颈、内存泄漏或不必要的计算。
|
|
29
|
+
3. 检查安全漏洞(如注入、越权、敏感信息泄露等)。
|
|
30
|
+
4. 评估代码的可维护性、可读性和是否符合最佳实践。
|
|
31
|
+
5. 检查是否涵盖了必要的单元测试和边界条件。
|
|
32
|
+
|
|
33
|
+
你的输出格式必须清晰,请使用以下 Markdown 结构:
|
|
34
|
+
### 1. 变更总结 (Summary)
|
|
35
|
+
简要描述这次提交的主要目的和影响面。
|
|
36
|
+
### 2. 核心缺陷 (Critical Issues)
|
|
37
|
+
列出 Bug、安全隐患或会导致程序崩溃/逻辑错误的问题。请注明文件名和行号。
|
|
38
|
+
### 3. 改进建议 (Suggestions)
|
|
39
|
+
列出关于代码风格、性能优化或架构设计的改进点。
|
|
40
|
+
### 4. 审查结论 (Conclusion)
|
|
41
|
+
如果发现明显缺陷,总结修复建议;如果未发现明显缺陷,请说明“未发现明显缺陷”并指出可能的残留风险。
|
|
42
|
+
|
|
43
|
+
注意:你正处于只读审查模式,请勿表现出“正在应用补丁”或“准备执行代码”的行为。只需提供文字审查分析。`;
|
|
8
44
|
}
|
|
9
|
-
return
|
|
45
|
+
return `You are a Senior Software Engineer and Code Review Expert with over 10 years of experience. Your task is to perform a rigorous and high-quality review of the following code changes.
|
|
46
|
+
Your goals are to:
|
|
47
|
+
1. Identify bugs, logical flaws, and potential regression risks.
|
|
48
|
+
2. Spot performance bottlenecks, memory leaks, or unnecessary computations.
|
|
49
|
+
3. Check for security vulnerabilities (e.g., injection, authorization issues, sensitive data leaks).
|
|
50
|
+
4. Evaluate maintainability, readability, and adherence to best practices.
|
|
51
|
+
5. Verify coverage of necessary unit tests and boundary conditions.
|
|
52
|
+
|
|
53
|
+
Your output must be structured using the following Markdown headers:
|
|
54
|
+
### 1. Summary
|
|
55
|
+
Briefly describe the purpose and impact of this change.
|
|
56
|
+
### 2. Critical Issues
|
|
57
|
+
List bugs, security risks, or problems that could cause crashes or logical errors. Include file names and line numbers.
|
|
58
|
+
### 3. Suggestions
|
|
59
|
+
List points for improvement regarding code style, performance, or architectural design.
|
|
60
|
+
### 4. Conclusion
|
|
61
|
+
Summarize with a "Pass" or "Needs Revision". If no clear flaws are found, state "No clear flaws found" and mention any residual risks.
|
|
62
|
+
|
|
63
|
+
Note: You are in a read-only review mode. Do not act as if you are "applying the patch" or "executing code". Provide only textual analysis and feedback.`;
|
|
10
64
|
}
|
|
11
65
|
|
|
12
66
|
export function getReviewWorkspaceRoot(config, backend, targetInfo) {
|
|
@@ -40,52 +94,52 @@ function getLanguageDisplayName(lang) {
|
|
|
40
94
|
|
|
41
95
|
const LOCALIZED_PHRASES = {
|
|
42
96
|
en: {
|
|
43
|
-
workspaceRoot: "
|
|
97
|
+
workspaceRoot: "Workspace context (read-only):",
|
|
44
98
|
noWorkspace: "No local repository workspace is available for this review run.",
|
|
45
|
-
besidesDiff: "
|
|
46
|
-
reviewFromDiff: "Review primarily
|
|
47
|
-
fileRefs: "
|
|
99
|
+
besidesDiff: "You can read related files in the workspace to understand call sites, shared utilities, configuration, or data flow.",
|
|
100
|
+
reviewFromDiff: "Review primarily based on the provided diff. Do not assume access to other local files or shell commands.",
|
|
101
|
+
fileRefs: "Reference files using plain text like 'path/to/file.js:123'. Do not generate clickable workspace links.",
|
|
48
102
|
repoType: "Repository Type",
|
|
49
103
|
changeId: "Change ID",
|
|
50
104
|
author: "Author",
|
|
51
105
|
date: "Date",
|
|
52
106
|
changedFiles: "Changed files",
|
|
53
107
|
commitMessage: "Commit message",
|
|
54
|
-
diffNoteTruncated: "
|
|
55
|
-
diffNoteFull: "
|
|
56
|
-
langRule: "---
|
|
108
|
+
diffNoteTruncated: "Note: The diff was truncated to fit size limits. Original: {originalLineCount} lines / {originalCharCount} chars. Included: {outputLineCount} lines / {outputCharCount} chars.",
|
|
109
|
+
diffNoteFull: "Note: Full diff provided ({originalLineCount} lines / {originalCharCount} chars).",
|
|
110
|
+
langRule: "--- LANGUAGE RULE ---\nYour entire response must be in {langName}. No other language allowed."
|
|
57
111
|
},
|
|
58
112
|
zh: {
|
|
59
|
-
workspaceRoot: "
|
|
113
|
+
workspaceRoot: "只读工作区上下文:",
|
|
60
114
|
noWorkspace: "此审查运行没有可用的本地仓库工作区。",
|
|
61
|
-
besidesDiff: "
|
|
62
|
-
reviewFromDiff: "
|
|
63
|
-
fileRefs: "
|
|
115
|
+
besidesDiff: "你可以阅读工作区中的其他文件以了解调用点、工具类、配置或数据流。",
|
|
116
|
+
reviewFromDiff: "主要根据提供的 Diff 进行审查。不要假设可以访问其他文件或执行 Shell 命令。",
|
|
117
|
+
fileRefs: "使用纯文本引用文件,如 'path/to/file.js:123'。不要生成可点击的链接。",
|
|
64
118
|
repoType: "仓库类型",
|
|
65
119
|
changeId: "变更 ID",
|
|
66
120
|
author: "作者",
|
|
67
121
|
date: "日期",
|
|
68
122
|
changedFiles: "已变更文件",
|
|
69
123
|
commitMessage: "提交信息",
|
|
70
|
-
diffNoteTruncated: "Diff
|
|
71
|
-
diffNoteFull: "
|
|
72
|
-
langRule: "---
|
|
124
|
+
diffNoteTruncated: "注意:Diff 已截断。原始:{originalLineCount} 行 / {originalCharCount} 字符。包含:{outputLineCount} 行 / {outputCharCount} 字符。",
|
|
125
|
+
diffNoteFull: "注意:包含完整 Diff ({originalLineCount} 行 / {originalCharCount} 字符)。",
|
|
126
|
+
langRule: "--- 语言规则 ---\n你必须完全使用 {langName} 进行回复。不得使用其他语言进行解释或总结。"
|
|
73
127
|
},
|
|
74
128
|
"zh-tw": {
|
|
75
|
-
workspaceRoot: "
|
|
129
|
+
workspaceRoot: "唯讀工作區上下文:",
|
|
76
130
|
noWorkspace: "此審查運行沒有可用的本地倉庫工作區。",
|
|
77
|
-
besidesDiff: "
|
|
78
|
-
reviewFromDiff: "
|
|
79
|
-
fileRefs: "
|
|
131
|
+
besidesDiff: "你可以閱讀工作區中的其他文件以了解調用點、工具類、配置或資料流。",
|
|
132
|
+
reviewFromDiff: "主要根據提供的 Diff 進行審查。不要假設可以訪問其他文件或執行 Shell 命令。",
|
|
133
|
+
fileRefs: "使用純文本引用文件,如 'path/to/file.js:123'。不要生成可點擊的連結。",
|
|
80
134
|
repoType: "倉庫類型",
|
|
81
135
|
changeId: "變更 ID",
|
|
82
136
|
author: "作者",
|
|
83
137
|
date: "日期",
|
|
84
138
|
changedFiles: "已變更文件",
|
|
85
139
|
commitMessage: "提交信息",
|
|
86
|
-
diffNoteTruncated: "Diff
|
|
87
|
-
diffNoteFull: "
|
|
88
|
-
langRule: "---
|
|
140
|
+
diffNoteTruncated: "注意:Diff 已截斷。原始:{originalLineCount} 行 / {originalCharCount} 字符。包含:{outputLineCount} 行 / {outputCharCount} 字符。",
|
|
141
|
+
diffNoteFull: "注意:包含完整 Diff ({originalLineCount} 行 / {originalCharCount} 字符)。",
|
|
142
|
+
langRule: "--- 語言規則 ---\n你必須完全使用 {langName} 進行回覆。不得使用其他語言進行解釋或總結。"
|
|
89
143
|
}
|
|
90
144
|
};
|
|
91
145
|
|
|
@@ -109,51 +163,52 @@ export function buildPrompt(config, backend, targetInfo, details, reviewDiffPayl
|
|
|
109
163
|
const langName = getLanguageDisplayName(lang);
|
|
110
164
|
const lowLang = lang.toLowerCase();
|
|
111
165
|
|
|
112
|
-
let langInstruction = `
|
|
113
|
-
|
|
166
|
+
let langInstruction = `CRITICAL: YOUR ENTIRE RESPONSE MUST BE IN ${langName.toUpperCase()}.`;
|
|
114
167
|
if (lowLang.startsWith("zh")) {
|
|
115
168
|
if (lowLang === "zh-tw" || lowLang === "zh-hk") {
|
|
116
|
-
langInstruction += "\n
|
|
169
|
+
langInstruction += "\n請務必完全使用繁體中文進行回覆。";
|
|
117
170
|
} else {
|
|
118
|
-
langInstruction += "\n
|
|
171
|
+
langInstruction += "\n请务必完全使用简体中文进行回复。";
|
|
119
172
|
}
|
|
120
173
|
}
|
|
121
174
|
|
|
122
|
-
|
|
123
|
-
langInstruction,
|
|
124
|
-
getCoreReviewInstruction(lang),
|
|
125
|
-
config.prompt,
|
|
126
|
-
canReadRelatedFiles
|
|
127
|
-
? `${getPhrase("workspaceRoot", lang)} ${workspaceRoot}`
|
|
128
|
-
: getPhrase("noWorkspace", lang),
|
|
129
|
-
canReadRelatedFiles
|
|
130
|
-
? getPhrase("besidesDiff", lang)
|
|
131
|
-
: getPhrase("reviewFromDiff", lang),
|
|
132
|
-
getPhrase("fileRefs", lang),
|
|
175
|
+
const metadata = [
|
|
133
176
|
`${getPhrase("repoType", lang)}: ${backend.displayName}`,
|
|
134
177
|
`${getPhrase("changeId", lang)}: ${details.displayId}`,
|
|
135
178
|
`${getPhrase("author", lang)}: ${details.author}`,
|
|
136
179
|
`${getPhrase("date", lang)}: ${details.date || "unknown"}`,
|
|
137
180
|
`${getPhrase("changedFiles", lang)}:\n${fileList || "(none)"}`,
|
|
138
|
-
`${getPhrase("commitMessage", lang)}:\n${details.message || "(empty)"}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
181
|
+
`${getPhrase("commitMessage", lang)}:\n${details.message || "(empty)"}`
|
|
182
|
+
].join("\n");
|
|
183
|
+
|
|
184
|
+
const diffNote = reviewDiffPayload.wasTruncated
|
|
185
|
+
? getPhrase("diffNoteTruncated", lang, {
|
|
186
|
+
originalLineCount: reviewDiffPayload.originalLineCount,
|
|
187
|
+
originalCharCount: reviewDiffPayload.originalCharCount,
|
|
188
|
+
outputLineCount: reviewDiffPayload.outputLineCount,
|
|
189
|
+
outputCharCount: reviewDiffPayload.outputCharCount
|
|
190
|
+
})
|
|
191
|
+
: getPhrase("diffNoteFull", lang, {
|
|
192
|
+
originalLineCount: reviewDiffPayload.originalLineCount,
|
|
193
|
+
originalCharCount: reviewDiffPayload.originalCharCount
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const sections = [
|
|
197
|
+
langInstruction,
|
|
198
|
+
getCoreReviewInstruction(lang),
|
|
199
|
+
config.prompt ? `### Additional User Instructions:\n${config.prompt}` : null,
|
|
200
|
+
"### Change Context:",
|
|
201
|
+
metadata,
|
|
202
|
+
diffNote,
|
|
203
|
+
"### Environment:",
|
|
204
|
+
canReadRelatedFiles
|
|
205
|
+
? `${getPhrase("workspaceRoot", lang)} ${workspaceRoot}\n${getPhrase("besidesDiff", lang)}`
|
|
206
|
+
: getPhrase("noWorkspace", lang),
|
|
207
|
+
getPhrase("fileRefs", lang),
|
|
208
|
+
getPhrase("langRule", lang, { langName })
|
|
209
|
+
];
|
|
210
|
+
|
|
211
|
+
return sections.filter(Boolean).join("\n\n");
|
|
157
212
|
}
|
|
158
213
|
|
|
159
214
|
export function formatTokenUsage(tokenUsage) {
|
package/src/review-runner.js
CHANGED
|
@@ -20,6 +20,7 @@ async function reviewChange(config, backend, targetInfo, changeId, progress) {
|
|
|
20
20
|
logger.info(`Starting review for ${backend.changeName} ${displayId}`);
|
|
21
21
|
progress?.update(0.05, "loading change details");
|
|
22
22
|
const details = await backend.getChangeDetails(config, targetInfo, changeId);
|
|
23
|
+
const resolvedChangeId = details.id;
|
|
23
24
|
|
|
24
25
|
if (details.changedPaths.length === 0) {
|
|
25
26
|
progress?.update(0.7, "writing skipped report");
|
|
@@ -29,7 +30,7 @@ async function reviewChange(config, backend, targetInfo, changeId, progress) {
|
|
|
29
30
|
"No file changes were captured for this change under the configured target."
|
|
30
31
|
].join("\n");
|
|
31
32
|
|
|
32
|
-
const markdownReportFile = path.join(config.outputDir, backend.getReportFileName(
|
|
33
|
+
const markdownReportFile = path.join(config.outputDir, backend.getReportFileName(resolvedChangeId));
|
|
33
34
|
const jsonReportFile = markdownReportFile.replace(/\.md$/i, ".json");
|
|
34
35
|
|
|
35
36
|
if (shouldWriteFormat(config, "markdown")) {
|
|
@@ -55,7 +56,7 @@ async function reviewChange(config, backend, targetInfo, changeId, progress) {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
progress?.update(0.2, "loading diff");
|
|
58
|
-
const diffText = await backend.getChangeDiff(config, targetInfo,
|
|
59
|
+
const diffText = await backend.getChangeDiff(config, targetInfo, resolvedChangeId);
|
|
59
60
|
const reviewersToTry = [config.reviewer, ...(config.fallbackReviewers || [])];
|
|
60
61
|
|
|
61
62
|
let reviewer;
|
|
@@ -99,7 +100,7 @@ async function reviewChange(config, backend, targetInfo, changeId, progress) {
|
|
|
99
100
|
progress?.update(0.82, "writing report");
|
|
100
101
|
logger.debug(`Token usage: input=${tokenUsage.inputTokens} output=${tokenUsage.outputTokens} total=${tokenUsage.totalTokens} source=${tokenUsage.source}`);
|
|
101
102
|
const report = buildReport(currentReviewerConfig, backend, targetInfo, details, diffPayloads, reviewer, reviewerResult, tokenUsage);
|
|
102
|
-
const outputFile = path.join(config.outputDir, backend.getReportFileName(
|
|
103
|
+
const outputFile = path.join(config.outputDir, backend.getReportFileName(resolvedChangeId));
|
|
103
104
|
const jsonOutputFile = outputFile.replace(/\.md$/i, ".json");
|
|
104
105
|
|
|
105
106
|
if (shouldWriteFormat(config, "markdown")) {
|
|
@@ -156,7 +157,7 @@ export async function runReviewCycle(config) {
|
|
|
156
157
|
let changeIdsToReview = [];
|
|
157
158
|
|
|
158
159
|
if (config.rev) {
|
|
159
|
-
changeIdsToReview =
|
|
160
|
+
changeIdsToReview = await backend.resolveChangeIds(config, targetInfo, config.rev);
|
|
160
161
|
} else {
|
|
161
162
|
changeIdsToReview = await backend.getLatestChangeIds(config, targetInfo, config.last || 1);
|
|
162
163
|
}
|
package/src/vcs-client.js
CHANGED
|
@@ -36,6 +36,10 @@ function createSvnBackend() {
|
|
|
36
36
|
return `${datePrefix}-svn-r${revision}.md`;
|
|
37
37
|
},
|
|
38
38
|
|
|
39
|
+
async resolveChangeIds(config, targetInfo, revString) {
|
|
40
|
+
if (!revString) return [];
|
|
41
|
+
return String(revString).split(',').map(s => s.trim()).filter(Boolean);
|
|
42
|
+
},
|
|
39
43
|
async getTargetInfo(config) {
|
|
40
44
|
return await svnClient.getTargetInfo(config);
|
|
41
45
|
},
|
|
@@ -83,6 +87,16 @@ function createGitBackend() {
|
|
|
83
87
|
return `${datePrefix}-git-${commitHash.slice(0, 12)}.md`;
|
|
84
88
|
},
|
|
85
89
|
|
|
90
|
+
async resolveChangeIds(config, targetInfo, revString) {
|
|
91
|
+
if (!revString) return [];
|
|
92
|
+
const specs = String(revString).split(',').map(s => s.trim()).filter(Boolean);
|
|
93
|
+
const allHashes = [];
|
|
94
|
+
for (const spec of specs) {
|
|
95
|
+
const hashes = await gitClient.resolveCommits(config, targetInfo, spec);
|
|
96
|
+
allHashes.push(...hashes);
|
|
97
|
+
}
|
|
98
|
+
return [...new Set(allHashes)];
|
|
99
|
+
},
|
|
86
100
|
async getTargetInfo(config) {
|
|
87
101
|
return await gitClient.getTargetInfo(config);
|
|
88
102
|
},
|
|
@@ -99,8 +113,8 @@ function createGitBackend() {
|
|
|
99
113
|
const details = await gitClient.getCommitDetails(config, targetInfo, commitHash);
|
|
100
114
|
|
|
101
115
|
return {
|
|
102
|
-
id: commitHash,
|
|
103
|
-
displayId: commitHash.slice(0, 12),
|
|
116
|
+
id: details.commitHash,
|
|
117
|
+
displayId: details.commitHash.slice(0, 12),
|
|
104
118
|
author: details.author,
|
|
105
119
|
date: details.date,
|
|
106
120
|
message: details.message,
|