var h=1,m="review-record",_=204800,N=2e3,A=["blocker","should-fix","nit"],a={blocker:0,"should-fix":1,nit:2},S=["open","conceded","held","resolved"];function R(e){let n=String(e??"").trim().toLowerCase();return n?n.includes("\u{1F534}")||n.includes("blocker")||n.includes("critical")||n.includes("high")?"blocker":n.includes("\u{1F7E2}")||n.includes("nit")||n.includes("minor")||n.includes("low")||n.includes("info")?"nit":(n.includes("\u{1F7E1}")||n.includes("should")||n.includes("medium")||n.includes("warn"),"should-fix"):"should-fix"}var u=(e,n)=>{let t=e==null?"":String(e);return t.length>n?t.slice(0,n):t},g=e=>typeof Buffer<"u"&&typeof Buffer.byteLength=="function"?Buffer.byteLength(e,"utf8"):new TextEncoder().encode(e).length;function v({headSha:e=null,verdict:n="COMMENT",objectivesChecked:t=!1,findings:o=[],nowIso:i=null}={}){let s=Array.isArray(o)?o:[];return{schemaVersion:1,kind:m,headSha:e||null,verdict:String(n||"COMMENT"),objectivesChecked:!!t,reviewedAt:i||null,findings:s.map((r,c)=>({id:`f${c+1}`,file:u(r?.file,512),line:r?.line==null?null:r.line,severity:R(r?.severity),category:u(r?.category,64),claim:u(r?.claim,2e3),evidence:u(r?.evidence,2e3),suggestion:u(r?.suggestion,2e3),confidence:typeof r?.confidence=="number"?r.confidence:null,status:"open"}))}}function k(e,{findingId:n,status:t,note:o}={}){if(!e||!Array.isArray(e.findings))return e;let i=S.includes(t)?t:"held";return{...e,findings:e.findings.map(s=>s.id===n?{...s,status:i,replyNote:u(o,2e3)}:s)}}function C(e){if(!e)return"";let n=[...e.findings||[]].sort((s,r)=>{let c=(a[s.severity]??9)-(a[r.severity]??9);if(c!==0)return c;let l=s.file||"",d=r.file||"";if(l!==d)return l<d?-1:1;let f=Number(s.line)||0,y=Number(r.line)||0;return f!==y?f-y:(s.id||"")<(r.id||"")?-1:1}),t={...e,findings:n},o=JSON.stringify(t);if(g(o)<=204800)return o;let i=[...n];for(t={...e,findings:i,truncated:!0};i.length>0&&g(JSON.stringify(t))>204800;)i.pop(),t={...e,findings:i,truncated:!0};return JSON.stringify(t)}var E=e=>e&&typeof e=="object"&&!Array.isArray(e)&&e.kind===m;function I(e){if(e==null)return{kind:"empty"};if(typeof e=="object"){if(!Array.isArray(e)&&typeof e.error=="string")return{kind:"empty"};if(E(e)){let o=Number(e.schemaVersion)>1;return{kind:"record",record:e,future:o}}return{kind:"legacy",legacyNote:p(e)}}if(typeof e!="string")return{kind:"empty"};let n=e.trim();if(!n)return{kind:"empty"};let t;try{t=JSON.parse(n)}catch{return{kind:"legacy",legacyNote:n}}if(t&&typeof t=="object"&&typeof t.error=="string")return{kind:"empty"};if(E(t)){let o=Number(t.schemaVersion)>1;return{kind:"record",record:t,future:o}}return{kind:"legacy",legacyNote:n}}function p(e){try{return JSON.stringify(e)}catch{return String(e)}}function O(e){if(!e||e.kind==="empty")return"";if(e.kind==="legacy")return`Prior review memory (legacy note, advisory only):
${e.legacyNote}`;let n=e.record||{};if(e.future)return`Prior review memory (newer format ${n.schemaVersion} \u2014 advisory; verify against the live thread):
${p(n).slice(0,2e3)}`;let t=[`Prior review of this change (verdict: ${n.verdict||"COMMENT"}${n.headSha?`, commit ${n.headSha}`:""}):`],o=(n.findings||[]).map(i=>{let s=i.file?`${i.file}${i.line!=null?`:${i.line}`:""}`:"(general)",r=i.status&&i.status!=="open"?` [${i.status}]`:"";return`- [${i.severity}] ${s} \u2014 ${i.claim||""}${r}`});return n.truncated&&o.push("- (\u2026older/lower-severity findings were truncated to fit memory)"),[...t,...o].join(`
`)}export{_ as CONTENT_MAX_BYTES,N as FIELD_MAX_CHARS,S as FINDING_STATUSES,m as REVIEW_RECORD_KIND,h as REVIEW_RECORD_SCHEMA_VERSION,A as SEVERITY_TIERS,v as buildReviewRecord,R as normalizeSeverity,I as parseReviewMemory,C as serializeReviewRecord,O as summarizeForPrompt,k as upsertReplyOutcome};
