@crewx/sdk 0.9.0-rc.189 → 0.9.0-rc.190

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -49,7 +49,7 @@ ${r.join(`
49
49
  `);for(let r of e)if(r.trim())try{let s=JSON.parse(r);if(s.type==="result"){let o=s.usage,i=o?{inputTokens:Number(o.input_tokens??0)+Number(o.cache_read_input_tokens??0),outputTokens:Number(o.output_tokens??0),cachedInputTokens:Number(o.cache_read_input_tokens??0),costUsd:Number(s.total_cost_usd??0)}:null,u=s.modelUsage,d=u?Object.keys(u)[0]??null:null;return {usage:i,model:d}}}catch{}let n=Gd(t);return n?{usage:{inputTokens:n.inputTokens,outputTokens:0,cachedInputTokens:n.cachedInputTokens,costUsd:0},model:n.model??null}:{usage:null,model:null}},parseEvent(t,e){let n;try{n=JSON.parse(t);}catch{return []}let r=n.type;if(!r)return [];let s=je(n,e??new Date().toISOString()),o=Uf(n);if(o)return [{timestamp:s,type:"error",content:o,errorMessage:o}];let i=n.output_file,u=n.summary;if(r==="system"&&n.subtype==="task_notification"&&n.status==="completed"&&typeof i=="string"&&i.trim().length>0&&typeof u=="string"&&u.trim().length>0)return [{timestamp:s,type:"text",content:u}];if(r!=="assistant"&&r!=="user")return [];let c=n.message?.content;if(!Array.isArray(c))return [];let l=[];for(let p of c){let g=Wf(s,p);g&&l.push(g);}return l},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?Lf.has(r):!1}catch{return false}}};Xd=200;});function Zd(t){let e=t.split(`
50
50
  `).filter(s=>s.trim()),n=[],r=null;for(let s of e)try{let o=JSON.parse(s);if(o.type==="assistant.message"&&typeof o.data?.content=="string"){let i=o.data.content;i.trim()&&n.push(i.trim());}o.type==="result"&&typeof o.result=="string"&&(r=o.result);}catch{}if(n.length>0)return n[n.length-1];if(r)return r}var Gf,ho,mo=v(()=>{_();un();Vn();cn();pn();ln();jt();jr();zt();Gf=new Set(["interactive","plan","autopilot"]);ho={command:"copilot",meta:{displayName:"Copilot",models:bd()},buildArgs(t,e,n){let r=e.additionalArgs?[...e.additionalArgs]:[];return e.model&&r.push("--model",e.model),e.mode&&Gf.has(e.mode)&&r.push("--mode",e.mode),e.effort&&(Gr.copilot??[]).includes(e.effort)&&r.push("--effort",e.effort),{args:r,stdinMessage:t}},extractText(t){let e=Zd(t);if(e)return e;let n=t.trim();return it(n,"copilot")?"":n},extractPartialText(t){return Zd(t)},parseResultMeta(t){let e=fn(t);return e?{usage:{inputTokens:e.inputTokens,outputTokens:e.outputTokens,cachedInputTokens:e.cachedInputTokens,costUsd:0},model:null}:{usage:null,model:null}},parseEvent(t,e){let n;try{n=JSON.parse(t);}catch{return []}let r=n.type;if(!r)return [];if(!r.startsWith("tool.execution")&&!r.startsWith("assistant.")&&r!=="user.message")return [];let s=n.data;if(!s)return [];let o=je(n,e??new Date().toISOString()),i=s.toolCallId;if(r==="tool.execution_start"){let u=String(s.toolName||""),d=s.arguments,c=Ge(d);return (u==="bash"||u==="Bash")&&at(c)?[dt(o,c,i)]:[{timestamp:o,type:"tool_use",toolName:u,toolInput:c,...i&&{toolUseId:i}}]}if(r==="tool.execution_complete"){let u=s.error;if(u)return [{timestamp:o,type:"tool_result",...i&&{toolUseId:i},...We(String(u.message||""),true)}];let d=s.result,c=String(d?.content||"");return [{timestamp:o,type:"tool_result",...i&&{toolUseId:i},...We(c,false)}]}if(r==="assistant.message"){let u=String(s.content||"");return u?[{timestamp:o,type:"text",content:u}]:[]}return []}};});function Kf(t){let e=[],n=0,r=false,s=false,o=0;for(let u=0;u<t.length;u++){let d=t[u];if(s){s=false;continue}if(d==="\\"&&r){s=true;continue}if(d==='"'){r=!r;continue}if(!r){if(d==="{")n++;else if(d==="}"&&(n--,n===0)){let c=t.slice(o,u+1).trim();c&&e.push(c),o=u+1;}}}let i=t.slice(o).trim();return i&&e.push(i),e}function Jf(t){return t[0]==="exec"?t.slice(1):t}function eu(t){let e=t.split(`
51
51
  `).map(s=>s.trim()).filter(Boolean),n=[],r=null;for(let s of e)try{let o=JSON.parse(s);if(o.type==="item.completed"&&(o.item?.type==="message"||o.item?.type==="agent_message")&&typeof o.item?.text=="string"){let i=o.item.text;i.trim()&&n.push(i.trim());}o.type==="result"&&typeof o.result=="string"&&(r=o.result);}catch{}if(n.length>0)return n[n.length-1];if(r)return r}function Ot(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function nu(t){return t.type==="turn.failed"?true:t.type!=="error"?false:typeof t.message=="string"||typeof t.errorMessage=="string"||typeof t.error=="string"||Ot(t.error)}function ru(t){let e=Ot(t.error)?t.error:void 0,n=[t.message,t.errorMessage,e?.message,e?.detail,typeof t.error=="string"?t.error:void 0];for(let r of n)if(typeof r=="string"&&r.trim())return r;return t.type==="turn.failed"?"Codex turn failed.":"Codex CLI reported an error."}function Vf(t){for(let e of t.split(/\r?\n/)){if(!e.trim())continue;let n;try{n=JSON.parse(e);}catch{continue}if(Ot(n)&&nu(n))return ru(n)}}function tu(t,e,n,r){if(!n||t.type!=="command_execution"&&t.type!=="mcp_tool_call"||typeof t.id!="string"||!t.id.trim()||t.type==="mcp_tool_call"&&e==="item.started"&&(typeof t.server!="string"||typeof t.tool!="string"))return;let s=n.state.get("codex.pending");s||(s=new Map,n.state.set("codex.pending",s));let o=JSON.stringify([t.type,t.id]);if(e==="item.started"){let d=`codex:${JSON.stringify(t.id)}#${n.rowIndex}:${r}`,c=s.get(o)??[];return c.push(d),s.set(o,c),d}let i=s.get(o),u=i?.pop();return i?.length||s.delete(o),u}function Xf(t,e,n){let r=e.type;if(r==="command_execution"){let s=String(e.command||"");return at(s)?[dt(t,s,n)]:[{timestamp:t,type:"tool_use",toolName:"Bash",toolInput:s,...n?{toolUseId:n}:{}}]}return r==="mcp_tool_call"?typeof e.server!="string"||typeof e.tool!="string"?[]:[{timestamp:t,type:"tool_use",toolName:`${e.server}/${e.tool}`,toolInput:Ge(e.arguments),...n?{toolUseId:n}:{}}]:[]}function Yf(t,e,n){let r=e.type;if(r==="message"||r==="text"){let s=e.content;if(Array.isArray(s))for(let o of s){let i=Qf(t,o);if(i)return i}if(typeof e.text=="string")return {timestamp:t,type:"text",content:e.text}}if(r==="agent_message"&&typeof e.text=="string")return {timestamp:t,type:"text",content:e.text};if(r==="reasoning"){let s=typeof e.text=="string"?e.text.trim():"";return s?{timestamp:t,type:"thinking",content:s}:null}if(r==="command_execution"){let s=String(e.aggregated_output||e.output||""),o=!!e.is_error;return {timestamp:t,type:"tool_result",...We(s,o),...n?{toolUseId:n}:{}}}if(r==="mcp_tool_call"){let s=Ot(e.result)?e.result:void 0,i=(Array.isArray(s?.content)?s.content:[]).filter(d=>Ot(d)&&d.type==="text"&&typeof d.text=="string").map(d=>d.text).join(`
52
- `),u=typeof e.error=="string"?e.error:Ot(e.error)&&typeof e.error.message=="string"?e.error.message:"";return {timestamp:t,type:"tool_result",resultPreview:i||u,isError:e.status==="failed"||e.status==="error"||e.is_error===true||e.error!=null,...n?{toolUseId:n}:{}}}if(r==="tool_use"){let s=String(e.name||e.tool_name||""),o=e.input,i=Ge(o);return s==="Bash"&&at(i)?dt(t,i):{timestamp:t,type:"tool_use",toolName:s,toolInput:i}}if(r==="tool_result"){let s=!!e.is_error,o=String(e.output||e.content||"");return {timestamp:t,type:"tool_result",...We(o,s)}}if(r==="web_search"){let s=e.action,o;if(s?.type==="search"){let i=s.queries;o=String(s.query||"")||(i?.length?i.join(", "):"")||String(e.query||"");}else o=e.query?"open: "+String(e.query):"";return !o&&!(Ot(s)&&s.type==="other"&&e.query==="")?null:{timestamp:t,type:"tool_use",toolName:"WebSearch",toolInput:o}}if(r==="file_change"){let s=e.changes;if(!Array.isArray(s)||s.length===0)return null;let o=s.map(u=>String(u.path||"")).filter(Boolean);if(o.length===0)return null;let i=o.length===1?o[0]:`${o.slice(0,2).join(", ")}${o.length>2?` (+${o.length-2})`:""}`;return {timestamp:t,type:"tool_use",toolName:"Edit",toolInput:i}}return null}function Qf(t,e){let n=e.type;if(n==="text")return {timestamp:t,type:"text",content:String(e.text||"")};if(n==="tool_use"){let r=String(e.name||""),s=e.input,o=Ge(s);return r==="Bash"&&at(o)?dt(t,o):{timestamp:t,type:"tool_use",toolName:r,toolInput:o}}return null}var jf,zf,ko,To=v(()=>{_();Wt();un();Vn();cn();pn();ao();ln();Jn();jt();zt();jf=new Set(["turn.started","turn.completed","item.updated"]),zf="cli/codex";ko={command:"codex",meta:{displayName:"Codex",models:Nd(),capabilities:{resume:true}},buildArgs(t,e,n){let{model:r,effort:s}=At(e.model),o=e.effort??s,i=e.resumeSessionId?Pd(e.mode):Dd(e.mode),u=Ld(o),d=r?["-m",r]:[],c=Jf(e.additionalArgs??[]),p=c.includes("--json")||c.includes("--experimental-json")?[]:["--json"];return e.resumeSessionId?{args:["exec","resume",...p,...i,...u,...d,...c,e.resumeSessionId,"-"],stdinMessage:t}:{args:["exec",...p,...i,...u,...d,...c],stdinMessage:t}},extractText(t){let e=Vf(t);if(e)throw new V(e,zf);let n=eu(t);if(n)return n;let r=t.trim();return it(r,"codex")?"":r},extractPartialText(t){return eu(t)},parseResultMeta(t){let e=fn(t);return e?{usage:{inputTokens:e.inputTokens,outputTokens:e.outputTokens,cachedInputTokens:e.cachedInputTokens,costUsd:0},model:null}:{usage:null,model:null}},parseEvent(t,e,n){let r=e??new Date().toISOString(),s=[],o;try{JSON.parse(t),o=[t];}catch{o=Kf(t),o.length>1&&console.warn("[codex] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let[i,u]of o.entries()){let d;try{d=JSON.parse(u);}catch{continue}if(!Ot(d))continue;let c=d.type;if(!c)continue;let l=je(d,r);if(nu(d)){let g=ru(d);s.push({timestamp:l,type:"error",content:g,errorMessage:g});continue}if(!c.startsWith("item.")&&!c.startsWith("turn.")&&!c.startsWith("thread.")||io(d))continue;c==="thread.started"&&n&&n.state.delete("codex.pending");let p=d.item;if(p){if(c==="item.started"){s.push(...Xf(l,p,tu(p,c,n,i)));continue}if(c==="item.completed"){let g=Yf(l,p,tu(p,c,n,i));g&&s.push(g);continue}}}return s},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?jf.has(r):!1}catch{return false}}};});function tg(t){return t?eg[t]??{agent:"build",autoApprove:false}:{agent:void 0,autoApprove:false}}function Xr(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function du(t){let e=[],n=0,r=false,s=false,o=0;for(let u=0;u<t.length;u++){let d=t[u];if(s){s=false;continue}if(d==="\\"&&r){s=true;continue}if(d==='"'){r=!r;continue}if(!r){if(d==="{")n++;else if(d==="}"&&(n--,n===0)){let c=t.slice(o,u+1).trim();c&&e.push(c),o=u+1;}}}let i=t.slice(o).trim();return i&&e.push(i),e}function hn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function ng(t){let e=[],n=false;for(let r of t.split(/\r?\n/)){let s=r.trim();if(!s)continue;try{let i=JSON.parse(s);hn(i)?e.push(i):n=!0;continue}catch{}let o=du(s);o.length>1&&console.warn("[opencode] extractText: falling back to concatenated-JSON split for a malformed line");for(let i of o)try{let u=JSON.parse(i);hn(u)?e.push(u):n=!0;}catch{n=true;}}return {events:e,malformed:n}}function Kt(t){if(typeof t!="string")return;let e=t.split(/\r?\n/).map(n=>n.trim()).find(n=>n&&!/^at\s+/.test(n));if(e)return e.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g,"").replace(/(?:[A-Za-z]:[\\/]|\/)(?:[^\s"'`()\[\]{}]+[\\/])*[^\s"'`()\[\]{}]+/g,"[path]").slice(0,au).trim()}function uu(t){let e=hn(t.error)?t.error:void 0,n=e&&hn(e.data)?e.data:void 0,r=Kt(e?.name),s=Kt(n?.message)??Kt(e?.message)??Kt(t.message)??Kt(t.errorMessage)??Kt(t.error),o=Kt(t.ref),i=r&&s&&r!==s?`${r}: ${s}`:r??s??iu;return (o?`${i} (ref: ${o})`:i).slice(0,au)}function su(t){let e=ng(t),n=[],r=null,s=0,o=[],i,u=false;for(let d of e.events){let c=typeof d.type=="string"?d.type:void 0;if(c){if(c==="text"){let l=hn(d.part)?d.part:void 0,p=typeof l?.text=="string"?l.text:void 0;p?.trim()&&n.push(p.trim());continue}if(c==="result"){typeof d.result=="string"&&(r=d.result);continue}if(c==="tool_use"){s++;continue}if(c==="error"){o.push(uu(d));continue}if(c==="step_finish"){u=true;let l=hn(d.part)?d.part:void 0;i=typeof l?.reason=="string"?l.reason:void 0;}}}return {...e,texts:n,resultText:r,toolUseCount:s,errorMessages:o,terminalReason:i,hasTerminal:u}}function cu(t){return (t??"unknown").trim().toLowerCase().replace(/_/g,"-")}function Yr(){return new V("OpenCode returned no assistant output.",_n,{code:"EMPTY_OUTPUT",kind:"transient"})}function rg(){return new V("OpenCode emitted malformed JSON output.",_n,{code:"PROVIDER_CRASHED",kind:"transient"})}function ou(t,e){switch(cu(t)){case "length":return new V("OpenCode stopped because the context window was exceeded.",_n,{code:"UNKNOWN",kind:"permanent"});case "content-filter":return new V("OpenCode stopped because the content filter blocked the response.",_n,{code:"UNKNOWN",kind:"permanent"});case "error":return new V(e?`OpenCode error: ${e}`:`${iu} while generating a response.`,_n,{code:"PROVIDER_CRASHED",kind:"transient"});default:return null}}var Zf,_n,iu,au,eg,yo,wo=v(()=>{_();Wt();Vn();pn();zt();Zf=new Set(["step_start","step_finish"]),_n="cli/opencode",iu="OpenCode provider error",au=240,eg={build:{agent:"build",autoApprove:false},"build-auto":{agent:"build",autoApprove:true},plan:{agent:"plan",autoApprove:false},"plan-auto":{agent:"plan",autoApprove:true}};yo={command:"opencode",meta:{displayName:"OpenCode",capabilities:{resume:true}},buildArgs(t,e,n){let r=e.additionalArgs,s=r!==void 0?[...r]:["run"];Xr(s,"--format")||s.push("--format","json"),e.resumeSessionId&&!s.includes("-s")&&!s.includes("--session")&&s.push("-s",e.resumeSessionId);let{agent:o,autoApprove:i}=tg(e.mode);Xr(s,"--agent")||o!==void 0&&s.push("--agent",o),i&&!Xr(s,"--auto")&&s.push("--auto"),e.effort!==void 0&&!Xr(s,"--variant")&&s.push("--variant",e.effort),e.model&&s.push("--model",e.model);let u;return !n&&!i&&!e.env?.OPENCODE_PERMISSION&&(u={OPENCODE_PERMISSION:JSON.stringify({external_directory:"allow"})}),{args:s,stdinMessage:t,env:u}},extractText(t){let e=su(t),n=e.errorMessages[0];if(n){let i=ou("error",n);if(i)throw i}let r=ou(e.terminalReason??"",void 0);if(r)throw r;let s=e.texts.length>0?e.texts[e.texts.length-1]:void 0;if(s!==void 0){if(!e.hasTerminal)throw Yr();return s}if(e.resultText?.trim()){if(!e.hasTerminal)throw Yr();return e.resultText}if(e.malformed)throw rg();if(!e.hasTerminal)throw Yr();let o=cu(e.terminalReason);if((o==="stop"||o==="tool-calls")&&e.toolUseCount>0)return "";throw Yr()},interpretExit(t,e,n=""){if(t===0)return null;let s=su(n).errorMessages[0];return s?new V(`OpenCode error: ${s}`,_n,{code:"PROVIDER_CRASHED",kind:"transient"}):null},parseResultMeta(t){let e=fn(t);return e?{usage:{inputTokens:e.inputTokens,outputTokens:e.outputTokens,cachedInputTokens:e.cachedInputTokens,costUsd:0},model:null}:{usage:null,model:null}},parseEvent(t,e){let n=e??new Date().toISOString(),r=[],s;try{JSON.parse(t),s=[t];}catch{s=du(t),s.length>1&&console.warn("[opencode] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let o of s){let i;try{i=JSON.parse(o);}catch{continue}let u=je(i,n),d=i.type;if(d){if(d==="text"){let l=i.part?.text;l&&r.push({timestamp:u,type:"text",content:l});continue}if(d==="tool_use"){let c=i.part;if(!c)continue;let l=String(c.tool||""),p=String(c.callID||""),g=c.state,h=String(g?.status||""),m=g?.input,E=Ge(m);if(r.push({timestamp:u,type:"tool_use",toolName:l,toolUseId:p,toolInput:E}),h==="completed"&&g?.output!==void 0){let S=g.output,D=typeof S=="string"?S:JSON.stringify(S);r.push({timestamp:u,type:"tool_result",toolUseId:p,resultPreview:D,isError:false});}else h==="error"&&r.push({timestamp:u,type:"tool_result",toolUseId:p,resultPreview:String(g?.error||"tool error"),isError:true});continue}if(d==="error"){let c=uu(i);r.push({timestamp:u,type:"error",content:c,errorMessage:c});continue}}}return r},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?Zf.has(r):!1}catch{return false}}};});var lu=v(()=>{_();});function Qr(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function dg(t,e){let n=[];for(let r=0;r<t.length;r+=1){let s=t[r],o=[...e].find(i=>s===i||s.startsWith(`${i}=`));o?s===o&&r+1<t.length&&(r+=1):n.push(s);}return n}function ug(t){let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],s=r.indexOf("="),o=s>0?r.slice(0,s):r;if(!ig.has(o)){e.push(r);continue}r===o&&n+1<t.length&&!t[n+1].startsWith("-")&&(n+=1);}return e}function ut(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function cg(t,e){if(!(t?og.has(t)||It(Eo).some(o=>o.id===t):false)||!t)return e;let r=Kn(Eo,t),s=Ad(Eo)[t]?.defaultEffort;if(r.length!==0)return e?r.includes(e)?e:s&&r.includes(s)?s:void 0:s}function ft(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0?t:void 0}function Io(t){return t.kind==="step_update"?typeof t.step.conversation_id=="string"?t.step.conversation_id:void 0:typeof t.envelope.conversation_id=="string"?t.envelope.conversation_id:void 0}function Ao(t){return t.step.step_index}function Se(t){if(typeof t!="string")return;let e=t.split(/\r?\n/,1)[0]?.trim();return e&&Br(e)?.slice(0,500).trim()||void 0}function lg(t,e){let n=(t??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&ag.has(n))return n;let r=`${n} ${e??""}`.toLowerCase();return /quota|resource_exhausted|usage[ _-]?limit|credits?.{0,20}exhaust/.test(r)?"QUOTA_EXHAUSTED":/rate[ _-]?limit|throttl/.test(r)?"RATE_LIMITED":/auth|sign[ _-]?in|log(?:ged)?[ _-]?in|unauthori[sz]ed|credential/.test(r)?"AUTH_REQUIRED":[/unknown (?:flag|option)/,/flag provided but not defined/,/unrecognized (?:flag|option)/,/invalid (?:value for )?(?:flag|option|argument)/].some(o=>o.test(r))?"INVALID_PROVIDER_FORMAT":/invalid.{0,24}model|model.{0,24}(unknown|unavailable|not found|not recognized)|config/.test(r)?"MODEL_UNAVAILABLE":"UNKNOWN"}function pg(t){return t==="AUTH_REQUIRED"||t==="TIMEOUT_IDLE"||t==="TIMEOUT_TOTAL"||t==="TIMEOUT_RESUME"||t==="PROVIDER_CRASHED"?"permanent":t==="MODEL_UNAVAILABLE"||t==="INVALID_PROVIDER_FORMAT"||t==="PROVIDER_NOT_FOUND"?"config":"transient"}function fg(t){let e=ut(t)?t:void 0,n=e&&ut(e.error)?e.error:void 0,r=e?Se(e.code)??Se(e.error_code)??Se(n?.code)??Se(n?.error_code):void 0,s=typeof t=="string"?Se(t):e?Se(e.message)??Se(e.error)??Se(e.reason)??Se(n?.message)??Se(n?.error)??Se(n?.reason):void 0,o=lg(r,s),i=e?ft(e.retry_after_ms)??ft(e.retryAfterMs)??ft(n?.retry_after_ms)??ft(n?.retryAfterMs):void 0;return {code:o,kind:pg(o),message:s??"Antigravity reported a terminal error.",...i===void 0?{}:{retryAfterMs:i}}}function es(t){let e=fg(t);return new V(e.message,"cli/antigravity",{code:e.code,kind:e.kind,...e.retryAfterMs===void 0?{}:{retryAfterMs:e.retryAfterMs}})}function Oo(t){return new V(t,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function gg(t){let e=new TextEncoder().encode(t).byteLength;if(!(e<=So))throw new V(`Input is too large: final provider initial input is ${e} UTF-8 bytes; budget is ${So} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function Ro(){return new V("Antigravity CLI returned empty output with exit code 0. agy may have hidden an auth/quota/model error in its log file; inspect ~/.gemini/antigravity-cli/log for details.","cli/antigravity",{code:"EMPTY_OUTPUT",kind:"transient"})}function ts(t){if(t.kind==="result"||t.kind==="legacy_result")return t.result}function ns(t){for(let e=t.length-1;e>=0;e-=1){let n=t[e];if(n&&(n.kind==="result"||n.kind==="legacy_result"||n.kind==="agy_error"))return {event:n,index:e}}}function _g(t){let e=ns(t);if(!e||e.event.kind==="agy_error"||e.index!==t.length-1||ts(e.event)?.status!=="SUCCESS"||Zr(t))return false;let r=new Map;for(let s of t){if(s.kind!=="step_update"||s.step.step_type!=="agent_response")continue;let o=Io(s),i=Ao(s);!o||!Number.isSafeInteger(i)||r.set(JSON.stringify([o,i]),s.step);}if(r.size===0)return false;for(let s of r.values())if(s.state!=="DONE"||!ut(s.usage)||ft(s.usage.input_tokens)===void 0||ft(s.usage.output_tokens)===void 0)return false;return true}function hg(t,e){for(let n=e-1;n>=0;n-=1){let r=t[n];if(r?.kind==="agy_error")return r.error}}function mg(t,e){return ut(t)&&ut(e)?{...e,...t}:ut(t)&&typeof e=="string"?{...t,message:e}:typeof t=="string"&&ut(e)?{...e,message:t}:t??e}function kg(t){let e=Array.isArray(t.denied_actions)?t.denied_actions:[],n=[];for(let o of e){let i=ut(o)?o:void 0,u=typeof o=="string"?Se(o):Se(i?.display_name)??Se(i?.action);u&&!n.includes(u)&&n.length<5&&n.push(u.slice(0,80));}let r=Math.max(0,e.length-n.length),s=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"";return new V(`Permission denied: Antigravity blocked ${e.length} requested action${e.length===1?"":"s"}${s}.`,"cli/antigravity",{code:"UNKNOWN",kind:"permanent"})}function Zr(t){let e=ns(t);if(!e)return;if(e.event.kind==="agy_error")return es(e.event.error);let n=ts(e.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return kg(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return Oo("Antigravity returned a result with an unsupported status.");let r=n.error,s=mg(r==null||r===""?n:r,hg(t,e.index));return es(s)}function gu(t){if(typeof t=="string")return t;if(t!=null)try{return JSON.stringify(t)}catch{return}}function Tg(t){return `agy:${String(t.conversation_id)}:${String(t.step_index)}`}function yg(t,e){let n=typeof e?.name=="string"?e.name:t.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function wg(t){let e=gu(t);if(e)return e.length<=2e3?e:`${e.slice(0,1999)}\u2026`}function pu(t,e){return t?t.state.has(e)?true:(t.state.set(e,true),false):false}function fu(t,e){return {timestamp:t,type:"error",content:e.message,errorMessage:e.message,isError:true}}var Eo,og,ig,So,ag,No,bo=v(()=>{_();Wt();lu();so();zn();jt();Jn();co();Eo="antigravity",og=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),ig=new Set(["--conversation","--resume","--continue"]),So=18e4,ag=new Set(["QUOTA_EXHAUSTED","RATE_LIMITED","EMPTY_OUTPUT","AUTH_REQUIRED","MODEL_UNAVAILABLE","TIMEOUT_IDLE","TIMEOUT_TOTAL","TIMEOUT_RESUME","PROVIDER_NOT_FOUND","INVALID_PROVIDER_FORMAT","PROVIDER_CRASHED","UNKNOWN"]);No={command:"agy",maxInitialInputBytes:So,meta:{displayName:"Antigravity",models:vd(),defaultTimeoutMs:{query:12e4,execute:3e5},defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(t){let e=Gn(t);if(e?.kind!=="init")return null;let n=e.envelope.conversation_id;return typeof n=="string"&&n.trim().length>0?n.trim():null},buildArgs(t,e,n){gg(t);let{model:r,effort:s}=At(e.model),o=fo(r),i=o.model,u=e.effort??s??o.effort,d=cg(i,u),c=e.additionalArgs??[],l=ug(dg(c,new Set(["--input-format","--output-format"]))),p=i&&!Qr(c,"--model")?["--model",i]:[],g=Qr(c,"--effort")?[]:Wd(d),h=Qr(c,"--mode")||Qr(c,"--dangerously-skip-permissions")?[]:Bd(e.mode),m=typeof e.resumeSessionId=="string"&&e.resumeSessionId.trim().length>0?["--conversation",e.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...p,...g,...h,...m,...l],stdinMessage:`${JSON.stringify({event:"user",message:{content:t}})}
52
+ `),u=typeof e.error=="string"?e.error:Ot(e.error)&&typeof e.error.message=="string"?e.error.message:"";return {timestamp:t,type:"tool_result",resultPreview:i||u,isError:e.status==="failed"||e.status==="error"||e.is_error===true||e.error!=null,...n?{toolUseId:n}:{}}}if(r==="tool_use"){let s=String(e.name||e.tool_name||""),o=e.input,i=Ge(o);return s==="Bash"&&at(i)?dt(t,i):{timestamp:t,type:"tool_use",toolName:s,toolInput:i}}if(r==="tool_result"){let s=!!e.is_error,o=String(e.output||e.content||"");return {timestamp:t,type:"tool_result",...We(o,s)}}if(r==="web_search"){let s=e.action,o;if(s?.type==="search"){let i=s.queries;o=String(s.query||"")||(i?.length?i.join(", "):"")||String(e.query||"");}else o=e.query?"open: "+String(e.query):"";return !o&&!(Ot(s)&&s.type==="other"&&e.query==="")?null:{timestamp:t,type:"tool_use",toolName:"WebSearch",toolInput:o}}if(r==="file_change"){let s=e.changes;if(!Array.isArray(s)||s.length===0)return null;let o=s.map(u=>String(u.path||"")).filter(Boolean);if(o.length===0)return null;let i=o.length===1?o[0]:`${o.slice(0,2).join(", ")}${o.length>2?` (+${o.length-2})`:""}`;return {timestamp:t,type:"tool_use",toolName:"Edit",toolInput:i}}return null}function Qf(t,e){let n=e.type;if(n==="text")return {timestamp:t,type:"text",content:String(e.text||"")};if(n==="tool_use"){let r=String(e.name||""),s=e.input,o=Ge(s);return r==="Bash"&&at(o)?dt(t,o):{timestamp:t,type:"tool_use",toolName:r,toolInput:o}}return null}var jf,zf,ko,To=v(()=>{_();Wt();un();Vn();cn();pn();ao();ln();Jn();jt();zt();jf=new Set(["turn.started","turn.completed","item.updated"]),zf="cli/codex";ko={command:"codex",meta:{displayName:"Codex",models:Nd(),capabilities:{resume:true}},buildArgs(t,e,n){let{model:r,effort:s}=At(e.model),o=e.effort??s,i=e.resumeSessionId?Pd(e.mode):Dd(e.mode),u=Ld(o),d=r?["-m",r]:[],c=Jf(e.additionalArgs??[]),p=c.includes("--json")||c.includes("--experimental-json")?[]:["--json"];return e.resumeSessionId?{args:["exec","resume",...p,...i,...u,...d,...c,e.resumeSessionId,"-"],stdinMessage:t}:{args:["exec",...p,...i,...u,...d,...c],stdinMessage:t}},extractText(t){let e=Vf(t);if(e)throw new V(e,zf);let n=eu(t);if(n)return n;let r=t.trim();return it(r,"codex")?"":r},extractPartialText(t){return eu(t)},parseResultMeta(t){let e=fn(t);return e?{usage:{inputTokens:e.inputTokens,outputTokens:e.outputTokens,cachedInputTokens:e.cachedInputTokens,costUsd:0},model:null}:{usage:null,model:null}},parseEvent(t,e,n){let r=e??new Date().toISOString(),s=[],o;try{JSON.parse(t),o=[t];}catch{o=Kf(t),o.length>1&&console.warn("[codex] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let[i,u]of o.entries()){let d;try{d=JSON.parse(u);}catch{continue}if(!Ot(d))continue;let c=d.type;if(!c)continue;let l=je(d,r);if(nu(d)){let g=ru(d);s.push({timestamp:l,type:"error",content:g,errorMessage:g});continue}if(!c.startsWith("item.")&&!c.startsWith("turn.")&&!c.startsWith("thread.")||io(d))continue;c==="thread.started"&&n&&n.state.delete("codex.pending");let p=d.item;if(p){if(c==="item.started"){s.push(...Xf(l,p,tu(p,c,n,i)));continue}if(c==="item.completed"){let g=Yf(l,p,tu(p,c,n,i));g&&s.push(g);continue}}}return s},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?jf.has(r):!1}catch{return false}}};});function tg(t){return t?eg[t]??{agent:"build",autoApprove:false}:{agent:void 0,autoApprove:false}}function Xr(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function du(t){let e=[],n=0,r=false,s=false,o=0;for(let u=0;u<t.length;u++){let d=t[u];if(s){s=false;continue}if(d==="\\"&&r){s=true;continue}if(d==='"'){r=!r;continue}if(!r){if(d==="{")n++;else if(d==="}"&&(n--,n===0)){let c=t.slice(o,u+1).trim();c&&e.push(c),o=u+1;}}}let i=t.slice(o).trim();return i&&e.push(i),e}function hn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function ng(t){let e=[],n=false;for(let r of t.split(/\r?\n/)){let s=r.trim();if(!s)continue;try{let i=JSON.parse(s);hn(i)?e.push(i):n=!0;continue}catch{}let o=du(s);o.length>1&&console.warn("[opencode] extractText: falling back to concatenated-JSON split for a malformed line");for(let i of o)try{let u=JSON.parse(i);hn(u)?e.push(u):n=!0;}catch{n=true;}}return {events:e,malformed:n}}function Kt(t){if(typeof t!="string")return;let e=t.split(/\r?\n/).map(n=>n.trim()).find(n=>n&&!/^at\s+/.test(n));if(e)return e.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g,"").replace(/(?:[A-Za-z]:[\\/]|\/)(?:[^\s"'`()\[\]{}]+[\\/])*[^\s"'`()\[\]{}]+/g,"[path]").slice(0,au).trim()}function uu(t){let e=hn(t.error)?t.error:void 0,n=e&&hn(e.data)?e.data:void 0,r=Kt(e?.name),s=Kt(n?.message)??Kt(e?.message)??Kt(t.message)??Kt(t.errorMessage)??Kt(t.error),o=Kt(t.ref),i=r&&s&&r!==s?`${r}: ${s}`:r??s??iu;return (o?`${i} (ref: ${o})`:i).slice(0,au)}function su(t){let e=ng(t),n=[],r=null,s=0,o=[],i,u=false;for(let d of e.events){let c=typeof d.type=="string"?d.type:void 0;if(c){if(c==="text"){let l=hn(d.part)?d.part:void 0,p=typeof l?.text=="string"?l.text:void 0;p?.trim()&&n.push(p.trim());continue}if(c==="result"){typeof d.result=="string"&&(r=d.result);continue}if(c==="tool_use"){s++;continue}if(c==="error"){o.push(uu(d));continue}if(c==="step_finish"){u=true;let l=hn(d.part)?d.part:void 0;i=typeof l?.reason=="string"?l.reason:void 0;}}}return {...e,texts:n,resultText:r,toolUseCount:s,errorMessages:o,terminalReason:i,hasTerminal:u}}function cu(t){return (t??"unknown").trim().toLowerCase().replace(/_/g,"-")}function Yr(){return new V("OpenCode returned no assistant output.",_n,{code:"EMPTY_OUTPUT",kind:"transient"})}function rg(){return new V("OpenCode emitted malformed JSON output.",_n,{code:"PROVIDER_CRASHED",kind:"transient"})}function ou(t,e){switch(cu(t)){case "length":return new V("OpenCode stopped because the context window was exceeded.",_n,{code:"UNKNOWN",kind:"permanent"});case "content-filter":return new V("OpenCode stopped because the content filter blocked the response.",_n,{code:"UNKNOWN",kind:"permanent"});case "error":return new V(e?`OpenCode error: ${e}`:`${iu} while generating a response.`,_n,{code:"PROVIDER_CRASHED",kind:"transient"});default:return null}}var Zf,_n,iu,au,eg,yo,wo=v(()=>{_();Wt();Vn();pn();zt();Zf=new Set(["step_start","step_finish"]),_n="cli/opencode",iu="OpenCode provider error",au=240,eg={build:{agent:"build",autoApprove:false},"build-auto":{agent:"build",autoApprove:true},plan:{agent:"plan",autoApprove:false},"plan-auto":{agent:"plan",autoApprove:true}};yo={command:"opencode",meta:{displayName:"OpenCode",capabilities:{resume:true}},buildArgs(t,e,n){let r=e.additionalArgs,s=r!==void 0?[...r]:["run"];Xr(s,"--format")||s.push("--format","json"),e.resumeSessionId&&!s.includes("-s")&&!s.includes("--session")&&s.push("-s",e.resumeSessionId);let{agent:o,autoApprove:i}=tg(e.mode);Xr(s,"--agent")||o!==void 0&&s.push("--agent",o),i&&!Xr(s,"--auto")&&s.push("--auto"),e.effort!==void 0&&!Xr(s,"--variant")&&s.push("--variant",e.effort),e.model&&s.push("--model",e.model);let u;return !n&&!i&&!e.env?.OPENCODE_PERMISSION&&(u={OPENCODE_PERMISSION:JSON.stringify({external_directory:"allow"})}),{args:s,stdinMessage:t,env:u}},extractText(t){let e=su(t),n=e.errorMessages[0];if(n){let i=ou("error",n);if(i)throw i}let r=ou(e.terminalReason??"",void 0);if(r)throw r;let s=e.texts.length>0?e.texts[e.texts.length-1]:void 0;if(s!==void 0){if(!e.hasTerminal)throw Yr();return s}if(e.resultText?.trim()){if(!e.hasTerminal)throw Yr();return e.resultText}if(e.malformed)throw rg();if(!e.hasTerminal)throw Yr();let o=cu(e.terminalReason);if((o==="stop"||o==="tool-calls")&&e.toolUseCount>0)return "";throw Yr()},interpretExit(t,e,n=""){if(t===0)return null;let s=su(n).errorMessages[0];return s?new V(`OpenCode error: ${s}`,_n,{code:"PROVIDER_CRASHED",kind:"transient"}):null},parseResultMeta(t){let e=fn(t);return e?{usage:{inputTokens:e.inputTokens,outputTokens:e.outputTokens,cachedInputTokens:e.cachedInputTokens,costUsd:0},model:null}:{usage:null,model:null}},parseEvent(t,e){let n=e??new Date().toISOString(),r=[],s;try{JSON.parse(t),s=[t];}catch{s=du(t),s.length>1&&console.warn("[opencode] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let o of s){let i;try{i=JSON.parse(o);}catch{continue}let u=je(i,n),d=i.type;if(d){if(d==="text"){let l=i.part?.text;l&&r.push({timestamp:u,type:"text",content:l});continue}if(d==="tool_use"){let c=i.part;if(!c)continue;let l=String(c.tool||""),p=String(c.callID||""),g=c.state,h=String(g?.status||""),m=g?.input,E=Ge(m);if(r.push({timestamp:u,type:"tool_use",toolName:l,toolUseId:p,toolInput:E}),h==="completed"&&g?.output!==void 0){let S=g.output,D=typeof S=="string"?S:JSON.stringify(S);r.push({timestamp:u,type:"tool_result",toolUseId:p,resultPreview:D,isError:false});}else h==="error"&&r.push({timestamp:u,type:"tool_result",toolUseId:p,resultPreview:String(g?.error||"tool error"),isError:true});continue}if(d==="error"){let c=uu(i);r.push({timestamp:u,type:"error",content:c,errorMessage:c});continue}}}return r},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?Zf.has(r):!1}catch{return false}}};});var lu=v(()=>{_();});function Qr(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function dg(t,e){let n=[];for(let r=0;r<t.length;r+=1){let s=t[r],o=[...e].find(i=>s===i||s.startsWith(`${i}=`));o?s===o&&r+1<t.length&&(r+=1):n.push(s);}return n}function ug(t){let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],s=r.indexOf("="),o=s>0?r.slice(0,s):r;if(!ig.has(o)){e.push(r);continue}r===o&&n+1<t.length&&!t[n+1].startsWith("-")&&(n+=1);}return e}function ut(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function cg(t,e){if(!(t?og.has(t)||It(Eo).some(o=>o.id===t):false)||!t)return e;let r=Kn(Eo,t),s=Ad(Eo)[t]?.defaultEffort;if(r.length!==0)return e?r.includes(e)?e:s&&r.includes(s)?s:void 0:s}function ft(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0?t:void 0}function Io(t){return t.kind==="step_update"?typeof t.step.conversation_id=="string"?t.step.conversation_id:void 0:typeof t.envelope.conversation_id=="string"?t.envelope.conversation_id:void 0}function Ao(t){return t.step.step_index}function Se(t){if(typeof t!="string")return;let e=t.split(/\r?\n/,1)[0]?.trim();return e&&Br(e)?.slice(0,500).trim()||void 0}function lg(t,e){let n=(t??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&ag.has(n))return n;let r=`${n} ${e??""}`.toLowerCase();return /quota|resource_exhausted|usage[ _-]?limit|credits?.{0,20}exhaust/.test(r)?"QUOTA_EXHAUSTED":/rate[ _-]?limit|throttl/.test(r)?"RATE_LIMITED":/auth|sign[ _-]?in|log(?:ged)?[ _-]?in|unauthori[sz]ed|credential/.test(r)?"AUTH_REQUIRED":[/unknown (?:flag|option)/,/flag provided but not defined/,/unrecognized (?:flag|option)/,/invalid (?:value for )?(?:flag|option|argument)/].some(o=>o.test(r))?"INVALID_PROVIDER_FORMAT":/invalid.{0,24}model|model.{0,24}(unknown|unavailable|not found|not recognized)|config/.test(r)?"MODEL_UNAVAILABLE":"UNKNOWN"}function pg(t){return t==="AUTH_REQUIRED"||t==="TIMEOUT_IDLE"||t==="TIMEOUT_TOTAL"||t==="TIMEOUT_RESUME"||t==="PROVIDER_CRASHED"?"permanent":t==="MODEL_UNAVAILABLE"||t==="INVALID_PROVIDER_FORMAT"||t==="PROVIDER_NOT_FOUND"?"config":"transient"}function fg(t){let e=ut(t)?t:void 0,n=e&&ut(e.error)?e.error:void 0,r=e?Se(e.code)??Se(e.error_code)??Se(n?.code)??Se(n?.error_code):void 0,s=typeof t=="string"?Se(t):e?Se(e.message)??Se(e.error)??Se(e.reason)??Se(n?.message)??Se(n?.error)??Se(n?.reason):void 0,o=lg(r,s),i=e?ft(e.retry_after_ms)??ft(e.retryAfterMs)??ft(n?.retry_after_ms)??ft(n?.retryAfterMs):void 0;return {code:o,kind:pg(o),message:s??"Antigravity reported a terminal error.",...i===void 0?{}:{retryAfterMs:i}}}function es(t){let e=fg(t);return new V(e.message,"cli/antigravity",{code:e.code,kind:e.kind,...e.retryAfterMs===void 0?{}:{retryAfterMs:e.retryAfterMs}})}function Oo(t){return new V(t,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function gg(t){let e=new TextEncoder().encode(t).byteLength;if(!(e<=So))throw new V(`Input is too large: final provider initial input is ${e} UTF-8 bytes; budget is ${So} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function Ro(){return new V("Antigravity CLI returned empty output with exit code 0. agy may have hidden an auth/quota/model error in its log file; inspect ~/.gemini/antigravity-cli/log for details.","cli/antigravity",{code:"EMPTY_OUTPUT",kind:"transient"})}function ts(t){if(t.kind==="result"||t.kind==="legacy_result")return t.result}function ns(t){for(let e=t.length-1;e>=0;e-=1){let n=t[e];if(n&&(n.kind==="result"||n.kind==="legacy_result"||n.kind==="agy_error"))return {event:n,index:e}}}function _g(t){let e=ns(t);if(!e||e.event.kind==="agy_error"||e.index!==t.length-1||ts(e.event)?.status!=="SUCCESS"||Zr(t))return false;let r=new Map;for(let s of t){if(s.kind!=="step_update"||s.step.step_type!=="agent_response")continue;let o=Io(s),i=Ao(s);!o||!Number.isSafeInteger(i)||r.set(JSON.stringify([o,i]),s.step);}if(r.size===0)return false;for(let s of r.values())if(s.state!=="DONE"||!ut(s.usage)||ft(s.usage.input_tokens)===void 0||ft(s.usage.output_tokens)===void 0)return false;return true}function hg(t,e){for(let n=e-1;n>=0;n-=1){let r=t[n];if(r?.kind==="agy_error")return r.error}}function mg(t,e){return ut(t)&&ut(e)?{...e,...t}:ut(t)&&typeof e=="string"?{...t,message:e}:typeof t=="string"&&ut(e)?{...e,message:t}:t??e}function kg(t){let e=Array.isArray(t.denied_actions)?t.denied_actions:[],n=[];for(let o of e){let i=ut(o)?o:void 0,u=typeof o=="string"?Se(o):Se(i?.display_name)??Se(i?.action);u&&!n.includes(u)&&n.length<5&&n.push(u.slice(0,80));}let r=Math.max(0,e.length-n.length),s=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"";return new V(`Permission denied: Antigravity blocked ${e.length} requested action${e.length===1?"":"s"}${s}.`,"cli/antigravity",{code:"UNKNOWN",kind:"permanent"})}function Zr(t){let e=ns(t);if(!e)return;if(e.event.kind==="agy_error")return es(e.event.error);let n=ts(e.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return kg(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return Oo("Antigravity returned a result with an unsupported status.");let r=n.error,s=mg(r==null||r===""?n:r,hg(t,e.index));return es(s)}function gu(t){if(typeof t=="string")return t;if(t!=null)try{return JSON.stringify(t)}catch{return}}function Tg(t){return `agy:${String(t.conversation_id)}:${String(t.step_index)}`}function yg(t,e){let n=typeof e?.name=="string"?e.name:t.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function wg(t){let e=gu(t);if(e)return e.length<=2e3?e:`${e.slice(0,1999)}\u2026`}function pu(t,e){return t?t.state.has(e)?true:(t.state.set(e,true),false):false}function fu(t,e){return {timestamp:t,type:"error",content:e.message,errorMessage:e.message,isError:true}}var Eo,og,ig,So,ag,No,bo=v(()=>{_();Wt();lu();so();zn();jt();Jn();co();Eo="antigravity",og=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),ig=new Set(["--conversation","--resume","--continue"]),So=18e4,ag=new Set(["QUOTA_EXHAUSTED","RATE_LIMITED","EMPTY_OUTPUT","AUTH_REQUIRED","MODEL_UNAVAILABLE","TIMEOUT_IDLE","TIMEOUT_TOTAL","TIMEOUT_RESUME","PROVIDER_NOT_FOUND","INVALID_PROVIDER_FORMAT","PROVIDER_CRASHED","UNKNOWN"]);No={command:"agy",maxInitialInputBytes:So,meta:{displayName:"Antigravity",models:vd(),defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(t){let e=Gn(t);if(e?.kind!=="init")return null;let n=e.envelope.conversation_id;return typeof n=="string"&&n.trim().length>0?n.trim():null},buildArgs(t,e,n){gg(t);let{model:r,effort:s}=At(e.model),o=fo(r),i=o.model,u=e.effort??s??o.effort,d=cg(i,u),c=e.additionalArgs??[],l=ug(dg(c,new Set(["--input-format","--output-format"]))),p=i&&!Qr(c,"--model")?["--model",i]:[],g=Qr(c,"--effort")?[]:Wd(d),h=Qr(c,"--mode")||Qr(c,"--dangerously-skip-permissions")?[]:Bd(e.mode),m=typeof e.resumeSessionId=="string"&&e.resumeSessionId.trim().length>0?["--conversation",e.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...p,...g,...h,...m,...l],stdinMessage:`${JSON.stringify({event:"user",message:{content:t}})}
53
53
  `,env:{AGY_CLI_DISABLE_AUTO_UPDATE:"true"}}},extractText(t){let e=jn(t),n=ns(e)?.event,r=Zr(e);if(r)throw r;let s=n?ts(n):void 0;if(s){if(s.status!=="SUCCESS")throw Oo("Antigravity returned a result with an unsupported status.");if(typeof s.response!="string")throw Oo("Antigravity returned a successful result without a response string.");if(!s.response.trim())throw Ro();return s.response}if(e.length>0)throw Ro();let o=t.trim();if(!o)throw Ro();return o},extractPartialText(t){let e=jn(t),n=ns(e)?.event;if(!n||n.kind==="agy_error")return;let r=ts(n);return r&&typeof r.response=="string"&&r.response.trim()?r.response:void 0},interpretExit(t,e,n){let r=jn(n??""),s=Zr(r);return s||(t!==0&&e.trim()?es(e):null)},parseResultMeta(t){let e=jn(t),n=0,r=0,s=0,o=0,i=new Set;for(let d of e){if(d.kind!=="step_update"||d.step.state!=="DONE"||!ut(d.step.usage))continue;let c=Io(d),l=Ao(d);if(!c||!Number.isSafeInteger(l))continue;let p=JSON.stringify([c,l]);if(i.has(p))continue;let g=d.step.usage,h=ft(g.input_tokens),m=ft(g.output_tokens);h===void 0||m===void 0||(i.add(p),n+=h,r+=m,s+=ft(g.cache_read_tokens)??0,o+=1);}return {usage:o===0?null:{inputTokens:n,outputTokens:r,cachedInputTokens:s,costUsd:0,complete:_g(e)},model:null}},parseEvent(t,e,n){let r=Gn(t);if(!r)return [];let s=e??new Date().toISOString();if(r.kind==="agy_error")return [fu(s,es(r.error))];if(r.kind==="legacy_result"||r.kind==="result"){let h=Zr([r]);return h?[fu(s,h)]:[]}if(r.kind!=="step_update")return [];let{step:o}=r,i=Io(r)??"unknown",u=Ao(r),d=`${i}:${u}`;if(o.state==="DONE"&&pu(n,`antigravity:terminal:${d}`))return [];if(o.step_type==="agent_response")return typeof o.text_delta=="string"&&o.text_delta.length>0?[{timestamp:s,type:"text",content:o.text_delta}]:[];if(o.step_type!=="tool")return [];let c=ut(o.tool_info)?o.tool_info:void 0,l=yg(o,c);if(!l)return [];let p=Tg(o);if(o.state==="ACTIVE"){if(pu(n,`antigravity:active:${d}`))return [];let h=gu(c?.parameters);return [{timestamp:s,type:"tool_use",toolName:l,toolUseId:p,...h===void 0?{}:{toolInput:h}}]}let g=wg(c?.output);return [{timestamp:s,type:"tool_result",toolName:l,toolUseId:p,...g===void 0?{}:{resultPreview:g}}]}};});var _u=v(()=>{_();cn();pn();ln();zt();});function mn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function kn(t){return mn(t)?t:void 0}function Ie(t){return typeof t=="string"?t:void 0}function Vt(t){let e=typeof t=="number"?t:Number(t??0);return Number.isFinite(e)?e:0}function Ag(t){let e=[],n=-1,r=0,s=false,o=false;for(let i=0;i<t.length;i+=1){let u=t[i];if(n===-1){(u==="{"||u==="[")&&(n=i,r=1);continue}if(o){o=false;continue}if(u==="\\"&&s){o=true;continue}if(u==='"'){s=!s;continue}s||(u==="{"||u==="["?r+=1:(u==="}"||u==="]")&&(r-=1,r===0&&(e.push(t.slice(n,i+1)),n=-1)));}return n!==-1&&e.push(t.slice(n)),e}function Xn(t){let e=t.trim();if(!e)return [];try{let n=JSON.parse(e);return mn(n)?[n]:[]}catch{return Ag(e).flatMap(n=>{try{let r=JSON.parse(n);return mn(r)?[r]:[]}catch{return []}})}}function yu(t){let e=JSON.stringify(t);return e===void 0?String(t):e}function Jt(t){if(typeof t=="string")return t;if(Array.isArray(t)){let e=t.map(Jt).filter(n=>n!==void 0);return e.length>0?e.join(`
54
54
  `):void 0}if(mn(t)){if(typeof t.text=="string")return t.text;if(typeof t.message=="string")return t.message;if(typeof t.error=="string")return t.error;if(t.type==="text"&&typeof t.data=="string")return t.data;for(let e of ["content","FileContent","rawOutput"]){let n=Jt(t[e]);if(n!==void 0)return n}}}function Og(t){let e=i=>Array.isArray(i)&&i.every(u=>Number.isInteger(u)&&u>=0&&u<=255),n=i=>typeof i=="string"&&i.trim().length>0?i:void 0,r=i=>new TextDecoder("utf-8",{fatal:false}).decode(Uint8Array.from(i)),s=i=>{let u=JSON.stringify(i,(d,c)=>e(c)?`<bytes:${c.length}>`:c);return u===void 0?String(i):u},o=t.rawOutput;if(o!=null){let i=kn(o);if(!i)return n(Jt(o))??s(o);let u;if(e(i.output)&&i.output.length>0&&(u=n(r(i.output))),!u&&e(i.stdout)&&i.stdout.length>0&&(u=n(r(i.stdout))),!u){let l=kn(i.Result);u=n(i.output)??n(l?.output)??n(Jt(o));}let d=e(i.stderr)&&i.stderr.length>0?r(i.stderr):void 0;if(d!==void 0)if(u){let l=u.endsWith(`
55
55
  `)||u.endsWith("\r")?"":`
@@ -49,7 +49,7 @@ ${r.join(`
49
49
  `);for(let r of e)if(r.trim())try{let s=JSON.parse(r);if(s.type==="result"){let o=s.usage,i=o?{inputTokens:Number(o.input_tokens??0)+Number(o.cache_read_input_tokens??0),outputTokens:Number(o.output_tokens??0),cachedInputTokens:Number(o.cache_read_input_tokens??0),costUsd:Number(s.total_cost_usd??0)}:null,a=s.modelUsage,u=a?Object.keys(a)[0]??null:null;return {usage:i,model:u}}}catch{}let n=Il(t);return n?{usage:{inputTokens:n.inputTokens,outputTokens:0,cachedInputTokens:n.cachedInputTokens,costUsd:0},model:n.model??null}:{usage:null,model:null}},parseEvent(t,e){let n;try{n=JSON.parse(t);}catch{return []}let r=n.type;if(!r)return [];let s=At(n,e??new Date().toISOString()),o=Ok(n);if(o)return [{timestamp:s,type:"error",content:o,errorMessage:o}];let i=n.output_file,a=n.summary;if(r==="system"&&n.subtype==="task_notification"&&n.status==="completed"&&typeof i=="string"&&i.trim().length>0&&typeof a=="string"&&a.trim().length>0)return [{timestamp:s,type:"text",content:a}];if(r!=="assistant"&&r!=="user")return [];let c=n.message?.content;if(!Array.isArray(c))return [];let p=[];for(let l of c){let g=Dk(s,l);g&&p.push(g);}return p},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?Sk.has(r):!1}catch{return false}}};Dl=200;});function Pl(t){let e=t.split(`
50
50
  `).filter(s=>s.trim()),n=[],r=null;for(let s of e)try{let o=JSON.parse(s);if(o.type==="assistant.message"&&typeof o.data?.content=="string"){let i=o.data.content;i.trim()&&n.push(i.trim());}o.type==="result"&&typeof o.result=="string"&&(r=o.result);}catch{}if(n.length>0)return n[n.length-1];if(r)return r}var xk,ca,la=D(()=>{h();ns();is();dr();cr();ur();vn();lo();Cn();xk=new Set(["interactive","plan","autopilot"]);ca={command:"copilot",meta:{displayName:"Copilot",models:ll()},buildArgs(t,e,n){let r=e.additionalArgs?[...e.additionalArgs]:[];return e.model&&r.push("--model",e.model),e.mode&&xk.has(e.mode)&&r.push("--mode",e.mode),e.effort&&(co.copilot??[]).includes(e.effort)&&r.push("--effort",e.effort),{args:r,stdinMessage:t}},extractText(t){let e=Pl(t);if(e)return e;let n=t.trim();return Yt(n,"copilot")?"":n},extractPartialText(t){return Pl(t)},parseResultMeta(t){let e=lr(t);return e?{usage:{inputTokens:e.inputTokens,outputTokens:e.outputTokens,cachedInputTokens:e.cachedInputTokens,costUsd:0},model:null}:{usage:null,model:null}},parseEvent(t,e){let n;try{n=JSON.parse(t);}catch{return []}let r=n.type;if(!r)return [];if(!r.startsWith("tool.execution")&&!r.startsWith("assistant.")&&r!=="user.message")return [];let s=n.data;if(!s)return [];let o=At(n,e??new Date().toISOString()),i=s.toolCallId;if(r==="tool.execution_start"){let a=String(s.toolName||""),u=s.arguments,c=It(u);return (a==="bash"||a==="Bash")&&Bt(c)?[Ft(o,c,i)]:[{timestamp:o,type:"tool_use",toolName:a,toolInput:c,...i&&{toolUseId:i}}]}if(r==="tool.execution_complete"){let a=s.error;if(a)return [{timestamp:o,type:"tool_result",...i&&{toolUseId:i},...bt(String(a.message||""),true)}];let u=s.result,c=String(u?.content||"");return [{timestamp:o,type:"tool_result",...i&&{toolUseId:i},...bt(c,false)}]}if(r==="assistant.message"){let a=String(s.content||"");return a?[{timestamp:o,type:"text",content:a}]:[]}return []}};});function Mk(t){let e=[],n=0,r=false,s=false,o=0;for(let a=0;a<t.length;a++){let u=t[a];if(s){s=false;continue}if(u==="\\"&&r){s=true;continue}if(u==='"'){r=!r;continue}if(!r){if(u==="{")n++;else if(u==="}"&&(n--,n===0)){let c=t.slice(o,a+1).trim();c&&e.push(c),o=a+1;}}}let i=t.slice(o).trim();return i&&e.push(i),e}function $k(t){return t[0]==="exec"?t.slice(1):t}function Ml(t){let e=t.split(`
51
51
  `).map(s=>s.trim()).filter(Boolean),n=[],r=null;for(let s of e)try{let o=JSON.parse(s);if(o.type==="item.completed"&&(o.item?.type==="message"||o.item?.type==="agent_message")&&typeof o.item?.text=="string"){let i=o.item.text;i.trim()&&n.push(i.trim());}o.type==="result"&&typeof o.result=="string"&&(r=o.result);}catch{}if(n.length>0)return n[n.length-1];if(r)return r}function cn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Hl(t){return t.type==="turn.failed"?true:t.type!=="error"?false:typeof t.message=="string"||typeof t.errorMessage=="string"||typeof t.error=="string"||cn(t.error)}function Ul(t){let e=cn(t.error)?t.error:void 0,n=[t.message,t.errorMessage,e?.message,e?.detail,typeof t.error=="string"?t.error:void 0];for(let r of n)if(typeof r=="string"&&r.trim())return r;return t.type==="turn.failed"?"Codex turn failed.":"Codex CLI reported an error."}function Hk(t){for(let e of t.split(/\r?\n/)){if(!e.trim())continue;let n;try{n=JSON.parse(e);}catch{continue}if(cn(n)&&Hl(n))return Ul(n)}}function $l(t,e,n,r){if(!n||t.type!=="command_execution"&&t.type!=="mcp_tool_call"||typeof t.id!="string"||!t.id.trim()||t.type==="mcp_tool_call"&&e==="item.started"&&(typeof t.server!="string"||typeof t.tool!="string"))return;let s=n.state.get("codex.pending");s||(s=new Map,n.state.set("codex.pending",s));let o=JSON.stringify([t.type,t.id]);if(e==="item.started"){let u=`codex:${JSON.stringify(t.id)}#${n.rowIndex}:${r}`,c=s.get(o)??[];return c.push(u),s.set(o,c),u}let i=s.get(o),a=i?.pop();return i?.length||s.delete(o),a}function Uk(t,e,n){let r=e.type;if(r==="command_execution"){let s=String(e.command||"");return Bt(s)?[Ft(t,s,n)]:[{timestamp:t,type:"tool_use",toolName:"Bash",toolInput:s,...n?{toolUseId:n}:{}}]}return r==="mcp_tool_call"?typeof e.server!="string"||typeof e.tool!="string"?[]:[{timestamp:t,type:"tool_use",toolName:`${e.server}/${e.tool}`,toolInput:It(e.arguments),...n?{toolUseId:n}:{}}]:[]}function Bk(t,e,n){let r=e.type;if(r==="message"||r==="text"){let s=e.content;if(Array.isArray(s))for(let o of s){let i=Fk(t,o);if(i)return i}if(typeof e.text=="string")return {timestamp:t,type:"text",content:e.text}}if(r==="agent_message"&&typeof e.text=="string")return {timestamp:t,type:"text",content:e.text};if(r==="reasoning"){let s=typeof e.text=="string"?e.text.trim():"";return s?{timestamp:t,type:"thinking",content:s}:null}if(r==="command_execution"){let s=String(e.aggregated_output||e.output||""),o=!!e.is_error;return {timestamp:t,type:"tool_result",...bt(s,o),...n?{toolUseId:n}:{}}}if(r==="mcp_tool_call"){let s=cn(e.result)?e.result:void 0,i=(Array.isArray(s?.content)?s.content:[]).filter(u=>cn(u)&&u.type==="text"&&typeof u.text=="string").map(u=>u.text).join(`
52
- `),a=typeof e.error=="string"?e.error:cn(e.error)&&typeof e.error.message=="string"?e.error.message:"";return {timestamp:t,type:"tool_result",resultPreview:i||a,isError:e.status==="failed"||e.status==="error"||e.is_error===true||e.error!=null,...n?{toolUseId:n}:{}}}if(r==="tool_use"){let s=String(e.name||e.tool_name||""),o=e.input,i=It(o);return s==="Bash"&&Bt(i)?Ft(t,i):{timestamp:t,type:"tool_use",toolName:s,toolInput:i}}if(r==="tool_result"){let s=!!e.is_error,o=String(e.output||e.content||"");return {timestamp:t,type:"tool_result",...bt(o,s)}}if(r==="web_search"){let s=e.action,o;if(s?.type==="search"){let i=s.queries;o=String(s.query||"")||(i?.length?i.join(", "):"")||String(e.query||"");}else o=e.query?"open: "+String(e.query):"";return !o&&!(cn(s)&&s.type==="other"&&e.query==="")?null:{timestamp:t,type:"tool_use",toolName:"WebSearch",toolInput:o}}if(r==="file_change"){let s=e.changes;if(!Array.isArray(s)||s.length===0)return null;let o=s.map(a=>String(a.path||"")).filter(Boolean);if(o.length===0)return null;let i=o.length===1?o[0]:`${o.slice(0,2).join(", ")}${o.length>2?` (+${o.length-2})`:""}`;return {timestamp:t,type:"tool_use",toolName:"Edit",toolInput:i}}return null}function Fk(t,e){let n=e.type;if(n==="text")return {timestamp:t,type:"text",content:String(e.text||"")};if(n==="tool_use"){let r=String(e.name||""),s=e.input,o=It(s);return r==="Bash"&&Bt(o)?Ft(t,o):{timestamp:t,type:"tool_use",toolName:r,toolInput:o}}return null}var Lk,Pk,pa,fa=D(()=>{h();An();ns();is();dr();cr();ra();ur();os();vn();Cn();Lk=new Set(["turn.started","turn.completed","item.updated"]),Pk="cli/codex";pa={command:"codex",meta:{displayName:"Codex",models:cl(),capabilities:{resume:true}},buildArgs(t,e,n){let{model:r,effort:s}=un(e.model),o=e.effort??s,i=e.resumeSessionId?hl(e.mode):_l(e.mode),a=ml(o),u=r?["-m",r]:[],c=$k(e.additionalArgs??[]),l=c.includes("--json")||c.includes("--experimental-json")?[]:["--json"];return e.resumeSessionId?{args:["exec","resume",...l,...i,...a,...u,...c,e.resumeSessionId,"-"],stdinMessage:t}:{args:["exec",...l,...i,...a,...u,...c],stdinMessage:t}},extractText(t){let e=Hk(t);if(e)throw new ie(e,Pk);let n=Ml(t);if(n)return n;let r=t.trim();return Yt(r,"codex")?"":r},extractPartialText(t){return Ml(t)},parseResultMeta(t){let e=lr(t);return e?{usage:{inputTokens:e.inputTokens,outputTokens:e.outputTokens,cachedInputTokens:e.cachedInputTokens,costUsd:0},model:null}:{usage:null,model:null}},parseEvent(t,e,n){let r=e??new Date().toISOString(),s=[],o;try{JSON.parse(t),o=[t];}catch{o=Mk(t),o.length>1&&console.warn("[codex] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let[i,a]of o.entries()){let u;try{u=JSON.parse(a);}catch{continue}if(!cn(u))continue;let c=u.type;if(!c)continue;let p=At(u,r);if(Hl(u)){let g=Ul(u);s.push({timestamp:p,type:"error",content:g,errorMessage:g});continue}if(!c.startsWith("item.")&&!c.startsWith("turn.")&&!c.startsWith("thread.")||na(u))continue;c==="thread.started"&&n&&n.state.delete("codex.pending");let l=u.item;if(l){if(c==="item.started"){s.push(...Uk(p,l,$l(l,c,n,i)));continue}if(c==="item.completed"){let g=Bk(p,l,$l(l,c,n,i));g&&s.push(g);continue}}}return s},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?Lk.has(r):!1}catch{return false}}};});function Wk(t){return t?jk[t]??{agent:"build",autoApprove:false}:{agent:void 0,autoApprove:false}}function ho(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function Wl(t){let e=[],n=0,r=false,s=false,o=0;for(let a=0;a<t.length;a++){let u=t[a];if(s){s=false;continue}if(u==="\\"&&r){s=true;continue}if(u==='"'){r=!r;continue}if(!r){if(u==="{")n++;else if(u==="}"&&(n--,n===0)){let c=t.slice(o,a+1).trim();c&&e.push(c),o=a+1;}}}let i=t.slice(o).trim();return i&&e.push(i),e}function gr(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Gk(t){let e=[],n=false;for(let r of t.split(/\r?\n/)){let s=r.trim();if(!s)continue;try{let i=JSON.parse(s);gr(i)?e.push(i):n=!0;continue}catch{}let o=Wl(s);o.length>1&&console.warn("[opencode] extractText: falling back to concatenated-JSON split for a malformed line");for(let i of o)try{let a=JSON.parse(i);gr(a)?e.push(a):n=!0;}catch{n=true;}}return {events:e,malformed:n}}function Dn(t){if(typeof t!="string")return;let e=t.split(/\r?\n/).map(n=>n.trim()).find(n=>n&&!/^at\s+/.test(n));if(e)return e.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g,"").replace(/(?:[A-Za-z]:[\\/]|\/)(?:[^\s"'`()\[\]{}]+[\\/])*[^\s"'`()\[\]{}]+/g,"[path]").slice(0,jl).trim()}function Gl(t){let e=gr(t.error)?t.error:void 0,n=e&&gr(e.data)?e.data:void 0,r=Dn(e?.name),s=Dn(n?.message)??Dn(e?.message)??Dn(t.message)??Dn(t.errorMessage)??Dn(t.error),o=Dn(t.ref),i=r&&s&&r!==s?`${r}: ${s}`:r??s??ql;return (o?`${i} (ref: ${o})`:i).slice(0,jl)}function Bl(t){let e=Gk(t),n=[],r=null,s=0,o=[],i,a=false;for(let u of e.events){let c=typeof u.type=="string"?u.type:void 0;if(c){if(c==="text"){let p=gr(u.part)?u.part:void 0,l=typeof p?.text=="string"?p.text:void 0;l?.trim()&&n.push(l.trim());continue}if(c==="result"){typeof u.result=="string"&&(r=u.result);continue}if(c==="tool_use"){s++;continue}if(c==="error"){o.push(Gl(u));continue}if(c==="step_finish"){a=true;let p=gr(u.part)?u.part:void 0;i=typeof p?.reason=="string"?p.reason:void 0;}}}return {...e,texts:n,resultText:r,toolUseCount:s,errorMessages:o,terminalReason:i,hasTerminal:a}}function zl(t){return (t??"unknown").trim().toLowerCase().replace(/_/g,"-")}function mo(){return new ie("OpenCode returned no assistant output.",fr,{code:"EMPTY_OUTPUT",kind:"transient"})}function zk(){return new ie("OpenCode emitted malformed JSON output.",fr,{code:"PROVIDER_CRASHED",kind:"transient"})}function Fl(t,e){switch(zl(t)){case "length":return new ie("OpenCode stopped because the context window was exceeded.",fr,{code:"UNKNOWN",kind:"permanent"});case "content-filter":return new ie("OpenCode stopped because the content filter blocked the response.",fr,{code:"UNKNOWN",kind:"permanent"});case "error":return new ie(e?`OpenCode error: ${e}`:`${ql} while generating a response.`,fr,{code:"PROVIDER_CRASHED",kind:"transient"});default:return null}}var qk,fr,ql,jl,jk,ga,_a=D(()=>{h();An();is();cr();Cn();qk=new Set(["step_start","step_finish"]),fr="cli/opencode",ql="OpenCode provider error",jl=240,jk={build:{agent:"build",autoApprove:false},"build-auto":{agent:"build",autoApprove:true},plan:{agent:"plan",autoApprove:false},"plan-auto":{agent:"plan",autoApprove:true}};ga={command:"opencode",meta:{displayName:"OpenCode",capabilities:{resume:true}},buildArgs(t,e,n){let r=e.additionalArgs,s=r!==void 0?[...r]:["run"];ho(s,"--format")||s.push("--format","json"),e.resumeSessionId&&!s.includes("-s")&&!s.includes("--session")&&s.push("-s",e.resumeSessionId);let{agent:o,autoApprove:i}=Wk(e.mode);ho(s,"--agent")||o!==void 0&&s.push("--agent",o),i&&!ho(s,"--auto")&&s.push("--auto"),e.effort!==void 0&&!ho(s,"--variant")&&s.push("--variant",e.effort),e.model&&s.push("--model",e.model);let a;return !n&&!i&&!e.env?.OPENCODE_PERMISSION&&(a={OPENCODE_PERMISSION:JSON.stringify({external_directory:"allow"})}),{args:s,stdinMessage:t,env:a}},extractText(t){let e=Bl(t),n=e.errorMessages[0];if(n){let i=Fl("error",n);if(i)throw i}let r=Fl(e.terminalReason??"",void 0);if(r)throw r;let s=e.texts.length>0?e.texts[e.texts.length-1]:void 0;if(s!==void 0){if(!e.hasTerminal)throw mo();return s}if(e.resultText?.trim()){if(!e.hasTerminal)throw mo();return e.resultText}if(e.malformed)throw zk();if(!e.hasTerminal)throw mo();let o=zl(e.terminalReason);if((o==="stop"||o==="tool-calls")&&e.toolUseCount>0)return "";throw mo()},interpretExit(t,e,n=""){if(t===0)return null;let s=Bl(n).errorMessages[0];return s?new ie(`OpenCode error: ${s}`,fr,{code:"PROVIDER_CRASHED",kind:"transient"}):null},parseResultMeta(t){let e=lr(t);return e?{usage:{inputTokens:e.inputTokens,outputTokens:e.outputTokens,cachedInputTokens:e.cachedInputTokens,costUsd:0},model:null}:{usage:null,model:null}},parseEvent(t,e){let n=e??new Date().toISOString(),r=[],s;try{JSON.parse(t),s=[t];}catch{s=Wl(t),s.length>1&&console.warn("[opencode] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let o of s){let i;try{i=JSON.parse(o);}catch{continue}let a=At(i,n),u=i.type;if(u){if(u==="text"){let p=i.part?.text;p&&r.push({timestamp:a,type:"text",content:p});continue}if(u==="tool_use"){let c=i.part;if(!c)continue;let p=String(c.tool||""),l=String(c.callID||""),g=c.state,_=String(g?.status||""),m=g?.input,k=It(m);if(r.push({timestamp:a,type:"tool_use",toolName:p,toolUseId:l,toolInput:k}),_==="completed"&&g?.output!==void 0){let R=g.output,O=typeof R=="string"?R:JSON.stringify(R);r.push({timestamp:a,type:"tool_result",toolUseId:l,resultPreview:O,isError:false});}else _==="error"&&r.push({timestamp:a,type:"tool_result",toolUseId:l,resultPreview:String(g?.error||"tool error"),isError:true});continue}if(u==="error"){let c=Gl(i);r.push({timestamp:a,type:"error",content:c,errorMessage:c});continue}}}return r},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?qk.has(r):!1}catch{return false}}};});var Kl=D(()=>{h();});function ko(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function Yk(t,e){let n=[];for(let r=0;r<t.length;r+=1){let s=t[r],o=[...e].find(i=>s===i||s.startsWith(`${i}=`));o?s===o&&r+1<t.length&&(r+=1):n.push(s);}return n}function Qk(t){let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],s=r.indexOf("="),o=s>0?r.slice(0,s):r;if(!Jk.has(o)){e.push(r);continue}r===o&&n+1<t.length&&!t[n+1].startsWith("-")&&(n+=1);}return e}function qt(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Zk(t,e){if(!(t?Vk.has(t)||dn(ha).some(o=>o.id===t):false)||!t)return e;let r=ss(ha,t),s=dl(ha)[t]?.defaultEffort;if(r.length!==0)return e?r.includes(e)?e:s&&r.includes(s)?s:void 0:s}function Qt(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0?t:void 0}function Ta(t){return t.kind==="step_update"?typeof t.step.conversation_id=="string"?t.step.conversation_id:void 0:typeof t.envelope.conversation_id=="string"?t.envelope.conversation_id:void 0}function ya(t){return t.step.step_index}function Ye(t){if(typeof t!="string")return;let e=t.split(/\r?\n/,1)[0]?.trim();return e&&io(e)?.slice(0,500).trim()||void 0}function eT(t,e){let n=(t??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&Xk.has(n))return n;let r=`${n} ${e??""}`.toLowerCase();return /quota|resource_exhausted|usage[ _-]?limit|credits?.{0,20}exhaust/.test(r)?"QUOTA_EXHAUSTED":/rate[ _-]?limit|throttl/.test(r)?"RATE_LIMITED":/auth|sign[ _-]?in|log(?:ged)?[ _-]?in|unauthori[sz]ed|credential/.test(r)?"AUTH_REQUIRED":[/unknown (?:flag|option)/,/flag provided but not defined/,/unrecognized (?:flag|option)/,/invalid (?:value for )?(?:flag|option|argument)/].some(o=>o.test(r))?"INVALID_PROVIDER_FORMAT":/invalid.{0,24}model|model.{0,24}(unknown|unavailable|not found|not recognized)|config/.test(r)?"MODEL_UNAVAILABLE":"UNKNOWN"}function tT(t){return t==="AUTH_REQUIRED"||t==="TIMEOUT_IDLE"||t==="TIMEOUT_TOTAL"||t==="TIMEOUT_RESUME"||t==="PROVIDER_CRASHED"?"permanent":t==="MODEL_UNAVAILABLE"||t==="INVALID_PROVIDER_FORMAT"||t==="PROVIDER_NOT_FOUND"?"config":"transient"}function nT(t){let e=qt(t)?t:void 0,n=e&&qt(e.error)?e.error:void 0,r=e?Ye(e.code)??Ye(e.error_code)??Ye(n?.code)??Ye(n?.error_code):void 0,s=typeof t=="string"?Ye(t):e?Ye(e.message)??Ye(e.error)??Ye(e.reason)??Ye(n?.message)??Ye(n?.error)??Ye(n?.reason):void 0,o=eT(r,s),i=e?Qt(e.retry_after_ms)??Qt(e.retryAfterMs)??Qt(n?.retry_after_ms)??Qt(n?.retryAfterMs):void 0;return {code:o,kind:tT(o),message:s??"Antigravity reported a terminal error.",...i===void 0?{}:{retryAfterMs:i}}}function yo(t){let e=nT(t);return new ie(e.message,"cli/antigravity",{code:e.code,kind:e.kind,...e.retryAfterMs===void 0?{}:{retryAfterMs:e.retryAfterMs}})}function wa(t){return new ie(t,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function rT(t){let e=new TextEncoder().encode(t).byteLength;if(!(e<=ka))throw new ie(`Input is too large: final provider initial input is ${e} UTF-8 bytes; budget is ${ka} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function ma(){return new ie("Antigravity CLI returned empty output with exit code 0. agy may have hidden an auth/quota/model error in its log file; inspect ~/.gemini/antigravity-cli/log for details.","cli/antigravity",{code:"EMPTY_OUTPUT",kind:"transient"})}function wo(t){if(t.kind==="result"||t.kind==="legacy_result")return t.result}function Ro(t){for(let e=t.length-1;e>=0;e-=1){let n=t[e];if(n&&(n.kind==="result"||n.kind==="legacy_result"||n.kind==="agy_error"))return {event:n,index:e}}}function sT(t){let e=Ro(t);if(!e||e.event.kind==="agy_error"||e.index!==t.length-1||wo(e.event)?.status!=="SUCCESS"||To(t))return false;let r=new Map;for(let s of t){if(s.kind!=="step_update"||s.step.step_type!=="agent_response")continue;let o=Ta(s),i=ya(s);!o||!Number.isSafeInteger(i)||r.set(JSON.stringify([o,i]),s.step);}if(r.size===0)return false;for(let s of r.values())if(s.state!=="DONE"||!qt(s.usage)||Qt(s.usage.input_tokens)===void 0||Qt(s.usage.output_tokens)===void 0)return false;return true}function oT(t,e){for(let n=e-1;n>=0;n-=1){let r=t[n];if(r?.kind==="agy_error")return r.error}}function iT(t,e){return qt(t)&&qt(e)?{...e,...t}:qt(t)&&typeof e=="string"?{...t,message:e}:typeof t=="string"&&qt(e)?{...e,message:t}:t??e}function aT(t){let e=Array.isArray(t.denied_actions)?t.denied_actions:[],n=[];for(let o of e){let i=qt(o)?o:void 0,a=typeof o=="string"?Ye(o):Ye(i?.display_name)??Ye(i?.action);a&&!n.includes(a)&&n.length<5&&n.push(a.slice(0,80));}let r=Math.max(0,e.length-n.length),s=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"";return new ie(`Permission denied: Antigravity blocked ${e.length} requested action${e.length===1?"":"s"}${s}.`,"cli/antigravity",{code:"UNKNOWN",kind:"permanent"})}function To(t){let e=Ro(t);if(!e)return;if(e.event.kind==="agy_error")return yo(e.event.error);let n=wo(e.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return aT(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return wa("Antigravity returned a result with an unsupported status.");let r=n.error,s=iT(r==null||r===""?n:r,oT(t,e.index));return yo(s)}function Xl(t){if(typeof t=="string")return t;if(t!=null)try{return JSON.stringify(t)}catch{return}}function dT(t){return `agy:${String(t.conversation_id)}:${String(t.step_index)}`}function uT(t,e){let n=typeof e?.name=="string"?e.name:t.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function cT(t){let e=Xl(t);if(e)return e.length<=2e3?e:`${e.slice(0,1999)}\u2026`}function Vl(t,e){return t?t.state.has(e)?true:(t.state.set(e,true),false):false}function Jl(t,e){return {timestamp:t,type:"error",content:e.message,errorMessage:e.message,isError:true}}var ha,Vk,Jk,ka,Xk,Ra,Ea=D(()=>{h();An();Kl();ea();rs();vn();os();uo();ha="antigravity",Vk=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),Jk=new Set(["--conversation","--resume","--continue"]),ka=18e4,Xk=new Set(["QUOTA_EXHAUSTED","RATE_LIMITED","EMPTY_OUTPUT","AUTH_REQUIRED","MODEL_UNAVAILABLE","TIMEOUT_IDLE","TIMEOUT_TOTAL","TIMEOUT_RESUME","PROVIDER_NOT_FOUND","INVALID_PROVIDER_FORMAT","PROVIDER_CRASHED","UNKNOWN"]);Ra={command:"agy",maxInitialInputBytes:ka,meta:{displayName:"Antigravity",models:pl(),defaultTimeoutMs:{query:12e4,execute:3e5},defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(t){let e=ts(t);if(e?.kind!=="init")return null;let n=e.envelope.conversation_id;return typeof n=="string"&&n.trim().length>0?n.trim():null},buildArgs(t,e,n){rT(t);let{model:r,effort:s}=un(e.model),o=aa(r),i=o.model,a=e.effort??s??o.effort,u=Zk(i,a),c=e.additionalArgs??[],p=Qk(Yk(c,new Set(["--input-format","--output-format"]))),l=i&&!ko(c,"--model")?["--model",i]:[],g=ko(c,"--effort")?[]:bl(u),_=ko(c,"--mode")||ko(c,"--dangerously-skip-permissions")?[]:Sl(e.mode),m=typeof e.resumeSessionId=="string"&&e.resumeSessionId.trim().length>0?["--conversation",e.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...l,...g,..._,...m,...p],stdinMessage:`${JSON.stringify({event:"user",message:{content:t}})}
52
+ `),a=typeof e.error=="string"?e.error:cn(e.error)&&typeof e.error.message=="string"?e.error.message:"";return {timestamp:t,type:"tool_result",resultPreview:i||a,isError:e.status==="failed"||e.status==="error"||e.is_error===true||e.error!=null,...n?{toolUseId:n}:{}}}if(r==="tool_use"){let s=String(e.name||e.tool_name||""),o=e.input,i=It(o);return s==="Bash"&&Bt(i)?Ft(t,i):{timestamp:t,type:"tool_use",toolName:s,toolInput:i}}if(r==="tool_result"){let s=!!e.is_error,o=String(e.output||e.content||"");return {timestamp:t,type:"tool_result",...bt(o,s)}}if(r==="web_search"){let s=e.action,o;if(s?.type==="search"){let i=s.queries;o=String(s.query||"")||(i?.length?i.join(", "):"")||String(e.query||"");}else o=e.query?"open: "+String(e.query):"";return !o&&!(cn(s)&&s.type==="other"&&e.query==="")?null:{timestamp:t,type:"tool_use",toolName:"WebSearch",toolInput:o}}if(r==="file_change"){let s=e.changes;if(!Array.isArray(s)||s.length===0)return null;let o=s.map(a=>String(a.path||"")).filter(Boolean);if(o.length===0)return null;let i=o.length===1?o[0]:`${o.slice(0,2).join(", ")}${o.length>2?` (+${o.length-2})`:""}`;return {timestamp:t,type:"tool_use",toolName:"Edit",toolInput:i}}return null}function Fk(t,e){let n=e.type;if(n==="text")return {timestamp:t,type:"text",content:String(e.text||"")};if(n==="tool_use"){let r=String(e.name||""),s=e.input,o=It(s);return r==="Bash"&&Bt(o)?Ft(t,o):{timestamp:t,type:"tool_use",toolName:r,toolInput:o}}return null}var Lk,Pk,pa,fa=D(()=>{h();An();ns();is();dr();cr();ra();ur();os();vn();Cn();Lk=new Set(["turn.started","turn.completed","item.updated"]),Pk="cli/codex";pa={command:"codex",meta:{displayName:"Codex",models:cl(),capabilities:{resume:true}},buildArgs(t,e,n){let{model:r,effort:s}=un(e.model),o=e.effort??s,i=e.resumeSessionId?hl(e.mode):_l(e.mode),a=ml(o),u=r?["-m",r]:[],c=$k(e.additionalArgs??[]),l=c.includes("--json")||c.includes("--experimental-json")?[]:["--json"];return e.resumeSessionId?{args:["exec","resume",...l,...i,...a,...u,...c,e.resumeSessionId,"-"],stdinMessage:t}:{args:["exec",...l,...i,...a,...u,...c],stdinMessage:t}},extractText(t){let e=Hk(t);if(e)throw new ie(e,Pk);let n=Ml(t);if(n)return n;let r=t.trim();return Yt(r,"codex")?"":r},extractPartialText(t){return Ml(t)},parseResultMeta(t){let e=lr(t);return e?{usage:{inputTokens:e.inputTokens,outputTokens:e.outputTokens,cachedInputTokens:e.cachedInputTokens,costUsd:0},model:null}:{usage:null,model:null}},parseEvent(t,e,n){let r=e??new Date().toISOString(),s=[],o;try{JSON.parse(t),o=[t];}catch{o=Mk(t),o.length>1&&console.warn("[codex] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let[i,a]of o.entries()){let u;try{u=JSON.parse(a);}catch{continue}if(!cn(u))continue;let c=u.type;if(!c)continue;let p=At(u,r);if(Hl(u)){let g=Ul(u);s.push({timestamp:p,type:"error",content:g,errorMessage:g});continue}if(!c.startsWith("item.")&&!c.startsWith("turn.")&&!c.startsWith("thread.")||na(u))continue;c==="thread.started"&&n&&n.state.delete("codex.pending");let l=u.item;if(l){if(c==="item.started"){s.push(...Uk(p,l,$l(l,c,n,i)));continue}if(c==="item.completed"){let g=Bk(p,l,$l(l,c,n,i));g&&s.push(g);continue}}}return s},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?Lk.has(r):!1}catch{return false}}};});function Wk(t){return t?jk[t]??{agent:"build",autoApprove:false}:{agent:void 0,autoApprove:false}}function ho(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function Wl(t){let e=[],n=0,r=false,s=false,o=0;for(let a=0;a<t.length;a++){let u=t[a];if(s){s=false;continue}if(u==="\\"&&r){s=true;continue}if(u==='"'){r=!r;continue}if(!r){if(u==="{")n++;else if(u==="}"&&(n--,n===0)){let c=t.slice(o,a+1).trim();c&&e.push(c),o=a+1;}}}let i=t.slice(o).trim();return i&&e.push(i),e}function gr(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Gk(t){let e=[],n=false;for(let r of t.split(/\r?\n/)){let s=r.trim();if(!s)continue;try{let i=JSON.parse(s);gr(i)?e.push(i):n=!0;continue}catch{}let o=Wl(s);o.length>1&&console.warn("[opencode] extractText: falling back to concatenated-JSON split for a malformed line");for(let i of o)try{let a=JSON.parse(i);gr(a)?e.push(a):n=!0;}catch{n=true;}}return {events:e,malformed:n}}function Dn(t){if(typeof t!="string")return;let e=t.split(/\r?\n/).map(n=>n.trim()).find(n=>n&&!/^at\s+/.test(n));if(e)return e.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g,"").replace(/(?:[A-Za-z]:[\\/]|\/)(?:[^\s"'`()\[\]{}]+[\\/])*[^\s"'`()\[\]{}]+/g,"[path]").slice(0,jl).trim()}function Gl(t){let e=gr(t.error)?t.error:void 0,n=e&&gr(e.data)?e.data:void 0,r=Dn(e?.name),s=Dn(n?.message)??Dn(e?.message)??Dn(t.message)??Dn(t.errorMessage)??Dn(t.error),o=Dn(t.ref),i=r&&s&&r!==s?`${r}: ${s}`:r??s??ql;return (o?`${i} (ref: ${o})`:i).slice(0,jl)}function Bl(t){let e=Gk(t),n=[],r=null,s=0,o=[],i,a=false;for(let u of e.events){let c=typeof u.type=="string"?u.type:void 0;if(c){if(c==="text"){let p=gr(u.part)?u.part:void 0,l=typeof p?.text=="string"?p.text:void 0;l?.trim()&&n.push(l.trim());continue}if(c==="result"){typeof u.result=="string"&&(r=u.result);continue}if(c==="tool_use"){s++;continue}if(c==="error"){o.push(Gl(u));continue}if(c==="step_finish"){a=true;let p=gr(u.part)?u.part:void 0;i=typeof p?.reason=="string"?p.reason:void 0;}}}return {...e,texts:n,resultText:r,toolUseCount:s,errorMessages:o,terminalReason:i,hasTerminal:a}}function zl(t){return (t??"unknown").trim().toLowerCase().replace(/_/g,"-")}function mo(){return new ie("OpenCode returned no assistant output.",fr,{code:"EMPTY_OUTPUT",kind:"transient"})}function zk(){return new ie("OpenCode emitted malformed JSON output.",fr,{code:"PROVIDER_CRASHED",kind:"transient"})}function Fl(t,e){switch(zl(t)){case "length":return new ie("OpenCode stopped because the context window was exceeded.",fr,{code:"UNKNOWN",kind:"permanent"});case "content-filter":return new ie("OpenCode stopped because the content filter blocked the response.",fr,{code:"UNKNOWN",kind:"permanent"});case "error":return new ie(e?`OpenCode error: ${e}`:`${ql} while generating a response.`,fr,{code:"PROVIDER_CRASHED",kind:"transient"});default:return null}}var qk,fr,ql,jl,jk,ga,_a=D(()=>{h();An();is();cr();Cn();qk=new Set(["step_start","step_finish"]),fr="cli/opencode",ql="OpenCode provider error",jl=240,jk={build:{agent:"build",autoApprove:false},"build-auto":{agent:"build",autoApprove:true},plan:{agent:"plan",autoApprove:false},"plan-auto":{agent:"plan",autoApprove:true}};ga={command:"opencode",meta:{displayName:"OpenCode",capabilities:{resume:true}},buildArgs(t,e,n){let r=e.additionalArgs,s=r!==void 0?[...r]:["run"];ho(s,"--format")||s.push("--format","json"),e.resumeSessionId&&!s.includes("-s")&&!s.includes("--session")&&s.push("-s",e.resumeSessionId);let{agent:o,autoApprove:i}=Wk(e.mode);ho(s,"--agent")||o!==void 0&&s.push("--agent",o),i&&!ho(s,"--auto")&&s.push("--auto"),e.effort!==void 0&&!ho(s,"--variant")&&s.push("--variant",e.effort),e.model&&s.push("--model",e.model);let a;return !n&&!i&&!e.env?.OPENCODE_PERMISSION&&(a={OPENCODE_PERMISSION:JSON.stringify({external_directory:"allow"})}),{args:s,stdinMessage:t,env:a}},extractText(t){let e=Bl(t),n=e.errorMessages[0];if(n){let i=Fl("error",n);if(i)throw i}let r=Fl(e.terminalReason??"",void 0);if(r)throw r;let s=e.texts.length>0?e.texts[e.texts.length-1]:void 0;if(s!==void 0){if(!e.hasTerminal)throw mo();return s}if(e.resultText?.trim()){if(!e.hasTerminal)throw mo();return e.resultText}if(e.malformed)throw zk();if(!e.hasTerminal)throw mo();let o=zl(e.terminalReason);if((o==="stop"||o==="tool-calls")&&e.toolUseCount>0)return "";throw mo()},interpretExit(t,e,n=""){if(t===0)return null;let s=Bl(n).errorMessages[0];return s?new ie(`OpenCode error: ${s}`,fr,{code:"PROVIDER_CRASHED",kind:"transient"}):null},parseResultMeta(t){let e=lr(t);return e?{usage:{inputTokens:e.inputTokens,outputTokens:e.outputTokens,cachedInputTokens:e.cachedInputTokens,costUsd:0},model:null}:{usage:null,model:null}},parseEvent(t,e){let n=e??new Date().toISOString(),r=[],s;try{JSON.parse(t),s=[t];}catch{s=Wl(t),s.length>1&&console.warn("[opencode] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let o of s){let i;try{i=JSON.parse(o);}catch{continue}let a=At(i,n),u=i.type;if(u){if(u==="text"){let p=i.part?.text;p&&r.push({timestamp:a,type:"text",content:p});continue}if(u==="tool_use"){let c=i.part;if(!c)continue;let p=String(c.tool||""),l=String(c.callID||""),g=c.state,_=String(g?.status||""),m=g?.input,k=It(m);if(r.push({timestamp:a,type:"tool_use",toolName:p,toolUseId:l,toolInput:k}),_==="completed"&&g?.output!==void 0){let R=g.output,O=typeof R=="string"?R:JSON.stringify(R);r.push({timestamp:a,type:"tool_result",toolUseId:l,resultPreview:O,isError:false});}else _==="error"&&r.push({timestamp:a,type:"tool_result",toolUseId:l,resultPreview:String(g?.error||"tool error"),isError:true});continue}if(u==="error"){let c=Gl(i);r.push({timestamp:a,type:"error",content:c,errorMessage:c});continue}}}return r},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?qk.has(r):!1}catch{return false}}};});var Kl=D(()=>{h();});function ko(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function Yk(t,e){let n=[];for(let r=0;r<t.length;r+=1){let s=t[r],o=[...e].find(i=>s===i||s.startsWith(`${i}=`));o?s===o&&r+1<t.length&&(r+=1):n.push(s);}return n}function Qk(t){let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],s=r.indexOf("="),o=s>0?r.slice(0,s):r;if(!Jk.has(o)){e.push(r);continue}r===o&&n+1<t.length&&!t[n+1].startsWith("-")&&(n+=1);}return e}function qt(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Zk(t,e){if(!(t?Vk.has(t)||dn(ha).some(o=>o.id===t):false)||!t)return e;let r=ss(ha,t),s=dl(ha)[t]?.defaultEffort;if(r.length!==0)return e?r.includes(e)?e:s&&r.includes(s)?s:void 0:s}function Qt(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0?t:void 0}function Ta(t){return t.kind==="step_update"?typeof t.step.conversation_id=="string"?t.step.conversation_id:void 0:typeof t.envelope.conversation_id=="string"?t.envelope.conversation_id:void 0}function ya(t){return t.step.step_index}function Ye(t){if(typeof t!="string")return;let e=t.split(/\r?\n/,1)[0]?.trim();return e&&io(e)?.slice(0,500).trim()||void 0}function eT(t,e){let n=(t??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&Xk.has(n))return n;let r=`${n} ${e??""}`.toLowerCase();return /quota|resource_exhausted|usage[ _-]?limit|credits?.{0,20}exhaust/.test(r)?"QUOTA_EXHAUSTED":/rate[ _-]?limit|throttl/.test(r)?"RATE_LIMITED":/auth|sign[ _-]?in|log(?:ged)?[ _-]?in|unauthori[sz]ed|credential/.test(r)?"AUTH_REQUIRED":[/unknown (?:flag|option)/,/flag provided but not defined/,/unrecognized (?:flag|option)/,/invalid (?:value for )?(?:flag|option|argument)/].some(o=>o.test(r))?"INVALID_PROVIDER_FORMAT":/invalid.{0,24}model|model.{0,24}(unknown|unavailable|not found|not recognized)|config/.test(r)?"MODEL_UNAVAILABLE":"UNKNOWN"}function tT(t){return t==="AUTH_REQUIRED"||t==="TIMEOUT_IDLE"||t==="TIMEOUT_TOTAL"||t==="TIMEOUT_RESUME"||t==="PROVIDER_CRASHED"?"permanent":t==="MODEL_UNAVAILABLE"||t==="INVALID_PROVIDER_FORMAT"||t==="PROVIDER_NOT_FOUND"?"config":"transient"}function nT(t){let e=qt(t)?t:void 0,n=e&&qt(e.error)?e.error:void 0,r=e?Ye(e.code)??Ye(e.error_code)??Ye(n?.code)??Ye(n?.error_code):void 0,s=typeof t=="string"?Ye(t):e?Ye(e.message)??Ye(e.error)??Ye(e.reason)??Ye(n?.message)??Ye(n?.error)??Ye(n?.reason):void 0,o=eT(r,s),i=e?Qt(e.retry_after_ms)??Qt(e.retryAfterMs)??Qt(n?.retry_after_ms)??Qt(n?.retryAfterMs):void 0;return {code:o,kind:tT(o),message:s??"Antigravity reported a terminal error.",...i===void 0?{}:{retryAfterMs:i}}}function yo(t){let e=nT(t);return new ie(e.message,"cli/antigravity",{code:e.code,kind:e.kind,...e.retryAfterMs===void 0?{}:{retryAfterMs:e.retryAfterMs}})}function wa(t){return new ie(t,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function rT(t){let e=new TextEncoder().encode(t).byteLength;if(!(e<=ka))throw new ie(`Input is too large: final provider initial input is ${e} UTF-8 bytes; budget is ${ka} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function ma(){return new ie("Antigravity CLI returned empty output with exit code 0. agy may have hidden an auth/quota/model error in its log file; inspect ~/.gemini/antigravity-cli/log for details.","cli/antigravity",{code:"EMPTY_OUTPUT",kind:"transient"})}function wo(t){if(t.kind==="result"||t.kind==="legacy_result")return t.result}function Ro(t){for(let e=t.length-1;e>=0;e-=1){let n=t[e];if(n&&(n.kind==="result"||n.kind==="legacy_result"||n.kind==="agy_error"))return {event:n,index:e}}}function sT(t){let e=Ro(t);if(!e||e.event.kind==="agy_error"||e.index!==t.length-1||wo(e.event)?.status!=="SUCCESS"||To(t))return false;let r=new Map;for(let s of t){if(s.kind!=="step_update"||s.step.step_type!=="agent_response")continue;let o=Ta(s),i=ya(s);!o||!Number.isSafeInteger(i)||r.set(JSON.stringify([o,i]),s.step);}if(r.size===0)return false;for(let s of r.values())if(s.state!=="DONE"||!qt(s.usage)||Qt(s.usage.input_tokens)===void 0||Qt(s.usage.output_tokens)===void 0)return false;return true}function oT(t,e){for(let n=e-1;n>=0;n-=1){let r=t[n];if(r?.kind==="agy_error")return r.error}}function iT(t,e){return qt(t)&&qt(e)?{...e,...t}:qt(t)&&typeof e=="string"?{...t,message:e}:typeof t=="string"&&qt(e)?{...e,message:t}:t??e}function aT(t){let e=Array.isArray(t.denied_actions)?t.denied_actions:[],n=[];for(let o of e){let i=qt(o)?o:void 0,a=typeof o=="string"?Ye(o):Ye(i?.display_name)??Ye(i?.action);a&&!n.includes(a)&&n.length<5&&n.push(a.slice(0,80));}let r=Math.max(0,e.length-n.length),s=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"";return new ie(`Permission denied: Antigravity blocked ${e.length} requested action${e.length===1?"":"s"}${s}.`,"cli/antigravity",{code:"UNKNOWN",kind:"permanent"})}function To(t){let e=Ro(t);if(!e)return;if(e.event.kind==="agy_error")return yo(e.event.error);let n=wo(e.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return aT(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return wa("Antigravity returned a result with an unsupported status.");let r=n.error,s=iT(r==null||r===""?n:r,oT(t,e.index));return yo(s)}function Xl(t){if(typeof t=="string")return t;if(t!=null)try{return JSON.stringify(t)}catch{return}}function dT(t){return `agy:${String(t.conversation_id)}:${String(t.step_index)}`}function uT(t,e){let n=typeof e?.name=="string"?e.name:t.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function cT(t){let e=Xl(t);if(e)return e.length<=2e3?e:`${e.slice(0,1999)}\u2026`}function Vl(t,e){return t?t.state.has(e)?true:(t.state.set(e,true),false):false}function Jl(t,e){return {timestamp:t,type:"error",content:e.message,errorMessage:e.message,isError:true}}var ha,Vk,Jk,ka,Xk,Ra,Ea=D(()=>{h();An();Kl();ea();rs();vn();os();uo();ha="antigravity",Vk=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),Jk=new Set(["--conversation","--resume","--continue"]),ka=18e4,Xk=new Set(["QUOTA_EXHAUSTED","RATE_LIMITED","EMPTY_OUTPUT","AUTH_REQUIRED","MODEL_UNAVAILABLE","TIMEOUT_IDLE","TIMEOUT_TOTAL","TIMEOUT_RESUME","PROVIDER_NOT_FOUND","INVALID_PROVIDER_FORMAT","PROVIDER_CRASHED","UNKNOWN"]);Ra={command:"agy",maxInitialInputBytes:ka,meta:{displayName:"Antigravity",models:pl(),defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(t){let e=ts(t);if(e?.kind!=="init")return null;let n=e.envelope.conversation_id;return typeof n=="string"&&n.trim().length>0?n.trim():null},buildArgs(t,e,n){rT(t);let{model:r,effort:s}=un(e.model),o=aa(r),i=o.model,a=e.effort??s??o.effort,u=Zk(i,a),c=e.additionalArgs??[],p=Qk(Yk(c,new Set(["--input-format","--output-format"]))),l=i&&!ko(c,"--model")?["--model",i]:[],g=ko(c,"--effort")?[]:bl(u),_=ko(c,"--mode")||ko(c,"--dangerously-skip-permissions")?[]:Sl(e.mode),m=typeof e.resumeSessionId=="string"&&e.resumeSessionId.trim().length>0?["--conversation",e.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...l,...g,..._,...m,...p],stdinMessage:`${JSON.stringify({event:"user",message:{content:t}})}
53
53
  `,env:{AGY_CLI_DISABLE_AUTO_UPDATE:"true"}}},extractText(t){let e=Nn(t),n=Ro(e)?.event,r=To(e);if(r)throw r;let s=n?wo(n):void 0;if(s){if(s.status!=="SUCCESS")throw wa("Antigravity returned a result with an unsupported status.");if(typeof s.response!="string")throw wa("Antigravity returned a successful result without a response string.");if(!s.response.trim())throw ma();return s.response}if(e.length>0)throw ma();let o=t.trim();if(!o)throw ma();return o},extractPartialText(t){let e=Nn(t),n=Ro(e)?.event;if(!n||n.kind==="agy_error")return;let r=wo(n);return r&&typeof r.response=="string"&&r.response.trim()?r.response:void 0},interpretExit(t,e,n){let r=Nn(n??""),s=To(r);return s||(t!==0&&e.trim()?yo(e):null)},parseResultMeta(t){let e=Nn(t),n=0,r=0,s=0,o=0,i=new Set;for(let u of e){if(u.kind!=="step_update"||u.step.state!=="DONE"||!qt(u.step.usage))continue;let c=Ta(u),p=ya(u);if(!c||!Number.isSafeInteger(p))continue;let l=JSON.stringify([c,p]);if(i.has(l))continue;let g=u.step.usage,_=Qt(g.input_tokens),m=Qt(g.output_tokens);_===void 0||m===void 0||(i.add(l),n+=_,r+=m,s+=Qt(g.cache_read_tokens)??0,o+=1);}return {usage:o===0?null:{inputTokens:n,outputTokens:r,cachedInputTokens:s,costUsd:0,complete:sT(e)},model:null}},parseEvent(t,e,n){let r=ts(t);if(!r)return [];let s=e??new Date().toISOString();if(r.kind==="agy_error")return [Jl(s,yo(r.error))];if(r.kind==="legacy_result"||r.kind==="result"){let _=To([r]);return _?[Jl(s,_)]:[]}if(r.kind!=="step_update")return [];let{step:o}=r,i=Ta(r)??"unknown",a=ya(r),u=`${i}:${a}`;if(o.state==="DONE"&&Vl(n,`antigravity:terminal:${u}`))return [];if(o.step_type==="agent_response")return typeof o.text_delta=="string"&&o.text_delta.length>0?[{timestamp:s,type:"text",content:o.text_delta}]:[];if(o.step_type!=="tool")return [];let c=qt(o.tool_info)?o.tool_info:void 0,p=uT(o,c);if(!p)return [];let l=dT(o);if(o.state==="ACTIVE"){if(Vl(n,`antigravity:active:${u}`))return [];let _=Xl(c?.parameters);return [{timestamp:s,type:"tool_use",toolName:p,toolUseId:l,..._===void 0?{}:{toolInput:_}}]}let g=cT(c?.output);return [{timestamp:s,type:"tool_result",toolName:p,toolUseId:l,...g===void 0?{}:{resultPreview:g}}]}};});var Yl=D(()=>{h();dr();cr();ur();Cn();});function _r(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function hr(t){return _r(t)?t:void 0}function Qe(t){return typeof t=="string"?t:void 0}function Ln(t){let e=typeof t=="number"?t:Number(t??0);return Number.isFinite(e)?e:0}function _T(t){let e=[],n=-1,r=0,s=false,o=false;for(let i=0;i<t.length;i+=1){let a=t[i];if(n===-1){(a==="{"||a==="[")&&(n=i,r=1);continue}if(o){o=false;continue}if(a==="\\"&&s){o=true;continue}if(a==='"'){s=!s;continue}s||(a==="{"||a==="["?r+=1:(a==="}"||a==="]")&&(r-=1,r===0&&(e.push(t.slice(n,i+1)),n=-1)));}return n!==-1&&e.push(t.slice(n)),e}function as(t){let e=t.trim();if(!e)return [];try{let n=JSON.parse(e);return _r(n)?[n]:[]}catch{return _T(e).flatMap(n=>{try{let r=JSON.parse(n);return _r(r)?[r]:[]}catch{return []}})}}function np(t){let e=JSON.stringify(t);return e===void 0?String(t):e}function xn(t){if(typeof t=="string")return t;if(Array.isArray(t)){let e=t.map(xn).filter(n=>n!==void 0);return e.length>0?e.join(`
54
54
  `):void 0}if(_r(t)){if(typeof t.text=="string")return t.text;if(typeof t.message=="string")return t.message;if(typeof t.error=="string")return t.error;if(t.type==="text"&&typeof t.data=="string")return t.data;for(let e of ["content","FileContent","rawOutput"]){let n=xn(t[e]);if(n!==void 0)return n}}}function hT(t){let e=i=>Array.isArray(i)&&i.every(a=>Number.isInteger(a)&&a>=0&&a<=255),n=i=>typeof i=="string"&&i.trim().length>0?i:void 0,r=i=>new TextDecoder("utf-8",{fatal:false}).decode(Uint8Array.from(i)),s=i=>{let a=JSON.stringify(i,(u,c)=>e(c)?`<bytes:${c.length}>`:c);return a===void 0?String(i):a},o=t.rawOutput;if(o!=null){let i=hr(o);if(!i)return n(xn(o))??s(o);let a;if(e(i.output)&&i.output.length>0&&(a=n(r(i.output))),!a&&e(i.stdout)&&i.stdout.length>0&&(a=n(r(i.stdout))),!a){let p=hr(i.Result);a=n(i.output)??n(p?.output)??n(xn(o));}let u=e(i.stderr)&&i.stderr.length>0?r(i.stderr):void 0;if(u!==void 0)if(a){let p=a.endsWith(`
55
55
  `)||a.endsWith("\r")?"":`