kodevu 0.1.45 → 0.1.46

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.45",
3
+ "version": "0.1.46",
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.",
package/src/config.js CHANGED
@@ -66,14 +66,13 @@ function detectLanguage() {
66
66
  }
67
67
  })();
68
68
 
69
- if (os.platform() === "win32" && intlLocale.startsWith("zh")) return "zh";
70
- if (envLang.startsWith("zh")) return "zh";
71
- if (envLang.startsWith("en")) return "en";
72
- if (envLang) return envLang.split(/[._-]/)[0];
73
- if (intlLocale.startsWith("zh")) return "zh";
74
- if (intlLocale.startsWith("en")) return "en";
75
- if (intlLocale) return intlLocale.split("-")[0];
76
- return "en";
69
+ const locales = [envLang, intlLocale].filter(Boolean);
70
+ for (const loc of locales) {
71
+ if (loc.startsWith("zh")) return "zh";
72
+ if (loc.startsWith("en")) return "en";
73
+ }
74
+
75
+ return locales[0]?.split(/[._-]/)[0] || "en";
77
76
  }
78
77
 
79
78
  async function resolveAutoReviewers(debug) {
@@ -204,20 +203,9 @@ export async function resolveConfig(cliArgs = {}) {
204
203
  }
205
204
 
206
205
  // 2. Merge CLI Arguments
207
- const cliMapping = {
208
- target: "target",
209
- reviewer: "reviewer",
210
- prompt: "prompt",
211
- lang: "lang",
212
- rev: "rev",
213
- last: "last",
214
- outputDir: "outputDir",
215
- outputFormats: "outputFormats"
216
- };
217
-
218
- for (const [cliKey, configKey] of Object.entries(cliMapping)) {
219
- if (cliArgs[cliKey]) {
220
- config[configKey] = cliArgs[cliKey];
206
+ for (const key of ["target", "reviewer", "prompt", "lang", "rev", "last", "outputDir", "outputFormats"]) {
207
+ if (cliArgs[key] !== undefined && cliArgs[key] !== "") {
208
+ config[key] = cliArgs[key];
221
209
  }
222
210
  }
223
211
 
package/src/git-client.js CHANGED
@@ -61,8 +61,7 @@ export async function getTargetInfo(config) {
61
61
  requestedTargetPath,
62
62
  targetDisplay: requestedTargetPath,
63
63
  targetPathspec: relativeTargetPath ? relativeTargetPath : "",
64
- branchName: branchResult.stdout || "HEAD",
65
- stateKey: `git:${repoRootPath}:${relativeTargetPath || "."}`
64
+ branchName: branchResult.stdout || "HEAD"
66
65
  };
67
66
  }
68
67
 
@@ -81,29 +80,6 @@ export async function getLatestCommit(config, targetInfo) {
81
80
  return latestCommit;
82
81
  }
83
82
 
84
- export async function isValidCheckpoint(config, targetInfo, checkpointCommit, latestCommit) {
85
- if (!checkpointCommit) {
86
- return true;
87
- }
88
-
89
- const commitExists = await runGit(config, ["cat-file", "-e", `${checkpointCommit}^{commit}`], {
90
- cwd: targetInfo.repoRootPath,
91
- allowFailure: true,
92
- trim: true
93
- });
94
-
95
- if (commitExists.code !== 0) {
96
- return false;
97
- }
98
-
99
- const ancestorResult = await runGit(config, ["merge-base", "--is-ancestor", checkpointCommit, latestCommit], {
100
- cwd: targetInfo.repoRootPath,
101
- allowFailure: true,
102
- trim: true
103
- });
104
-
105
- return ancestorResult.code === 0;
106
- }
107
83
 
108
84
  export async function resolveCommits(config, targetInfo, revSpec) {
109
85
  const result = await runGit(
@@ -124,24 +100,6 @@ export async function resolveCommits(config, targetInfo, revSpec) {
124
100
  return splitLines(result.stdout);
125
101
  }
126
102
 
127
- export async function getPendingCommits(config, targetInfo, startExclusive, endInclusive, limit) {
128
- const args = ["rev-list", "--reverse"];
129
-
130
- if (startExclusive) {
131
- args.push(endInclusive, `^${startExclusive}`);
132
- } else {
133
- args.push(endInclusive);
134
- }
135
-
136
- args.push(...buildPathArgs(targetInfo));
137
-
138
- const result = await runGit(config, args, {
139
- cwd: targetInfo.repoRootPath,
140
- trim: true
141
- });
142
-
143
- return splitLines(result.stdout).slice(0, limit);
144
- }
145
103
 
146
104
  export async function getLatestCommitIds(config, targetInfo, limit) {
147
105
  const result = await runGit(
@@ -1,29 +1,48 @@
1
1
  import { formatDate } from "./utils.js";
2
- export function getCoreReviewInstruction(lang) {
3
- const lowLang = (lang || "").toLowerCase();
4
- if (lowLang.startsWith("zh")) {
5
- if (lowLang === "zh-tw" || lowLang === "zh-hk") {
6
- return `你是一位擁有 10 年以上經驗的高級軟體架構師和代碼審查專家。你的任務是對以下代碼變更進行嚴格且高質量的審查。
7
- 你的目標是:
8
- 1. 發現代碼中的 Bug、邏輯缺陷和潛在的回歸風險。
9
- 2. 識別性能瓶頸、記憶體洩漏或不必要的計算。
10
- 3. 檢查安全漏洞(如注入、越權、敏感信息洩露等)。
11
- 4. 評估代碼的可維護性、可讀性和是否符合最佳實踐。
12
- 5. 檢查是否涵蓋了必要的單元測試和邊界條件。
13
2
 
14
- 你的輸出格式必須清晰,請使用以下 Markdown 結構:
15
- ### 1. 變更總結 (Summary)
16
- 簡要描述這次提交的主要目的和影響面。
17
- ### 2. 核心缺陷 (Critical Issues)
18
- 列出 Bug、安全隱患或會導致程序崩潰/邏輯錯誤的問題。請註明檔案名和行號。
19
- ### 3. 改進建議 (Suggestions)
20
- 列出關於代碼風格、性能優化或架構設計的改進點。
21
- ### 4. 審查結論 (Conclusion)
22
- 如果發現明顯缺陷,總結修復建議;如果未發現明顯缺陷,請說明「未發現明顯缺陷」並指出可能的殘留風險。
3
+ const LOCALIZED_DATA = {
4
+ en: {
5
+ displayName: "English",
6
+ coreInstruction: `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.
7
+ Your goals are to:
8
+ 1. Identify bugs, logical flaws, and potential regression risks.
9
+ 2. Spot performance bottlenecks, memory leaks, or unnecessary computations.
10
+ 3. Check for security vulnerabilities (e.g., injection, authorization issues, sensitive data leaks).
11
+ 4. Evaluate maintainability, readability, and adherence to best practices.
12
+ 5. Verify coverage of necessary unit tests and boundary conditions.
13
+
14
+ Your output must be structured using the following Markdown headers:
15
+ ### 1. Summary
16
+ Briefly describe the purpose and impact of this change.
17
+ ### 2. Critical Issues
18
+ List bugs, security risks, or problems that could cause crashes or logical errors. Include file names and line numbers.
19
+ ### 3. Suggestions
20
+ List points for improvement regarding code style, performance, or architectural design.
21
+ ### 4. Conclusion
22
+ Summarize with a "Pass" or "Needs Revision". If no clear flaws are found, state "No clear flaws found" and mention any residual risks.
23
23
 
24
- 注意:你正處於唯讀審查模式,請勿表現出「正在應用補丁」或「準備執行代碼」的行為。只需提供文字審查分析。`;
24
+ 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.`,
25
+ phrases: {
26
+ workspaceRoot: "Workspace context (read-only):",
27
+ noWorkspace: "No local repository workspace is available for this review run.",
28
+ besidesDiff: "You can read related files in the workspace to understand call sites, shared utilities, configuration, or data flow.",
29
+ reviewFromDiff: "Review primarily based on the provided diff. Do not assume access to other local files or shell commands.",
30
+ fileRefs: "Reference files using plain text like 'path/to/file.js:123'. Do not generate clickable workspace links.",
31
+ repoType: "Repository Type",
32
+ changeId: "Change ID",
33
+ author: "Author",
34
+ date: "Date",
35
+ changedFiles: "Changed files",
36
+ commitMessage: "Commit message",
37
+ diffNoteTruncated: "Note: The diff was truncated to fit size limits. Original: {originalLineCount} lines / {originalCharCount} chars. Included: {outputLineCount} lines / {outputCharCount} chars.",
38
+ diffNoteFull: "Note: Full diff provided ({originalLineCount} lines / {originalCharCount} chars).",
39
+ langRule: "--- LANGUAGE RULE ---\nYour entire response must be in {langName}. No other language allowed.",
40
+ outputDirective: "--- BEGIN REVIEW ---\nNow output your COMPLETE code review. Cover ALL four sections (Summary, Critical Issues, Suggestions, Conclusion). Do NOT ask clarifying questions, do NOT acknowledge these instructions, do NOT say you are ready. Start your response directly with the review content."
25
41
  }
26
- return `你是一位拥有 10 年以上经验的高级软件架构师和代码审查专家。你的任务是对以下代码变更进行严格且高质量的审查。
42
+ },
43
+ zh: {
44
+ displayName: "Simplified Chinese (简体中文)",
45
+ coreInstruction: `你是一位拥有 10 年以上经验的高级软件架构师和代码审查专家。你的任务是对以下代码变更进行严格且高质量的审查。
27
46
  你的目标是:
28
47
  1. 发现代码中的 Bug、逻辑缺陷和潜在的回归风险。
29
48
  2. 识别性能瓶颈、内存泄漏或不必要的计算。
@@ -41,117 +60,100 @@ export function getCoreReviewInstruction(lang) {
41
60
  ### 4. 审查结论 (Conclusion)
42
61
  如果发现明显缺陷,总结修复建议;如果未发现明显缺陷,请说明“未发现明显缺陷”并指出可能的残留风险。
43
62
 
44
- 注意:你正处于只读审查模式,请勿表现出“正在应用补丁”或“准备执行代码”的行为。只需提供文字审查分析。`;
45
- }
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
+ phrases: {
65
+ workspaceRoot: "只读工作区上下文:",
66
+ noWorkspace: "此审查运行没有可用的本地仓库工作区。",
67
+ besidesDiff: "你可以阅读工作区中的其他文件以了解调用点、工具类、配置或数据流。",
68
+ reviewFromDiff: "主要根据提供的 Diff 进行审查。不要假设可以访问其他文件或执行 Shell 命令。",
69
+ fileRefs: "使用纯文本引用文件,如 'path/to/file.js:123'。不要生成可点击的链接。",
70
+ repoType: "仓库类型",
71
+ changeId: "变更 ID",
72
+ author: "作者",
73
+ date: "日期",
74
+ changedFiles: "已变更文件",
75
+ commitMessage: "提交信息",
76
+ diffNoteTruncated: "注意:Diff 已截断。原始:{originalLineCount} 行 / {originalCharCount} 字符。包含:{outputLineCount} 行 / {outputCharCount} 字符。",
77
+ diffNoteFull: "注意:包含完整 Diff ({originalLineCount} / {originalCharCount} 字符)。",
78
+ langRule: "--- 语言规则 ---\n你必须完全使用 {langName} 进行回复。不得使用其他语言进行解释或总结。",
79
+ outputDirective: "--- 开始输出审查结果 ---\n请立即输出完整的代码审查结果,必须包含全部四个章节(变更总结、核心缺陷、改进建议、审查结论)。不要提问,不要确认收到指令,不要说准备好了,直接以审查内容开始输出。"
80
+ }
81
+ },
82
+ "zh-tw": {
83
+ displayName: "Traditional Chinese (繁體中文)",
84
+ coreInstruction: `你是一位擁有 10 年以上經驗的高級軟體架構師和代碼審查專家。你的任務是對以下代碼變更進行嚴格且高質量的審查。
85
+ 你的目標是:
86
+ 1. 發現代碼中的 Bug、邏輯缺陷和潛在的回歸風險。
87
+ 2. 識別性能瓶頸、記憶體洩漏或不必要的計算。
88
+ 3. 檢查安全漏洞(如注入、越權、敏感信息洩露等)。
89
+ 4. 評估代碼的可維護性、可讀性和是否符合最佳實踐。
90
+ 5. 檢查是否涵蓋了必要的單元測試和邊界條件。
63
91
 
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.`;
65
- }
92
+ 你的輸出格式必須清晰,請使用以下 Markdown 結構:
93
+ ### 1. 變更總結 (Summary)
94
+ 簡要描述這次提交的主要目的和影響面。
95
+ ### 2. 核心缺陷 (Critical Issues)
96
+ 列出 Bug、安全隱患或會導致程序崩潰/邏輯錯誤的問題。請註明檔案名和行號。
97
+ ### 3. 改進建議 (Suggestions)
98
+ 列出關於代碼風格、性能優化或架構設計的改進點。
99
+ ### 4. 審查結論 (Conclusion)
100
+ 如果發現明顯缺陷,總結修復建議;如果未發現明顯缺陷,請說明「未發現明顯缺陷」並指出可能的殘留風險。
66
101
 
67
- export function getReviewWorkspaceRoot(config, backend, targetInfo) {
68
- if (backend.kind === "git" && targetInfo.repoRootPath) {
69
- return targetInfo.repoRootPath;
102
+ 注意:你正處於唯讀審查模式,請勿表現出「正在應用補丁」或「準備執行代碼」的行為。只需提供文字審查分析。`,
103
+ phrases: {
104
+ workspaceRoot: "唯讀工作區上下文:",
105
+ noWorkspace: "此審查運行沒有可用的本地倉庫工作區。",
106
+ besidesDiff: "你可以閱讀工作區中的其他文件以了解調用點、工具類、配置或資料流。",
107
+ reviewFromDiff: "主要根據提供的 Diff 進行審查。不要假設可以訪問其他文件或執行 Shell 命令。",
108
+ fileRefs: "使用純文本引用文件,如 'path/to/file.js:123'。不要生成可點擊的連結。",
109
+ repoType: "倉庫類型",
110
+ changeId: "變更 ID",
111
+ author: "作者",
112
+ date: "日期",
113
+ changedFiles: "已變更文件",
114
+ commitMessage: "提交信息",
115
+ diffNoteTruncated: "注意:Diff 已截斷。原始:{originalLineCount} 行 / {originalCharCount} 字符。包含:{outputLineCount} 行 / {outputCharCount} 字符。",
116
+ diffNoteFull: "注意:包含完整 Diff ({originalLineCount} 行 / {originalCharCount} 字符)。",
117
+ langRule: "--- 語言規則 ---\n你必須完全使用 {langName} 進行回覆。不得使用其他語言進行解釋或總結。",
118
+ outputDirective: "--- 開始輸出審查結果 ---\n請立即輸出完整的代碼審查結果,必須包含全部四個章節(變更總結、核心缺陷、改進建議、審查結論)。不要提問,不要確認收到指令,不要說準備好了,直接以審查內容開始輸出。"
119
+ }
70
120
  }
121
+ };
71
122
 
72
- if (backend.kind === "svn" && targetInfo.workingCopyPath) {
73
- return targetInfo.workingCopyPath;
123
+ function getLangKey(lang) {
124
+ const lowArg = (lang || "en").toLowerCase();
125
+ if (lowArg.startsWith("zh")) {
126
+ return (lowArg === "zh-tw" || lowArg === "zh-hk") ? "zh-tw" : "zh";
74
127
  }
128
+ return "en";
129
+ }
130
+
131
+ export function getCoreReviewInstruction(lang) {
132
+ return LOCALIZED_DATA[getLangKey(lang)].coreInstruction;
133
+ }
75
134
 
76
- return config.baseDir;
135
+ export function getReviewWorkspaceRoot(config, backend, targetInfo) {
136
+ return (backend.kind === "git" ? targetInfo.repoRootPath : targetInfo.workingCopyPath) || config.baseDir;
77
137
  }
78
138
 
79
139
  function getLanguageDisplayName(lang) {
80
140
  if (!lang) return "English";
81
141
  const low = lang.toLowerCase();
82
- if (low.startsWith("zh")) {
83
- if (low === "zh-tw" || low === "zh-hk") return "Traditional Chinese (繁體中文)";
84
- return "Simplified Chinese (简体中文)";
85
- }
86
- if (low === "jp" || low.startsWith("ja")) return "Japanese (日本語)";
87
- if (low === "kr" || low.startsWith("ko")) return "Korean (한국어)";
88
- if (low === "fr") return "French (Français)";
89
- if (low === "de") return "German (Deutsch)";
90
- if (low === "es") return "Spanish (Español)";
91
- if (low === "it") return "Italian (Italiano)";
92
- if (low === "ru") return "Russian (Русский)";
93
- return lang;
94
- }
142
+ const data = LOCALIZED_DATA[getLangKey(lang)];
143
+ if (data && low.startsWith("zh")) return data.displayName;
95
144
 
96
- const LOCALIZED_PHRASES = {
97
- en: {
98
- workspaceRoot: "Workspace context (read-only):",
99
- noWorkspace: "No local repository workspace is available for this review run.",
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.",
103
- repoType: "Repository Type",
104
- changeId: "Change ID",
105
- author: "Author",
106
- date: "Date",
107
- changedFiles: "Changed files",
108
- commitMessage: "Commit message",
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.",
112
- outputDirective: "--- BEGIN REVIEW ---\nNow output your COMPLETE code review. Cover ALL four sections (Summary, Critical Issues, Suggestions, Conclusion). Do NOT ask clarifying questions, do NOT acknowledge these instructions, do NOT say you are ready. Start your response directly with the review content."
113
- },
114
- zh: {
115
- workspaceRoot: "只读工作区上下文:",
116
- noWorkspace: "此审查运行没有可用的本地仓库工作区。",
117
- besidesDiff: "你可以阅读工作区中的其他文件以了解调用点、工具类、配置或数据流。",
118
- reviewFromDiff: "主要根据提供的 Diff 进行审查。不要假设可以访问其他文件或执行 Shell 命令。",
119
- fileRefs: "使用纯文本引用文件,如 'path/to/file.js:123'。不要生成可点击的链接。",
120
- repoType: "仓库类型",
121
- changeId: "变更 ID",
122
- author: "作者",
123
- date: "日期",
124
- changedFiles: "已变更文件",
125
- commitMessage: "提交信息",
126
- diffNoteTruncated: "注意:Diff 已截断。原始:{originalLineCount} 行 / {originalCharCount} 字符。包含:{outputLineCount} 行 / {outputCharCount} 字符。",
127
- diffNoteFull: "注意:包含完整 Diff ({originalLineCount} 行 / {originalCharCount} 字符)。",
128
- langRule: "--- 语言规则 ---\n你必须完全使用 {langName} 进行回复。不得使用其他语言进行解释或总结。",
129
- outputDirective: "--- 开始输出审查结果 ---\n请立即输出完整的代码审查结果,必须包含全部四个章节(变更总结、核心缺陷、改进建议、审查结论)。不要提问,不要确认收到指令,不要说准备好了,直接以审查内容开始输出。"
130
- },
131
- "zh-tw": {
132
- workspaceRoot: "唯讀工作區上下文:",
133
- noWorkspace: "此審查運行沒有可用的本地倉庫工作區。",
134
- besidesDiff: "你可以閱讀工作區中的其他文件以了解調用點、工具類、配置或資料流。",
135
- reviewFromDiff: "主要根據提供的 Diff 進行審查。不要假設可以訪問其他文件或執行 Shell 命令。",
136
- fileRefs: "使用純文本引用文件,如 'path/to/file.js:123'。不要生成可點擊的連結。",
137
- repoType: "倉庫類型",
138
- changeId: "變更 ID",
139
- author: "作者",
140
- date: "日期",
141
- changedFiles: "已變更文件",
142
- commitMessage: "提交信息",
143
- diffNoteTruncated: "注意:Diff 已截斷。原始:{originalLineCount} 行 / {originalCharCount} 字符。包含:{outputLineCount} 行 / {outputCharCount} 字符。",
144
- diffNoteFull: "注意:包含完整 Diff ({originalLineCount} 行 / {originalCharCount} 字符)。",
145
- langRule: "--- 語言規則 ---\n你必須完全使用 {langName} 進行回覆。不得使用其他語言進行解釋或總結。",
146
- outputDirective: "--- 開始輸出審查結果 ---\n請立即輸出完整的代碼審查結果,必須包含全部四個章節(變更總結、核心缺陷、改進建議、審查結論)。不要提問,不要確認收到指令,不要說準備好了,直接以審查內容開始輸出。"
147
- }
148
- };
145
+ const extras = {
146
+ jp: "Japanese (日本語)", ja: "Japanese (日本語)",
147
+ kr: "Korean (한국어)", ko: "Korean (한국어)",
148
+ fr: "French (Français)", de: "German (Deutsch)",
149
+ es: "Spanish (Español)", it: "Italian (Italiano)",
150
+ ru: "Russian (Русский)"
151
+ };
152
+ return extras[low] || extras[low.split("-")[0]] || lang;
153
+ }
149
154
 
150
155
  function getPhrase(key, lang, placeholders = {}) {
151
- const lowLang = (lang || "en").toLowerCase();
152
- const langKey = lowLang.startsWith("zh") ? (lowLang === "zh-tw" || lowLang === "zh-hk" ? "zh-tw" : "zh") : "en";
153
- let phrase = LOCALIZED_PHRASES[langKey][key] || LOCALIZED_PHRASES.en[key];
154
-
156
+ let phrase = LOCALIZED_DATA[getLangKey(lang)].phrases[key] || LOCALIZED_DATA.en.phrases[key];
155
157
  for (const [k, v] of Object.entries(placeholders)) {
156
158
  phrase = phrase.replace(`{${k}}`, v);
157
159
  }
package/src/svn-client.js CHANGED
@@ -57,7 +57,6 @@ export async function getTargetInfo(config) {
57
57
  targetUrl,
58
58
  targetRepoPath,
59
59
  targetDisplay: config.target,
60
- stateKey: `svn:${targetUrl}`,
61
60
  workingCopyPath:
62
61
  entry["wc-info"]?.["wcroot-abspath"] || (path.isAbsolute(config.target) ? config.target : null)
63
62
  };
@@ -84,33 +83,6 @@ export async function getLatestRevision(config, targetInfo) {
84
83
  return revision;
85
84
  }
86
85
 
87
- export async function getPendingRevisions(config, targetInfo, startExclusive, endInclusive, limit) {
88
- const startRevision = Number.isInteger(startExclusive) ? startExclusive + 1 : 1;
89
-
90
- if (endInclusive < startRevision) {
91
- return [];
92
- }
93
-
94
- const result = await runCommand(
95
- SVN_COMMAND,
96
- [
97
- "log",
98
- "--xml",
99
- "--quiet",
100
- "-r",
101
- `${startRevision}:${endInclusive}`,
102
- getRemoteTarget(targetInfo, config)
103
- ],
104
- { encoding: COMMAND_ENCODING, trim: true, debug: config.debug }
105
- );
106
- const parsed = xmlParser.parse(result.stdout);
107
-
108
- return asArray(parsed?.log?.logentry)
109
- .map((entry) => Number(entry?.revision))
110
- .filter((revision) => Number.isInteger(revision))
111
- .sort((left, right) => left - right)
112
- .slice(0, limit);
113
- }
114
86
 
115
87
  export async function getLatestRevisionIds(config, targetInfo, limit) {
116
88
  const result = await runCommand(
@@ -6,7 +6,7 @@ export function estimateTokenCount(text) {
6
6
  return Math.ceil(text.length / 4);
7
7
  }
8
8
 
9
- export function parseGeminiTokenUsage(stderr) {
9
+ export function parseTokenUsage(stderr) {
10
10
  if (!stderr) {
11
11
  return null;
12
12
  }
@@ -32,67 +32,8 @@ export function parseGeminiTokenUsage(stderr) {
32
32
  return { inputTokens, outputTokens, totalTokens };
33
33
  }
34
34
 
35
- export function parseCodexTokenUsage(stderr) {
36
- if (!stderr) {
37
- return null;
38
- }
39
-
40
- const patterns = [
41
- /input[_ ]tokens?\s*[:=]\s*(\d+)/i,
42
- /output[_ ]tokens?\s*[:=]\s*(\d+)/i,
43
- /total[_ ]tokens?\s*[:=]\s*(\d+)/i
44
- ];
45
-
46
- const inputMatch = stderr.match(patterns[0]);
47
- const outputMatch = stderr.match(patterns[1]);
48
- const totalMatch = stderr.match(patterns[2]);
49
-
50
- if (!inputMatch && !outputMatch && !totalMatch) {
51
- return null;
52
- }
53
-
54
- const inputTokens = inputMatch ? Number(inputMatch[1]) : 0;
55
- const outputTokens = outputMatch ? Number(outputMatch[1]) : 0;
56
- const totalTokens = totalMatch ? Number(totalMatch[1]) : inputTokens + outputTokens;
57
-
58
- return { inputTokens, outputTokens, totalTokens };
59
- }
60
-
61
- export function parseCopilotTokenUsage(stderr) {
62
- if (!stderr) {
63
- return null;
64
- }
65
-
66
- const patterns = [
67
- /input[_ ]tokens?\s*[:=]\s*(\d+)/i,
68
- /output[_ ]tokens?\s*[:=]\s*(\d+)/i,
69
- /total[_ ]tokens?\s*[:=]\s*(\d+)/i
70
- ];
71
-
72
- const inputMatch = stderr.match(patterns[0]);
73
- const outputMatch = stderr.match(patterns[1]);
74
- const totalMatch = stderr.match(patterns[2]);
75
-
76
- if (!inputMatch && !outputMatch && !totalMatch) {
77
- return null;
78
- }
79
-
80
- const inputTokens = inputMatch ? Number(inputMatch[1]) : 0;
81
- const outputTokens = outputMatch ? Number(outputMatch[1]) : 0;
82
- const totalTokens = totalMatch ? Number(totalMatch[1]) : inputTokens + outputTokens;
83
-
84
- return { inputTokens, outputTokens, totalTokens };
85
- }
86
-
87
- export const TOKEN_PARSERS = {
88
- gemini: parseGeminiTokenUsage,
89
- codex: parseCodexTokenUsage,
90
- copilot: parseCopilotTokenUsage
91
- };
92
-
93
35
  export function resolveTokenUsage(reviewerName, stderr, promptText, diffText, responseText) {
94
- const parseFn = TOKEN_PARSERS[reviewerName] || parseCopilotTokenUsage;
95
- const parsed = parseFn(stderr);
36
+ const parsed = parseTokenUsage(stderr);
96
37
 
97
38
  if (parsed && parsed.totalTokens > 0) {
98
39
  return { ...parsed, source: "reviewer" };
package/src/utils.js CHANGED
@@ -54,3 +54,16 @@ export function formatDate(dateInput) {
54
54
 
55
55
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds} ${offset}`;
56
56
  }
57
+ export function getTimestampPrefix() {
58
+ const now = new Date();
59
+ const pad = (n) => String(n).padStart(2, "0");
60
+ return (
61
+ now.getFullYear() +
62
+ pad(now.getMonth() + 1) +
63
+ pad(now.getDate()) +
64
+ "-" +
65
+ pad(now.getHours()) +
66
+ pad(now.getMinutes()) +
67
+ pad(now.getSeconds())
68
+ );
69
+ }
package/src/vcs-client.js CHANGED
@@ -1,21 +1,12 @@
1
- import fs from "node:fs/promises";
2
1
  import path from "node:path";
3
2
  import * as gitClient from "./git-client.js";
4
3
  import * as svnClient from "./svn-client.js";
4
+ import { pathExists, getTimestampPrefix } from "./utils.js";
5
5
 
6
6
  function isLikelyUrl(value) {
7
7
  return /^[a-z][a-z0-9+.-]*:\/\//i.test(value);
8
8
  }
9
9
 
10
- async function pathExists(targetPath) {
11
- try {
12
- await fs.access(targetPath);
13
- return true;
14
- } catch {
15
- return false;
16
- }
17
- }
18
-
19
10
  function createSvnBackend() {
20
11
  return {
21
12
  kind: "svn",
@@ -25,15 +16,7 @@ function createSvnBackend() {
25
16
  return `r${revision}`;
26
17
  },
27
18
  getReportFileName(revision) {
28
- const now = new Date();
29
- const datePrefix = now.getFullYear() +
30
- String(now.getMonth() + 1).padStart(2, '0') +
31
- String(now.getDate()).padStart(2, '0') +
32
- '-' +
33
- String(now.getHours()).padStart(2, '0') +
34
- String(now.getMinutes()).padStart(2, '0') +
35
- String(now.getSeconds()).padStart(2, '0');
36
- return `${datePrefix}-svn-r${revision}.md`;
19
+ return `${getTimestampPrefix()}-svn-r${revision}.md`;
37
20
  },
38
21
 
39
22
  async resolveChangeIds(config, targetInfo, revString) {
@@ -76,15 +59,7 @@ function createGitBackend() {
76
59
  return commitHash.slice(0, 12);
77
60
  },
78
61
  getReportFileName(commitHash) {
79
- const now = new Date();
80
- const datePrefix = now.getFullYear() +
81
- String(now.getMonth() + 1).padStart(2, '0') +
82
- String(now.getDate()).padStart(2, '0') +
83
- '-' +
84
- String(now.getHours()).padStart(2, '0') +
85
- String(now.getMinutes()).padStart(2, '0') +
86
- String(now.getSeconds()).padStart(2, '0');
87
- return `${datePrefix}-git-${commitHash.slice(0, 12)}.md`;
62
+ return `${getTimestampPrefix()}-git-${commitHash.slice(0, 12)}.md`;
88
63
  },
89
64
 
90
65
  async resolveChangeIds(config, targetInfo, revString) {