export const meta = {
name: 'pre-pr-review',
description: 'Adversarial pre-PR review of a branch diff + PR description draft',
phases: [{ title: 'Review' }, { title: 'Verify' }],
}
const CWD = '<repo root>'
const MODIFIED = [ ]
const NEW = [ ]
const CONTEXT = `Reviewing branch <X> at ${CWD}. ONLY these files are in scope (ignore git-diff-vs-default noise). Inspect modified via \`git diff -- <file>\`, NEW via Read.\n<file lists>\n<invariants to verify>`
const FINDINGS = { type:'object', additionalProperties:false, required:['findings'], properties:{ findings:{ type:'array', items:{ type:'object', additionalProperties:false, required:['title','file','severity','detail'], properties:{ title:{type:'string'}, file:{type:'string'}, line:{type:'string'}, severity:{type:'string', enum:['critical','major','minor','nit']}, detail:{type:'string'}, suggestedFix:{type:'string'} } } } } }
const VERDICT = { type:'object', additionalProperties:false, required:['isReal','reasoning'], properties:{ isReal:{type:'boolean'}, confirmedSeverity:{type:'string', enum:['critical','major','minor','nit']}, reasoning:{type:'string'} } }
const DIMENSIONS = [ {key:'correctness', prompt:'...'}, {key:'design', prompt:'...'}, {key:'copy', prompt:'...'}, {key:'hygiene', prompt:'...'} ]
phase('Review')
const [reviewed, prDraft] = await Promise.all([
pipeline(
DIMENSIONS,
(d) => agent(`${CONTEXT}\n\nDIMENSION: ${d.prompt}`, { label:`review:${d.key}`, phase:'Review', schema:FINDINGS, agentType:'Explore' }),
(review, d) => parallel((review?.findings || []).map((f) => () =>
agent(`${CONTEXT}\n\nAdversarially verify this ${d.key} finding. Default isReal=false unless you cite the exact line.\n${JSON.stringify(f)}`,
{ label:`verify:${d.key}`, phase:'Verify', schema:VERDICT })
.then((v) => ({ ...f, dimension:d.key, verdict:v })))),
),
agent(`${CONTEXT}\n\nDraft a TERSE PR description (Current Behavior 1-3 sentences, Expected Behavior 1-3, ASCII punctuation).`, { label:'pr-description', phase:'Review', schema:{ type:'object', additionalProperties:false, required:['currentBehavior','expectedBehavior'], properties:{ currentBehavior:{type:'string'}, expectedBehavior:{type:'string'}, surfaces:{type:'array', items:{type:'string'}} } } }),
])
const confirmed = reviewed.flat().filter(Boolean).filter((f) => f.verdict?.isReal)
return { confirmed, prDraft }