kodevu 0.1.31 → 0.1.32

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kodevu",
3
- "version": "0.1.31",
3
+ "version": "0.1.32",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "Poll SVN revisions or Git commits, send each change diff to a reviewer CLI, and write configurable review reports.",
@@ -1,5 +1,13 @@
1
- export const CORE_REVIEW_INSTRUCTION =
2
- "Please strictly review the current changes, prioritizing bugs, regression risks, compatibility issues, security concerns, boundary condition flaws, and missing tests. Please use Markdown for your response. If no clear flaws are found, write \"No clear flaws found\" and supplement with residual risks.";
1
+ export function getCoreReviewInstruction(lang) {
2
+ const lowLang = (lang || "").toLowerCase();
3
+ if (lowLang.startsWith("zh")) {
4
+ if (lowLang === "zh-tw" || lowLang === "zh-hk") {
5
+ return "請嚴格審查目前的更改,優先考慮錯誤、回歸風險、相容性問題、安全問題、邊界條件缺陷和缺失的測試。請使用 Markdown 進行回覆。如果未發現明顯缺陷,請寫「未發現明顯缺陷」並補充風險。";
6
+ }
7
+ return "请严格审查当前的更改,优先处理 Bug、回归风险、兼容性问题、安全问题、边界条件缺陷和缺失的测试。请使用 Markdown 进行回复。如果未发现明显缺陷,请写“未发现明显缺陷”并补充残留风险。";
8
+ }
9
+ return "Please strictly review the current changes, prioritizing bugs, regression risks, compatibility issues, security concerns, boundary condition flaws, and missing tests. Please use Markdown for your response. If no clear flaws are found, write \"No clear flaws found\" and supplement with residual risks.";
10
+ }
3
11
 
