Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 16x 16x 16x 1x 1x 1x 1x 1x 1x 1x 1x 16x 1x 1x 1x 1x 1x 1x 1x 1x 14x 14x 14x 14x 14x 14x 14x 14x 2x 16x 16x 16x 16x 16x 16x 16x 16x 16x 8x 8x 16x 16x 16x 2x 13x 13x 13x 13x 13x 13x 39x 39x 13x 13x 2x 7x 7x 7x 1x 1x 1x 1x 7x 1x 1x 1x 1x 5x 5x 5x 5x 2x 5x 5x 5x 5x 5x 5x 5x 5x 5x | import type { LinterDiagnostic, AiFixSnippet } from '../types';
import { getLanguage } from '../i18n/messages';
export interface ReviewIssueInput {
ruleId: string;
line: number;
message: string;
suggestion?: string;
fix?: AiFixSnippet;
}
export function buildFixSystemPrompt(): string {
const lang = getLanguage();
if (lang === 'ja') {
return `あなたはシニアコード修正の専門家です。与えられた問題とコードコンテキストから、最小で正しい修正を生成してください。
JSONのみを出力:{ "originalText": "置換対象の原文(コードコンテキスト内に完全一致すること)", "newText": "修正後の新コード" }
要件:
- originalText は提供されたコードコンテキスト内に逐語的に存在し、正確な空白・インデントも含むこと
- 指定された問題のみ修正し、無関係なコードは変更しないこと
- コードスタイルとインデントを維持すること
- 必ず修正コードを出力すること。空の修正を出力しないこと。問題を完全に解消できない場合でも、問題を緩和・改善する最小のコード片を出力すること`;
}
if (lang === 'en') {
return `You are a senior code fixer. Given the code issue and context, produce the minimal correct fix.
Output JSON only: { "originalText": "the exact original snippet to replace (must be found verbatim in the code context)", "newText": "the fixed replacement snippet" }
Requirements:
- originalText must exist verbatim in the provided code context, including exact whitespace and indentation
- Fix only the reported issue; do not modify unrelated code
- Preserve code style and indentation
- Always output a fix snippet; never output an empty fix. Even if the issue cannot be fully resolved, output the minimal snippet that mitigates or improves it`;
}
return `你是资深代码修复专家。根据给定的代码问题与上下文,给出最小且正确的修复。
仅输出 JSON:{ "originalText": "需要被替换的原文片段(必须在代码上下文中逐字存在,含精确的前后空白与缩进)", "newText": "修复后的新代码片段" }
要求:
- originalText 必须在提供的代码上下文中逐字存在,包含精确的缩进与前后空白
- 只修复指定问题,不要改动无关代码
- 保持代码风格与缩进
- 必须输出修复片段,禁止输出空修复;即使无法完全消除问题,也要给出能缓解/改善问题的最小代码片段`;
}
export function buildFixUserPrompt(diag: ReviewIssueInput, context: string): string {
const lang = getLanguage();
const issueLabel = lang === 'ja' ? '問題' : lang === 'en' ? 'Issue' : '问题';
const suggestionLabel = lang === 'ja' ? '参考提案' : lang === 'en' ? 'Reference suggestion' : '参考建议';
const contextLabel = lang === 'ja' ? 'コードコンテキスト(行番号付き)' : lang === 'en' ? 'Code context (with line numbers)' : '代码上下文(带行号)';
const parts: string[] = [];
parts.push(`## ${issueLabel}\n[${diag.ruleId}] ${diag.message}`);
if (diag.suggestion && diag.suggestion.trim() !== '') {
parts.push(`## ${suggestionLabel}\n${diag.suggestion}`);
}
parts.push(`## ${contextLabel}\n${context}`);
return parts.join('\n\n');
}
export function buildFixContext(code: string, line: number): string {
const lines = code.split('\n');
const start = Math.max(0, line - 6);
const end = Math.min(lines.length - 1, line + 6);
const out: string[] = [];
for (let i = start; i <= end; i++) {
out.push(`${String(i + 1).padStart(4, ' ')}| ${lines[i]}`);
}
return out.join('\n');
}
export function buildVerifySystemPrompt(): string {
const lang = getLanguage();
if (lang === 'ja') {
return `あなたはコードレビュアーです。修正後のコードに指定された問題がまだ存在するか確認してください。
JSONのみを出力:{ "fixed": true|false, "reason": "まだ残る場合の理由" }
問題が完全に解消されていれば "fixed": true、まだ残っていれば "fixed": false を返してください。`;
}
if (lang === 'en') {
return `You are a code reviewer. Check whether the reported issue still exists in the fixed code.
Output JSON only: { "fixed": true|false, "reason": "reason if it still remains" }
Return "fixed": true if the issue is fully resolved, otherwise "fixed": false.`;
}
return `你是代码审查员。检查修复后的代码中指定问题是否仍然存在。
仅输出 JSON:{ "fixed": true|false, "reason": "如果问题仍存在的原因" }
问题已完全解决返回 "fixed": true,仍存在返回 "fixed": false。`;
}
export function buildVerifyUserPrompt(diag: ReviewIssueInput, code: string): string {
const lang = getLanguage();
const issueLabel = lang === 'ja' ? '問題' : lang === 'en' ? 'Issue' : '问题';
const codeLabel = lang === 'ja' ? '修正後コード' : lang === 'en' ? 'Fixed code' : '修复后代码';
const parts: string[] = [];
parts.push(`## ${issueLabel}\n[${diag.ruleId}] ${diag.message}`);
parts.push(`## ${codeLabel}\n${code}`);
return parts.join('\n\n');
}
|