diff --git a/ts/src/agents/pr_assistant/pipeline-fix-flow.ts b/ts/src/agents/pr_assistant/pipeline-fix-flow.ts index bb4291d3..8ea1608a 100644 --- a/ts/src/agents/pr_assistant/pipeline-fix-flow.ts +++ b/ts/src/agents/pr_assistant/pipeline-fix-flow.ts @@ -3,7 +3,7 @@ import type { GithubClient, PR } from "../../github/client.ts"; import { commitsBehind } from "./branch-staleness.ts"; import { getPipelineErrorLogs } from "./logs.ts"; import { checkPipelineStatus } from "./pipeline.ts"; -import { MANUAL_PIPELINE_LABEL, buildMarker, fixPipelineAutonomously, maxAttempts, pipelineFixEnabled, readAttemptState } from "./pipeline-fixer.ts"; +import { MANUAL_PIPELINE_LABEL, buildMarker, fixPipelineAutonomously, maxAttempts, pipelineFixEnabled, previousAttemptFailures, readAttemptState } from "./pipeline-fixer.ts"; type Log = (m: string, level?: string) => void; @@ -53,7 +53,7 @@ export async function attemptPipelineFix(pr: PR, gh: GithubClient, log: Log): Pr if (!data.logs.trim()) { log(`No actionable pipeline logs for PR #${pr.number}`, "WARNING"); return false; } const attempt = last + 1; log(`PR #${pr.number}: pipeline failing — fix attempt ${attempt}/${mx}`); - const [success, msg, sha] = await fixPipelineAutonomously(gh, pr, data.logs, data.failed_checks, attempt, mx); + const [success, msg, sha] = await fixPipelineAutonomously(gh, pr, data.logs, data.failed_checks, attempt, mx, previousAttemptFailures(comments)); await commentAttempt(pr, gh, log, msg, attempt, mx, sha || pr.head.sha, success); if (success) return true; if (attempt >= mx) await markManual(pr, gh, log, msg); diff --git a/ts/src/agents/pr_assistant/pipeline-fixer.ts b/ts/src/agents/pr_assistant/pipeline-fixer.ts index e1213bce..032925b8 100644 --- a/ts/src/agents/pr_assistant/pipeline-fixer.ts +++ b/ts/src/agents/pr_assistant/pipeline-fixer.ts @@ -44,7 +44,18 @@ export function readAttemptState(comments: { body?: string | null }[]): [number, for (const c of comments) { const m = MARKER_RE.exec(c.body ?? ""); if (m) { attempt = parseInt(m[1]!, 10); sha = m[2]!; } } return [attempt, sha]; } -export function buildPrompt(errorLogs: string, failedChecks: string[]): string { +/** Reasons of the earlier failed attempts (newest last), read back from the attempt comments so a retry does not repeat them. */ +export function previousAttemptFailures(comments: { body?: string | null }[], limit = 3): string[] { + const out: string[] = []; + for (const c of comments) { + const body = c.body ?? ""; + if (!MARKER_RE.test(body) || !body.includes("a tentativa falhou")) continue; + const m = /\*\*Detalhes:\*\*\s*([\s\S]*?)\s*