import{qh as u,rh as LJ}from"./cli-0.5.12-bxsvvg0q.mjs";import{JD as QJ,KD as BJ,PF as E,RF as OJ,SF as g,TF as c,UF as i,XF as l,YF as UJ,km as KJ,lm as IJ}from"./cli-0.5.12-zc0qwdy2.mjs";import"./cli-0.5.12-whfz3xsx.mjs";import"./cli-0.5.12-z100r543.mjs";import"./cli-0.5.12-bzab36pn.mjs";import"./cli-0.5.12-pp1549k7.mjs";import"./cli-0.5.12-9mq24qzr.mjs";import"./cli-0.5.12-7repzgzv.mjs";import"./cli-0.5.12-pdqnfqg3.mjs";import"./cli-0.5.12-c2yq69h9.mjs";import"./cli-0.5.12-kez9r81a.mjs";import"./cli-0.5.12-zbcr8cbk.mjs";import"./cli-0.5.12-2wf629mh.mjs";import"./cli-0.5.12-ghtxkxqx.mjs";import"./cli-0.5.12-xg7a0dy4.mjs";import"./cli-0.5.12-s0h788we.mjs";import"./cli-0.5.12-m22yxpb9.mjs";import"./cli-0.5.12-cw1qs4bg.mjs";import"./cli-0.5.12-yq8ds97a.mjs";import"./cli-0.5.12-qew4mzgp.mjs";import"./cli-0.5.12-gwg1e43k.mjs";import"./cli-0.5.12-36swspqa.mjs";import"./cli-0.5.12-4dn79vqp.mjs";import"./cli-0.5.12-f5pfjvdk.mjs";import{YX as _J,_V as RJ,rX as JJ,tX as S}from"./cli-0.5.12-fqp5s15p.mjs";import"./cli-0.5.12-rc1p9wk6.mjs";import"./cli-0.5.12-x479axrj.mjs";import"./cli-0.5.12-ysy6e9rz.mjs";import"./cli-0.5.12-cqv7z22w.mjs";import"./cli-0.5.12-7cn41yy7.mjs";import"./cli-0.5.12-34cd39ve.mjs";import"./cli-0.5.12-m2gh4ewc.mjs";import{BZ as V,CZ as e,DZ as R}from"./cli-0.5.12-c6whkxmz.mjs";import{EZ as wJ}from"./cli-0.5.12-w3hy6c60.mjs";import"./cli-0.5.12-5d3qcvf5.mjs";import"./cli-0.5.12-f141d2qa.mjs";import{SZ as C,UZ as D,ZZ as PJ}from"./cli-0.5.12-khvy67r3.mjs";import{K3 as k,S3 as m,U3 as b,d4 as v}from"./cli-0.5.12-pycnjaeg.mjs";import"./cli-0.5.12-8v5w8znc.mjs";import"./cli-0.5.12-ctqkj6ve.mjs";import"./cli-0.5.12-cbevkwg4.mjs";import"./cli-0.5.12-w00qj83e.mjs";import"./cli-0.5.12-nbcjwzzn.mjs";import"./cli-0.5.12-3t06hwwh.mjs";import"./cli-0.5.12-057c2cp2.mjs";import{m6 as d,q6 as VJ}from"./cli-0.5.12-ecgx5n54.mjs";import{L7 as AJ,Q6 as I,S6 as yJ,n7 as B,u7 as h}from"./cli-0.5.12-g4wb8mj2.mjs";import"./cli-0.5.12-vp5smcs1.mjs";import"./cli-0.5.12-y2kq7fe8.mjs";import"./cli-0.5.12-7vxpqr5a.mjs";import{aea as $,mea as TJ}from"./cli-0.5.12-hvtcdcev.mjs";import"./cli-0.5.12-asbn3d19.mjs";import{bfa as f,cfa as HJ}from"./cli-0.5.12-k1crwtdc.mjs";import{dfa as F,ffa as qJ}from"./cli-0.5.12-2jxq8gnm.mjs";import{fga as N,iga as FJ}from"./cli-0.5.12-p5ps8gf0.mjs";import"./cli-0.5.12-hp0508v9.mjs";import"./cli-0.5.12-tfdwzg37.mjs";import"./cli-0.5.12-60w1a0bs.mjs";import"./cli-0.5.12-c8f4daey.mjs";import"./cli-0.5.12-0qasc0ef.mjs";import"./cli-0.5.12-f8850v2j.mjs";import{Dna as WJ,lna as j}from"./cli-0.5.12-495d826j.mjs";import"./cli-0.5.12-rt0k97yj.mjs";import"./cli-0.5.12-1vyz0tt9.mjs";import{Yna as t,aoa as w}from"./cli-0.5.12-xzeb7mtb.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(()=>{TJ();qJ();x();LJ();UJ();v();VJ();yJ();AJ();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};
