refactor(ai-review 診斷): 收斂失敗輸出處理與推送註解
This commit is contained in:
+15
-4
@@ -29,6 +29,19 @@ function redactSecrets(text) {
|
||||
.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 將 AI CLI 失敗輸出整理成單行、遮罩且限長的診斷片段。
|
||||
*
|
||||
* @param {string[]} parts - 要附加診斷片段的陣列。
|
||||
* @param {string} label - 診斷欄位名稱(如 stderr/stdout)。
|
||||
* @param {*} value - 原始診斷輸出。
|
||||
* @returns {void}
|
||||
*/
|
||||
function appendRedactedOutput(parts, label, value) {
|
||||
const redacted = redactSecrets(String(value || '').slice(0, AGENT_DIAGNOSTIC_INPUT_LIMIT));
|
||||
if (redacted) parts.push(`${label}:${redacted.slice(0, AGENT_DIAGNOSTIC_OUTPUT_LIMIT)}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 從 `runAgent` 的失敗結果組出可診斷的一行摘要:退出碼/訊號為主,原始輸出預設隱藏。
|
||||
*
|
||||
@@ -52,10 +65,8 @@ function agentFailureDetail(agentResult) {
|
||||
}
|
||||
// 失敗輸出可能含 token 或 PII,預設不寫入長期 CI log;debug 模式才輸出遮罩後片段。
|
||||
if (process.env.ACTIONS_STEP_DEBUG === 'true') {
|
||||
const stderr = redactSecrets(String((agentResult && agentResult.stderr) || '').slice(0, AGENT_DIAGNOSTIC_INPUT_LIMIT));
|
||||
if (stderr) parts.push(`stderr:${stderr.slice(0, AGENT_DIAGNOSTIC_OUTPUT_LIMIT)}`);
|
||||
const stdout = redactSecrets(String((agentResult && agentResult.output) || '').slice(0, AGENT_DIAGNOSTIC_INPUT_LIMIT));
|
||||
if (stdout) parts.push(`stdout:${stdout.slice(0, AGENT_DIAGNOSTIC_OUTPUT_LIMIT)}`);
|
||||
appendRedactedOutput(parts, 'stderr', agentResult && agentResult.stderr);
|
||||
appendRedactedOutput(parts, 'stdout', agentResult && agentResult.output);
|
||||
}
|
||||
if (parts.length === 0) {
|
||||
parts.push((err && err.message && redactSecrets(err.message)) || 'AI CLI 執行失敗(無診斷輸出)');
|
||||
|
||||
Reference in New Issue
Block a user