feat(腳色系統): 改用 skill RPG 攻防腳色、新增 Mage 邏輯角色並讓 Step3/4 套上 Paladin 裁決人設
This commit is contained in:
+8
-6
@@ -1,19 +1,21 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { chatJSON } from './llm.js';
|
||||
import { buildAnalysisPrompt } from './roles.js';
|
||||
import { FINDINGS_PATH, EXCLUSIONS_PATH } from './config.js';
|
||||
import { line, ok, warn } from './log.js';
|
||||
|
||||
const LEVELS = ['critical', 'warning', 'info'];
|
||||
|
||||
/**
|
||||
* 用單一角色分析 diff,回傳 findings 陣列
|
||||
* 用單一角色分析 diff,回傳 findings 陣列。
|
||||
* role 欄位一律以角色定義的 name 為準,避免 LLM 自行填入不一致的名稱。
|
||||
*/
|
||||
export async function analyzeWithRole(role, diff) {
|
||||
line(`[${role.name}] 開始分析`);
|
||||
const findings = await chatJSON(role.system_prompt, `以下是 Git Diff 內容:\n\n${diff}`);
|
||||
const valid = findings.filter(f => f.level && f.role && f.location && f.suggestion)
|
||||
.map(f => ({ ...f, is_new: true }));
|
||||
const findings = await chatJSON(buildAnalysisPrompt(role), `以下是 Git Diff 內容:\n\n${diff}`);
|
||||
const valid = findings.filter(f => f.level && f.location && f.suggestion)
|
||||
.map(f => ({ ...f, role: role.name, is_new: true }));
|
||||
ok(`[${role.name}] 找到 ${valid.length} 個問題`);
|
||||
return valid;
|
||||
}
|
||||
@@ -253,7 +255,7 @@ function toAIPayload(findings) {
|
||||
export async function deduplicateWithAI(findings) {
|
||||
if (findings.length === 0) return findings;
|
||||
|
||||
const systemPrompt = `移除語意重複的程式碼審查問題(JSON 陣列)。保留等級較高者(critical > warning > info)。只回傳去重後的 JSON 陣列。`;
|
||||
const systemPrompt = `你是 🛡️ Paladin(聖騎士),這座程式碼競技場沉穩公正的裁判。攻擊方提出了一批程式碼審查問題(JSON 陣列)。請就事論事,把「同檔案位置 + 同問題本質」的重複指控合併,重複者只保留等級較高的一條(critical > warning > info)。只回傳去重後的 JSON 陣列,不要有其他文字。`;
|
||||
|
||||
try {
|
||||
const result = await chatJSON(systemPrompt, JSON.stringify(toAIPayload(findings)));
|
||||
@@ -350,7 +352,7 @@ export async function filterFalsePositivesWithAI(findings, exclusions = [], chat
|
||||
? `\n${exclusionContext.prompt}\n規則:若 finding 與上述任何一類的路徑、角色或描述高度相似,優先視為誤報或不適用。`
|
||||
: '';
|
||||
|
||||
const systemPrompt = `判斷以下程式碼審查問題是否為誤報或不適用(如已正確使用 secrets、CI/CD 必要權限等),移除後只回傳需保留的 JSON 陣列。${exclusionHint}`;
|
||||
const systemPrompt = `你是 🛡️ Paladin(聖騎士),公正的裁判。逐條審視攻擊方的指控,剔除誤報或不適用者(例如:已正確使用 secrets、CI/CD 必要權限、他處已妥善處理、語義其實正確)。不冤枉無辜的程式碼,也不放水。移除誤報後,只回傳需保留(成立)的 JSON 陣列,不要有其他文字。${exclusionHint}`;
|
||||
|
||||
try {
|
||||
const result = await chatFn(systemPrompt, JSON.stringify(toAIPayload(findings)));
|
||||
|
||||
Reference in New Issue
Block a user