kodevu 0.1.36 → 0.1.38
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/logger.js +3 -2
- package/src/report-generator.js +118 -62
- package/src/review-runner.js +3 -2
- package/src/utils.js +22 -0
package/package.json
CHANGED
package/src/logger.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { formatDate } from "./utils.js";
|
|
3
4
|
|
|
4
5
|
class Logger {
|
|
5
6
|
constructor() {
|
|
@@ -18,7 +19,7 @@ class Logger {
|
|
|
18
19
|
if (!fs.existsSync(config.logsDir)) {
|
|
19
20
|
fs.mkdirSync(config.logsDir, { recursive: true });
|
|
20
21
|
}
|
|
21
|
-
const date = new Date()
|
|
22
|
+
const date = formatDate(new Date()).split(" ")[0];
|
|
22
23
|
this.logFile = path.join(config.logsDir, `run-${date}.log`);
|
|
23
24
|
|
|
24
25
|
// Simple rotation: Clean up logs older than 7 days
|
|
@@ -57,7 +58,7 @@ class Logger {
|
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
_log(level, message) {
|
|
60
|
-
const timestamp = new Date()
|
|
61
|
+
const timestamp = formatDate(new Date());
|
|
61
62
|
const logLine = `[${timestamp}] [${level}] ${message}`;
|
|
62
63
|
|
|
63
64
|
// Write to file
|
package/src/report-generator.js
CHANGED
|
@@ -1,12 +1,67 @@
|
|
|
1
|
+
import { formatDate } from "./utils.js";
|
|
1
2
|
export function getCoreReviewInstruction(lang) {
|
|
2
3
|
const lowLang = (lang || "").toLowerCase();
|
|
3
4
|
if (lowLang.startsWith("zh")) {
|
|
4
5
|
if (lowLang === "zh-tw" || lowLang === "zh-hk") {
|
|
5
|
-
return
|
|
6
|
+
return `你是一位擁有 10 年以上經驗的高級軟體架構師和代碼審查專家。你的任務是對以下代碼變更進行嚴格且高質量的審查。
|
|
7
|
+
你的目標是:
|
|
8
|
+
1. 發現代碼中的 Bug、邏輯缺陷和潛在的回歸風險。
|
|
9
|
+
2. 識別性能瓶頸、記憶體洩漏或不必要的計算。
|
|
10
|
+
3. 檢查安全漏洞(如注入、越權、敏感信息洩露等)。
|
|
11
|
+
4. 評估代碼的可維護性、可讀性和是否符合最佳實踐。
|
|
12
|
+
5. 檢查是否涵蓋了必要的單元測試和邊界條件。
|
|
13
|
+
|
|
14
|
+
你的輸出格式必須清晰,請使用以下 Markdown 結構:
|
|
15
|
+
### 1. 變更總結 (Summary)
|
|
16
|
+
簡要描述這次提交的主要目的和影響面。
|
|
17
|
+
### 2. 核心缺陷 (Critical Issues)
|
|
18
|
+
列出 Bug、安全隱患或會導致程序崩潰/邏輯錯誤的問題。請註明檔案名和行號。
|
|
19
|
+
### 3. 改進建議 (Suggestions)
|
|
20
|
+
列出關於代碼風格、性能優化或架構設計的改進點。
|
|
21
|
+
### 4. 審查結論 (Conclusion)
|
|
22
|
+
如果發現明顯缺陷,總結修復建議;如果未發現明顯缺陷,請說明「未發現明顯缺陷」並指出可能的殘留風險。
|
|
23
|
+
|
|
24
|
+
注意:你正處於唯讀審查模式,請勿表現出「正在應用補丁」或「準備執行代碼」的行為。只需提供文字審查分析。`;
|
|
6
25
|
}
|
|
7
|
-
return
|
|
26
|
+
return `你是一位拥有 10 年以上经验的高级软件架构师和代码审查专家。你的任务是对以下代码变更进行严格且高质量的审查。
|
|
27
|
+
你的目标是:
|
|
28
|
+
1. 发现代码中的 Bug、逻辑缺陷和潜在的回归风险。
|
|
29
|
+
2. 识别性能瓶颈、内存泄漏或不必要的计算。
|
|
30
|
+
3. 检查安全漏洞(如注入、越权、敏感信息泄露等)。
|
|
31
|
+
4. 评估代码的可维护性、可读性和是否符合最佳实践。
|
|
32
|
+
5. 检查是否涵盖了必要的单元测试和边界条件。
|
|
33
|
+
|
|
34
|
+
你的输出格式必须清晰,请使用以下 Markdown 结构:
|
|
35
|
+
### 1. 变更总结 (Summary)
|
|
36
|
+
简要描述这次提交的主要目的和影响面。
|
|
37
|
+
### 2. 核心缺陷 (Critical Issues)
|
|
38
|
+
列出 Bug、安全隐患或会导致程序崩溃/逻辑错误的问题。请注明文件名和行号。
|
|
39
|
+
### 3. 改进建议 (Suggestions)
|
|
40
|
+
列出关于代码风格、性能优化或架构设计的改进点。
|
|
41
|
+
### 4. 审查结论 (Conclusion)
|
|
42
|
+
如果发现明显缺陷,总结修复建议;如果未发现明显缺陷,请说明“未发现明显缺陷”并指出可能的残留风险。
|
|
43
|
+
|
|
44
|
+
注意:你正处于只读审查模式,请勿表现出“正在应用补丁”或“准备执行代码”的行为。只需提供文字审查分析。`;
|
|
8
45
|
}
|
|
9
|
-
return
|
|
46
|
+
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.
|
|
47
|
+
Your goals are to:
|
|
48
|
+
1. Identify bugs, logical flaws, and potential regression risks.
|
|
49
|
+
2. Spot performance bottlenecks, memory leaks, or unnecessary computations.
|
|
50
|
+
3. Check for security vulnerabilities (e.g., injection, authorization issues, sensitive data leaks).
|
|
51
|
+
4. Evaluate maintainability, readability, and adherence to best practices.
|
|
52
|
+
5. Verify coverage of necessary unit tests and boundary conditions.
|
|
53
|
+
|
|
54
|
+
Your output must be structured using the following Markdown headers:
|
|
55
|
+
### 1. Summary
|
|
56
|
+
Briefly describe the purpose and impact of this change.
|
|
57
|
+
### 2. Critical Issues
|
|
58
|
+
List bugs, security risks, or problems that could cause crashes or logical errors. Include file names and line numbers.
|
|
59
|
+
### 3. Suggestions
|
|
60
|
+
List points for improvement regarding code style, performance, or architectural design.
|
|
61
|
+
### 4. Conclusion
|
|
62
|
+
Summarize with a "Pass" or "Needs Revision". If no clear flaws are found, state "No clear flaws found" and mention any residual risks.
|
|
63
|
+
|
|
64
|
+
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
65
|
}
|
|
11
66
|
|
|
12
67
|
export function getReviewWorkspaceRoot(config, backend, targetInfo) {
|
|
@@ -40,52 +95,52 @@ function getLanguageDisplayName(lang) {
|
|
|
40
95
|
|
|
41
96
|
const LOCALIZED_PHRASES = {
|
|
42
97
|
en: {
|
|
43
|
-
workspaceRoot: "
|
|
98
|
+
workspaceRoot: "Workspace context (read-only):",
|
|
44
99
|
noWorkspace: "No local repository workspace is available for this review run.",
|
|
45
|
-
besidesDiff: "
|
|
46
|
-
reviewFromDiff: "Review primarily
|
|
47
|
-
fileRefs: "
|
|
100
|
+
besidesDiff: "You can read related files in the workspace to understand call sites, shared utilities, configuration, or data flow.",
|
|
101
|
+
reviewFromDiff: "Review primarily based on the provided diff. Do not assume access to other local files or shell commands.",
|
|
102
|
+
fileRefs: "Reference files using plain text like 'path/to/file.js:123'. Do not generate clickable workspace links.",
|
|
48
103
|
repoType: "Repository Type",
|
|
49
104
|
changeId: "Change ID",
|
|
50
105
|
author: "Author",
|
|
51
106
|
date: "Date",
|
|
52
107
|
changedFiles: "Changed files",
|
|
53
108
|
commitMessage: "Commit message",
|
|
54
|
-
diffNoteTruncated: "
|
|
55
|
-
diffNoteFull: "
|
|
56
|
-
langRule: "---
|
|
109
|
+
diffNoteTruncated: "Note: The diff was truncated to fit size limits. Original: {originalLineCount} lines / {originalCharCount} chars. Included: {outputLineCount} lines / {outputCharCount} chars.",
|
|
110
|
+
diffNoteFull: "Note: Full diff provided ({originalLineCount} lines / {originalCharCount} chars).",
|
|
111
|
+
langRule: "--- LANGUAGE RULE ---\nYour entire response must be in {langName}. No other language allowed."
|
|
57
112
|
},
|
|
58
113
|
zh: {
|
|
59
|
-
workspaceRoot: "
|
|
114
|
+
workspaceRoot: "只读工作区上下文:",
|
|
60
115
|
noWorkspace: "此审查运行没有可用的本地仓库工作区。",
|
|
61
|
-
besidesDiff: "
|
|
62
|
-
reviewFromDiff: "
|
|
63
|
-
fileRefs: "
|
|
116
|
+
besidesDiff: "你可以阅读工作区中的其他文件以了解调用点、工具类、配置或数据流。",
|
|
117
|
+
reviewFromDiff: "主要根据提供的 Diff 进行审查。不要假设可以访问其他文件或执行 Shell 命令。",
|
|
118
|
+
fileRefs: "使用纯文本引用文件,如 'path/to/file.js:123'。不要生成可点击的链接。",
|
|
64
119
|
repoType: "仓库类型",
|
|
65
120
|
changeId: "变更 ID",
|
|
66
121
|
author: "作者",
|
|
67
122
|
date: "日期",
|
|
68
123
|
changedFiles: "已变更文件",
|
|
69
124
|
commitMessage: "提交信息",
|
|
70
|
-
diffNoteTruncated: "Diff
|
|
71
|
-
diffNoteFull: "
|
|
72
|
-
langRule: "---
|
|
125
|
+
diffNoteTruncated: "注意:Diff 已截断。原始:{originalLineCount} 行 / {originalCharCount} 字符。包含:{outputLineCount} 行 / {outputCharCount} 字符。",
|
|
126
|
+
diffNoteFull: "注意:包含完整 Diff ({originalLineCount} 行 / {originalCharCount} 字符)。",
|
|
127
|
+
langRule: "--- 语言规则 ---\n你必须完全使用 {langName} 进行回复。不得使用其他语言进行解释或总结。"
|
|
73
128
|
},
|
|
74
129
|
"zh-tw": {
|
|
75
|
-
workspaceRoot: "
|
|
130
|
+
workspaceRoot: "唯讀工作區上下文:",
|
|
76
131
|
noWorkspace: "此審查運行沒有可用的本地倉庫工作區。",
|
|
77
|
-
besidesDiff: "
|
|
78
|
-
reviewFromDiff: "
|
|
79
|
-
fileRefs: "
|
|
132
|
+
besidesDiff: "你可以閱讀工作區中的其他文件以了解調用點、工具類、配置或資料流。",
|
|
133
|
+
reviewFromDiff: "主要根據提供的 Diff 進行審查。不要假設可以訪問其他文件或執行 Shell 命令。",
|
|
134
|
+
fileRefs: "使用純文本引用文件,如 'path/to/file.js:123'。不要生成可點擊的連結。",
|
|
80
135
|
repoType: "倉庫類型",
|
|
81
136
|
changeId: "變更 ID",
|
|
82
137
|
author: "作者",
|
|
83
138
|
date: "日期",
|
|
84
139
|
changedFiles: "已變更文件",
|
|
85
140
|
commitMessage: "提交信息",
|
|
86
|
-
diffNoteTruncated: "Diff
|
|
87
|
-
diffNoteFull: "
|
|
88
|
-
langRule: "---
|
|
141
|
+
diffNoteTruncated: "注意:Diff 已截斷。原始:{originalLineCount} 行 / {originalCharCount} 字符。包含:{outputLineCount} 行 / {outputCharCount} 字符。",
|
|
142
|
+
diffNoteFull: "注意:包含完整 Diff ({originalLineCount} 行 / {originalCharCount} 字符)。",
|
|
143
|
+
langRule: "--- 語言規則 ---\n你必須完全使用 {langName} 進行回覆。不得使用其他語言進行解釋或總結。"
|
|
89
144
|
}
|
|
90
145
|
};
|
|
91
146
|
|
|
@@ -109,51 +164,52 @@ export function buildPrompt(config, backend, targetInfo, details, reviewDiffPayl
|
|
|
109
164
|
const langName = getLanguageDisplayName(lang);
|
|
110
165
|
const lowLang = lang.toLowerCase();
|
|
111
166
|
|
|
112
|
-
let langInstruction = `
|
|
113
|
-
|
|
167
|
+
let langInstruction = `CRITICAL: YOUR ENTIRE RESPONSE MUST BE IN ${langName.toUpperCase()}.`;
|
|
114
168
|
if (lowLang.startsWith("zh")) {
|
|
115
169
|
if (lowLang === "zh-tw" || lowLang === "zh-hk") {
|
|
116
|
-
langInstruction += "\n
|
|
170
|
+
langInstruction += "\n請務必完全使用繁體中文進行回覆。";
|
|
117
171
|
} else {
|
|
118
|
-
langInstruction += "\n
|
|
172
|
+
langInstruction += "\n请务必完全使用简体中文进行回复。";
|
|
119
173
|
}
|
|
120
174
|
}
|
|
121
175
|
|
|
122
|
-
|
|
176
|
+
const metadata = [
|
|
177
|
+
`${getPhrase("repoType", lang)}: ${backend.displayName}`,
|
|
178
|
+
`${getPhrase("changeId", lang)}: ${details.displayId}`,
|
|
179
|
+
`${getPhrase("author", lang)}: ${details.author}`,
|
|
180
|
+
`${getPhrase("date", lang)}: ${formatDate(details.date) || "unknown"}`,
|
|
181
|
+
`${getPhrase("changedFiles", lang)}:\n${fileList || "(none)"}`,
|
|
182
|
+
`${getPhrase("commitMessage", lang)}:\n${details.message || "(empty)"}`
|
|
183
|
+
].join("\n");
|
|
184
|
+
|
|
185
|
+
const diffNote = reviewDiffPayload.wasTruncated
|
|
186
|
+
? getPhrase("diffNoteTruncated", lang, {
|
|
187
|
+
originalLineCount: reviewDiffPayload.originalLineCount,
|
|
188
|
+
originalCharCount: reviewDiffPayload.originalCharCount,
|
|
189
|
+
outputLineCount: reviewDiffPayload.outputLineCount,
|
|
190
|
+
outputCharCount: reviewDiffPayload.outputCharCount
|
|
191
|
+
})
|
|
192
|
+
: getPhrase("diffNoteFull", lang, {
|
|
193
|
+
originalLineCount: reviewDiffPayload.originalLineCount,
|
|
194
|
+
originalCharCount: reviewDiffPayload.originalCharCount
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
const sections = [
|
|
123
198
|
langInstruction,
|
|
124
199
|
getCoreReviewInstruction(lang),
|
|
125
|
-
config.prompt,
|
|
200
|
+
config.prompt ? `### Additional User Instructions:\n${config.prompt}` : null,
|
|
201
|
+
"### Change Context:",
|
|
202
|
+
metadata,
|
|
203
|
+
diffNote,
|
|
204
|
+
"### Environment:",
|
|
126
205
|
canReadRelatedFiles
|
|
127
|
-
? `${getPhrase("workspaceRoot", lang)} ${workspaceRoot}`
|
|
206
|
+
? `${getPhrase("workspaceRoot", lang)} ${workspaceRoot}\n${getPhrase("besidesDiff", lang)}`
|
|
128
207
|
: getPhrase("noWorkspace", lang),
|
|
129
|
-
canReadRelatedFiles
|
|
130
|
-
? getPhrase("besidesDiff", lang)
|
|
131
|
-
: getPhrase("reviewFromDiff", lang),
|
|
132
208
|
getPhrase("fileRefs", lang),
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
`${getPhrase("changedFiles", lang)}:\n${fileList || "(none)"}`,
|
|
138
|
-
`${getPhrase("commitMessage", lang)}:\n${details.message || "(empty)"}`,
|
|
139
|
-
reviewDiffPayload.wasTruncated
|
|
140
|
-
? getPhrase("diffNoteTruncated", lang, {
|
|
141
|
-
originalLineCount: reviewDiffPayload.originalLineCount,
|
|
142
|
-
originalCharCount: reviewDiffPayload.originalCharCount,
|
|
143
|
-
outputLineCount: reviewDiffPayload.outputLineCount,
|
|
144
|
-
outputCharCount: reviewDiffPayload.outputCharCount
|
|
145
|
-
})
|
|
146
|
-
: getPhrase("diffNoteFull", lang, {
|
|
147
|
-
originalLineCount: reviewDiffPayload.originalLineCount,
|
|
148
|
-
originalCharCount: reviewDiffPayload.originalCharCount
|
|
149
|
-
}),
|
|
150
|
-
getPhrase("langRule", lang, { langName }) +
|
|
151
|
-
(lowLang.startsWith("zh")
|
|
152
|
-
? lowLang === "zh-tw" || lowLang === "zh-hk"
|
|
153
|
-
? "\n請務必完全使用繁體中文進行回覆,所有的審查分析、注釋和總結都必須使用繁體中文。"
|
|
154
|
-
: "\n请务必完全使用简体中文进行回复,所有的审查分析、注释和总结都必须使用简体中文。"
|
|
155
|
-
: "")
|
|
156
|
-
].filter(Boolean).join("\n\n");
|
|
209
|
+
getPhrase("langRule", lang, { langName })
|
|
210
|
+
];
|
|
211
|
+
|
|
212
|
+
return sections.filter(Boolean).join("\n\n");
|
|
157
213
|
}
|
|
158
214
|
|
|
159
215
|
export function formatTokenUsage(tokenUsage) {
|
|
@@ -205,8 +261,8 @@ export function buildReport(config, backend, targetInfo, details, diffPayloads,
|
|
|
205
261
|
`- Target: \`${targetInfo.targetDisplay || config.target}\``,
|
|
206
262
|
`- Change ID: \`${details.displayId}\``,
|
|
207
263
|
`- Author: \`${details.author}\``,
|
|
208
|
-
`- Commit Date: \`${details.date
|
|
209
|
-
`- Generated At: \`${new Date()
|
|
264
|
+
`- Commit Date: \`${formatDate(details.date)}\``,
|
|
265
|
+
`- Generated At: \`${formatDate(new Date())}\``,
|
|
210
266
|
`- Reviewer: \`${reviewer.displayName}\``,
|
|
211
267
|
`- Reviewer Exit Code: \`${reviewerResult.code}\``,
|
|
212
268
|
`- Reviewer Timed Out: \`${reviewerResult.timedOut ? "yes" : "no"}\``,
|
|
@@ -254,8 +310,8 @@ export function buildJsonReport(config, backend, targetInfo, details, diffPayloa
|
|
|
254
310
|
target: targetInfo.targetDisplay || config.target,
|
|
255
311
|
changeId: details.displayId,
|
|
256
312
|
author: details.author,
|
|
257
|
-
commitDate: details.date
|
|
258
|
-
generatedAt: new Date()
|
|
313
|
+
commitDate: formatDate(details.date),
|
|
314
|
+
generatedAt: formatDate(new Date()),
|
|
259
315
|
reviewer: {
|
|
260
316
|
name: reviewer.displayName,
|
|
261
317
|
exitCode: reviewerResult.code,
|
package/src/review-runner.js
CHANGED
|
@@ -5,7 +5,8 @@ import { logger } from "./logger.js";
|
|
|
5
5
|
import {
|
|
6
6
|
ensureDir,
|
|
7
7
|
writeTextFile,
|
|
8
|
-
writeJsonFile
|
|
8
|
+
writeJsonFile,
|
|
9
|
+
formatDate
|
|
9
10
|
} from "./utils.js";
|
|
10
11
|
import {
|
|
11
12
|
shouldWriteFormat,
|
|
@@ -42,7 +43,7 @@ async function reviewChange(config, backend, targetInfo, changeId, progress) {
|
|
|
42
43
|
repositoryType: backend.displayName,
|
|
43
44
|
target: targetInfo.targetDisplay || config.target,
|
|
44
45
|
changeId: details.displayId,
|
|
45
|
-
generatedAt: new Date()
|
|
46
|
+
generatedAt: formatDate(new Date()),
|
|
46
47
|
skipped: true,
|
|
47
48
|
message: "No file changes were captured for this change under the configured target."
|
|
48
49
|
});
|
package/src/utils.js
CHANGED
|
@@ -32,3 +32,25 @@ export function countLines(text) {
|
|
|
32
32
|
}
|
|
33
33
|
return text.split(/\r?\n/).length;
|
|
34
34
|
}
|
|
35
|
+
|
|
36
|
+
export function formatDate(dateInput) {
|
|
37
|
+
if (!dateInput || dateInput === "unknown") return "unknown";
|
|
38
|
+
const d = new Date(dateInput);
|
|
39
|
+
if (isNaN(d.getTime())) return dateInput;
|
|
40
|
+
|
|
41
|
+
const offsetMinutes = -d.getTimezoneOffset();
|
|
42
|
+
const offsetHours = Math.floor(Math.abs(offsetMinutes) / 60);
|
|
43
|
+
const offsetMins = Math.abs(offsetMinutes) % 60;
|
|
44
|
+
const sign = offsetMinutes >= 0 ? "+" : "-";
|
|
45
|
+
|
|
46
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
47
|
+
const year = d.getFullYear();
|
|
48
|
+
const month = pad(d.getMonth() + 1);
|
|
49
|
+
const day = pad(d.getDate());
|
|
50
|
+
const hours = pad(d.getHours());
|
|
51
|
+
const minutes = pad(d.getMinutes());
|
|
52
|
+
const seconds = pad(d.getSeconds());
|
|
53
|
+
const offset = `${sign}${pad(offsetHours)}:${pad(offsetMins)}`;
|
|
54
|
+
|
|
55
|
+
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds} ${offset}`;
|
|
56
|
+
}
|