smart-review 1.0.1 → 1.0.2
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/README.en-US.md +580 -0
- package/README.md +93 -54
- package/bin/install.js +192 -55
- package/bin/review.js +42 -47
- package/index.js +0 -1
- package/lib/ai-client-pool.js +63 -25
- package/lib/ai-client.js +262 -415
- package/lib/config-loader.js +35 -7
- package/lib/default-config.js +33 -24
- package/lib/reviewer.js +267 -97
- package/lib/segmented-analyzer.js +102 -126
- package/lib/utils/git-diff-parser.js +9 -8
- package/lib/utils/i18n.js +986 -0
- package/package.json +2 -10
- package/templates/rules/en-US/best-practices.js +111 -0
- package/templates/rules/en-US/performance.js +123 -0
- package/templates/rules/en-US/security.js +311 -0
- package/templates/rules/zh-CN/best-practices.js +111 -0
- package/templates/rules/zh-CN/performance.js +123 -0
- package/templates/rules/zh-CN/security.js +311 -0
- package/templates/smart-review.json +2 -1
|
@@ -0,0 +1,986 @@
|
|
|
1
|
+
// Internationalization utilities: messages, prompt builders, and helpers
|
|
2
|
+
|
|
3
|
+
// Determine effective locale from config or environment
|
|
4
|
+
export function getLocale(configOrLocale) {
|
|
5
|
+
const raw = typeof configOrLocale === 'string'
|
|
6
|
+
? configOrLocale
|
|
7
|
+
: (configOrLocale?.locale || process.env.SMART_REVIEW_LOCALE || 'zh-CN');
|
|
8
|
+
const lower = String(raw).toLowerCase();
|
|
9
|
+
if (lower.startsWith('en')) return 'en-US';
|
|
10
|
+
return 'zh-CN';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function format(str, params) {
|
|
14
|
+
if (!params) return str;
|
|
15
|
+
return String(str).replace(/\{(\w+)\}/g, (m, k) => (params[k] !== undefined ? String(params[k]) : m));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Field labels used in AI outputs and parsing
|
|
19
|
+
export const FIELD_LABELS = {
|
|
20
|
+
'zh-CN': {
|
|
21
|
+
file: '文件路径:',
|
|
22
|
+
risk: '风险等级:',
|
|
23
|
+
reason: '风险原因:',
|
|
24
|
+
suggestion: '修改建议:',
|
|
25
|
+
snippet: '代码片段:',
|
|
26
|
+
content: '代码内容:'
|
|
27
|
+
},
|
|
28
|
+
'en-US': {
|
|
29
|
+
file: 'File Path:',
|
|
30
|
+
risk: 'Risk Level:',
|
|
31
|
+
reason: 'Risk Reason:',
|
|
32
|
+
suggestion: 'Suggestions:',
|
|
33
|
+
snippet: 'Code Snippet:',
|
|
34
|
+
content: 'Code Content:'
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// Display risk in target language
|
|
39
|
+
export function displayRisk(risk, localeOrConfig) {
|
|
40
|
+
const loc = getLocale(localeOrConfig);
|
|
41
|
+
const DICT_RISK = {
|
|
42
|
+
'zh-CN': {
|
|
43
|
+
critical: '致命',
|
|
44
|
+
high: '高危',
|
|
45
|
+
medium: '中危',
|
|
46
|
+
low: '低危',
|
|
47
|
+
suggestion: '建议'
|
|
48
|
+
},
|
|
49
|
+
'en-US': {
|
|
50
|
+
critical: 'Critical',
|
|
51
|
+
high: 'High',
|
|
52
|
+
medium: 'Medium',
|
|
53
|
+
low: 'Low',
|
|
54
|
+
suggestion: 'Suggestion'
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const dict = DICT_RISK[loc] || DICT_RISK['en-US'];
|
|
58
|
+
return dict[risk] || risk;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Translated message catalog
|
|
62
|
+
const MESSAGES = {
|
|
63
|
+
'zh-CN': {
|
|
64
|
+
// Git hook script messages (pre-rendered at install time)
|
|
65
|
+
hook_header_comment: '智能代码审查 - pre-commit钩子(子项目兼容,基于暂存文件逐层定位)',
|
|
66
|
+
hook_start_review: '🔍 启动代码审查...',
|
|
67
|
+
hook_no_staged: '📭 没有暂存的文件需要审查',
|
|
68
|
+
hook_found_staged_header: '📁 发现暂存文件:',
|
|
69
|
+
hook_cd_repo_fail: '❌ 无法进入仓库根目录',
|
|
70
|
+
hook_cmd_not_found1: '❌ 未找到 smart-review。请在对应子项目安装:npm i -D smart-review',
|
|
71
|
+
hook_cmd_not_found2: ' 或在仓库根安装供统一使用:npm i -D smart-review',
|
|
72
|
+
hook_use_command_prefix: '⚙️ 使用命令:',
|
|
73
|
+
hook_review_fail: '❌ 代码审查未通过,请修复问题后重新提交',
|
|
74
|
+
hook_review_pass: '✅ 代码审查通过,继续提交',
|
|
75
|
+
|
|
76
|
+
// Install
|
|
77
|
+
install_search_git_root_dbg: '查找Git根目录,从 {dir} 开始...',
|
|
78
|
+
install_found_git_root_success: '找到Git根目录: {dir}',
|
|
79
|
+
install_no_git_use_current: 'ℹ️ 未找到.git目录,使用当前目录作为项目根目录',
|
|
80
|
+
install_start: '🚀 开始安装智能代码审查系统...',
|
|
81
|
+
install_done_success: '🎉 智能代码审查系统安装完成!',
|
|
82
|
+
install_bundled_info: '💡 系统已内置默认配置和规则,无需额外配置即可使用',
|
|
83
|
+
install_customize_tip: '📝 如需自定义,请编辑 .smart-review/ 目录下的配置文件',
|
|
84
|
+
install_failed: '安装失败: {error}',
|
|
85
|
+
install_create_review_dir: '创建 .smart-review 目录',
|
|
86
|
+
install_create_ai_rules_dir: '创建 ai-rules 子目录(AI提示词)',
|
|
87
|
+
install_create_local_rules_dir: '创建 local-rules 子目录(静态规则)',
|
|
88
|
+
install_create_template_success: '创建 {desc}',
|
|
89
|
+
install_git_missing: '未检测到 Git,请先安装后重试: {url}',
|
|
90
|
+
install_init_git_warn: '未检测到 .git 目录,尝试初始化 Git 仓库...',
|
|
91
|
+
install_init_git_failed: 'Git 仓库初始化失败,跳过钩子安装',
|
|
92
|
+
install_precommit_installed_success: '安装 pre-commit Git钩子',
|
|
93
|
+
install_precommit_perm_warn: '无法设置执行权限,但钩子文件已创建',
|
|
94
|
+
install_test_hook: '🧪 测试Git钩子...',
|
|
95
|
+
install_test_hook_success: '钩子检测通过',
|
|
96
|
+
install_hook_missing: '钩子文件不存在',
|
|
97
|
+
install_hook_perm_dbg: '钩子文件权限: {mode}, 可执行: {exec}',
|
|
98
|
+
install_hook_perm_fix_warn: '钩子文件不可执行,尝试重新设置权限...',
|
|
99
|
+
install_hook_perm_check_failed: '无法检查钩子文件权限: {error}',
|
|
100
|
+
install_optional_header: '📝 可选配置:',
|
|
101
|
+
install_optional_item1: '1. 编辑 .smart-review/smart-review.json 配置AI参数和风险等级',
|
|
102
|
+
install_optional_item2: '2. 在 .smart-review/local-rules/ 目录添加静态规则文件',
|
|
103
|
+
install_optional_item3: '3. 在 .smart-review/ai-rules/ 目录添加AI提示词文件',
|
|
104
|
+
install_optional_item4: '4. 设置 OPENAI_API_KEY 环境变量启用AI审查',
|
|
105
|
+
install_paths_header: '⚙️ 配置文件位置:',
|
|
106
|
+
install_local_rules_path: '静态规则: {path}',
|
|
107
|
+
install_ai_rules_path: 'AI提示词: {path}',
|
|
108
|
+
install_test_header: '🔧 测试命令:',
|
|
109
|
+
install_test_git_commit: 'git add . && git commit -m "test" # 测试提交触发审查',
|
|
110
|
+
install_test_cli: 'npx smart-review --files test/src/test-file.js # 手动测试审查(使用项目内CLI)',
|
|
111
|
+
// System prompt templates
|
|
112
|
+
system_prompt_template: '你是一个资深代码审查与优化专家。\n\n请严格按照以下格式返回每个问题,每个问题使用开始/结束标记包裹,并以空行分隔:\n{start}\n{Lfile}{绝对文件路径}\n{Lsnippet}{具体的代码片段;如片段中存在每行的[n]前缀,请原样保留}\n{Lrisk}{致命/高危/中危/低危/建议}\n{Lreason}{详细原因}\n{Lsuggestion}{具体的修改建议(允许多行)}\n{end}\n\n约束:\n- 必须包含绝对文件路径与具体片段;禁止使用文字行号或行范围(如“第X行/第X-Y行”)。\n- 如片段存在每行的[n]前缀,请原样保留。\n- 由于预处理(剥离注释、忽略无需审查片段),片段中的[n]源行号可能不连续,这是正常的,严格忽略“行号跳跃/行号不连续”等现象,不得作为问题或风险原因。\n- 重点关注安全、性能、代码质量、架构设计。',
|
|
113
|
+
diff_system_prompt_template: '你负责Git变更的增量审查,仅审查新增行(+)。删除行(-)与上下文仅用于理解。\n\n请严格按照以下格式返回每个问题:\n{start}\n{Lfile}{绝对文件路径}\n{Lsnippet}{新增的具体代码片段,去除+号前缀;如存在每行的[n]前缀,请原样保留}\n{Lrisk}{致命/高危/中危/低危/建议}\n{Lreason}{说明新增代码可能引入的问题}\n{Lsuggestion}{针对新增代码的具体修改建议}\n{end}\n\n说明:\n- 片段只包含新增代码(不含+前缀),允许保留[n]行号前缀。\n- 忽略由预处理或增量片段带来的行号不连续。',
|
|
114
|
+
// CLI
|
|
115
|
+
cli_start: '代码审查启动中,请等待...',
|
|
116
|
+
debug_enabled: '通过命令行参数启用调试日志模式',
|
|
117
|
+
ai_disabled: '通过命令行参数禁用AI分析',
|
|
118
|
+
ai_enabled: '通过命令行参数启用AI分析',
|
|
119
|
+
diff_only_enabled: '通过命令行参数启用Git Diff增量审查模式',
|
|
120
|
+
usage_header: '使用方法:',
|
|
121
|
+
usage_staged: ' npx smart-code-reviewer --staged # 审查暂存区文件',
|
|
122
|
+
usage_diffonly: ' npx smart-code-reviewer --staged --diff-only # 仅审查暂存区变动内容(git diff)',
|
|
123
|
+
usage_files: ' npx smart-code-reviewer --files file1,file2 # 审查指定文件',
|
|
124
|
+
review_error: '审查执行失败: {error}',
|
|
125
|
+
|
|
126
|
+
// Config loader
|
|
127
|
+
external_config_parse_failed_warn: '外部配置文件解析失败,使用默认配置: {error}',
|
|
128
|
+
use_external_rules_only_info: '使用外部规则模式:仅加载 local-rules 目录中的规则',
|
|
129
|
+
load_external_rules_failed_warn: '加载外部规则失败: {error}',
|
|
130
|
+
temp_file_method_failed_fallback_info: '临时文件方法失败,回退到 base64 方法: {error}',
|
|
131
|
+
load_rule_file_failed_warn: '加载规则文件失败 {file}: {error}',
|
|
132
|
+
|
|
133
|
+
// Reviewer
|
|
134
|
+
review_staged_start: '开始审查暂存区代码...',
|
|
135
|
+
using_diff_mode: '🔍 使用Git Diff增量审查模式 - 仅审查变动内容',
|
|
136
|
+
using_full_mode: '📁 使用全文件审查模式',
|
|
137
|
+
no_staged_files: '📭 暂存区没有文件需要审查',
|
|
138
|
+
found_staged_files_n: '📁 发现 {count} 个文件需要审查',
|
|
139
|
+
get_staged_failed: '获取暂存区文件失败: {error}',
|
|
140
|
+
review_specific_start: '开始审查指定文件: {files}',
|
|
141
|
+
file_not_exists: '文件不存在: {path}',
|
|
142
|
+
start_git_diff_mode: '🔍 启动Git Diff增量审查模式...',
|
|
143
|
+
no_changes_skip: '📝 暂存区无变更内容,跳过审查',
|
|
144
|
+
found_changed_files_n: '📊 发现 {count} 个变更文件,开始增量审查...',
|
|
145
|
+
// Merge/Rebase filters
|
|
146
|
+
merge_rebase_detected_info: '🔀 检测到 Git 合并/变基过程,按策略过滤审查文件',
|
|
147
|
+
merge_conflict_paths_found_n: '⚔️ 冲突文件 {count} 个,仅审查这些文件',
|
|
148
|
+
merge_rebase_no_conflict_skip: '✅ 合并/变基期间未检测到冲突文件,跳过审查',
|
|
149
|
+
apply_static_rules_dbg: '应用静态规则检查...',
|
|
150
|
+
static_rules_found_n_dbg: '静态规则发现 {count} 个问题',
|
|
151
|
+
file_skipped_by_type: '文件已跳过审查: {path} (文件类型被忽略)',
|
|
152
|
+
blocking_risk_detected_skip_ai: '发现阻断等级风险 ({levels}),跳过AI分析',
|
|
153
|
+
blocking_risk_terminate: '发现阻断等级风险,终止审查流程',
|
|
154
|
+
ai_start_n_files: '🤖 开始AI智能分析 {count} 个文件...',
|
|
155
|
+
ai_diff_failed: 'AI分析文件变更失败 {path}: {error}',
|
|
156
|
+
git_diff_done: '✨ Git Diff增量审查完成',
|
|
157
|
+
git_diff_error: 'Git Diff审查过程出错: {error}',
|
|
158
|
+
smart_segmentation_done_dbg: '文件 {file} 智能分段完成: {raw} 个原始段 -> {smart} 个智能段',
|
|
159
|
+
all_added_lines_ignored_dbg: '所有新增行都被代码内指令忽略: {file}',
|
|
160
|
+
|
|
161
|
+
// Reviewer (additional)
|
|
162
|
+
review_file_dbg: '审查文件: {file}',
|
|
163
|
+
review_file_progress: '[{index}/{total}] 审查: {file}(+{added} 行,{segments} 段)',
|
|
164
|
+
using_incremental_analyzer_progress: '使用增量式分析器进行分析...',
|
|
165
|
+
incremental_analyzer_failed_error: '增量式分析器失败: {error}',
|
|
166
|
+
ai_smart_analysis_start_progress: '开始AI智能分析,根据文件大小耗时不同,请耐心等待...',
|
|
167
|
+
smart_batching_process_error: 'AI智能批量分析过程出错: {error}',
|
|
168
|
+
fallback_simple_analysis_progress: '回退到简单分析方式...',
|
|
169
|
+
ai_analysis_start_batches: '开始AI分析,共{count}批文件',
|
|
170
|
+
batch_info_header: '批次 {index}/{total}: 分析{files}个文件',
|
|
171
|
+
batch_done_success: '批次 {index}/{total} 完成',
|
|
172
|
+
fallback_analysis_failed: '回退分析也失败: {error}',
|
|
173
|
+
serial_process_batches_info: '使用串行模式处理 {count} 个批次',
|
|
174
|
+
start_concurrency_enabled_info: '启用并发处理,并发数: {concurrency}',
|
|
175
|
+
start_concurrency_dbg: '使用并发模式处理 {count} 个批次',
|
|
176
|
+
serial_large_file_batch_info: '批次 {index}/{total}: 分析 {file} 文件,共{segments}段',
|
|
177
|
+
serial_small_file_batch_info: '批次 {index}/{total}: 分析 {files} 文件',
|
|
178
|
+
ai_analysis_done_summary: 'AI分析完成,发现{totalIssues}个问题,共耗时:{elapsed}秒',
|
|
179
|
+
rule_exec_failed_warn: '规则 {id} 执行失败: {error}',
|
|
180
|
+
skip_by_comments_dbg: '注释代码已跳过审查({count}条匹配)',
|
|
181
|
+
skip_by_directives_dbg: '指令禁用范围已跳过审查({count}条匹配)',
|
|
182
|
+
skip_ai_large_file: '跳过AI分析大文件: {file}',
|
|
183
|
+
blocking_risk_skip_all_ai_info: '本地规则存在阻断等级风险,跳过所有文件的AI分析。',
|
|
184
|
+
stream_read_large_file_dbg: '使用流式读取大文件: {file} ({sizeKB}KB)',
|
|
185
|
+
read_file_failed: '读取文件失败 {file}: {error}',
|
|
186
|
+
|
|
187
|
+
// Print Results
|
|
188
|
+
local_analysis_header: '本地规则审查结果',
|
|
189
|
+
ai_analysis_header: 'AI代码分析结果',
|
|
190
|
+
no_issues: '无',
|
|
191
|
+
file_label: '文件: {file}',
|
|
192
|
+
issue_label: '问题{index}:',
|
|
193
|
+
snippet_label: '代码片段:',
|
|
194
|
+
snippet_global_label: '代码片段:(全局性问题)',
|
|
195
|
+
risk_level_label: '风险等级:',
|
|
196
|
+
risk_reason_label: '风险原因:',
|
|
197
|
+
suggestions_label: '修改建议:',
|
|
198
|
+
tip_line_numbers: '提示:片段行号为源文件绝对行号,因清洗注释/无需审查片段可能出现跳跃,请忽略行号不连续。',
|
|
199
|
+
line_label: '行号:{line}',
|
|
200
|
+
line_range_label: '行号范围:{start}-{end}',
|
|
201
|
+
|
|
202
|
+
// AI Client
|
|
203
|
+
node_version_warn: '检测到 Node 版本 < 18 或缺少全局 fetch,可能导致连接异常。建议升级到 Node >=18。',
|
|
204
|
+
ai_batch_failed: 'AI批量文件分析失败: {error}',
|
|
205
|
+
ai_connection_failed: 'AI服务连接失败,终止分析过程',
|
|
206
|
+
ai_retry_warn: 'AI请求失败,重试({attempt}/{retries}),等待{delay}ms: {error}',
|
|
207
|
+
read_ai_prompt_file_failed: '读取AI提示词文件失败 {file}: {error}',
|
|
208
|
+
read_custom_prompts_failed: '读取自定义提示词失败: {error}',
|
|
209
|
+
custom_prompts_label: '自定义提示词',
|
|
210
|
+
ignore_rule: '注意:代码可能经过预处理(剥离注释、跳过无需审查片段),因此行号前缀可能不连续。这是正常的,请严格忽略“行号跳跃/行号不连续/被预处理移除”等现象,不要将其视为问题或风险,也不要提出“检查代码完整性/补全缺失代码”类建议。仅针对给定片段中的有效代码提出问题与修改建议。',
|
|
211
|
+
// Batch and files intro/instruction
|
|
212
|
+
batch_intro: '我会发送一个批次的文件进行代码审查。其中可能包含分段文件(大文件被分成多段)。对于分段文件,请在收到所有段后进行整体分析。每个问题用空行分隔,务必包含“文件路径:绝对路径”与代码片段,且禁止任何“第X行/第X-Y行”等行号或行范围描述。',
|
|
213
|
+
batch_files_intro: '我会一次性发送多个文件的完整代码,请逐文件进行审查并返回结果。每个问题用空行分隔,务必包含“文件路径:绝对路径”与代码片段,且禁止任何“第X行/第X-Y行”等行号或行范围描述。',
|
|
214
|
+
final_instruction_batch: '请逐文件进行审查,每个问题用空行分隔,必须包含“文件路径:绝对路径”和具体的代码片段。禁止使用文字行号或行范围描述(如“第X行/第X-Y行”);如片段中存在每行的[n]前缀请原样保留。',
|
|
215
|
+
file_failed_static_suffix: '(本地审查未通过)',
|
|
216
|
+
// Local rule hints
|
|
217
|
+
local_rule_findings: '本地规则发现的问题',
|
|
218
|
+
local_rule_findings_header: '[本地规则发现的问题 - {file}]',
|
|
219
|
+
inline_suggestion: ';建议:{suggestion}',
|
|
220
|
+
local_rule_hint_line: '{index}. 片段({risk}):{message}{suggest};代码片段:{snippet}',
|
|
221
|
+
// Diff prompts and logs
|
|
222
|
+
ai_diff_start_dbg: '开始Git Diff分析: {file}({added} 行新增代码)',
|
|
223
|
+
ai_diff_send_dbg: '发送Git Diff AI请求 - 模型: {model},消息数: {messages}',
|
|
224
|
+
ai_diff_done_dbg: 'Git Diff分析完成: {file},发现 {issues} 个问题',
|
|
225
|
+
ai_issues_found_n_dbg: 'AI分析发现 {count} 个问题',
|
|
226
|
+
diff_intro: '请对以下Git变更进行代码审查。重点关注新增的代码行(+号标记),上下文代码仅供理解,无需审查。',
|
|
227
|
+
diff_added_lines_label: '新增代码行数:',
|
|
228
|
+
diff_smart_segments_label: '智能分段数:',
|
|
229
|
+
diff_changes_label: '变更内容:',
|
|
230
|
+
diff_segment_title: '智能分段 {index}/{total}',
|
|
231
|
+
diff_segment_meta: '行范围: {start}-{end}, 新增{added}行, 约{tokens} tokens',
|
|
232
|
+
diff_final_instruction: '请仅对标记为“+”的新增代码行进行审查,忽略删除行(-)和上下文行。每个问题用空行分隔,必须包含“文件路径:{file}”和具体的代码片段。禁止使用文字行号或行范围描述(如“第X行/第X-Y行”);如片段中存在每行的[行号]前缀请原样保留。',
|
|
233
|
+
// Fallback messages for static/local rules
|
|
234
|
+
fallback_static_reason: '基于本地规则:{message}',
|
|
235
|
+
fallback_static_suggestion: '请根据本地规则进行复核与修复,并补充测试与监控以验证风险。',
|
|
236
|
+
|
|
237
|
+
// Pool
|
|
238
|
+
init_pool_dbg: '初始化AI客户端池,大小: {size}',
|
|
239
|
+
pool_init_done_dbg: 'AI客户端池初始化完成,共{count}个客户端',
|
|
240
|
+
start_concurrent_dbg: '开始并发处理 {count} 个批次',
|
|
241
|
+
concurrent_done_dbg: '并发处理完成: 成功 {succ}, 失败 {fail}',
|
|
242
|
+
concurrent_group_failed: '文件组 {index} 处理失败: {error}',
|
|
243
|
+
concurrent_processing_error: '并发处理过程中发生错误: {error}',
|
|
244
|
+
cleanup_pool_dbg: '清理AI客户端池资源',
|
|
245
|
+
request_batch_start_dbg: '开始AI分析请求,批次 {index},使用客户端: {client}',
|
|
246
|
+
seg_chunk_no_issues_dbg: '{file} 第 {chunk}/{total} 段未发现问题,AI响应内容: {preview}',
|
|
247
|
+
files_no_issues_dbg: '{files} 未发现问题,AI响应内容: {preview}',
|
|
248
|
+
issues_risk_levels_dbg: '{file} 发现的问题风险等级: {levels}',
|
|
249
|
+
issues_details_dbg: '{file} 发现的问题详情:',
|
|
250
|
+
issue_item_dbg: ' 问题 {index}: {risk} - {message}',
|
|
251
|
+
batch_start_regular: '开始批次 {i}/{total}:文件 {files}({count} 个,tokens {tokens})',
|
|
252
|
+
batch_start_segmented: '开始批次 {i}/{total}:分段文件 {path},总段数 {segments}',
|
|
253
|
+
batch_complete: '批次 {i}/{total} 完成:{context},发现 {issues} 个问题,用时 {secs}s',
|
|
254
|
+
batch_process_failed: '批次 {i} 处理失败:{error}',
|
|
255
|
+
batch_retry_warn: '批次 {i} 请求失败,进行第 {retry} 次重试: {error}',
|
|
256
|
+
batch_retry_error: '批次 {i} 多次重试仍失败({max} 次): {error}',
|
|
257
|
+
|
|
258
|
+
// Diff parser
|
|
259
|
+
git_diff_parse_failed: '获取git diff失败: {error}',
|
|
260
|
+
file_skipped_by_ignore_rule_dbg: '文件被忽略规则跳过: {file}',
|
|
261
|
+
smart_seg_done_dbg: '文件 {file} 智能分段完成: {orig} 个原始段 -> {smart} 个智能段',
|
|
262
|
+
rule_diff_exec_failed_warn: '规则 {id} 在diff模式下执行失败: {error}',
|
|
263
|
+
|
|
264
|
+
// Segment analysis (large-file segmented processing)
|
|
265
|
+
segment_overall_start: '开始逐段分析文件: {file},共 {total} 段{concurrency}{totalNote}',
|
|
266
|
+
segment_concurrency_note: '(并发 {workers})',
|
|
267
|
+
segment_total_note: '(总段数 {totalChunks},当前批次 {effectiveTotal})',
|
|
268
|
+
segment_wait_start_dbg: '分段待启动:第 {index}/{total} 段 (行 {start}-{end})',
|
|
269
|
+
segment_worker_start_dbg: '启动分段并发协程 #{id}',
|
|
270
|
+
segment_schedule_dbg: '分段并发调度:workers={workers}, total={total}{note}',
|
|
271
|
+
segment_concurrency_done_dbg: '分段并发完成:已处理 {total}{extra} 段',
|
|
272
|
+
segment_start_label: '开始分析 {file} 第 {index}/{total} 段(行 {start}-{end})',
|
|
273
|
+
segment_batch_prefix: '批次 {index}/{total} ',
|
|
274
|
+
segment_size_estimate_dbg: '预估 {tokens} tokens, 共 {lines} 行代码',
|
|
275
|
+
segment_prepare_content_dbg: '准备第 {index} 段代码内容...',
|
|
276
|
+
segment_build_prompt_dbg: '构建第 {index} 段分析提示词...',
|
|
277
|
+
segment_analysis_done_n_issues: '{batch}({file})第 {index} 段分析完成,发现 {count} 个问题',
|
|
278
|
+
segment_analysis_done_zero: '{batch}({file})第 {index} 段分析完成,发现 0 个问题',
|
|
279
|
+
segment_analysis_failed: '第 {index} 段分析失败: {error}',
|
|
280
|
+
segment_file_failed: '分段文件分析失败: {error}',
|
|
281
|
+
parse_seg_response_failed_warn: '解析AI响应失败: {error}',
|
|
282
|
+
parse_issue_section_failed_warn: '解析问题段落失败: {error}',
|
|
283
|
+
segment_prev_context_header: '**前面段落摘要**:',
|
|
284
|
+
segment_prev_context_item: '第{index}段(行{range}): {summary}',
|
|
285
|
+
segment_summary_marker: '**-----段落摘要-----**',
|
|
286
|
+
segment_response_parsed_info: '第 {index} 段响应解析完成,发现 {count} 个问题',
|
|
287
|
+
// Chunked response and request logs (AI client)
|
|
288
|
+
detected_segmented_batch_dbg: '检测到分段批次,改用分段整体分析:{path}({segments}段)',
|
|
289
|
+
chunk_req_info_dbg: '发送分段AI请求 - 模型: {model}, 消息数: {count}',
|
|
290
|
+
chunk_req_preview_dbg: 'AI请求消息预览:\n{preview}',
|
|
291
|
+
chunk_req_preview_fail_dbg: 'AI请求消息预览失败: {error}',
|
|
292
|
+
preview_truncated_suffix: '...省略 {count} 字符',
|
|
293
|
+
ai_response_len_dbg: 'AI响应: {len} 字符',
|
|
294
|
+
chunk_continue_needed_dbg: '分段响应未完成,发送“继续”请求下一段',
|
|
295
|
+
chunk_continue_prompt: '继续',
|
|
296
|
+
segment_static_issues_header: '[本地规则发现的问题 - 第{index}段]',
|
|
297
|
+
segment_static_issue_line: '{index}. 片段({risk}):{message}{suggest};{snippetLabel}{snippet}',
|
|
298
|
+
// File review status reasons
|
|
299
|
+
file_ext_not_supported_reason: '文件扩展名 {ext} 不在支持列表中',
|
|
300
|
+
file_reason_exact_match: '匹配精确模式',
|
|
301
|
+
file_reason_regex_match: '匹配正则表达式',
|
|
302
|
+
file_reason_glob_match: '匹配glob模式',
|
|
303
|
+
segment_prompt_template: '请对以下代码段进行完整的代码审查分析。这是一个大文件的第 {index}/{total} 段:\n\n{Lfile}{file}\n{Lcontent}\n```\n{content}\n```\n\n请仔细审查这段代码,查找以下类型的问题:\n- 类型安全问题(如使用any类型)\n- 安全漏洞\n- 性能问题\n- 代码质量问题\n- 最佳实践违反\n\n重要:请立即开始分析,不要只是确认收到。必须按以下格式输出每个发现的问题:\n\n**-----代码分析结果-----**\n{Lfile}{file}\n{Lsnippet}[具体的问题代码]\n{Lrisk}[高/中/低]\n{Lreason}[问题描述]\n{Lsuggestion}[具体的修改建议]\n\n如果发现多个问题,每个问题都要用 **-----代码分析结果-----** 开头。\n如果没有发现问题,请回复:\n\n**-----代码分析结果-----**\n本段代码无明显问题\n\n注意:如片段中每行包含形如 [n] 的源行号前缀,请在你的输出的代码片段中原样保留这些前缀,以便后续定位。\n\n分段上下文限制:不要评估“导入是否被使用”,严格忽略关于“未使用的导入/模块/依赖”的任何提示或建议(包括建议删除未使用的导入)。',
|
|
304
|
+
// Static rule i18n (Best Practices)
|
|
305
|
+
rule_BP001_name: '调试代码',
|
|
306
|
+
rule_BP001_message: '发现调试代码,建议在提交前移除',
|
|
307
|
+
rule_BP001_suggestion: '使用日志系统替代console.log',
|
|
308
|
+
rule_BP002_name: '魔法数字',
|
|
309
|
+
rule_BP002_message: '检测到魔法数字,建议使用常量定义',
|
|
310
|
+
rule_BP002_suggestion: '将数字定义为有意义的常量',
|
|
311
|
+
rule_BP003_name: '空的异常捕获块',
|
|
312
|
+
rule_BP003_message: '检测到空的catch块,可能隐藏错误并导致不可预期行为',
|
|
313
|
+
rule_BP003_suggestion: '记录日志或采取补救措施,避免吞掉异常',
|
|
314
|
+
rule_BP004_name: '忽略TypeScript类型检查',
|
|
315
|
+
rule_BP004_message: '检测到@ts-ignore,可能掩盖类型错误',
|
|
316
|
+
rule_BP004_suggestion: '修复类型问题或使用更精确的类型定义',
|
|
317
|
+
rule_BP005_name: '使用any类型',
|
|
318
|
+
rule_BP005_message: '检测到any类型,可能削弱类型系统保护',
|
|
319
|
+
rule_BP005_suggestion: '使用具体类型或泛型替代any,提高类型安全',
|
|
320
|
+
rule_BP006_name: '禁用ESLint规则',
|
|
321
|
+
rule_BP006_message: '检测到禁用ESLint,可能隐藏代码质量问题',
|
|
322
|
+
rule_BP006_suggestion: '只在必要范围局部禁用,并给出明确原因',
|
|
323
|
+
rule_BP007_name: '调试断点未移除',
|
|
324
|
+
rule_BP007_message: '检测到调试断点,可能影响线上行为',
|
|
325
|
+
rule_BP007_suggestion: '在提交前移除debugger并使用日志或断言',
|
|
326
|
+
rule_BP008_name: '过于宽泛的异常捕获',
|
|
327
|
+
rule_BP008_message: '捕获过于宽泛的异常类型且未进行适当处理',
|
|
328
|
+
rule_BP008_suggestion: '捕获具体的异常类型,并确保进行适当的日志记录或重新抛出',
|
|
329
|
+
rule_BP009_name: '打印堆栈而非日志记录',
|
|
330
|
+
rule_BP009_message: '检测到直接打印堆栈跟踪,可能导致信息丢失与不可控输出',
|
|
331
|
+
rule_BP009_suggestion: '使用结构化日志记录错误,并附带上下文信息',
|
|
332
|
+
rule_BP010_name: '进程级退出调用',
|
|
333
|
+
rule_BP010_message: '检测到System.exit,可能导致服务非预期中断',
|
|
334
|
+
rule_BP010_suggestion: '使用受控的停止流程(优雅关闭)、信号处理与资源回收',
|
|
335
|
+
rule_BP011_name: '使用root数据库用户',
|
|
336
|
+
rule_BP011_message: '检测到使用root作为数据库用户,存在安全与审计风险',
|
|
337
|
+
rule_BP011_suggestion: '使用最小权限的应用专用账户,分离权限与职责',
|
|
338
|
+
rule_BP012_name: '禁用CSRF(Spring Security)',
|
|
339
|
+
rule_BP012_message: '检测到全局禁用CSRF保护,可能导致跨站请求伪造风险',
|
|
340
|
+
rule_BP012_suggestion: '在必要的API上采用令牌/同源策略,避免全局关闭',
|
|
341
|
+
rule_BP013_name: '使用var声明',
|
|
342
|
+
rule_BP013_message: '检测到使用var声明变量,可能导致作用域问题',
|
|
343
|
+
rule_BP013_suggestion: '使用let或const替代var,提高代码安全性',
|
|
344
|
+
|
|
345
|
+
// Static rule i18n (Performance)
|
|
346
|
+
rule_PERF001_name: '循环内数据库查询',
|
|
347
|
+
rule_PERF001_message: '在循环内执行数据库查询,可能导致N+1查询问题',
|
|
348
|
+
rule_PERF001_suggestion: '使用批量查询或预加载数据',
|
|
349
|
+
rule_PERF002_name: '内存泄漏风险(定时器使用)',
|
|
350
|
+
rule_PERF002_message: '发现定时器使用,若未清理可能导致内存泄漏或残留任务',
|
|
351
|
+
rule_PERF002_suggestion: '确保在适当生命周期调用 clearInterval/clearTimeout 进行清理',
|
|
352
|
+
rule_PERF003_name: '同步文件IO阻塞',
|
|
353
|
+
rule_PERF003_message: '检测到同步文件IO,可能阻塞事件循环并影响吞吐',
|
|
354
|
+
rule_PERF003_suggestion: '优先使用异步IO或队列化处理,避免阻塞主线程',
|
|
355
|
+
rule_PERF004_name: '循环内网络请求',
|
|
356
|
+
rule_PERF004_message: '检测到循环内执行网络请求,可能导致级联延迟与拥塞',
|
|
357
|
+
rule_PERF004_suggestion: '合并请求、并发控制或批量处理,减少往返次数',
|
|
358
|
+
rule_PERF005_name: '循环内JSON序列化',
|
|
359
|
+
rule_PERF005_message: '循环内频繁序列化可能导致CPU开销过大',
|
|
360
|
+
rule_PERF005_suggestion: '将序列化移到循环外或进行缓存/批量处理',
|
|
361
|
+
rule_PERF006_name: '循环内正则编译',
|
|
362
|
+
rule_PERF006_message: '循环内重复编译正则会增加不必要的开销',
|
|
363
|
+
rule_PERF006_suggestion: '将正则常量化或预编译,避免在循环中创建',
|
|
364
|
+
rule_PERF007_name: '忙等待循环',
|
|
365
|
+
rule_PERF007_message: '检测到可能的忙等待循环,可能导致CPU飙升与资源浪费',
|
|
366
|
+
rule_PERF007_suggestion: '使用事件驱动或阻塞等待机制,避免空循环',
|
|
367
|
+
rule_PERF008_name: '循环内DOM布局抖动',
|
|
368
|
+
rule_PERF008_message: '循环内读取布局信息会触发频繁回流/重绘',
|
|
369
|
+
rule_PERF008_suggestion: '合并DOM读写、使用批处理、减少同步布局查询',
|
|
370
|
+
rule_PERF009_name: '阻塞等待(sleep)',
|
|
371
|
+
rule_PERF009_message: '检测到阻塞等待调用,可能降低服务吞吐和响应',
|
|
372
|
+
rule_PERF009_suggestion: '改用异步等待或限流/队列机制,避免阻塞主线程',
|
|
373
|
+
rule_PERF010_name: '无界线程池',
|
|
374
|
+
rule_PERF010_message: '检测到无界线程池,可能导致线程爆炸与资源枯竭',
|
|
375
|
+
rule_PERF010_suggestion: '使用有界线程池并设置合理最大值与队列长度',
|
|
376
|
+
rule_PERF011_name: '循环内字符串拼接',
|
|
377
|
+
rule_PERF011_message: '循环内频繁字符串拼接会造成较大CPU与内存开销',
|
|
378
|
+
rule_PERF011_suggestion: '使用StringBuilder/列表收集再join,或其他批量化策略',
|
|
379
|
+
rule_PERF012_name: '循环内创建数据库连接',
|
|
380
|
+
rule_PERF012_message: '循环内反复创建数据库连接会导致严重性能问题',
|
|
381
|
+
rule_PERF012_suggestion: '使用连接池与复用策略,在循环外预先获取连接',
|
|
382
|
+
rule_PERF013_name: 'HTTP请求缺少超时(Python)',
|
|
383
|
+
rule_PERF013_message: '网络请求未设置超时会造成资源悬挂与吞吐下降',
|
|
384
|
+
rule_PERF013_suggestion: '设置合理的timeout参数,并对重试与熔断进行控制',
|
|
385
|
+
|
|
386
|
+
// Static rule i18n (Security)
|
|
387
|
+
rule_SEC001_name: '硬编码密码检测',
|
|
388
|
+
rule_SEC001_message: '发现硬编码的密码或密钥',
|
|
389
|
+
rule_SEC001_suggestion: '使用环境变量或安全的密钥管理服务',
|
|
390
|
+
rule_SEC002_name: 'SQL注入风险',
|
|
391
|
+
rule_SEC002_message: '发现字符串拼接SQL查询,存在SQL注入风险',
|
|
392
|
+
rule_SEC002_suggestion: '使用参数化查询或ORM的安全方法',
|
|
393
|
+
rule_SEC003_name: 'XSS风险',
|
|
394
|
+
rule_SEC003_message: '发现直接操作HTML内容,可能存在XSS风险',
|
|
395
|
+
rule_SEC003_suggestion: '使用textContent或安全的DOM操作方法',
|
|
396
|
+
rule_SEC004_name: '命令注入风险',
|
|
397
|
+
rule_SEC004_message: '发现命令执行函数调用,且可能包含用户输入',
|
|
398
|
+
rule_SEC004_suggestion: '避免使用用户输入构造命令,或进行严格的输入验证',
|
|
399
|
+
rule_SEC005_name: '路径遍历风险',
|
|
400
|
+
rule_SEC005_message: '可能存在路径遍历或未校验的文件路径使用',
|
|
401
|
+
rule_SEC005_suggestion: '对路径进行规范化、白名单校验,并避免直接拼接用户输入',
|
|
402
|
+
rule_SEC006_name: '禁用SSL证书校验',
|
|
403
|
+
rule_SEC006_message: '发现禁用SSL证书校验的HTTP请求',
|
|
404
|
+
rule_SEC006_suggestion: '启用证书校验或使用可信证书,避免中间人攻击',
|
|
405
|
+
rule_SEC007_name: '弱加密算法使用',
|
|
406
|
+
rule_SEC007_message: '检测到MD5/SHA1等弱加密算法的使用',
|
|
407
|
+
rule_SEC007_suggestion: '使用更安全的算法,如SHA-256/512、Argon2、bcrypt、scrypt',
|
|
408
|
+
rule_SEC008_name: '硬编码密钥/Token',
|
|
409
|
+
rule_SEC008_message: '检测到硬编码的密钥或访问令牌',
|
|
410
|
+
rule_SEC008_suggestion: '将敏感信息存放在安全的密钥管理或环境变量中',
|
|
411
|
+
rule_SEC009_name: '不安全反序列化',
|
|
412
|
+
rule_SEC009_message: '检测到潜在的不安全反序列化操作',
|
|
413
|
+
rule_SEC009_suggestion: '使用安全的反序列化方式,例如 yaml.safe_load,避免反序列化不可信数据',
|
|
414
|
+
rule_SEC010_name: 'SSRF风险',
|
|
415
|
+
rule_SEC010_message: '检测到可能由用户输入构成的URL请求,存在SSRF风险',
|
|
416
|
+
rule_SEC010_suggestion: '对外部URL进行白名单限制并校验,禁止访问内部地址',
|
|
417
|
+
rule_SEC011_name: 'NoSQL注入风险',
|
|
418
|
+
rule_SEC011_message: '检测到可能的NoSQL注入(动态拼接查询条件)',
|
|
419
|
+
rule_SEC011_suggestion: '使用参数化查询或安全的查询构建器,避免直接拼接',
|
|
420
|
+
rule_SEC012_name: '开放重定向',
|
|
421
|
+
rule_SEC012_message: '检测到基于用户输入的重定向,可能导致开放重定向',
|
|
422
|
+
rule_SEC012_suggestion: '对目标URL进行白名单校验或固定化处理',
|
|
423
|
+
rule_SEC013_name: '系统命令执行(Python)',
|
|
424
|
+
rule_SEC013_message: '检测到系统命令执行调用,若包含用户输入可能导致命令注入',
|
|
425
|
+
rule_SEC013_suggestion: '避免直接调用系统命令,改用安全库或严格白名单参数',
|
|
426
|
+
rule_SEC014_name: '不安全随机数',
|
|
427
|
+
rule_SEC014_message: '检测到在安全相关场景中使用非加密安全的随机数生成方法',
|
|
428
|
+
rule_SEC014_suggestion: '使用加密安全的随机数生成器,如 crypto.randomBytes、secrets.SystemRandom',
|
|
429
|
+
rule_SEC015_name: '危险的eval/Function使用',
|
|
430
|
+
rule_SEC015_message: '检测到可能导致代码注入的动态执行',
|
|
431
|
+
rule_SEC015_suggestion: '避免使用eval/Function,改用安全的解析与映射逻辑',
|
|
432
|
+
rule_SEC016_name: '原型污染',
|
|
433
|
+
rule_SEC016_message: '检测到对对象原型的直接赋值,可能导致原型污染',
|
|
434
|
+
rule_SEC016_suggestion: '避免从不可信数据合并到对象原型,使用安全的合并策略',
|
|
435
|
+
rule_SEC017_name: 'Java字符串拼接SQL执行',
|
|
436
|
+
rule_SEC017_message: '检测到通过字符串拼接构造SQL语句的执行',
|
|
437
|
+
rule_SEC017_suggestion: '使用PreparedStatement与占位符进行参数化查询',
|
|
438
|
+
rule_SEC018_name: 'jQuery.html导致XSS风险',
|
|
439
|
+
rule_SEC018_message: '检测到直接注入HTML内容,可能导致XSS',
|
|
440
|
+
rule_SEC018_suggestion: '使用text()或可信模板引擎进行转义输出',
|
|
441
|
+
rule_SEC019_name: '过大文件权限(777)',
|
|
442
|
+
rule_SEC019_message: '检测到设置过大的文件权限,存在安全风险',
|
|
443
|
+
rule_SEC019_suggestion: '使用最小权限原则,避免设置777等过宽权限',
|
|
444
|
+
rule_SEC020_name: '系统命令执行(多语言)',
|
|
445
|
+
rule_SEC020_message: '检测到系统命令执行调用,若包含用户输入可能导致命令注入',
|
|
446
|
+
rule_SEC020_suggestion: '避免直接调用系统命令,改用安全库或严格白名单参数',
|
|
447
|
+
rule_SEC021_name: '禁用TLS校验(Node)',
|
|
448
|
+
rule_SEC021_message: '检测到禁用TLS证书校验的配置',
|
|
449
|
+
rule_SEC021_suggestion: '启用证书校验并使用可信CA,避免中间人攻击',
|
|
450
|
+
rule_SEC022_name: 'CORS任意来源',
|
|
451
|
+
rule_SEC022_message: '检测到CORS允许任意来源,可能导致跨域数据泄露',
|
|
452
|
+
rule_SEC022_suggestion: '仅对可信来源开放,或使用令牌校验与细粒度策略',
|
|
453
|
+
rule_SEC023_name: 'LDAP注入风险',
|
|
454
|
+
rule_SEC023_message: '检测到基于字符串拼接的LDAP查询过滤器',
|
|
455
|
+
rule_SEC023_suggestion: '使用安全的过滤器构造与参数绑定,避免直接拼接',
|
|
456
|
+
rule_SEC024_name: 'XXE(XML外部实体)风险',
|
|
457
|
+
rule_SEC024_message: '检测到可能的XML解析,未禁用外部实体可能导致XXE',
|
|
458
|
+
rule_SEC024_suggestion: '禁用外部实体解析,或使用安全解析库(如defusedxml)',
|
|
459
|
+
rule_SEC025_name: 'Java HostnameVerifier始终返回true',
|
|
460
|
+
rule_SEC025_message: '检测到跳过主机名校验的HTTPS验证',
|
|
461
|
+
rule_SEC025_suggestion: '实现严格的主机名校验逻辑,避免任意通过',
|
|
462
|
+
rule_SEC026_name: 'Node禁用证书错误忽略',
|
|
463
|
+
rule_SEC026_message: '检测到全局禁用证书错误的环境变量设置',
|
|
464
|
+
rule_SEC026_suggestion: '移除该设置并使用合法证书,或在测试环境隔离',
|
|
465
|
+
rule_SEC027_name: '连接字符串包含凭据',
|
|
466
|
+
rule_SEC027_message: '检测到在连接字符串中硬编码了账号密码',
|
|
467
|
+
rule_SEC027_suggestion: '使用环境变量或安全凭据存储,避免明文出现在代码中',
|
|
468
|
+
rule_SEC028_name: '日志输出敏感信息',
|
|
469
|
+
rule_SEC028_message: '检测到将敏感信息输出到日志',
|
|
470
|
+
rule_SEC028_suggestion: '对敏感字段进行脱敏或完全避免记录',
|
|
471
|
+
rule_SEC029_name: 'Mass Assignment(Rails/Laravel)',
|
|
472
|
+
rule_SEC029_message: '检测到可能的批量赋值风险,未进行字段白名单校验',
|
|
473
|
+
rule_SEC029_suggestion: '启用强参数/属性白名单,仅允许安全字段写入',
|
|
474
|
+
rule_SEC030_name: '禁用TLS校验(Go)',
|
|
475
|
+
rule_SEC030_message: '检测到在Go中禁用了TLS证书校验',
|
|
476
|
+
rule_SEC030_suggestion: '启用证书校验并使用可信CA,避免中间人攻击',
|
|
477
|
+
rule_SEC031_name: '禁用证书校验(C#)',
|
|
478
|
+
rule_SEC031_message: '检测到覆盖全局证书校验回调,可能接受任意证书',
|
|
479
|
+
rule_SEC031_suggestion: '移除该回调并使用正确的证书验证机制',
|
|
480
|
+
rule_SEC032_name: 'Entity Framework原生SQL拼接',
|
|
481
|
+
rule_SEC032_message: '检测到EF Core使用FromSqlRaw并进行字符串拼接',
|
|
482
|
+
rule_SEC032_suggestion: '使用FromSqlInterpolated或参数化查询,避免注入风险',
|
|
483
|
+
rule_SEC033_name: 'Go系统命令执行',
|
|
484
|
+
rule_SEC033_message: '检测到Go中执行系统命令,若包含用户输入可能导致命令注入',
|
|
485
|
+
rule_SEC033_suggestion: '避免使用shell -c与拼接命令,采用白名单参数与直接可执行路径',
|
|
486
|
+
rule_SEC034_name: '不安全随机数(Go)',
|
|
487
|
+
rule_SEC034_message: '检测到使用math/rand生成随机数,非加密安全',
|
|
488
|
+
rule_SEC034_suggestion: '使用crypto/rand或安全随机数库生成敏感令牌与密钥',
|
|
489
|
+
},
|
|
490
|
+
'en-US': {
|
|
491
|
+
// Git hook script messages (pre-rendered at install time)
|
|
492
|
+
hook_header_comment: 'Smart Code Review - pre-commit hook (multi-project compatible; locates CLI via staged paths)',
|
|
493
|
+
hook_start_review: '🔍 Starting code review...',
|
|
494
|
+
hook_no_staged: '📭 No staged files to review',
|
|
495
|
+
hook_found_staged_header: '📁 Found staged files:',
|
|
496
|
+
hook_cd_repo_fail: '❌ Failed to cd to repo root',
|
|
497
|
+
hook_cmd_not_found1: '❌ smart-review not found. Please install in the subproject: npm i -D smart-review',
|
|
498
|
+
hook_cmd_not_found2: ' Or install at repo root for unified use: npm i -D smart-review',
|
|
499
|
+
hook_use_command_prefix: '⚙️ Using command:',
|
|
500
|
+
hook_review_fail: '❌ Code review failed; please fix issues and retry commit',
|
|
501
|
+
hook_review_pass: '✅ Code review passed; continuing commit',
|
|
502
|
+
|
|
503
|
+
// Install
|
|
504
|
+
install_search_git_root_dbg: 'Searching for Git root, starting from {dir}...',
|
|
505
|
+
install_found_git_root_success: 'Found Git root: {dir}',
|
|
506
|
+
install_no_git_use_current: 'ℹ️ .git directory not found, using current directory as project root',
|
|
507
|
+
install_start: '🚀 Starting installation of Smart Code Review system...',
|
|
508
|
+
install_done_success: '🎉 Smart Code Review system installed successfully!',
|
|
509
|
+
install_bundled_info: '💡 Default config and rules are bundled; works out-of-the-box',
|
|
510
|
+
install_customize_tip: '📝 To customize, edit config files under .smart-review/',
|
|
511
|
+
install_failed: 'Installation failed: {error}',
|
|
512
|
+
install_create_review_dir: 'Created .smart-review directory',
|
|
513
|
+
install_create_ai_rules_dir: 'Created ai-rules subdirectory (AI prompts)',
|
|
514
|
+
install_create_local_rules_dir: 'Created local-rules subdirectory (static rules)',
|
|
515
|
+
install_create_template_success: 'Created {desc}',
|
|
516
|
+
install_git_missing: 'Git not detected. Please install and retry: {url}',
|
|
517
|
+
install_init_git_warn: 'No .git directory detected. Attempting to initialize a Git repository...',
|
|
518
|
+
install_init_git_failed: 'Failed to initialize Git repository; skipping hook installation',
|
|
519
|
+
install_precommit_installed_success: 'Installed pre-commit Git hook',
|
|
520
|
+
install_precommit_perm_warn: 'Cannot set executable permission, but hook file created',
|
|
521
|
+
install_test_hook: '🧪 Testing Git hook...',
|
|
522
|
+
install_test_hook_success: 'Git hook check passed',
|
|
523
|
+
install_hook_missing: 'Hook file does not exist',
|
|
524
|
+
install_hook_perm_dbg: 'Hook file mode: {mode}, executable: {exec}',
|
|
525
|
+
install_hook_perm_fix_warn: 'Hook file not executable; trying to reset permission...',
|
|
526
|
+
install_hook_perm_check_failed: 'Failed to check hook permissions: {error}',
|
|
527
|
+
install_optional_header: '📝 Optional Configuration:',
|
|
528
|
+
install_optional_item1: '1. Edit .smart-review/smart-review.json to configure AI and risk levels',
|
|
529
|
+
install_optional_item2: '2. Add static rule files under .smart-review/local-rules/',
|
|
530
|
+
install_optional_item3: '3. Add AI prompt files under .smart-review/ai-rules/',
|
|
531
|
+
install_optional_item4: '4. Set OPENAI_API_KEY environment variable to enable AI review',
|
|
532
|
+
install_paths_header: '⚙️ Config Paths:',
|
|
533
|
+
install_local_rules_path: 'Static rules: {path}',
|
|
534
|
+
install_ai_rules_path: 'AI prompts: {path}',
|
|
535
|
+
install_test_header: '🔧 Test Commands:',
|
|
536
|
+
install_test_git_commit: 'git add . && git commit -m "test" # Test commit to trigger review',
|
|
537
|
+
install_test_cli: 'npx smart-review --files test/src/test-file.js # Manual review test (project CLI)',
|
|
538
|
+
// System prompt templates
|
|
539
|
+
system_prompt_template: 'You are a senior code review and optimization expert.\n\nStrictly follow this output format per issue, wrapped by start/end markers and separated by a blank line:\n{start}\n{Lfile}{absolute file path}\n{Lsnippet}{specific code snippet; if each line has a [n] prefix, keep it}\n{Lrisk}{Critical/High/Medium/Low/Suggestion}\n{Lreason}{detailed reason}\n{Lsuggestion}{specific, actionable modifications}\n{end}\n\nRules:\n- Always include the absolute file path and a concrete code snippet; do not use textual line numbers or ranges (e.g., "line X" or "lines X-Y").\n- If snippet lines include [n] prefixes, keep them exactly.\n- Because of pre-processing (comments stripped, ignored sections), line numbers can be non-contiguous. This is normal; ignore such gaps and NEVER treat them as an issue.\n- Focus on Security, Performance, Code Quality, Design & Architecture.',
|
|
540
|
+
diff_system_prompt_template: 'You review incremental Git changes.\n\nOnly review added lines marked by "+". Deleted "-" and context lines are for understanding only.\n\nOutput format per issue with start/end markers and blank line separation:\n{start}\n{Lfile}{absolute file path}\n{Lsnippet}{added code snippet only; if lines have [n] prefixes, keep them}\n{Lrisk}{Critical/High/Medium/Low/Suggestion}\n{Lreason}{why added code introduces issues}\n{Lsuggestion}{specific, actionable modifications}\n{end}\n\nImportant:\n- Snippet must only contain newly added code (without the "+" prefix), but keep any [n] line number prefixes.\n- Ignore non-contiguous line numbers caused by pre-processing or partial diffs.',
|
|
541
|
+
// CLI
|
|
542
|
+
cli_start: 'Code review starting, please wait...',
|
|
543
|
+
debug_enabled: 'Debug log mode enabled via CLI argument',
|
|
544
|
+
ai_disabled: 'AI analysis disabled via CLI argument',
|
|
545
|
+
ai_enabled: 'AI analysis enabled via CLI argument',
|
|
546
|
+
diff_only_enabled: 'Git Diff incremental review mode enabled',
|
|
547
|
+
usage_header: 'Usage:',
|
|
548
|
+
usage_staged: ' npx smart-code-reviewer --staged # Review staged files',
|
|
549
|
+
usage_diffonly: ' npx smart-code-reviewer --staged --diff-only # Review only changes (git diff)',
|
|
550
|
+
usage_files: ' npx smart-code-reviewer --files file1,file2 # Review specific files',
|
|
551
|
+
review_error: 'Review failed: {error}',
|
|
552
|
+
|
|
553
|
+
// Config loader
|
|
554
|
+
external_config_parse_failed_warn: 'External config parse failed; using default: {error}',
|
|
555
|
+
use_external_rules_only_info: 'Using external rules only: loading rules from local-rules directory',
|
|
556
|
+
load_external_rules_failed_warn: 'Failed to load external rules: {error}',
|
|
557
|
+
temp_file_method_failed_fallback_info: 'Temp-file approach failed; falling back to base64: {error}',
|
|
558
|
+
load_rule_file_failed_warn: 'Failed to load rule file {file}: {error}',
|
|
559
|
+
|
|
560
|
+
// Reviewer
|
|
561
|
+
review_staged_start: 'Reviewing staged code...',
|
|
562
|
+
using_diff_mode: '🔍 Using Git Diff incremental review - only changed lines',
|
|
563
|
+
using_full_mode: '📁 Using full-file review mode',
|
|
564
|
+
no_staged_files: '📭 No staged files to review',
|
|
565
|
+
found_staged_files_n: '📁 Found {count} files to review',
|
|
566
|
+
get_staged_failed: 'Failed to get staged files: {error}',
|
|
567
|
+
review_specific_start: 'Reviewing specific files: {files}',
|
|
568
|
+
file_not_exists: 'File does not exist: {path}',
|
|
569
|
+
start_git_diff_mode: '🔍 Starting Git Diff incremental review...',
|
|
570
|
+
no_changes_skip: '📝 No changes in staged area, skipping review',
|
|
571
|
+
found_changed_files_n: '📊 Found {count} changed files, starting incremental review...',
|
|
572
|
+
// Merge/Rebase filters
|
|
573
|
+
merge_rebase_detected_info: '🔀 Git merge/rebase detected; filtering to conflict files',
|
|
574
|
+
merge_conflict_paths_found_n: '⚔️ Found {count} conflict file(s); reviewing only these',
|
|
575
|
+
merge_rebase_no_conflict_skip: '✅ No conflict files during merge/rebase; skipping review',
|
|
576
|
+
apply_static_rules_dbg: 'Applying static rule checks...',
|
|
577
|
+
static_rules_found_n_dbg: 'Static rules found {count} issues',
|
|
578
|
+
file_skipped_by_type: 'File skipped: {path} (ignored file type)',
|
|
579
|
+
blocking_risk_detected_skip_ai: 'Blocking risk detected ({levels}), skipping AI analysis',
|
|
580
|
+
blocking_risk_terminate: 'Blocking risk detected, terminating review',
|
|
581
|
+
ai_start_n_files: '🤖 Starting AI analysis for {count} files...',
|
|
582
|
+
ai_diff_failed: 'AI diff analysis failed for {path}: {error}',
|
|
583
|
+
git_diff_done: '✨ Git Diff incremental review completed',
|
|
584
|
+
git_diff_error: 'Git Diff review encountered an error: {error}',
|
|
585
|
+
smart_segmentation_done_dbg: 'Smart segmentation done for {file}: {raw} raw -> {smart} smart segments',
|
|
586
|
+
all_added_lines_ignored_dbg: 'All added lines ignored by inline directives: {file}',
|
|
587
|
+
|
|
588
|
+
// Reviewer (additional)
|
|
589
|
+
review_file_dbg: 'Reviewing file: {file}',
|
|
590
|
+
using_incremental_analyzer_progress: 'Using incremental analyzer...',
|
|
591
|
+
incremental_analyzer_failed_error: 'Incremental analyzer failed: {error}',
|
|
592
|
+
smart_batching_process_error: 'Smart batching process error: {error}',
|
|
593
|
+
ai_smart_analysis_start_progress: 'Starting AI analysis; time varies with file sizes...',
|
|
594
|
+
ai_analysis_start_batches: 'Starting AI analysis, total {count} batches',
|
|
595
|
+
batch_info_header: 'Batch {index}/{total}: analyzing {files} files',
|
|
596
|
+
batch_done_success: 'Batch {index}/{total} completed',
|
|
597
|
+
fallback_analysis_failed: 'Fallback analysis failed: {error}',
|
|
598
|
+
serial_process_batches_info: 'Processing {count} batches in serial mode',
|
|
599
|
+
serial_large_file_batch_info: 'Batch {index}/{total}: analyzing {file}, {segments} segments',
|
|
600
|
+
serial_small_file_batch_info: 'Batch {index}/{total}: analyzing {files}',
|
|
601
|
+
ai_analysis_done_summary: 'AI analysis done: {totalIssues} issues found, elapsed {elapsed}s',
|
|
602
|
+
rule_exec_failed_warn: 'Rule {id} execution failed: {error}',
|
|
603
|
+
skip_by_comments_dbg: 'Comments skipped from review ({count} matches)',
|
|
604
|
+
skip_by_directives_dbg: 'Directive-disabled ranges skipped ({count} matches)',
|
|
605
|
+
skip_ai_large_file: 'Skipping AI for large file: {file}',
|
|
606
|
+
blocking_risk_skip_all_ai_info: 'Blocking local risks present; skipping AI analysis for all files.',
|
|
607
|
+
|
|
608
|
+
// Print Results
|
|
609
|
+
local_analysis_header: 'Local Rule Analysis',
|
|
610
|
+
ai_analysis_header: 'AI Code Analysis',
|
|
611
|
+
no_issues: 'None',
|
|
612
|
+
file_label: 'File: {file}',
|
|
613
|
+
issue_label: 'Issue {index}:',
|
|
614
|
+
snippet_label: 'Code Snippet:',
|
|
615
|
+
snippet_global_label: 'Code Snippet: (Global issue)',
|
|
616
|
+
risk_level_label: 'Risk Level:',
|
|
617
|
+
risk_reason_label: 'Risk Reason:',
|
|
618
|
+
suggestions_label: 'Suggestions:',
|
|
619
|
+
tip_line_numbers: 'Note: Snippet line numbers are absolute source lines. Due to pre-processing (stripping comments/ignoring segments), lines may be non-contiguous — ignore such gaps.',
|
|
620
|
+
line_label: 'Line: {line}',
|
|
621
|
+
line_range_label: 'Line Range: {start}-{end}',
|
|
622
|
+
|
|
623
|
+
// AI Client
|
|
624
|
+
node_version_warn: 'Detected Node < 18 or missing global fetch, may cause connection issues. Please upgrade to Node >=18.',
|
|
625
|
+
ai_batch_failed: 'AI batch file analysis failed: {error}',
|
|
626
|
+
ai_connection_failed: 'AI service connection failed, terminating analysis',
|
|
627
|
+
ai_retry_warn: 'AI request failed, retry ({attempt}/{retries}), wait {delay}ms: {error}',
|
|
628
|
+
read_ai_prompt_file_failed: 'Failed to read AI prompt file {file}: {error}',
|
|
629
|
+
read_custom_prompts_failed: 'Failed to read custom AI prompts: {error}',
|
|
630
|
+
custom_prompts_label: 'Custom Prompts',
|
|
631
|
+
ignore_rule: 'Note: Code may be pre-processed (comments stripped, segments skipped), so line number prefixes can be non-contiguous. This is normal — strictly ignore "line jumps/non-contiguous/removed by pre-processing". Do not treat them as issues or risk reasons; do not suggest "check completeness/fill missing code". Only analyze the provided snippet.',
|
|
632
|
+
// Batch and files intro/instruction
|
|
633
|
+
batch_intro: 'I will send a batch of files for code review. Some may be segmented (large files split into chunks). For segmented files, analyze holistically after receiving all segments. Separate each issue with a blank line and include the absolute file path and a concrete code snippet. Do not use textual line numbers or ranges.',
|
|
634
|
+
batch_files_intro: 'I will send multiple complete files at once. Review per file and return issues. Separate issues with a blank line. Always include "File Path: absolute path" and a concrete code snippet. Do not use textual line numbers or ranges (e.g., "line X" or "lines X-Y").',
|
|
635
|
+
final_instruction_batch: 'Review each file. Separate each issue by a blank line, and include "File Path: absolute path" and a specific code snippet. Do not use textual line numbers or ranges (e.g., "line X" or "lines X-Y"). If snippet lines have [n] prefixes, keep them as-is.',
|
|
636
|
+
file_failed_static_suffix: ' (Local analysis failed)',
|
|
637
|
+
// Local rule hints
|
|
638
|
+
local_rule_findings: 'Local Rule Findings',
|
|
639
|
+
local_rule_findings_header: '[Local Rule Findings - {file}]',
|
|
640
|
+
inline_suggestion: '; Suggestion: {suggestion}',
|
|
641
|
+
local_rule_hint_line: '{index}. Snippet ({risk}): {message}{suggest}; Code: {snippet}',
|
|
642
|
+
// Diff prompts and logs
|
|
643
|
+
ai_diff_start_dbg: 'Starting Git Diff analysis: {file} ({added} added lines)',
|
|
644
|
+
ai_diff_send_dbg: 'Sending Git Diff AI request - model: {model}, messages: {messages}',
|
|
645
|
+
ai_diff_done_dbg: 'Git Diff analysis completed: {file}, found {issues} issues',
|
|
646
|
+
ai_issues_found_n_dbg: 'AI analysis found {count} issues',
|
|
647
|
+
diff_intro: 'Please review the following Git changes. Focus ONLY on added lines (+). Context lines are for understanding only.',
|
|
648
|
+
diff_added_lines_label: 'Added Lines: ',
|
|
649
|
+
diff_smart_segments_label: 'Smart Segments: ',
|
|
650
|
+
diff_changes_label: 'Changes:',
|
|
651
|
+
diff_segment_title: 'Smart Segment {index}/{total}',
|
|
652
|
+
diff_segment_meta: 'line range: {start}-{end}, added {added} lines, ~{tokens} tokens',
|
|
653
|
+
diff_final_instruction: 'Only review lines marked with "+" and ignore deletions ("-") and context. Separate each issue by a blank line and include "File Path: {file}" and a concrete code snippet. Do not use textual line numbers or ranges; keep [n] prefixes if present.',
|
|
654
|
+
// Fallback messages for static/local rules
|
|
655
|
+
fallback_static_reason: 'Based on local rules: {message}',
|
|
656
|
+
fallback_static_suggestion: 'Please review and fix per local rules, and add tests and monitoring to validate the risk.',
|
|
657
|
+
// Reviewer extra
|
|
658
|
+
review_file_progress: '[{index}/{total}] Reviewing: {file} (+{added} lines, {segments} segments)',
|
|
659
|
+
ai_file_progress_dbg: '🤖 [{index}/{total}] AI analysis: {file}',
|
|
660
|
+
incremental_analyzer_start: 'Using incremental analyzer...',
|
|
661
|
+
ai_start_progress_note: 'Starting AI analysis; duration varies by file size...',
|
|
662
|
+
fallback_simple_analysis_progress: 'Falling back to simple analysis...',
|
|
663
|
+
ai_start_batches_count_info: 'Starting AI analysis, {count} batches',
|
|
664
|
+
batch_start_regular_simple: 'Batch {i}/{total}: analyzing {count} files',
|
|
665
|
+
start_concurrency_enabled_info: 'Concurrency enabled, workers: {concurrency}',
|
|
666
|
+
start_serial_dbg: 'Using serial mode for {count} batches',
|
|
667
|
+
start_concurrency_dbg: 'Using concurrent mode for {count} batches',
|
|
668
|
+
review_file_path_dbg: 'Reviewing file: {path}',
|
|
669
|
+
review_file_failed: 'Reviewing file failed {file}: {error}',
|
|
670
|
+
skip_by_comments_dbg: 'Comments skipped from review ({count} matches)',
|
|
671
|
+
skip_by_directives_dbg: 'Directive-disabled ranges skipped ({count} matches)',
|
|
672
|
+
skip_ai_large_file: 'Skipping AI for large file: {file}',
|
|
673
|
+
incremental_analyzer_failed_error: 'Incremental analyzer failed: {error}',
|
|
674
|
+
fallback_analysis_failed: 'Fallback analysis failed: {error}',
|
|
675
|
+
stream_read_large_file_dbg: 'Streaming large file: {file} ({sizeKB}KB)',
|
|
676
|
+
read_file_failed: 'Failed to read file {file}: {error}',
|
|
677
|
+
blocking_risk_skip_all_ai_info: 'Blocking local risks present; skipping AI analysis for all files.',
|
|
678
|
+
|
|
679
|
+
// Pool
|
|
680
|
+
init_pool_dbg: 'Initializing AI client pool, size: {size}',
|
|
681
|
+
pool_init_done_dbg: 'AI client pool initialized, {count} clients',
|
|
682
|
+
start_concurrent_dbg: 'Starting concurrent processing for {count} batches',
|
|
683
|
+
concurrent_done_dbg: 'Concurrent processing finished: success {succ}, fail {fail}',
|
|
684
|
+
concurrent_group_failed: 'File group {index} failed: {error}',
|
|
685
|
+
concurrent_processing_error: 'Error during concurrent processing: {error}',
|
|
686
|
+
cleanup_pool_dbg: 'Cleaning AI client pool resources',
|
|
687
|
+
request_batch_start_dbg: 'Starting AI request, batch {index}, client: {client}',
|
|
688
|
+
seg_chunk_no_issues_dbg: '{file} chunk {chunk}/{total} no issues; AI response: {preview}',
|
|
689
|
+
files_no_issues_dbg: '{files} no issues; AI response: {preview}',
|
|
690
|
+
issues_risk_levels_dbg: '{file} issue risk levels: {levels}',
|
|
691
|
+
issues_details_dbg: '{file} issue details:',
|
|
692
|
+
issue_item_dbg: ' Issue {index}: {risk} - {message}',
|
|
693
|
+
batch_start_regular: 'Batch {i}/{total} start: files {files} ({count} files, tokens {tokens})',
|
|
694
|
+
batch_start_segmented: 'Batch {i}/{total} start: segmented file {path}, total segments {segments}',
|
|
695
|
+
batch_complete: 'Batch {i}/{total} done: {context}, {issues} issues, took {secs}s',
|
|
696
|
+
batch_process_failed: 'Batch {i} failed: {error}',
|
|
697
|
+
batch_retry_warn: 'Batch {i} failed, retry #{retry}: {error}',
|
|
698
|
+
batch_retry_error: 'Batch {i} failed after {max} retries: {error}',
|
|
699
|
+
|
|
700
|
+
// Diff parser
|
|
701
|
+
git_diff_parse_failed: 'Failed to get git diff: {error}',
|
|
702
|
+
file_skipped_by_ignore_rule_dbg: 'File skipped by ignore rules: {file}',
|
|
703
|
+
smart_seg_done_dbg: 'File {file} smart segmentation: {orig} original -> {smart} segments',
|
|
704
|
+
rule_diff_exec_failed_warn: 'Rule {id} failed in diff mode: {error}',
|
|
705
|
+
analyze_staged_changes_progress: 'Analyzing staged changes...',
|
|
706
|
+
all_added_lines_ignored_by_directives_dbg: 'All added lines ignored by in-code directives: {file}',
|
|
707
|
+
get_staged_file_failed_dbg: 'Failed to get staged file content {file}: {error}',
|
|
708
|
+
|
|
709
|
+
// Segment analysis (large-file segmented processing)
|
|
710
|
+
segment_overall_start: 'Starting segmented analysis: {file}, total {total} segments{concurrency}{totalNote}',
|
|
711
|
+
segment_concurrency_note: ' (concurrency {workers})',
|
|
712
|
+
segment_total_note: ' (total segments {totalChunks}, current batch {effectiveTotal})',
|
|
713
|
+
segment_wait_start_dbg: 'Segment pending start: {index}/{total} (lines {start}-{end})',
|
|
714
|
+
segment_worker_start_dbg: 'Starting segment worker #{id}',
|
|
715
|
+
segment_schedule_dbg: 'Segment concurrency scheduling: workers={workers}, total={total}{note}',
|
|
716
|
+
segment_concurrency_done_dbg: 'Segment concurrency finished: processed {total}{extra} segments',
|
|
717
|
+
segment_start_label: 'Starting {file} segment {index}/{total} (lines {start}-{end})',
|
|
718
|
+
segment_batch_prefix: 'Batch {index}/{total} ',
|
|
719
|
+
segment_size_estimate_dbg: 'Estimated {tokens} tokens, {lines} lines of code',
|
|
720
|
+
segment_prepare_content_dbg: 'Preparing segment {index} code content...',
|
|
721
|
+
segment_build_prompt_dbg: 'Building prompt for segment {index}...',
|
|
722
|
+
segment_analysis_done_n_issues: '{batch}({file}) segment {index} analysis done; {count} issues found',
|
|
723
|
+
segment_analysis_done_zero: '{batch}({file}) segment {index} analysis done; 0 issues found',
|
|
724
|
+
segment_analysis_failed: 'Segment {index} analysis failed: {error}',
|
|
725
|
+
segment_file_failed: 'Segmented file analysis failed: {error}',
|
|
726
|
+
parse_seg_response_failed_warn: 'Failed to parse AI response: {error}',
|
|
727
|
+
parse_issue_section_failed_warn: 'Failed to parse issue section: {error}',
|
|
728
|
+
segment_prev_context_header: '**Previous Segment Summaries**:',
|
|
729
|
+
segment_prev_context_item: 'Segment {index} (lines {range}): {summary}',
|
|
730
|
+
segment_summary_marker: '**-----Segment Summary-----**',
|
|
731
|
+
segment_response_parsed_info: 'Segment {index} response parsed; {count} issues found',
|
|
732
|
+
// Chunked response and request logs (AI client)
|
|
733
|
+
detected_segmented_batch_dbg: 'Detected segmented batch; using overall analysis: {path} ({segments} segments)',
|
|
734
|
+
chunk_req_info_dbg: 'Send chunked AI request - model: {model}, messages: {count}',
|
|
735
|
+
chunk_req_preview_dbg: 'AI request messages preview:\n{preview}',
|
|
736
|
+
chunk_req_preview_fail_dbg: 'AI request preview failed: {error}',
|
|
737
|
+
preview_truncated_suffix: '...omitted {count} chars',
|
|
738
|
+
ai_response_len_dbg: 'AI response: {len} chars',
|
|
739
|
+
chunk_continue_needed_dbg: 'Chunked response incomplete; sending "continue" for next chunk',
|
|
740
|
+
chunk_continue_prompt: 'continue',
|
|
741
|
+
segment_static_issues_header: '[Local rule findings - Segment {index}]',
|
|
742
|
+
segment_static_issue_line: '{index}. Segment ({risk}): {message}{suggest}; {snippetLabel}{snippet}',
|
|
743
|
+
// File review status reasons
|
|
744
|
+
file_ext_not_supported_reason: 'File extension {ext} is not supported',
|
|
745
|
+
file_reason_exact_match: 'Exact match pattern',
|
|
746
|
+
file_reason_regex_match: 'Regex pattern matched',
|
|
747
|
+
file_reason_glob_match: 'Glob pattern matched',
|
|
748
|
+
segment_prompt_template: 'Please perform a thorough code review on the following code segment. This is segment {index}/{total} of a large file:\n\n{Lfile}{file}\n{Lcontent}\n```\n{content}\n```\n\nCarefully check for:\n- Type-safety issues (e.g., use of any)\n- Security vulnerabilities\n- Performance issues\n- Code quality problems\n- Violations of best practices\n\nImportant: Start analysis immediately; do not just acknowledge. You must output each finding in the following format:\n\n**-----Code Review Result-----**\n{Lfile}{file}\n{Lsnippet}[Specific problematic code]\n{Lrisk}[Critical/High/Medium/Low/Suggestion]\n{Lreason}[Problem description]\n{Lsuggestion}[Concrete suggestions]\n\nIf multiple issues are found, start every issue with **-----Code Review Result-----**.\nIf no issues are found, reply:\n\n**-----Code Review Result-----**\nNo obvious issues in this segment.\n\nNote: If each line contains a source-line prefix like [n], keep these prefixes unchanged in your output to help later localization.\n\nSegment context constraint: Do NOT evaluate whether imports/modules/dependencies are used in this segment; strictly ignore any suggestions about removing unused imports/modules/dependencies.',
|
|
749
|
+
// Static rule i18n (Best Practices)
|
|
750
|
+
rule_BP001_name: 'Debug code',
|
|
751
|
+
rule_BP001_message: 'Debug code found; remove before committing',
|
|
752
|
+
rule_BP001_suggestion: 'Use a logging system instead of console.log',
|
|
753
|
+
rule_BP002_name: 'Magic numbers',
|
|
754
|
+
rule_BP002_message: 'Magic numbers detected; define them as constants',
|
|
755
|
+
rule_BP002_suggestion: 'Define numbers as meaningful constants',
|
|
756
|
+
rule_BP003_name: 'Empty catch block',
|
|
757
|
+
rule_BP003_message: 'Empty catch may hide errors and cause unpredictable behavior',
|
|
758
|
+
rule_BP003_suggestion: 'Log or take remedial actions instead of swallowing exceptions',
|
|
759
|
+
rule_BP004_name: 'Ignore TypeScript type checking',
|
|
760
|
+
rule_BP004_message: 'Detected @ts-ignore; may conceal type errors',
|
|
761
|
+
rule_BP004_suggestion: 'Fix type issues or use precise type definitions',
|
|
762
|
+
rule_BP005_name: 'Use of any type',
|
|
763
|
+
rule_BP005_message: 'Using any weakens type safety guarantees',
|
|
764
|
+
rule_BP005_suggestion: 'Use concrete types or generics to improve safety',
|
|
765
|
+
rule_BP006_name: 'ESLint rule disabled',
|
|
766
|
+
rule_BP006_message: 'Disabling ESLint may hide code quality issues',
|
|
767
|
+
rule_BP006_suggestion: 'Disable locally only when necessary, and explain the reason',
|
|
768
|
+
rule_BP007_name: 'Debugger statement left',
|
|
769
|
+
rule_BP007_message: 'Debugger statement found; may affect production behavior',
|
|
770
|
+
rule_BP007_suggestion: 'Remove debugger before commit; use logs or assertions',
|
|
771
|
+
rule_BP008_name: 'Overly broad exception catch',
|
|
772
|
+
rule_BP008_message: 'Catching broad exception types without proper handling',
|
|
773
|
+
rule_BP008_suggestion: 'Catch specific types and ensure logging or rethrowing as needed',
|
|
774
|
+
rule_BP009_name: 'Print stack instead of logging',
|
|
775
|
+
rule_BP009_message: 'Direct stack printing may lose context and produce uncontrolled output',
|
|
776
|
+
rule_BP009_suggestion: 'Use structured logging with context information',
|
|
777
|
+
rule_BP010_name: 'Process-level exit call',
|
|
778
|
+
rule_BP010_message: 'System.exit detected; may cause unexpected service termination',
|
|
779
|
+
rule_BP010_suggestion: 'Use graceful shutdown, signal handling, and resource cleanup',
|
|
780
|
+
rule_BP011_name: 'Use root database user',
|
|
781
|
+
rule_BP011_message: 'Using root as DB user introduces security and audit risks',
|
|
782
|
+
rule_BP011_suggestion: 'Use a least-privileged application account and separate duties',
|
|
783
|
+
rule_BP012_name: 'Disable CSRF (Spring Security)',
|
|
784
|
+
rule_BP012_message: 'Globally disabling CSRF may cause CSRF vulnerabilities',
|
|
785
|
+
rule_BP012_suggestion: 'Use token/same-origin policies where needed; avoid global disable',
|
|
786
|
+
rule_BP013_name: 'Use of var declarations',
|
|
787
|
+
rule_BP013_message: 'Using var may cause scope issues',
|
|
788
|
+
rule_BP013_suggestion: 'Use let or const to improve safety',
|
|
789
|
+
|
|
790
|
+
// Static rule i18n (Performance)
|
|
791
|
+
rule_PERF001_name: 'Database queries inside loops',
|
|
792
|
+
rule_PERF001_message: 'Executing DB queries in loops may cause N+1 problems',
|
|
793
|
+
rule_PERF001_suggestion: 'Use batch queries or preload data',
|
|
794
|
+
rule_PERF002_name: 'Memory leak risk (timers)',
|
|
795
|
+
rule_PERF002_message: 'Timers without cleanup may cause leaks or lingering tasks',
|
|
796
|
+
rule_PERF002_suggestion: 'Call clearInterval/clearTimeout at the proper lifecycle point',
|
|
797
|
+
rule_PERF003_name: 'Synchronous file I/O blocking',
|
|
798
|
+
rule_PERF003_message: 'Sync file I/O may block the event loop and hurt throughput',
|
|
799
|
+
rule_PERF003_suggestion: 'Prefer async I/O or queued processing; avoid blocking the main thread',
|
|
800
|
+
rule_PERF004_name: 'Network requests inside loops',
|
|
801
|
+
rule_PERF004_message: 'Requests inside loops can cause cascading latency and congestion',
|
|
802
|
+
rule_PERF004_suggestion: 'Merge requests, control concurrency, or batch to reduce round-trips',
|
|
803
|
+
rule_PERF005_name: 'JSON serialization inside loops',
|
|
804
|
+
rule_PERF005_message: 'Frequent serialization in loops causes excessive CPU overhead',
|
|
805
|
+
rule_PERF005_suggestion: 'Move serialization out of the loop or cache/batch it',
|
|
806
|
+
rule_PERF006_name: 'Regex compilation inside loops',
|
|
807
|
+
rule_PERF006_message: 'Repeated regex compilation adds unnecessary overhead',
|
|
808
|
+
rule_PERF006_suggestion: 'Precompile or constantize regexes; avoid creating them in loops',
|
|
809
|
+
rule_PERF007_name: 'Busy-wait loops',
|
|
810
|
+
rule_PERF007_message: 'Possible busy-wait detected; can spike CPU and waste resources',
|
|
811
|
+
rule_PERF007_suggestion: 'Use event-driven or blocking waits; avoid empty loops',
|
|
812
|
+
rule_PERF008_name: 'Layout thrashing in loops',
|
|
813
|
+
rule_PERF008_message: 'Reading layout in loops triggers frequent reflow/repaint',
|
|
814
|
+
rule_PERF008_suggestion: 'Batch DOM reads/writes; reduce synchronous layout queries',
|
|
815
|
+
rule_PERF009_name: 'Blocking sleep',
|
|
816
|
+
rule_PERF009_message: 'Blocking waits reduce throughput and responsiveness',
|
|
817
|
+
rule_PERF009_suggestion: 'Use async waits or rate-limiting/queues; avoid blocking',
|
|
818
|
+
rule_PERF010_name: 'Unbounded thread pool',
|
|
819
|
+
rule_PERF010_message: 'Unbounded pools can explode thread count and exhaust resources',
|
|
820
|
+
rule_PERF010_suggestion: 'Use bounded pools with sane maximums and queue lengths',
|
|
821
|
+
rule_PERF011_name: 'String concatenation inside loops',
|
|
822
|
+
rule_PERF011_message: 'Frequent concatenation in loops consumes CPU and memory',
|
|
823
|
+
rule_PERF011_suggestion: 'Use StringBuilder/collect in lists then join, or batch strategies',
|
|
824
|
+
rule_PERF012_name: 'Create DB connections in loops',
|
|
825
|
+
rule_PERF012_message: 'Repeatedly creating DB connections causes severe performance issues',
|
|
826
|
+
rule_PERF012_suggestion: 'Use connection pools and reuse; acquire connections outside loops',
|
|
827
|
+
rule_PERF013_name: 'HTTP requests without timeout (Python)',
|
|
828
|
+
rule_PERF013_message: 'Requests without timeout can hang resources and reduce throughput',
|
|
829
|
+
rule_PERF013_suggestion: 'Set reasonable timeout; control retries and circuit breaking',
|
|
830
|
+
|
|
831
|
+
// Static rule i18n (Security)
|
|
832
|
+
rule_SEC001_name: 'Hard-coded password detection',
|
|
833
|
+
rule_SEC001_message: 'Hard-coded password or secret detected',
|
|
834
|
+
rule_SEC001_suggestion: 'Use environment variables or a secure secret manager',
|
|
835
|
+
rule_SEC002_name: 'SQL injection risk',
|
|
836
|
+
rule_SEC002_message: 'String-concatenated SQL detected; injection risk',
|
|
837
|
+
rule_SEC002_suggestion: 'Use parameterized queries or the ORM’s safe APIs',
|
|
838
|
+
rule_SEC003_name: 'XSS risk',
|
|
839
|
+
rule_SEC003_message: 'Direct HTML manipulation detected; possible XSS',
|
|
840
|
+
rule_SEC003_suggestion: 'Use textContent or safe DOM APIs',
|
|
841
|
+
rule_SEC004_name: 'Command injection risk',
|
|
842
|
+
rule_SEC004_message: 'Command execution with possible user input detected',
|
|
843
|
+
rule_SEC004_suggestion: 'Avoid constructing commands from user input; validate strictly',
|
|
844
|
+
rule_SEC005_name: 'Path traversal risk',
|
|
845
|
+
rule_SEC005_message: 'Potential path traversal or unvalidated file path usage',
|
|
846
|
+
rule_SEC005_suggestion: 'Normalize and whitelist paths; never concatenate untrusted input',
|
|
847
|
+
rule_SEC006_name: 'Disable SSL certificate verification',
|
|
848
|
+
rule_SEC006_message: 'HTTP request with certificate verification disabled detected',
|
|
849
|
+
rule_SEC006_suggestion: 'Enable verification and use trusted CAs; avoid MITM attacks',
|
|
850
|
+
rule_SEC007_name: 'Weak cryptographic algorithm',
|
|
851
|
+
rule_SEC007_message: 'Detected use of weak algorithms such as MD5/SHA-1',
|
|
852
|
+
rule_SEC007_suggestion: 'Use stronger algorithms: SHA-256/512, Argon2, bcrypt, scrypt',
|
|
853
|
+
rule_SEC008_name: 'Hard-coded secret/Token',
|
|
854
|
+
rule_SEC008_message: 'Hard-coded secret or access token detected',
|
|
855
|
+
rule_SEC008_suggestion: 'Store secrets in a manager or environment variables',
|
|
856
|
+
rule_SEC009_name: 'Unsafe deserialization',
|
|
857
|
+
rule_SEC009_message: 'Potentially unsafe deserialization detected',
|
|
858
|
+
rule_SEC009_suggestion: 'Use safe methods (e.g., yaml.safe_load); never deserialize untrusted data',
|
|
859
|
+
rule_SEC010_name: 'SSRF risk',
|
|
860
|
+
rule_SEC010_message: 'User-controlled URL request detected; SSRF risk',
|
|
861
|
+
rule_SEC010_suggestion: 'Whitelist external URLs; prohibit access to internal addresses',
|
|
862
|
+
rule_SEC011_name: 'NoSQL injection risk',
|
|
863
|
+
rule_SEC011_message: 'Possible NoSQL injection (dynamically concatenated conditions)',
|
|
864
|
+
rule_SEC011_suggestion: 'Use parameterized queries or safe builders; avoid concatenation',
|
|
865
|
+
rule_SEC012_name: 'Open redirect',
|
|
866
|
+
rule_SEC012_message: 'User-controlled redirection detected; open-redirect risk',
|
|
867
|
+
rule_SEC012_suggestion: 'Whitelist target URLs or fix them to safe destinations',
|
|
868
|
+
rule_SEC013_name: 'System command execution (Python)',
|
|
869
|
+
rule_SEC013_message: 'System command execution detected; injection risk if user input involved',
|
|
870
|
+
rule_SEC013_suggestion: 'Avoid direct system calls; use safe libraries or strict whitelists',
|
|
871
|
+
rule_SEC014_name: 'Insecure randomness',
|
|
872
|
+
rule_SEC014_message: 'Non-cryptographic RNG used in security-sensitive contexts',
|
|
873
|
+
rule_SEC014_suggestion: 'Use cryptographically secure RNGs (crypto.randomBytes, secrets.SystemRandom)',
|
|
874
|
+
rule_SEC015_name: 'Dangerous eval/Function usage',
|
|
875
|
+
rule_SEC015_message: 'Dynamic execution that may lead to code injection',
|
|
876
|
+
rule_SEC015_suggestion: 'Avoid eval/Function; use safe parsing/mapping logic',
|
|
877
|
+
rule_SEC016_name: 'Prototype pollution',
|
|
878
|
+
rule_SEC016_message: 'Direct assignment to object prototypes; may cause pollution',
|
|
879
|
+
rule_SEC016_suggestion: 'Avoid merging untrusted data into prototypes; use safe merging',
|
|
880
|
+
rule_SEC017_name: 'Java string-concatenated SQL execution',
|
|
881
|
+
rule_SEC017_message: 'SQL execution built via string concatenation detected',
|
|
882
|
+
rule_SEC017_suggestion: 'Use PreparedStatement with placeholders',
|
|
883
|
+
rule_SEC018_name: 'jQuery.html causing XSS risk',
|
|
884
|
+
rule_SEC018_message: 'Direct HTML injection detected; possible XSS',
|
|
885
|
+
rule_SEC018_suggestion: 'Use text() or trusted templating with escaping',
|
|
886
|
+
rule_SEC019_name: 'Overly permissive file mode (777)',
|
|
887
|
+
rule_SEC019_message: 'Setting wide-open file permissions detected',
|
|
888
|
+
rule_SEC019_suggestion: 'Apply least privilege; avoid 777 and similar modes',
|
|
889
|
+
rule_SEC020_name: 'System command execution (multi-language)',
|
|
890
|
+
rule_SEC020_message: 'System command execution detected; injection risk with user input',
|
|
891
|
+
rule_SEC020_suggestion: 'Avoid shell commands; use safe libraries and whitelist parameters',
|
|
892
|
+
rule_SEC021_name: 'Disable TLS verification (Node)',
|
|
893
|
+
rule_SEC021_message: 'TLS certificate verification disabled detected',
|
|
894
|
+
rule_SEC021_suggestion: 'Enable verification and use trusted CA to avoid MITM',
|
|
895
|
+
rule_SEC022_name: 'CORS allows any origin',
|
|
896
|
+
rule_SEC022_message: 'CORS allows "*"; may lead to cross-origin data leaks',
|
|
897
|
+
rule_SEC022_suggestion: 'Only allow trusted origins; use tokens and fine-grained policy',
|
|
898
|
+
rule_SEC023_name: 'LDAP injection risk',
|
|
899
|
+
rule_SEC023_message: 'String-concatenated LDAP filters detected',
|
|
900
|
+
rule_SEC023_suggestion: 'Build filters safely and bind parameters; avoid concatenation',
|
|
901
|
+
rule_SEC024_name: 'XXE (XML External Entity) risk',
|
|
902
|
+
rule_SEC024_message: 'XML parsing with external entities not disabled',
|
|
903
|
+
rule_SEC024_suggestion: 'Disable external entities or use safe libraries (e.g., defusedxml)',
|
|
904
|
+
rule_SEC025_name: 'Java HostnameVerifier always returns true',
|
|
905
|
+
rule_SEC025_message: 'Hostname verification bypass detected for HTTPS',
|
|
906
|
+
rule_SEC025_suggestion: 'Implement strict hostname verification to avoid permissive behavior',
|
|
907
|
+
rule_SEC026_name: 'Node ignore certificate errors',
|
|
908
|
+
rule_SEC026_message: 'Global env disables certificate errors detected',
|
|
909
|
+
rule_SEC026_suggestion: 'Remove the setting and use valid certs or isolate in test env',
|
|
910
|
+
rule_SEC027_name: 'Credentials in connection string',
|
|
911
|
+
rule_SEC027_message: 'Username/password hard-coded in connection string detected',
|
|
912
|
+
rule_SEC027_suggestion: 'Use env variables or secure credential storage; avoid plaintext in code',
|
|
913
|
+
rule_SEC028_name: 'Sensitive data in logs',
|
|
914
|
+
rule_SEC028_message: 'Sensitive information logged',
|
|
915
|
+
rule_SEC028_suggestion: 'Mask sensitive fields or avoid logging them altogether',
|
|
916
|
+
rule_SEC029_name: 'Mass Assignment (Rails/Laravel)',
|
|
917
|
+
rule_SEC029_message: 'Possible mass assignment risk; no whitelist validation',
|
|
918
|
+
rule_SEC029_suggestion: 'Enable strong parameters/whitelist; only allow safe fields',
|
|
919
|
+
rule_SEC030_name: 'Disable TLS verification (Go)',
|
|
920
|
+
rule_SEC030_message: 'TLS certificate verification disabled in Go detected',
|
|
921
|
+
rule_SEC030_suggestion: 'Enable verification and use trusted CA; avoid MITM attacks',
|
|
922
|
+
rule_SEC031_name: 'Disable certificate validation (C#)',
|
|
923
|
+
rule_SEC031_message: 'Overriding global certificate validation; may accept any certificate',
|
|
924
|
+
rule_SEC031_suggestion: 'Remove the override and use proper validation mechanisms',
|
|
925
|
+
rule_SEC032_name: 'EF Core raw SQL concatenation',
|
|
926
|
+
rule_SEC032_message: 'Using FromSqlRaw with string concatenation detected',
|
|
927
|
+
rule_SEC032_suggestion: 'Use FromSqlInterpolated or parameterized queries to avoid injection',
|
|
928
|
+
rule_SEC033_name: 'Go system command execution',
|
|
929
|
+
rule_SEC033_message: 'System command execution in Go; injection risk if user input involved',
|
|
930
|
+
rule_SEC033_suggestion: 'Avoid shell -c and concatenation; whitelist parameters and exec paths',
|
|
931
|
+
rule_SEC034_name: 'Insecure randomness (Go)',
|
|
932
|
+
rule_SEC034_message: 'Using math/rand for randomness; not cryptographically secure',
|
|
933
|
+
rule_SEC034_suggestion: 'Use crypto/rand or secure RNG libraries for tokens and keys',
|
|
934
|
+
}
|
|
935
|
+
};
|
|
936
|
+
|
|
937
|
+
export function t(configOrLocale, key, params) {
|
|
938
|
+
const loc = getLocale(configOrLocale);
|
|
939
|
+
const dict = MESSAGES[loc] || MESSAGES['zh-CN'];
|
|
940
|
+
const msg = dict[key] || key;
|
|
941
|
+
return format(msg, params);
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
// Prompt builders for system and diff prompts in both languages.
|
|
945
|
+
export function buildPrompts(localeOrConfig) {
|
|
946
|
+
const loc = getLocale(localeOrConfig);
|
|
947
|
+
const L = FIELD_LABELS[loc] || FIELD_LABELS['zh-CN'];
|
|
948
|
+
// Shared analysis markers for parser compatibility (locale-driven, no hardcoded branching)
|
|
949
|
+
const MARKERS = {
|
|
950
|
+
'zh-CN': {
|
|
951
|
+
start: '**-----代码分析结果开始-----**',
|
|
952
|
+
end: '**-----代码分析结果结束-----**',
|
|
953
|
+
startDiff: '**-----Git Diff代码分析结果开始-----**',
|
|
954
|
+
endDiff: '**-----Git Diff代码分析结果结束-----**'
|
|
955
|
+
},
|
|
956
|
+
'en-US': {
|
|
957
|
+
start: '**-----Code Analysis Result Start-----**',
|
|
958
|
+
end: '**-----Code Analysis Result End-----**',
|
|
959
|
+
startDiff: '**-----Git Diff Code Analysis Result Start-----**',
|
|
960
|
+
endDiff: '**-----Git Diff Code Analysis Result End-----**'
|
|
961
|
+
}
|
|
962
|
+
};
|
|
963
|
+
const m = MARKERS[loc] || MARKERS['en-US'];
|
|
964
|
+
|
|
965
|
+
const systemPrompt = t(loc, 'system_prompt_template', {
|
|
966
|
+
start: m.start,
|
|
967
|
+
end: m.end,
|
|
968
|
+
Lfile: L.file,
|
|
969
|
+
Lsnippet: L.snippet,
|
|
970
|
+
Lrisk: L.risk,
|
|
971
|
+
Lreason: L.reason,
|
|
972
|
+
Lsuggestion: L.suggestion
|
|
973
|
+
});
|
|
974
|
+
|
|
975
|
+
const diffSystemPrompt = t(loc, 'diff_system_prompt_template', {
|
|
976
|
+
start: m.startDiff,
|
|
977
|
+
end: m.endDiff,
|
|
978
|
+
Lfile: L.file,
|
|
979
|
+
Lsnippet: L.snippet,
|
|
980
|
+
Lrisk: L.risk,
|
|
981
|
+
Lreason: L.reason,
|
|
982
|
+
Lsuggestion: L.suggestion
|
|
983
|
+
});
|
|
984
|
+
|
|
985
|
+
return { systemPrompt, diffSystemPrompt };
|
|
986
|
+
}
|