File size: 2,880 Bytes
914f53d | 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 | import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { parse } from 'yaml';
import { z } from 'zod';
const ConfigSchema = z.object({
dryRun: z.boolean().default(true),
reviewModel: z.string().default('claude-opus-4-8'),
fixModel: z.string().default('claude-opus-4-8'),
/** Model for the Codex CLI reviewer slot (only used when OPENAI_API_KEY exists). */
codexModel: z.string().default('gpt-6.1-sol'),
authors: z
.object({
mode: z.enum(['allowlist', 'all', 'label_only']).default('label_only'),
allowlist: z.array(z.string()).default([]),
})
.default({ mode: 'label_only', allowlist: [] }),
limits: z
.object({
maxFixRounds: z.number().default(5),
maxOrchestratorCycles: z.number().default(8),
maxBugbotWaitMin: z.number().default(12),
/**
* How long to wait for Bugbot's check run to *appear* before concluding
* it declined the PR. Bounds the wasted poll on diffs Bugbot ignores.
*/
bugbotStartGraceMin: z.number().default(4),
maxCiWaitMin: z.number().default(45),
maxNewBlockingPerCycle: z.number().default(5),
maxFixAgentTurns: z.number().default(80),
consecutiveNoNewReviewsForHandoff: z.number().default(2),
/**
* Cap on orchestrator-initiated `workflow_dispatch` continuations for a
* single PR. Only used when nothing external will re-trigger the loop
* (no CI gates match the diff); `maxOrchestratorCycles` still applies.
*/
maxSelfDispatches: z.number().default(3),
})
.default({}),
ciGates: z
.array(
z.object({
paths: z.array(z.string()),
workflows: z.array(z.string()),
}),
)
.default([]),
/**
* External review-bot ingestion: native inline PR review comments from these
* bot logins are normalized into ledger findings so the fixer addresses them
* without a human copy/pasting them into the loop.
*/
externalReviewers: z
.object({
enabled: z.boolean().default(true),
bots: z.array(z.string()).default(['cursor[bot]', 'cubic-dev-ai[bot]']),
/**
* Per-bot regex overrides (case-insensitive) that classify a comment as
* blocking. Bots without an entry use the built-in defaults.
*/
blockingPatterns: z.record(z.array(z.string())).default({}),
})
.default({}),
});
export type PrAgentConfig = z.infer<typeof ConfigSchema>;
let cached: PrAgentConfig | null = null;
export function loadConfig(repoRoot: string): PrAgentConfig {
if (cached) return cached;
const path = join(repoRoot, '.github/pr-agent.yml');
const raw = parse(readFileSync(path, 'utf8'));
cached = ConfigSchema.parse(raw);
return cached;
}
export function resetConfigCache(): void {
cached = null;
}
|