export const meta = { name: 'sr-screener-ft', description: 'sr-screener: blinded dual full-text eligibility assessment (Reviewer A + B read each PDF) with third-reviewer adjudication of disagreements; missing decisions stay pending', phases: [ { title: 'Full text', detail: 'Reviewer A and Reviewer B assess each report independently' }, { title: 'Adjudication', detail: 'A third reviewer reads the reports the two reviewers disagreed on' }, ], } // Generated by sr-screener scripts/build_workflow.py - edit templates/prompts.md or the config, not this block. const CONFIG = __SR_CONFIG__ if (args && ['items', 'adj'].some((key) => key in args)) { throw new Error('Runtime job overrides are disabled; regenerate with build_workflow.py') } const JOBS = CONFIG.jobs const P = CONFIG.prompts const fill = (tpl, vars) => tpl.replace(/\{\{([A-Z_]+)\}\}/g, (m, k) => (k in vars ? String(vars[k]) : m)) const CODES = ['INC', 'UNC'].concat(CONFIG.codes) const DEC = { type: 'object', properties: { id: { type: 'string', pattern: '^R\\d{' + CONFIG.idWidth + '}$' }, d: { type: 'string', enum: ['include', 'unclear', 'exclude'] }, code: { type: 'string', enum: CODES }, why: { type: 'string', description: 'at most 20 words, English' }, where: { type: 'string', description: 'page and section of the decisive information' }, }, required: ['id', 'd', 'code', 'why', 'where'], } const SCHEMA = { type: 'object', properties: { decisions: { type: 'array', items: DEC } }, required: ['decisions'] } const STATIC = {} function staticPart(role) { if (STATIC[role]) return STATIC[role] const vars = { STAGE_NAME: 'full-text', CORE: CONFIG.core, CODES: CONFIG.codesText, PROTOCOL: CONFIG.protocol } const intro = role === 'FTADJ' ? fill(P.adjudicator_intro, vars) : fill(P.reviewer_intro, Object.assign({ PERSONA: CONFIG.personas[role === 'FTA' ? 'A' : 'B'] }, vars)) STATIC[role] = [intro, fill(P.rules_ft, vars), fill(P.protocol_wrapper, vars)].join('\n\n') return STATIC[role] } function opts(role, label, phase) { const o = { label: label + '@' + CONFIG.context.context_id, phase, schema: SCHEMA } if (CONFIG.models[role]) o.model = CONFIG.models[role] if (CONFIG.agentType) o.agentType = CONFIG.agentType return o } function pick(res, id) { const list = res && Array.isArray(res.decisions) ? res.decisions : [] for (const r of list) { if (!r || r.id !== id) continue const consistent = (r.d === 'include' && r.code === 'INC') || (r.d === 'unclear' && r.code === 'UNC') || (r.d === 'exclude' && CONFIG.codes.includes(r.code)) if (consistent) return r } return null } async function review(role, x, dispute) { const task = fill(P.task_ft_pdf, { ID: x.id, TITLE: (x.title || '').replace(/"/g, "'"), PDF: x.pdf, DISPUTE: dispute || '' }) const phase = role === 'FTADJ' ? 'Adjudication' : 'Full text' let r = pick(await agent(staticPart(role) + '\n\n' + task, opts(role, role + ':' + x.id, phase)), x.id) if (!r) r = pick(await agent(staticPart(role) + '\n\n' + task, opts(role, role + ':' + x.id + ':retry', phase)), x.id) return r } const collected = CONFIG.returnDecisions ? [] : null const keep = (label, r) => { if (collected && r) collected.push({ label: label + '@' + CONFIG.context.context_id, decisions: [r] }) } const items = JOBS.items || [] const adjJobs = JOBS.adj || [] log('sr-screener FT run: ' + items.length + ' reports, ' + adjJobs.length + ' adjudications') async function adjudicate(x, a, b) { const dispute = 'Disputed: Reviewer A = ' + a + '; Reviewer B = ' + b + '. Decide from the report and the protocol.\n' const r = await review('FTADJ', x, dispute) keep('FTADJ:' + x.id, r) return r } const [mainRes, adjRes] = await parallel([ () => pipeline( items, async (x) => { const runA = x.A !== false const runB = x.B !== false const [A, B] = await parallel([ () => (runA ? review('FTA', x) : Promise.resolve(null)), () => (runB ? review('FTB', x) : Promise.resolve(null)), ]) keep('FTA:' + x.id, A) keep('FTB:' + x.id, B) return { A, B, both: runA && runB } }, async (s, x) => { if (!s || !s.both) return { id: x.id, status: s ? 'partial-done' : 'failed' } if (!s.A || !s.B) { log(x.id + ': missing reviewer decision - pending') return { id: x.id, status: 'incomplete' } } if (s.A.d === s.B.d) return { id: x.id, status: 'done' } const r = await adjudicate(x, s.A.d + '/' + s.A.code, s.B.d + '/' + s.B.code) log(x.id + ': A ' + s.A.d + ' vs B ' + s.B.d + ' -> ' + (r ? r.d : 'NOT adjudicated (pending)')) return { id: x.id, status: r ? 'done' : 'adj-incomplete' } }, ), () => pipeline(adjJobs, async (x) => { const r = await adjudicate(x, x.A, x.B) return { id: x.id, status: r ? 'done' : 'adj-incomplete' } }), ]) const M = (mainRes || []).map((r, i) => r || { id: items[i].id, status: 'failed' }) const J = (adjRes || []).map((r, i) => r || { id: adjJobs[i].id, status: 'failed' }) const count = (rs) => rs.reduce((m, r) => ((m[r.status] = (m[r.status] || 0) + 1), m), {}) const out = { context: CONFIG.context, fulltext: count(M), adjudication: count(J), needsAttention: M.concat(J).filter((r) => r.status !== 'done' && r.status !== 'partial-done').map((r) => r.id + ':' + r.status).slice(0, 300), next: 'Run scripts/merge_decisions.py --stage ft on this run journal; it lists anything still pending.', } if (collected) out.decisions = collected return out