4
12
  export function getReviewWorkspaceRoot(config, backend, targetInfo) {
5
13
  if (backend.kind === "git" && targetInfo.repoRootPath) {
@@ -30,13 +38,77 @@ function getLanguageDisplayName(lang) {
30
38
  return lang;
31
39
  }
32
40
 
41
+ const LOCALIZED_PHRASES = {
42
+ en: {
43
+ workspaceRoot: "You are running inside a read-only workspace rooted at:",
44
+ noWorkspace: "No local repository workspace is available for this review run.",
45
+ besidesDiff: "Besides the diff below, you may read other related files in the workspace when needed to understand call sites, shared utilities, configuration, tests, or data flow. Do not modify files or rely on shell commands.",
46
+ reviewFromDiff: "Review primarily from the diff below. Do not assume access to other local files, shell commands, or repository history.",
47
+ fileRefs: "Use plain text file references like path/to/file.js:123. Do not emit clickable workspace links.",
48
+ repoType: "Repository Type",
49
+ changeId: "Change ID",
50
+ author: "Author",
51
+ date: "Date",
52
+ changedFiles: "Changed files",
53
+ commitMessage: "Commit message",
54
+ diffNoteTruncated: "Diff delivery note: the diff was truncated before being sent to the reviewer to stay within configured size limits. Original diff size was {originalLineCount} lines / {originalCharCount} chars, and the included excerpt is {outputLineCount} lines / {outputCharCount} chars. Use the changed file list and inspect related workspace files when needed.",
55
+ diffNoteFull: "Diff delivery note: the full diff is included. Size is {originalLineCount} lines / {originalCharCount} chars.",
56
+ langRule: "--- IMPORTANT LANGUAGE RULE ---\nYou MUST respond strictly in {langName}. No other language should be used for the explanation and comments."
57
+ },
58
+ zh: {
59
+ workspaceRoot: "你正运行在一个只读工作区内,根目录为:",
60
+ noWorkspace: "此审查运行没有可用的本地仓库工作区。",
61
+ besidesDiff: "除了下面的 Diff,你可以在需要时阅读工作区中的其他相关文件,以了解调用点、共享工具、配置、测试或数据流。请勿修改文件或依赖 Shell 命令。",
62
+ reviewFromDiff: "主要根据下面的 Diff 进行审查。不要假设可以访问其他本地文件、Shell 命令或仓库历史。",
63
+ fileRefs: "使用纯文本文件引用,如 path/to/file.js:123。不要生成可点击的工作区链接。",
64
+ repoType: "仓库类型",
65
+ changeId: "变更 ID",
66
+ author: "作者",
67
+ date: "日期",
68
+ changedFiles: "已变更文件",
69
+ commitMessage: "提交信息",
70
+ diffNoteTruncated: "Diff 交付说明:Diff 在发送给审查者之前已被截斷,以保持在配置的大小限制内。原始 Diff 大小为 {originalLineCount} 行 / {originalCharCount} 个字符,包含的摘录为 {outputLineCount} 行 / {outputCharCount} 个字符。在需要时使用已更正文件列表并检查相关工作区文件。",
71
+ diffNoteFull: "Diff 交付说明:包含完整的 Diff。大小为 {originalLineCount} 行 / {originalCharCount} 个字符。",
72
+ langRule: "--- 重要语言规则 ---\n你必须严格使用 {langName} 进行回复。解释、评论和总结均不得使用其他语言。"
73
+ },
74
+ "zh-tw": {
75
+ workspaceRoot: "你正運行在一個唯讀工作區內,根目錄為:",
76
+ noWorkspace: "此審查運行沒有可用的本地倉庫工作區。",
77
+ besidesDiff: "除了下面的 Diff,你可以在需要時閱讀工作區中的其他相關文件,以了解調用點、共享工具、配置、測試或資料流。請勿修改文件或依賴 Shell 命令。",
78
+ reviewFromDiff: "主要根據下面的 Diff 進行審查。不要假設可以訪問其他本地文件、Shell 命令或倉庫歷史。",
79
+ fileRefs: "使用純文本文件引用,如 path/to/file.js:123。不要生成可點擊的工作區連結。",
80
+ repoType: "倉庫類型",
81
+ changeId: "變更 ID",
82
+ author: "作者",
83
+ date: "日期",
84
+ changedFiles: "已變更文件",
85
+ commitMessage: "提交信息",
86
+ diffNoteTruncated: "Diff 交付說明:Diff 在傳送給審查者之前已被截斷,以保持在配置的大小限制內。原始 Diff 大小為 {originalLineCount} 行 / {originalCharCount} 個字符,包含的摘錄為 {outputLineCount} 行 / {outputCharCount} 個字符。在需要時使用已更正文件列表並檢查相關工作區文件。",
87
+ diffNoteFull: "Diff 交付說明:包含完整的 Diff。大小為 {originalLineCount} 行 / {originalCharCount} 個字符。",
88
+ langRule: "--- 重要語言規則 ---\n你必須嚴格使用 {langName} 進行回覆。解釋、評論和總結均不得使用其他語言。"
89
+ }
90
+ };
91
+
92
+ function getPhrase(key, lang, placeholders = {}) {
93
+ const lowLang = (lang || "en").toLowerCase();
94
+ const langKey = lowLang.startsWith("zh") ? (lowLang === "zh-tw" || lowLang === "zh-hk" ? "zh-tw" : "zh") : "en";
95
+ let phrase = LOCALIZED_PHRASES[langKey][key] || LOCALIZED_PHRASES.en[key];
96
+
97
+ for (const [k, v] of Object.entries(placeholders)) {
98
+ phrase = phrase.replace(`{${k}}`, v);
99
+ }
100
+ return phrase;
101
+ }
102
+
33
103
  export function buildPrompt(config, backend, targetInfo, details, reviewDiffPayload) {
34
104
  const fileList = details.changedPaths.map((item) => `${item.action} ${item.relativePath}`).join("\n");
35
105
  const workspaceRoot = getReviewWorkspaceRoot(config, backend, targetInfo);
36
106
  const canReadRelatedFiles = backend.kind === "git" || Boolean(targetInfo.workingCopyPath);
37
107
 
38
- const langName = getLanguageDisplayName(config.resolvedLang);
39
- const lowLang = (config.resolvedLang || "").toLowerCase();
108
+ const lang = config.resolvedLang || "en";
109
+ const langName = getLanguageDisplayName(lang);
110
+ const lowLang = lang.toLowerCase();
111
+
40
112
  let langInstruction = `IMPORTANT: Your entire response MUST be in ${langName}. All explanations, comments, and structure should strictly follow the ${langName} language rules.`;
41
113
 
42
114
  if (lowLang.startsWith("zh")) {
@@ -47,39 +119,41 @@ export function buildPrompt(config, backend, targetInfo, details, reviewDiffPayl
47
119
  }
48
120
  }
49
121
 
50
-
51
-
52
122
  return [
53
- CORE_REVIEW_INSTRUCTION,
54
123
  langInstruction,
124
+ getCoreReviewInstruction(lang),
55
125
  config.prompt,
56
126
  canReadRelatedFiles
57
- ? `You are running inside a read-only workspace rooted at: ${workspaceRoot}`
58
- : "No local repository workspace is available for this review run.",
127
+ ? `${getPhrase("workspaceRoot", lang)} ${workspaceRoot}`
128
+ : getPhrase("noWorkspace", lang),
59
129
  canReadRelatedFiles
60
- ? "Besides the diff below, you may read other related files in the workspace when needed to understand call sites, shared utilities, configuration, tests, or data flow. Do not modify files or rely on shell commands."
61
- : "Review primarily from the diff below. Do not assume access to other local files, shell commands, or repository history.",
62
- "Use plain text file references like path/to/file.js:123. Do not emit clickable workspace links.",
63
- `Repository Type: ${backend.displayName}`,
64
- `Change ID: ${details.displayId}`,
65
- `Author: ${details.author}`,
66
- `Date: ${details.date || "unknown"}`,
67
- `Changed files:\n${fileList || "(none)"}`,
68
- `Commit message:\n${details.message || "(empty)"}`,
130
+ ? getPhrase("besidesDiff", lang)
131
+ : getPhrase("reviewFromDiff", lang),
132
+ getPhrase("fileRefs", lang),
133
+ `${getPhrase("repoType", lang)}: ${backend.displayName}`,
134
+ `${getPhrase("changeId", lang)}: ${details.displayId}`,
135
+ `${getPhrase("author", lang)}: ${details.author}`,
136
+ `${getPhrase("date", lang)}: ${details.date || "unknown"}`,
137
+ `${getPhrase("changedFiles", lang)}:\n${fileList || "(none)"}`,
138
+ `${getPhrase("commitMessage", lang)}:\n${details.message || "(empty)"}`,
69
139
  reviewDiffPayload.wasTruncated
70
- ? `Diff delivery note: the diff was truncated before being sent to the reviewer to stay within configured size limits. Original diff size was ${reviewDiffPayload.originalLineCount} lines / ${reviewDiffPayload.originalCharCount} chars, and the included excerpt is ${reviewDiffPayload.outputLineCount} lines / ${reviewDiffPayload.outputCharCount} chars. Use the changed file list and inspect related workspace files when needed.`
71
- : `Diff delivery note: the full diff is included. Size is ${reviewDiffPayload.originalLineCount} lines / ${reviewDiffPayload.originalCharCount} chars.`,
72
- `--- IMPORTANT LANGUAGE RULE ---\nYou MUST respond strictly in ${langName}. No other language should be used for the explanation and comments.${
73
- lowLang.startsWith("zh")
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")
74
152
  ? lowLang === "zh-tw" || lowLang === "zh-hk"
75
153
  ? "\n請務必完全使用繁體中文進行回覆,所有的審查分析、注釋和總結都必須使用繁體中文。"
76
154
  : "\n请务必完全使用简体中文进行回复,所有的审查分析、注释和总结都必须使用简体中文。"
77
- : ""
78
- }`
79
-
155
+ : "")
80
156
  ].filter(Boolean).join("\n\n");
81
-
82
-
83
157
  }
84
158
 
85
159
  export function formatTokenUsage(tokenUsage) {