import{nh as u,oh as LJ}from"./cli-0.5.4-ngvrzzhe.mjs";import{FF as E,HD as QJ,HF as OJ,ID as BJ,IF as g,JF as c,KF as i,NF as l,OF as UJ,dm as KJ,em as IJ}from"./cli-0.5.4-k5fz4zd3.mjs";import"./cli-0.5.4-wbqf44ym.mjs";import"./cli-0.5.4-9ewg9gfs.mjs";import"./cli-0.5.4-we3mspgg.mjs";import"./cli-0.5.4-jzhazry0.mjs";import"./cli-0.5.4-82sw3hrw.mjs";import"./cli-0.5.4-31v143kt.mjs";import"./cli-0.5.4-1cy7wd6s.mjs";import"./cli-0.5.4-5e0pk96f.mjs";import"./cli-0.5.4-z154a7bp.mjs";import"./cli-0.5.4-ng5p0zjs.mjs";import"./cli-0.5.4-5hp7ks3t.mjs";import"./cli-0.5.4-8hdwp78f.mjs";import"./cli-0.5.4-mr9aznxx.mjs";import"./cli-0.5.4-jevfk5q7.mjs";import"./cli-0.5.4-27dzbzdy.mjs";import"./cli-0.5.4-a5bkdqqb.mjs";import"./cli-0.5.4-j2hnw539.mjs";import"./cli-0.5.4-9w59nnw4.mjs";import"./cli-0.5.4-z5d3q8kh.mjs";import"./cli-0.5.4-c0r12dqp.mjs";import"./cli-0.5.4-kqh172jk.mjs";import"./cli-0.5.4-vv4jbgkc.mjs";import{KW as JJ,MW as S,pX as _J,rV as RJ}from"./cli-0.5.4-s7k1f0wc.mjs";import"./cli-0.5.4-0h0yz2k5.mjs";import"./cli-0.5.4-942dm5q1.mjs";import"./cli-0.5.4-rcmp5h4y.mjs";import"./cli-0.5.4-xdcww3x8.mjs";import"./cli-0.5.4-fq32ny1h.mjs";import"./cli-0.5.4-h1m67ngp.mjs";import"./cli-0.5.4-49erze3e.mjs";import"./cli-0.5.4-jytjks37.mjs";import{PY as V,QY as e,RY as R}from"./cli-0.5.4-mn22gk7g.mjs";import{SY as wJ}from"./cli-0.5.4-5t3jj85n.mjs";import"./cli-0.5.4-5shjmmkz.mjs";import"./cli-0.5.4-zb412kkm.mjs";import{eZ as C,gZ as D,lZ as PJ}from"./cli-0.5.4-prfn3sxd.mjs";import"./cli-0.5.4-6xmgebmk.mjs";import"./cli-0.5.4-vjgejcrz.mjs";import{B3 as v,g3 as k,o3 as m,q3 as b}from"./cli-0.5.4-jqt00ywx.mjs";import"./cli-0.5.4-9e7rkd8e.mjs";import"./cli-0.5.4-jp4wtw87.mjs";import"./cli-0.5.4-hambpq58.mjs";import"./cli-0.5.4-syvgmg9g.mjs";import{A5 as d,E5 as yJ}from"./cli-0.5.4-w8ttefr5.mjs";import{F5 as j,X5 as WJ}from"./cli-0.5.4-j7kkqxv6.mjs";import"./cli-0.5.4-qrwczx7j.mjs";import"./cli-0.5.4-v2z6p9td.mjs";import{M7 as VJ,R6 as I,T6 as TJ,o7 as B,v7 as h}from"./cli-0.5.4-cbq01zg3.mjs";import"./cli-0.5.4-37v5fhf1.mjs";import"./cli-0.5.4-7grzwf6q.mjs";import"./cli-0.5.4-9qmek5dq.mjs";import"./cli-0.5.4-9c6r1fjg.mjs";import{Kda as $,Wda as qJ}from"./cli-0.5.4-2dw33ms6.mjs";import"./cli-0.5.4-x1fzfxmm.mjs";import{Lea as f,Mea as HJ}from"./cli-0.5.4-e822fzaq.mjs";import{Nea as F,Pea as AJ}from"./cli-0.5.4-09dvrzcr.mjs";import{Pfa as N,Sfa as FJ}from"./cli-0.5.4-end8wj9r.mjs";import"./cli-0.5.4-4x206j04.mjs";import"./cli-0.5.4-yd3rd9qt.mjs";import"./cli-0.5.4-sgcaw17t.mjs";import"./cli-0.5.4-jmc3bzbn.mjs";import"./cli-0.5.4-959vxhhb.mjs";import{Vma as t,Zma as w}from"./cli-0.5.4-aacw1src.mjs";async function p(){if(!k())return null;try{let{accessToken:Q,orgUUID:J}=await C();return(await j.get(`${f().BASE_API_URL}/v1/ultrareview/quota`,{headers:{...D(Q),"x-organization-uuid":J},timeout:5000})).data}catch(Q){return N(`fetchUltrareviewQuota failed: ${Q}`),null}}var x=w(()=>{WJ();HJ();v();FJ();PJ()});function s(){r=!0}async function o(){if(m()||b())return{kind:"proceed",billingNote:""};let[Q,J]=await Promise.all([p(),u().catch(()=>null)]);if(!Q)return{kind:"proceed",billingNote:""};if(Q.reviews_remaining>0)return{kind:"proceed",billingNote:` This is free ultrareview ${Q.reviews_used+1} of ${Q.reviews_limit}.`};if(!J)return{kind:"proceed",billingNote:""};let Z=J.extra_usage;if(!Z?.is_enabled)return F("tengu_review_overage_not_enabled",{}),{kind:"not-enabled"};let X=Z.monthly_limit,z=Z.used_credits??0,G=X===null||X===void 0?1/0:X-z;if(G<10)return F("tengu_review_overage_low_balance",{available:G}),{kind:"low-balance",available:G};if(!r)return F("tengu_review_overage_dialog_shown",{}),{kind:"needs-confirm"};return{kind:"proceed",billingNote:" This review bills as Extra Usage."}}async function a(Q,J,Z){let X=await g();if(!X.eligible){let K=X.errors.filter((Y)=>Y.type!=="no_remote_environment");if(K.length>0)return F("tengu_review_remote_precondition_failed",{precondition_errors:K.map((q)=>q.type).join(",")}),[{type:"text",text:`Ultrareview cannot launch:
${K.map(c).join(`
`)}`}]}let z=Z??"",G=Q.trim(),A=/^\d+$/.test(G),O="env_011111111111111111111113",H=$("tengu_review_bughunter_config",null),W=(K,Y,q)=>{if(typeof K!=="number"||!Number.isFinite(K))return Y;let y=Math.floor(K);if(y<=0)return Y;return q!==void 0&&y>q?Y:y},T={BUGHUNTER_DRY_RUN:"1",BUGHUNTER_FLEET_SIZE:String(W(H?.fleet_size,5,20)),BUGHUNTER_MAX_DURATION:String(W(H?.max_duration_minutes,10,25)),BUGHUNTER_AGENT_TIMEOUT:String(W(H?.agent_timeout_seconds,600,1800)),BUGHUNTER_TOTAL_WALLCLOCK:String(W(H?.total_wallclock_minutes,22,27)),...process.env.BUGHUNTER_DEV_BUNDLE_B64&&{BUGHUNTER_DEV_BUNDLE_B64:process.env.BUGHUNTER_DEV_BUNDLE_B64}},M,P,U;if(A){let K=await d();if(!K||K.host!=="github.com")return F("tengu_review_remote_precondition_failed",{}),null;M=await E({initialMessage:null,description:`ultrareview: ${K.owner}/${K.name}#${G}`,signal:J.abortController.signal,branchName:`refs/pull/${G}/head`,environmentId:O,environmentVariables:{BUGHUNTER_PR_NUMBER:G,BUGHUNTER_REPOSITORY:`${K.owner}/${K.name}`,...T}}),P=`/ultrareview ${G}`,U=`${K.owner}/${K.name}#${G}`}else{let K=await h()||"main",{stdout:Y,code:q}=await I(B(),["merge-base",K,"HEAD"],{preserveOutputOnError:!1}),y=Y.trim();if(q!==0||!y)return F("tengu_review_remote_precondition_failed",{}),[{type:"text",text:`Could not find merge-base with ${K}. Make sure you're in a git repo with a ${K} branch.`}];let{stdout:YJ,code:zJ}=await I(B(),["diff","--shortstat",y],{preserveOutputOnError:!1});if(zJ===0&&!YJ.trim())return F("tengu_review_remote_precondition_failed",{}),[{type:"text",text:`No changes against the ${K} fork point. Make some commits or stage files first.`}];if(M=await E({initialMessage:null,description:`ultrareview: ${K}`,signal:J.abortController.signal,useBundle:!0,environmentId:O,environmentVariables:{BUGHUNTER_BASE_BRANCH:y,...T}}),!M)return F("tengu_review_remote_teleport_failed",{}),[{type:"text",text:"Repo is too large. Push a PR and use `/ultrareview <PR#>` instead."}];P="/ultrareview",U=K}if(!M)return F("tengu_review_remote_teleport_failed",{}),null;i({remoteTaskType:"ultrareview",session:M,command:P,context:J,isRemoteReview:!0}),F("tengu_review_remote_launched",{});let L=l(M.id);return[{type:"text",text:`Ultrareview launched for ${U} (~10–20 min, runs in the cloud). Track: ${L}${z} Findings arrive via task-notification. Briefly acknowledge the launch to the user without repeating the target or URL — both are already visible in the tool output above.`}]}var r=!1;var n=w(()=>{qJ();AJ();x();LJ();UJ();v();yJ();TJ();VJ();OJ()});function ZJ(Q){let J=XJ.c(15),{onProceed:Z,onCancel:X}=Q,[z,G]=_.useState(!1),A;if(J[0]===Symbol.for("react.memo_cache_sentinel"))A=new AbortController,J[0]=A;else A=J[0];let O=_.useRef(A),H;if(J[1]!==X||J[2]!==Z)H=(q)=>{if(q==="proceed")G(!0),Z(O.current.signal).catch(()=>G(!1));else X()},J[1]=X,J[2]=Z,J[3]=H;else H=J[3];let W=H,T;if(J[4]!==X)T=()=>{O.current.abort(),X()},J[4]=X,J[5]=T;else T=J[5];let M=T,P;if(J[6]===Symbol.for("react.memo_cache_sentinel"))P=[{label:"Proceed with Extra Usage billing",value:"proceed"},{label:"Cancel",value:"cancel"}],J[6]=P;else P=J[6];let U=P,L;if(J[7]===Symbol.for("react.memo_cache_sentinel"))L=V(S,{children:"Your free ultrareviews for this organization are used. Further reviews bill as Extra Usage (pay-per-use)."}),J[7]=L;else L=J[7];let K;if(J[8]!==M||J[9]!==W||J[10]!==z)K=e(JJ,{flexDirection:"column",gap:1,children:[L,z?V(S,{color:"background",children:"Launching…"}):V(QJ,{options:U,onChange:W,onCancel:M})]}),J[8]=M,J[9]=W,J[10]=z,J[11]=K;else K=J[11];let Y;if(J[12]!==M||J[13]!==K)Y=V(KJ,{title:"Ultrareview billing",onCancel:M,color:"background",children:K}),J[12]=M,J[13]=K,J[14]=Y;else Y=J[14];return Y}var XJ,_;var GJ=w(()=>{BJ();IJ();_J();R();XJ=t(RJ(),1),_=t(wJ(),1)});function EJ(Q){return Q.map((J)=>J.type==="text"?J.text:"").filter(Boolean).join(`
`)}async function MJ(Q,J,Z,X,z){let G=await a(Q,J,X);if(z?.aborted)return;if(G)Z(EJ(G),{shouldQuery:!0});else Z("Ultrareview failed to launch the remote session. Check that this is a GitHub repo and try again.",{display:"system"})}var JK=async(Q,J,Z)=>{let X=await o();if(X.kind==="not-enabled")return Q("Free ultrareviews used. Enable Extra Usage at https://claude.ai/settings/billing to continue.",{display:"system"}),null;if(X.kind==="low-balance")return Q(`Balance too low to launch ultrareview ($${X.available.toFixed(2)} available, $10 minimum). Top up at https://claude.ai/settings/billing`,{display:"system"}),null;if(X.kind==="needs-confirm")return V(ZJ,{onProceed:async(z)=>{if(await MJ(Z,J,Q," This review bills as Extra Usage.",z),!z.aborted)s()},onCancel:()=>Q("Ultrareview cancelled.",{display:"system"})});return await MJ(Z,J,Q,X.billingNote),null};var SJ=w(()=>{n();GJ();R()});SJ();export{JK as call};
