feat(ai-review 行號): 角色 prompt 強制行號,缺行號時反問原角色依 diff 定位(重試上限)
This commit is contained in:
+20
-1
@@ -70,7 +70,7 @@ export function buildAnalysisPrompt(role) {
|
||||
'{',
|
||||
' "level": "critical|warning|info",',
|
||||
` "role": "${role.name}",`,
|
||||
' "location": "檔案路徑:行號 或 檔案路徑",',
|
||||
' "location": "檔案路徑:行號(行號為必填,例如 app/foo.js:42)",',
|
||||
' "problem": "繁體中文(台灣用語)說明審查員認為這裡有問題的原因,不要只填檔案路徑或行號",',
|
||||
' "suggestion": "繁體中文(台灣用語)的具體修改建議"',
|
||||
'}',
|
||||
@@ -80,10 +80,29 @@ export function buildAnalysisPrompt(role) {
|
||||
'- warning:建議修正的問題',
|
||||
'- info:可選的改善建議',
|
||||
'',
|
||||
'location 規則(務必遵守):',
|
||||
'- **每一條問題都必須帶行號**,格式一律為 `檔案路徑:行號`(單一行號,例如 `app/foo.js:42`)。',
|
||||
'- 嚴禁只給檔名而省略行號;行號請取該問題在 Git Diff 新增/修改處的實際行號。',
|
||||
'- 一條問題只對應一個檔案與一個行號,不要用逗號列多個檔案。',
|
||||
'',
|
||||
'只回傳 JSON 陣列,不要有其他文字。如果沒有問題,回傳空陣列 []。',
|
||||
].filter(l => l !== '').join('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* 由角色定義組出「補行號」的 system prompt:
|
||||
* 當該角色先前提出的問題只有檔名、缺行號時,請它對照 Git Diff 找出實際行號。
|
||||
*/
|
||||
export function buildLocateLinePrompt(role) {
|
||||
const name = role?.name || 'AI Review';
|
||||
const badge = role?.badge ? `${role.badge} ` : '';
|
||||
return [
|
||||
`你是 ${badge}${name}${role?.focus ? `(負責「${role.focus}」面向)` : ''}。`,
|
||||
'你先前提出了一個問題,但 location 只給了檔名、沒有行號。請對照下方提供的該檔案 Git Diff,找出這個問題對應的**實際行號**(新增/修改處在該檔案中的行號)。',
|
||||
'只回傳 JSON 物件:{"line": 數字},不要有其他文字。若 diff 中確實找不到對應行,回傳 {"line": 0}。',
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* 由防守方角色定義組出「單條 finding 誤報裁決」的 system prompt:
|
||||
* 套用其個性與裁決準則本文,要求對一條 finding 判定成立或誤報,回固定 JSON 物件。
|
||||
|
||||
Reference in New Issue
Block a user