@crewx/sdk 0.9.0-rc.222 → 0.9.0-rc.224

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.
@@ -62,7 +62,7 @@ ${r.join(`
62
62
  `);for(let r of e)if(r.trim())try{let o=JSON.parse(r);if(o.type==="result"){let s=o.usage,i=s?{inputTokens:Number(s.input_tokens??0)+Number(s.cache_read_input_tokens??0),outputTokens:Number(s.output_tokens??0),cachedInputTokens:Number(s.cache_read_input_tokens??0),costUsd:Number(o.total_cost_usd??0)}:null,a=o.modelUsage,c=a?Object.keys(a)[0]??null:null;return {usage:i,model:c}}}catch{}let n=vi(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 o=$e(n,e??new Date().toISOString()),s=nl(n);if(s)return [{timestamp:o,type:"error",content:s,errorMessage:s}];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:o,type:"text",content:a}];if(r!=="assistant"&&r!=="user")return [];let u=n.message?.content;if(!Array.isArray(u))return [];let p=[];for(let g of u){let _=il(o,g);_&&p.push(_);}return p},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?Qu.has(r):!1}catch{return false}}};Hi=200;});function ji(t){let e=t.split(`
63
63
  `).filter(o=>o.trim()),n=[],r=null;for(let o of e)try{let s=JSON.parse(o);if(s.type==="assistant.message"&&typeof s.data?.content=="string"){let i=s.data.content;i.trim()&&n.push(i.trim());}s.type==="result"&&typeof s.result=="string"&&(r=s.result);}catch{}if(n.length>0)return n[n.length-1];if(r)return r}var al,ro=k(()=>{d();Qt();on();Ct();Ot();Nt();Ye();Mn();ut();al=new Set(["interactive","plan","autopilot"]);({command:"copilot",meta:{displayName:"Copilot",models:Si()},buildArgs(t,e,n){let r=e.additionalArgs?[...e.additionalArgs]:[];return e.model&&r.push("--model",e.model),e.mode&&al.has(e.mode)&&r.push("--mode",e.mode),e.effort&&(Ln.copilot??[]).includes(e.effort)&&r.push("--effort",e.effort),{args:r,stdinMessage:t}},extractText(t){let e=ji(t);if(e)return e;let n=t.trim();return dt(n,"copilot")?"":n},extractPartialText(t){return ji(t)},parseResultMeta(t){let e=rn(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 o=n.data;if(!o)return [];let s=$e(n,e??new Date().toISOString()),i=o.toolCallId;if(r==="tool.execution_start"){let a=String(o.toolName||""),c=o.arguments,u=Me(c);return (a==="bash"||a==="Bash")&&Pe(u)?[xe(s,u,i)]:[{timestamp:s,type:"tool_use",toolName:a,toolInput:u,...i&&{toolUseId:i}}]}if(r==="tool.execution_complete"){let a=o.error;if(a)return [{timestamp:s,type:"tool_result",...i&&{toolUseId:i},...Le(String(a.message||""),true)}];let c=o.result,u=String(c?.content||"");return [{timestamp:s,type:"tool_result",...i&&{toolUseId:i},...Le(u,false)}]}if(r==="assistant.message"){let a=String(o.content||"");return a?[{timestamp:s,type:"text",content:a}]:[]}return []}});});function ul(t){let e=[],n=0,r=false,o=false,s=0;for(let a=0;a<t.length;a++){let c=t[a];if(o){o=false;continue}if(c==="\\"&&r){o=true;continue}if(c==='"'){r=!r;continue}if(!r){if(c==="{")n++;else if(c==="}"&&(n--,n===0)){let u=t.slice(s,a+1).trim();u&&e.push(u),s=a+1;}}}let i=t.slice(s).trim();return i&&e.push(i),e}function ll(t){return t[0]==="exec"?t.slice(1):t}function Ki(t){let e=t.split(`
64
64
  `).map(o=>o.trim()).filter(Boolean),n=[],r=null;for(let o of e)try{let s=JSON.parse(o);if(s.type==="item.completed"&&(s.item?.type==="message"||s.item?.type==="agent_message")&&typeof s.item?.text=="string"){let i=s.item.text;i.trim()&&n.push(i.trim());}s.type==="result"&&typeof s.result=="string"&&(r=s.result);}catch{}if(n.length>0)return n[n.length-1];if(r)return r}function Je(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function zi(t){return t.type==="turn.failed"?true:t.type!=="error"?false:typeof t.message=="string"||typeof t.errorMessage=="string"||typeof t.error=="string"||Je(t.error)}function Yi(t){let e=Je(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 pl(t){for(let e of t.split(/\r?\n/)){if(!e.trim())continue;let n;try{n=JSON.parse(e);}catch{continue}if(Je(n)&&zi(n))return Yi(n)}}function Vi(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 o=n.state.get("codex.pending");o||(o=new Map,n.state.set("codex.pending",o));let s=JSON.stringify([t.type,t.id]);if(e==="item.started"){let c=`codex:${JSON.stringify(t.id)}#${n.rowIndex}:${r}`,u=o.get(s)??[];return u.push(c),o.set(s,u),c}let i=o.get(s),a=i?.pop();return i?.length||o.delete(s),a}function _l(t,e,n){let r=e.type;if(r==="command_execution"){let o=String(e.command||"");return Pe(o)?[xe(t,o,n)]:[{timestamp:t,type:"tool_use",toolName:"Bash",toolInput:o,...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:Me(e.arguments),...n?{toolUseId:n}:{}}]:[]}function gl(t,e,n){let r=e.type;if(r==="message"||r==="text"){let o=e.content;if(Array.isArray(o))for(let s of o){let i=fl(t,s);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 o=typeof e.text=="string"?e.text.trim():"";return o?{timestamp:t,type:"thinking",content:o}:null}if(r==="command_execution"){let o=String(e.aggregated_output||e.output||""),s=!!e.is_error;return {timestamp:t,type:"tool_result",...Le(o,s),...n?{toolUseId:n}:{}}}if(r==="mcp_tool_call"){let o=Je(e.result)?e.result:void 0,i=(Array.isArray(o?.content)?o.content:[]).filter(c=>Je(c)&&c.type==="text"&&typeof c.text=="string").map(c=>c.text).join(`
65
- `),a=typeof e.error=="string"?e.error:Je(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 o=String(e.name||e.tool_name||""),s=e.input,i=Me(s);return o==="Bash"&&Pe(i)?xe(t,i):{timestamp:t,type:"tool_use",toolName:o,toolInput:i}}if(r==="tool_result"){let o=!!e.is_error,s=String(e.output||e.content||"");return {timestamp:t,type:"tool_result",...Le(s,o)}}if(r==="web_search"){let o=e.action,s;if(o?.type==="search"){let i=o.queries;s=String(o.query||"")||(i?.length?i.join(", "):"")||String(e.query||"");}else s=e.query?"open: "+String(e.query):"";return !s&&!(Je(o)&&o.type==="other"&&e.query==="")?null:{timestamp:t,type:"tool_use",toolName:"WebSearch",toolInput:s}}if(r==="file_change"){let o=e.changes;if(!Array.isArray(o)||o.length===0)return null;let s=o.map(a=>String(a.path||"")).filter(Boolean);if(s.length===0)return null;let i=s.length===1?s[0]:`${s.slice(0,2).join(", ")}${s.length>2?` (+${s.length-2})`:""}`;return {timestamp:t,type:"tool_use",toolName:"Edit",toolInput:i}}return null}function fl(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||""),o=e.input,s=Me(o);return r==="Bash"&&Pe(s)?xe(t,s):{timestamp:t,type:"tool_use",toolName:r,toolInput:s}}return null}var dl,cl,oo=k(()=>{d();Ve();Qt();on();Ct();Ot();Kr();Nt();nn();Ye();ut();dl=new Set(["turn.started","turn.completed","item.updated"]),cl="cli/codex";({command:"codex",meta:{displayName:"Codex",models:ki(),capabilities:{resume:true}},buildArgs(t,e,n){let{model:r,effort:o}=ct(e.model),s=e.effort??o,i=e.resumeSessionId?Ai(e.mode):Ti(e.mode),a=Ii(s),c=r?["-m",r]:[],u=ll(e.additionalArgs??[]),g=u.includes("--json")||u.includes("--experimental-json")?[]:["--json"];return e.resumeSessionId?{args:["exec","resume",...g,...i,...a,...c,...u,e.resumeSessionId,"-"],stdinMessage:t}:{args:["exec",...g,...i,...a,...c,...u],stdinMessage:t}},extractText(t){let e=pl(t);if(e)throw new j(e,cl);let n=Ki(t);if(n)return n;let r=t.trim();return dt(r,"codex")?"":r},extractPartialText(t){return Ki(t)},parseResultMeta(t){let e=rn(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(),o=[],s;try{JSON.parse(t),s=[t];}catch{s=ul(t),s.length>1&&console.warn("[codex] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let[i,a]of s.entries()){let c;try{c=JSON.parse(a);}catch{continue}if(!Je(c))continue;let u=c.type;if(!u)continue;let p=$e(c,r);if(zi(c)){let _=Yi(c);o.push({timestamp:p,type:"error",content:_,errorMessage:_});continue}if(!u.startsWith("item.")&&!u.startsWith("turn.")&&!u.startsWith("thread.")||Wr(c))continue;u==="thread.started"&&n&&n.state.delete("codex.pending");let g=c.item;if(g){if(u==="item.started"){o.push(..._l(p,g,Vi(g,u,n,i)));continue}if(u==="item.completed"){let _=gl(p,g,Vi(g,u,n,i));_&&o.push(_);continue}}}return o},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?dl.has(r):!1}catch{return false}}});});var Xi=k(()=>{d();});var Qi=k(()=>{d();});function ml(t){let e=t.match(/(?:^|[^0-9])([0-9]{1,5})(?![0-9])/);if(!e)return null;let n=Number(e[1]);return Number.isInteger(n)&&n>0&&n<=65535?n:null}function yl(){return new Promise(t=>{let e=false,n,r=o=>{e||(e=true,n&&clearTimeout(n),t(o));};n=setTimeout(()=>r(null),Zi),n.unref();try{child_process.execFile("chcp.com",[],{encoding:"ascii",timeout:Zi,windowsHide:!0},(s,i)=>{if(s){r(null);return}r(ml(String(i)));}).once("error",()=>r(null));}catch{r(null);}})}function kl(){return process.platform!=="win32"?Promise.resolve(null):(Un||(Un=yl(),Un.then(t=>{},()=>{})),Un)}function Sl(){process.platform==="win32"&&kl();}var Zi,Un,ta=k(()=>{d();Zi=1e3;Sl();});var so=k(()=>{d();});var na=k(()=>{d();});var io=k(()=>{d();Ve();so();na();});var ra=k(()=>{d();ao();Qi();ta();so();io();Ye();});var co=k(()=>{d();Ve();Xi();on();Ot();ut();ra();io();});var oa=k(()=>{d();});function Dt(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function Ol(t,e){return t&&sa.has(t)||Dt(e,"--dangerously-skip-permissions")?true:e.some((n,r)=>{let o=n==="--mode"?e[r+1]:n.startsWith("--mode=")?n.slice(7):void 0;return typeof o=="string"&&sa.has(o)})}function vl(t,e){let n=[];for(let r=0;r<t.length;r+=1){let o=t[r],s=[...e].find(i=>o===i||o.startsWith(`${i}=`));s?o===s&&r+1<t.length&&(r+=1):n.push(o);}return n}function Dl(t){let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],o=r.indexOf("="),s=o>0?r.slice(0,o):r;if(!Cl.has(s)){e.push(r);continue}r===s&&n+1<t.length&&!t[n+1].startsWith("-")&&(n+=1);}return e}function me(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Pl(t,e){if(!(t?bl.has(t)||ze(uo).some(s=>s.id===t):false)||!t)return e;let r=tn(uo,t),o=Qr(uo)[t]?.defaultEffort;if(r.length!==0)return e?r.includes(e)?e:o&&r.includes(o)?o:void 0:o}function Ge(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0?t:void 0}function _o(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 go(t){return t.step.step_index}function $(t){if(typeof t!="string")return;let e=t.split(/\r?\n/,1)[0]?.trim();return e&&Dn(e)?.slice(0,500).trim()||void 0}function xl(t,e){let n=(t??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&Nl.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)/,/invalid (?:flag|option)/].some(s=>s.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 Ll(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 da(t){let e=me(t)?t:void 0,n=e&&me(e.error)?e.error:void 0,r=e?$(e.code)??$(e.error_code)??$(n?.code)??$(n?.error_code):void 0,o=typeof t=="string"?$(t):e?$(e.message)??$(e.error)??$(e.reason)??$(n?.message)??$(n?.error)??$(n?.reason):void 0,s=xl(r,o),i=e?Ge(e.retry_after_ms)??Ge(e.retryAfterMs)??Ge(n?.retry_after_ms)??Ge(n?.retryAfterMs):void 0;return {code:s,kind:Ll(s),message:o??"Antigravity reported a terminal error.",...i===void 0?{}:{retryAfterMs:i}}}function Bn(t){let e=da(t);return new j(e.message,"cli/antigravity",{code:e.code,kind:e.kind,...e.retryAfterMs===void 0?{}:{retryAfterMs:e.retryAfterMs}})}function fo(t){return new j(t,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function Ml(t){let e=new TextEncoder().encode(t).byteLength;if(!(e<=po))throw new j(`Input is too large: final provider initial input is ${e} UTF-8 bytes; budget is ${po} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function lo(){return new j("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 Hn(t){if(t.kind==="result"||t.kind==="legacy_result")return t.result}function $n(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 Fl(t){let e=$n(t);if(!e||e.event.kind==="agy_error"||e.index!==t.length-1||Hn(e.event)?.status!=="SUCCESS"||qn(t))return false;let r=new Map;for(let o of t){if(o.kind!=="step_update"||o.step.step_type!=="agent_response")continue;let s=_o(o),i=go(o);!s||!Number.isSafeInteger(i)||r.set(JSON.stringify([s,i]),o.step);}if(r.size===0)return false;for(let o of r.values())if(o.state!=="DONE"||!me(o.usage)||Ge(o.usage.input_tokens)===void 0||Ge(o.usage.output_tokens)===void 0)return false;return true}function Ul(t,e){for(let n=e-1;n>=0;n-=1){let r=t[n];if(r?.kind==="agy_error")return r.error}}function ql(t,e){return me(t)&&me(e)?{...e,...t}:me(t)&&typeof e=="string"?{...t,message:e}:typeof t=="string"&&me(e)?{...e,message:t}:t??e}function Bl(t){let e=Array.isArray(t.denied_actions)?t.denied_actions:[],n=[];for(let i of e){let a=me(i)?i:void 0,c=typeof i=="string"?$(i):$(a?.display_name)??$(a?.action);c&&!n.includes(c)&&n.length<5&&n.push(c.slice(0,80));}let r=Math.max(0,e.length-n.length),o=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"",s=`Permission denied: Antigravity blocked ${e.length} requested action${e.length===1?"":"s"}${o}.`;return new j("\uAD8C\uD55C \uB54C\uBB38\uC5D0 \uC2E4\uD589\uD558\uC9C0 \uBABB\uD588\uC5B4\uC694","cli/antigravity",{code:"UNKNOWN",kind:"permanent",providerReason:s})}function qn(t){let e=$n(t);if(!e)return;if(e.event.kind==="agy_error")return Bn(e.event.error);let n=Hn(e.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return Bl(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return fo("Antigravity returned a result with an unsupported status.");let r=n.error,o=ql(r==null||r===""?n:r,Ul(t,e.index));return Bn(o)}function ca(t){if(typeof t=="string")return t;if(t!=null)try{return JSON.stringify(t)}catch{return}}function Hl(t){return `agy:${String(t.conversation_id)}:${String(t.step_index)}`}function $l(t,e){let n=typeof e?.name=="string"?e.name:t.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function ua(t){let e=ca(t);if(e)return e.length<=2e3?e:`${e.slice(0,1999)}\u2026`}function Gl(t){let e=me(t)?t:void 0,n=e&&me(e.error)?e.error:void 0,r=typeof t=="string"?t.trim().match(/^([A-Z][A-Z0-9_]*)(?:[:\s]|$)/)?.[1]:void 0,o=($(e?.type)??$(e?.code)??$(e?.error_type)??$(n?.type)??$(n?.code)??$(n?.error_type)??$(r)??"TOOL_ERROR").slice(0,60),s=da(t).message.slice(0,250);return ua({type:o,message:s})??"Antigravity reported a tool error."}function ia(t,e){return t?t.state.has(e)?true:(t.state.set(e,true),false):false}function aa(t,e){return {timestamp:t,type:"error",content:e.message,errorMessage:e.message,isError:true}}var uo,bl,Cl,sa,po,Nl,ho=k(()=>{d();Ve();oa();Gr();Zt();Ye();nn();xn();eo();uo="antigravity",bl=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),Cl=new Set(["--conversation","--resume","--continue"]),sa=new Set(["bypassPermissions","agent-full-access","yolo"]),po=18e4,Nl=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"]);({command:"agy",maxInitialInputBytes:po,meta:{displayName:"Antigravity",models:wi(),defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(t){let e=Xt(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){Ml(t);let{model:r,effort:o}=ct(e.model),s=Jr(r),i=s.model,a=e.effort??o??s.effort,c=Pl(i,a),u=e.additionalArgs??[],p=Dl(vl(u,new Set(["--input-format","--output-format"]))),g=i&&!Dt(u,"--model")?["--model",i]:[],_=Dt(u,"--effort")?[]:Oi(c),S=Dt(u,"--mode")||Dt(u,"--dangerously-skip-permissions")?[]:Ni(e.mode),w=Ol(e.mode,u)||Dt(u,"--settings")?[]:["--settings",JSON.stringify({permissions:{allow:Mi(e.builtinAllow)}})],E=typeof e.resumeSessionId=="string"&&e.resumeSessionId.trim().length>0?["--conversation",e.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...g,..._,...S,...E,...w,...p],stdinMessage:`${JSON.stringify({event:"user",message:{content:t}})}
65
+ `),a=typeof e.error=="string"?e.error:Je(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 o=String(e.name||e.tool_name||""),s=e.input,i=Me(s);return o==="Bash"&&Pe(i)?xe(t,i):{timestamp:t,type:"tool_use",toolName:o,toolInput:i}}if(r==="tool_result"){let o=!!e.is_error,s=String(e.output||e.content||"");return {timestamp:t,type:"tool_result",...Le(s,o)}}if(r==="web_search"){let o=e.action,s;if(o?.type==="search"){let i=o.queries;s=String(o.query||"")||(i?.length?i.join(", "):"")||String(e.query||"");}else s=e.query?"open: "+String(e.query):"";return !s&&!(Je(o)&&o.type==="other"&&e.query==="")?null:{timestamp:t,type:"tool_use",toolName:"WebSearch",toolInput:s}}if(r==="file_change"){let o=e.changes;if(!Array.isArray(o)||o.length===0)return null;let s=o.map(a=>String(a.path||"")).filter(Boolean);if(s.length===0)return null;let i=s.length===1?s[0]:`${s.slice(0,2).join(", ")}${s.length>2?` (+${s.length-2})`:""}`;return {timestamp:t,type:"tool_use",toolName:"Edit",toolInput:i}}return null}function fl(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||""),o=e.input,s=Me(o);return r==="Bash"&&Pe(s)?xe(t,s):{timestamp:t,type:"tool_use",toolName:r,toolInput:s}}return null}var dl,cl,oo=k(()=>{d();Ve();Qt();on();Ct();Ot();Kr();Nt();nn();Ye();ut();dl=new Set(["turn.started","turn.completed","item.updated"]),cl="cli/codex";({command:"codex",meta:{displayName:"Codex",models:ki(),capabilities:{resume:true}},buildArgs(t,e,n){let{model:r,effort:o}=ct(e.model),s=e.effort??o,i=e.resumeSessionId?Ai(e.mode):Ti(e.mode),a=Ii(s),c=r?["-m",r]:[],u=ll(e.additionalArgs??[]),g=u.includes("--json")||u.includes("--experimental-json")?[]:["--json"];return e.resumeSessionId?{args:["exec","resume",...g,...i,...a,...c,...u,e.resumeSessionId,"-"],stdinMessage:t}:{args:["exec",...g,...i,...a,...c,...u],stdinMessage:t}},extractText(t){let e=pl(t);if(e)throw new j(e,cl);let n=Ki(t);if(n)return n;let r=t.trim();return dt(r,"codex")?"":r},extractPartialText(t){return Ki(t)},parseResultMeta(t){let e=rn(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(),o=[],s;try{JSON.parse(t),s=[t];}catch{s=ul(t),s.length>1&&console.warn("[codex] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let[i,a]of s.entries()){let c;try{c=JSON.parse(a);}catch{continue}if(!Je(c))continue;let u=c.type;if(!u)continue;let p=$e(c,r);if(zi(c)){let _=Yi(c);o.push({timestamp:p,type:"error",content:_,errorMessage:_});continue}if(!u.startsWith("item.")&&!u.startsWith("turn.")&&!u.startsWith("thread.")||Wr(c))continue;u==="thread.started"&&n&&n.state.delete("codex.pending");let g=c.item;if(g){if(u==="item.started"){o.push(..._l(p,g,Vi(g,u,n,i)));continue}if(u==="item.completed"){let _=gl(p,g,Vi(g,u,n,i));_&&o.push(_);continue}}}return o},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?dl.has(r):!1}catch{return false}}});});var Xi=k(()=>{d();});var Qi=k(()=>{d();});function ml(t){let e=t.match(/(?:^|[^0-9])([0-9]{1,5})(?![0-9])/);if(!e)return null;let n=Number(e[1]);return Number.isInteger(n)&&n>0&&n<=65535?n:null}function yl(){return new Promise(t=>{let e=false,n,r=o=>{e||(e=true,n&&clearTimeout(n),t(o));};n=setTimeout(()=>r(null),Zi),n.unref();try{child_process.execFile("chcp.com",[],{encoding:"ascii",timeout:Zi,windowsHide:!0},(s,i)=>{if(s){r(null);return}r(ml(String(i)));}).once("error",()=>r(null));}catch{r(null);}})}function kl(){return process.platform!=="win32"?Promise.resolve(null):(Un||(Un=yl(),Un.then(t=>{},()=>{})),Un)}function Sl(){process.platform==="win32"&&kl();}var Zi,Un,ta=k(()=>{d();Zi=1e3;Sl();});var so=k(()=>{d();});var na=k(()=>{d();});var io=k(()=>{d();Ve();so();na();});var ra=k(()=>{d();ao();Qi();ta();so();io();Ye();});var co=k(()=>{d();Ve();Xi();on();Ot();ut();ra();io();});var oa=k(()=>{d();});function Dt(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function Ol(t,e){return t&&sa.has(t)||Dt(e,"--dangerously-skip-permissions")?true:e.some((n,r)=>{let o=n==="--mode"?e[r+1]:n.startsWith("--mode=")?n.slice(7):void 0;return typeof o=="string"&&sa.has(o)})}function vl(t,e){let n=[];for(let r=0;r<t.length;r+=1){let o=t[r],s=[...e].find(i=>o===i||o.startsWith(`${i}=`));s?o===s&&r+1<t.length&&(r+=1):n.push(o);}return n}function Dl(t){let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],o=r.indexOf("="),s=o>0?r.slice(0,o):r;if(!Cl.has(s)){e.push(r);continue}r===s&&n+1<t.length&&!t[n+1].startsWith("-")&&(n+=1);}return e}function me(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Pl(t,e){if(!(t?bl.has(t)||ze(uo).some(s=>s.id===t):false)||!t)return e;let r=tn(uo,t),o=Qr(uo)[t]?.defaultEffort;if(r.length!==0)return e?r.includes(e)?e:o&&r.includes(o)?o:void 0:o}function Ge(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0?t:void 0}function _o(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 go(t){return t.step.step_index}function $(t){if(typeof t!="string")return;let e=t.split(/\r?\n/,1)[0]?.trim();return e&&Dn(e)?.slice(0,500).trim()||void 0}function xl(t,e){let n=(t??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&Nl.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)/,/invalid (?:flag|option)/].some(s=>s.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 Ll(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 da(t){let e=me(t)?t:void 0,n=e&&me(e.error)?e.error:void 0,r=e?$(e.code)??$(e.error_code)??$(n?.code)??$(n?.error_code):void 0,o=typeof t=="string"?$(t):e?$(e.message)??$(e.error)??$(e.reason)??$(n?.message)??$(n?.error)??$(n?.reason):void 0,s=xl(r,o),i=e?Ge(e.retry_after_ms)??Ge(e.retryAfterMs)??Ge(n?.retry_after_ms)??Ge(n?.retryAfterMs):void 0;return {code:s,kind:Ll(s),message:o??"Antigravity reported a terminal error.",...i===void 0?{}:{retryAfterMs:i}}}function Bn(t){let e=da(t);return new j(e.message,"cli/antigravity",{code:e.code,kind:e.kind,...e.retryAfterMs===void 0?{}:{retryAfterMs:e.retryAfterMs}})}function fo(t){return new j(t,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function Ml(t){let e=new TextEncoder().encode(t).byteLength;if(!(e<=po))throw new j(`Input is too large: final provider initial input is ${e} UTF-8 bytes; budget is ${po} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function lo(){return new j("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 Hn(t){if(t.kind==="result"||t.kind==="legacy_result")return t.result}function $n(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 Fl(t){let e=$n(t);if(!e||e.event.kind==="agy_error"||e.index!==t.length-1||Hn(e.event)?.status!=="SUCCESS"||qn(t))return false;let r=new Map;for(let o of t){if(o.kind!=="step_update"||o.step.step_type!=="agent_response")continue;let s=_o(o),i=go(o);!s||!Number.isSafeInteger(i)||r.set(JSON.stringify([s,i]),o.step);}if(r.size===0)return false;for(let o of r.values())if(o.state!=="DONE"||!me(o.usage)||Ge(o.usage.input_tokens)===void 0||Ge(o.usage.output_tokens)===void 0)return false;return true}function Ul(t,e){for(let n=e-1;n>=0;n-=1){let r=t[n];if(r?.kind==="agy_error")return r.error}}function ql(t,e){return me(t)&&me(e)?{...e,...t}:me(t)&&typeof e=="string"?{...t,message:e}:typeof t=="string"&&me(e)?{...e,message:t}:t??e}function Bl(t){let e=Array.isArray(t.denied_actions)?t.denied_actions:[],n=[];for(let i of e){let a=me(i)?i:void 0,c=typeof i=="string"?$(i):$(a?.display_name)??$(a?.action);c&&!n.includes(c)&&n.length<5&&n.push(c.slice(0,80));}let r=Math.max(0,e.length-n.length),o=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"",s=`Permission denied: Antigravity blocked ${e.length} requested action${e.length===1?"":"s"}${o}.`;return new j("Could not run because of permissions.","cli/antigravity",{code:"UNKNOWN",kind:"permanent",providerReason:s})}function qn(t){let e=$n(t);if(!e)return;if(e.event.kind==="agy_error")return Bn(e.event.error);let n=Hn(e.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return Bl(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return fo("Antigravity returned a result with an unsupported status.");let r=n.error,o=ql(r==null||r===""?n:r,Ul(t,e.index));return Bn(o)}function ca(t){if(typeof t=="string")return t;if(t!=null)try{return JSON.stringify(t)}catch{return}}function Hl(t){return `agy:${String(t.conversation_id)}:${String(t.step_index)}`}function $l(t,e){let n=typeof e?.name=="string"?e.name:t.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function ua(t){let e=ca(t);if(e)return e.length<=2e3?e:`${e.slice(0,1999)}\u2026`}function Gl(t){let e=me(t)?t:void 0,n=e&&me(e.error)?e.error:void 0,r=typeof t=="string"?t.trim().match(/^([A-Z][A-Z0-9_]*)(?:[:\s]|$)/)?.[1]:void 0,o=($(e?.type)??$(e?.code)??$(e?.error_type)??$(n?.type)??$(n?.code)??$(n?.error_type)??$(r)??"TOOL_ERROR").slice(0,60),s=da(t).message.slice(0,250);return ua({type:o,message:s})??"Antigravity reported a tool error."}function ia(t,e){return t?t.state.has(e)?true:(t.state.set(e,true),false):false}function aa(t,e){return {timestamp:t,type:"error",content:e.message,errorMessage:e.message,isError:true}}var uo,bl,Cl,sa,po,Nl,ho=k(()=>{d();Ve();oa();Gr();Zt();Ye();nn();xn();eo();uo="antigravity",bl=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),Cl=new Set(["--conversation","--resume","--continue"]),sa=new Set(["bypassPermissions","agent-full-access","yolo"]),po=18e4,Nl=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"]);({command:"agy",maxInitialInputBytes:po,meta:{displayName:"Antigravity",models:wi(),defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(t){let e=Xt(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){Ml(t);let{model:r,effort:o}=ct(e.model),s=Jr(r),i=s.model,a=e.effort??o??s.effort,c=Pl(i,a),u=e.additionalArgs??[],p=Dl(vl(u,new Set(["--input-format","--output-format"]))),g=i&&!Dt(u,"--model")?["--model",i]:[],_=Dt(u,"--effort")?[]:Oi(c),S=Dt(u,"--mode")||Dt(u,"--dangerously-skip-permissions")?[]:Ni(e.mode),w=Ol(e.mode,u)||Dt(u,"--settings")?[]:["--settings",JSON.stringify({permissions:{allow:Mi(e.builtinAllow)}})],E=typeof e.resumeSessionId=="string"&&e.resumeSessionId.trim().length>0?["--conversation",e.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...g,..._,...S,...E,...w,...p],stdinMessage:`${JSON.stringify({event:"user",message:{content:t}})}
66
66
  `,env:{AGY_CLI_DISABLE_AUTO_UPDATE:"true"}}},extractText(t){let e=bt(t),n=$n(e)?.event,r=qn(e);if(r)throw r;let o=n?Hn(n):void 0;if(o){if(o.status!=="SUCCESS")throw fo("Antigravity returned a result with an unsupported status.");if(typeof o.response!="string")throw fo("Antigravity returned a successful result without a response string.");if(!o.response.trim())throw lo();return o.response}if(e.length>0)throw lo();let s=t.trim();if(!s)throw lo();return s},extractPartialText(t){let e=bt(t),n=$n(e)?.event;if(!n||n.kind==="agy_error")return;let r=Hn(n);return r&&typeof r.response=="string"&&r.response.trim()?r.response:void 0},interpretExit(t,e,n){let r=bt(n??""),o=qn(r);return o||(t!==0&&e.trim()?Bn(e):null)},parseResultMeta(t){let e=bt(t),n=0,r=0,o=0,s=0,i=new Set;for(let c of e){if(c.kind!=="step_update"||c.step.state!=="DONE"||!me(c.step.usage))continue;let u=_o(c),p=go(c);if(!u||!Number.isSafeInteger(p))continue;let g=JSON.stringify([u,p]);if(i.has(g))continue;let _=c.step.usage,S=Ge(_.input_tokens),w=Ge(_.output_tokens);if(S===void 0||w===void 0)continue;i.add(g);let E=Ge(_.cache_read_tokens)??0;n+=S+E,r+=w,o+=E,s+=1;}return {usage:s===0?null:{inputTokens:n,outputTokens:r,cachedInputTokens:o,costUsd:0,complete:Fl(e)},model:null}},parseEvent(t,e,n){let r=Xt(t);if(!r)return [];let o=e??new Date().toISOString();if(r.kind==="agy_error")return [aa(o,Bn(r.error))];if(r.kind==="legacy_result"||r.kind==="result"){let S=qn([r]);return S?[aa(o,S)]:[]}if(r.kind!=="step_update")return [];let{step:s}=r,i=_o(r)??"unknown",a=go(r),c=`${i}:${a}`;if((s.state==="DONE"||s.state==="ERROR")&&ia(n,`antigravity:terminal:${c}`))return [];if(s.step_type==="agent_response")return typeof s.text_delta=="string"&&s.text_delta.length>0?[{timestamp:o,type:"text",content:s.text_delta}]:[];if(s.step_type!=="tool")return [];let u=me(s.tool_info)?s.tool_info:void 0,p=$l(s,u);if(!p)return [];let g=Hl(s);if(s.state==="ACTIVE"){if(ia(n,`antigravity:active:${c}`))return [];let S=ca(u?.parameters);return [{timestamp:o,type:"tool_use",toolName:p,toolUseId:g,...S===void 0?{}:{toolInput:S}}]}let _=s.state==="ERROR"?Gl(u?.error):ua(u?.output);return [{timestamp:o,type:"tool_result",toolName:p,toolUseId:g,..._===void 0?{}:{resultPreview:_},...s.state==="ERROR"?{isError:true}:{}}]}});});var pa=k(()=>{d();Ct();Ot();Nt();ut();});var mo=k(()=>{d();Ve();$r();Ye();Nt();nn();ut();});var ao=k(()=>{d();no();ro();oo();co();ho();pa();mo();no();ro();oo();co();ho();mo();Ct();});var _a=k(()=>{d();ai();ao();});var yo=k(()=>{d();_a();On();});var sn,lt=k(()=>{d();sn=["success","completed","done","failed","error","stopped","runner_lost"];});var an=k(()=>{d();});var So=k(()=>{d();Hr();an();});var op,Pt=k(()=>{d();P();M();q();L();F();Tt();On();Br();Hr();vn();Fr();yo();lt();an();So();an();Tt();op="0.8.9-rc.13",parseInt(op.split("rc.")[1]),new Set(sn);});d();d();d();var T="workout-log",Xe="workout-log.records.v1",pt=500,Kn=100,Vn=4096,Lt=6e4,zn=200,Mt=20,dn=6e4;d();var Ft=class{epoch=0;activeSession=null;grantControllers=new Map;get activeAccountKey(){return this.activeSession?.accountKey??null}get activeSessionEpoch(){let e=this.activeSession;return e&&!e.controller.signal.aborted?e.epoch:null}currentToken(e){let n=this.activeSession;return !n||n.accountKey!==e||n.controller.signal.aborted?null:this.toSessionToken(n)}activate(e){if(!/^[0-9a-f]{64}$/.test(e))throw new Error("INVALID_ACCOUNT_KEY");if(this.activeSession?.accountKey===e&&!this.activeSession.controller.signal.aborted)return this.toSessionToken(this.activeSession);this.abortActiveSession();let n={accountKey:e,epoch:++this.epoch,controller:new AbortController};return this.activeSession=n,this.toSessionToken(n)}captureGrant(e,n,r){if(!this.isCurrent(e))throw new Error("APP_SYNC_SESSION_STALE");if(!n||!Number.isSafeInteger(r)||r<1)throw new Error("INVALID_GRANT_FENCE");let o=new AbortController,s=this.grantKey(e.accountKey,n,r),i=()=>o.abort(e.signal.reason);e.signal.aborted?i():e.signal.addEventListener("abort",i,{once:true});let a=this.grantControllers.get(s)??new Set;return a.add({controller:o,sessionSignal:e.signal,onSessionAbort:i}),this.grantControllers.set(s,a),{accountKey:e.accountKey,epoch:e.epoch,grantId:n,generation:r,signal:o.signal}}isCurrent(e){let n=this.activeSession;return n!==null&&n.accountKey===e.accountKey&&n.epoch===e.epoch&&!n.controller.signal.aborted&&!e.signal.aborted}release(e){let n=this.grantKey(e.accountKey,e.grantId,e.generation),r=this.grantControllers.get(n);if(r){for(let o of r)o.controller.signal===e.signal&&(o.sessionSignal.removeEventListener("abort",o.onSessionAbort),r.delete(o));r.size===0&&this.grantControllers.delete(n);}}cancelGrant(e,n,r){let o=this.grantKey(e,n,r),s=this.grantControllers.get(o);if(s){for(let i of s)i.sessionSignal.removeEventListener("abort",i.onSessionAbort),i.controller.abort("grant_invalidated");this.grantControllers.delete(o);}}suspend(e){this.activeSession&&(e===void 0||this.activeSession.accountKey===e)&&(this.abortActiveSession(),this.epoch+=1);}toSessionToken(e){return {accountKey:e.accountKey,epoch:e.epoch,signal:e.controller.signal}}abortActiveSession(){let e=this.activeSession;if(e){e.controller.abort("session_suspended");for(let[n,r]of this.grantControllers)if(n.startsWith(`${e.accountKey}:${e.epoch}:`)){for(let o of r)o.sessionSignal.removeEventListener("abort",o.onSessionAbort),o.controller.abort("session_suspended");this.grantControllers.delete(n);}this.activeSession=null;}}grantKey(e,n,r){return `${e}:${this.activeSession?.epoch??this.epoch}:${n}:${r}`}};d();var Da=Xe,_e=Object.freeze({root:"docs/apps/workout-log",include:Object.freeze(["exercises.md","routines/<id>.md","workouts/<YYYY-MM-DD>-<id>.md"]),idPattern:"^[A-Za-z0-9_-]{1,40}$",exclude:Object.freeze(["migration/**","*.json","app-state/**",".*","*~","*.tmp","*.swp","*.part",".env*","auth.json","*.key","*.pem"])}),Yn=Object.freeze({exactFiles:Object.freeze(["exercises.md"]),directFolders:Object.freeze(["routines","workouts"]),suffix:".md",maxDepth:1}),Pa=/^[A-Za-z0-9_-]{1,40}$/,No=["root","include","idPattern","exclude"];function Oo(t,e){return Array.isArray(t)&&t.length===e.length&&t.every((n,r)=>n===e[r])}function xa(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function La(t){if(t==="exercises.md")return "exercises";if(/^routines\/[A-Za-z0-9_-]{1,40}\.md$/.test(t))return "routine";let e=/^workouts\/(\d{4})-(\d{2})-(\d{2})-([A-Za-z0-9_-]{1,40})\.md$/.exec(t);if(!e||!Pa.test(e[4]))return null;let[,n,r,o]=e,s=Number(n),i=Number(r),a=Number(o);if(s<1||i<1||i>12||a<1||a>31)return null;let c=new Date(0);return c.setUTCHours(0,0,0,0),c.setUTCFullYear(s,i-1,a),c.getUTCFullYear()!==s||c.getUTCMonth()!==i-1||c.getUTCDate()!==a?null:"workout"}function Ma(t){let n=t.trim().replace(/[ \t]+#.*$/,"").trim();return /^[A-Za-z0-9_-]+$/.test(n)?n:/^"[A-Za-z0-9_-]+"$/.test(n)||/^'[A-Za-z0-9_-]+'$/.test(n)?n.slice(1,-1):null}function Fa(t){if(typeof t!="string")return null;let e=t.indexOf(`
67
67
  `);if((e<0?t:t.slice(0,e)).replace(/\r$/,"")!=="---")return null;let r=new Map,o=e<0?t.length:e+1;for(;o<=t.length;){let s=t.indexOf(`
68
68
  `,o),i=s<0?t.length:s,a=t.slice(o,i);a.endsWith("\r")&&(a=a.slice(0,-1));let c=s<0?i:s+1;if(Buffer.byteLength(t.slice(0,c),"utf8")>4096)return null;if(a==="---")return r.has("crewx_app")&&r.has("kind")?r:null;let u=/^(crewx_app|kind):[ \t]*(.*)$/.exec(a);if(u){let p=u[1];if(r.has(p))return null;let g=Ma(u[2]);if(g===null)return null;r.set(p,g);}if(s<0)break;o=s+1;}return null}var Ut=class{scopeVersion=Xe;definition=_e;matchesDefinition(e,n){return e!==Da||!xa(n)||Object.keys(n).length!==No.length||!No.every(r=>Object.hasOwn(n,r))?false:n.root===_e.root&&n.idPattern===_e.idPattern&&Oo(n.include,_e.include)&&Oo(n.exclude,_e.exclude)}validateRef(e){if(typeof e!="string"||e.length===0||e.length>256)return {valid:false,reason:"out_of_scope"};if(e.includes("\0")||e.includes("\\")||e.startsWith("/")||e.startsWith("~"))return {valid:false,reason:"out_of_scope"};if(e.split("/").some(o=>o===""||o==="."||o===".."))return {valid:false,reason:"out_of_scope"};if(e.startsWith(".")||/(?:^|\/)\./.test(e)||/(?:^|\/)[^/]*(?:~|\.tmp|\.swp|\.part)$/.test(e))return {valid:false,reason:"out_of_scope"};if(/(?:^|\/)(?:auth\.json|[^/]*\.key|[^/]*\.pem)$/.test(e)||/\.env[^/]*$/.test(e))return {valid:false,reason:"out_of_scope"};let r=La(e);return r===null?{valid:false,reason:"out_of_scope"}:{valid:true,kind:r}}validateFrontMatter(e,n){let r=this.validateRef(e);if(!r.valid)return {valid:false,reason:"invalid_front_matter"};let o=Fa(n);return o?o.get("crewx_app")!==T?{valid:false,reason:"app_mismatch"}:o.get("kind")!==r.kind?{valid:false,reason:"kind_mismatch"}:{valid:true,kind:r.kind}:{valid:false,reason:"invalid_front_matter"}}};function U(t){return `sha256:${crypto.createHash("sha256").update(t,"utf8").digest("hex")}`}function _t(t){if(!Array.isArray(t)||t.length===0||t.length>64)return null;let e=[];for(let n of t){if(typeof n!="string"||n.length===0)return null;let r=n.normalize("NFC");if(r==="."||r===".."||r.includes("/")||r.includes("\\")||r.includes("\0")||/^[A-Za-z]:$/.test(r)||r.startsWith("~"))return null;e.push(r);}return e}d();d();var qa=10*6e4,Ba=5e3,je=class extends Error{constructor(n){if(!Number.isSafeInteger(n)||n<0)throw new Error("INVALID_APP_SYNC_BUDGET_RETRY_AT");super("APP_SYNC_BUDGET_DEFERRED");this.retryAt=n;this.name="AppSyncBudgetDeferredError";}retryAt;code="APP_SYNC_BUDGET_DEFERRED"},Jn=class{constructor(e){this.sqlite=e;if(!e||typeof e.prepare!="function"||typeof e.transaction!="function")throw new Error("INVALID_DOC_CREATE_LEDGER_DATABASE")}sqlite;peek(e,n){Xn(e),cn(n),this.deleteExpired(n);let r=this.readWindow(e,n);return r.count<20?{available:true,remaining:20-r.count}:{available:false,retryAt:vo(r,n)}}reserve(e){return Do(e),this.sqlite.transaction(r=>{this.deleteExpired(r.now);let o=this.readWindow(r.accountKey,r.now);return o.count>=20?{ok:false,retryAt:vo(o,r.now)}:(this.insert(r),{ok:true})}).immediate(e)}reserveForced(e){Do(e),this.deleteExpired(e.now),this.insert(e);}prune(e){return cn(e),this.deleteExpired(e)}readWindow(e,n){let r=this.sqlite.prepare(`
@@ -62,7 +62,7 @@ ${r.join(`
62
62
  `);for(let r of e)if(r.trim())try{let o=JSON.parse(r);if(o.type==="result"){let s=o.usage,i=s?{inputTokens:Number(s.input_tokens??0)+Number(s.cache_read_input_tokens??0),outputTokens:Number(s.output_tokens??0),cachedInputTokens:Number(s.cache_read_input_tokens??0),costUsd:Number(o.total_cost_usd??0)}:null,a=o.modelUsage,c=a?Object.keys(a)[0]??null:null;return {usage:i,model:c}}}catch{}let n=Di(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 o=Ge(n,e??new Date().toISOString()),s=al(n);if(s)return [{timestamp:o,type:"error",content:s,errorMessage:s}];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:o,type:"text",content:a}];if(r!=="assistant"&&r!=="user")return [];let u=n.message?.content;if(!Array.isArray(u))return [];let _=[];for(let f of u){let g=ll(o,f);g&&_.push(g);}return _},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?rl.has(r):!1}catch{return false}}};$i=200;});function Wi(t){let e=t.split(`
63
63
  `).filter(o=>o.trim()),n=[],r=null;for(let o of e)try{let s=JSON.parse(o);if(s.type==="assistant.message"&&typeof s.data?.content=="string"){let i=s.data.content;i.trim()&&n.push(i.trim());}s.type==="result"&&typeof s.result=="string"&&(r=s.result);}catch{}if(n.length>0)return n[n.length-1];if(r)return r}var pl,oo=S(()=>{d();Zt();sn();Nt();vt();Ot();Je();Fn();lt();pl=new Set(["interactive","plan","autopilot"]);({command:"copilot",meta:{displayName:"Copilot",models:wi()},buildArgs(t,e,n){let r=e.additionalArgs?[...e.additionalArgs]:[];return e.model&&r.push("--model",e.model),e.mode&&pl.has(e.mode)&&r.push("--mode",e.mode),e.effort&&(Mn.copilot??[]).includes(e.effort)&&r.push("--effort",e.effort),{args:r,stdinMessage:t}},extractText(t){let e=Wi(t);if(e)return e;let n=t.trim();return ct(n,"copilot")?"":n},extractPartialText(t){return Wi(t)},parseResultMeta(t){let e=on(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 o=n.data;if(!o)return [];let s=Ge(n,e??new Date().toISOString()),i=o.toolCallId;if(r==="tool.execution_start"){let a=String(o.toolName||""),c=o.arguments,u=Fe(c);return (a==="bash"||a==="Bash")&&xe(u)?[Le(s,u,i)]:[{timestamp:s,type:"tool_use",toolName:a,toolInput:u,...i&&{toolUseId:i}}]}if(r==="tool.execution_complete"){let a=o.error;if(a)return [{timestamp:s,type:"tool_result",...i&&{toolUseId:i},...Me(String(a.message||""),true)}];let c=o.result,u=String(c?.content||"");return [{timestamp:s,type:"tool_result",...i&&{toolUseId:i},...Me(u,false)}]}if(r==="assistant.message"){let a=String(o.content||"");return a?[{timestamp:s,type:"text",content:a}]:[]}return []}});});function fl(t){let e=[],n=0,r=false,o=false,s=0;for(let a=0;a<t.length;a++){let c=t[a];if(o){o=false;continue}if(c==="\\"&&r){o=true;continue}if(c==='"'){r=!r;continue}if(!r){if(c==="{")n++;else if(c==="}"&&(n--,n===0)){let u=t.slice(s,a+1).trim();u&&e.push(u),s=a+1;}}}let i=t.slice(s).trim();return i&&e.push(i),e}function hl(t){return t[0]==="exec"?t.slice(1):t}function Vi(t){let e=t.split(`
64
64
  `).map(o=>o.trim()).filter(Boolean),n=[],r=null;for(let o of e)try{let s=JSON.parse(o);if(s.type==="item.completed"&&(s.item?.type==="message"||s.item?.type==="agent_message")&&typeof s.item?.text=="string"){let i=s.item.text;i.trim()&&n.push(i.trim());}s.type==="result"&&typeof s.result=="string"&&(r=s.result);}catch{}if(n.length>0)return n[n.length-1];if(r)return r}function Xe(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Yi(t){return t.type==="turn.failed"?true:t.type!=="error"?false:typeof t.message=="string"||typeof t.errorMessage=="string"||typeof t.error=="string"||Xe(t.error)}function Ji(t){let e=Xe(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 ml(t){for(let e of t.split(/\r?\n/)){if(!e.trim())continue;let n;try{n=JSON.parse(e);}catch{continue}if(Xe(n)&&Yi(n))return Ji(n)}}function zi(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 o=n.state.get("codex.pending");o||(o=new Map,n.state.set("codex.pending",o));let s=JSON.stringify([t.type,t.id]);if(e==="item.started"){let c=`codex:${JSON.stringify(t.id)}#${n.rowIndex}:${r}`,u=o.get(s)??[];return u.push(c),o.set(s,u),c}let i=o.get(s),a=i?.pop();return i?.length||o.delete(s),a}function yl(t,e,n){let r=e.type;if(r==="command_execution"){let o=String(e.command||"");return xe(o)?[Le(t,o,n)]:[{timestamp:t,type:"tool_use",toolName:"Bash",toolInput:o,...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:Fe(e.arguments),...n?{toolUseId:n}:{}}]:[]}function kl(t,e,n){let r=e.type;if(r==="message"||r==="text"){let o=e.content;if(Array.isArray(o))for(let s of o){let i=Sl(t,s);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 o=typeof e.text=="string"?e.text.trim():"";return o?{timestamp:t,type:"thinking",content:o}:null}if(r==="command_execution"){let o=String(e.aggregated_output||e.output||""),s=!!e.is_error;return {timestamp:t,type:"tool_result",...Me(o,s),...n?{toolUseId:n}:{}}}if(r==="mcp_tool_call"){let o=Xe(e.result)?e.result:void 0,i=(Array.isArray(o?.content)?o.content:[]).filter(c=>Xe(c)&&c.type==="text"&&typeof c.text=="string").map(c=>c.text).join(`
65
- `),a=typeof e.error=="string"?e.error:Xe(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 o=String(e.name||e.tool_name||""),s=e.input,i=Fe(s);return o==="Bash"&&xe(i)?Le(t,i):{timestamp:t,type:"tool_use",toolName:o,toolInput:i}}if(r==="tool_result"){let o=!!e.is_error,s=String(e.output||e.content||"");return {timestamp:t,type:"tool_result",...Me(s,o)}}if(r==="web_search"){let o=e.action,s;if(o?.type==="search"){let i=o.queries;s=String(o.query||"")||(i?.length?i.join(", "):"")||String(e.query||"");}else s=e.query?"open: "+String(e.query):"";return !s&&!(Xe(o)&&o.type==="other"&&e.query==="")?null:{timestamp:t,type:"tool_use",toolName:"WebSearch",toolInput:s}}if(r==="file_change"){let o=e.changes;if(!Array.isArray(o)||o.length===0)return null;let s=o.map(a=>String(a.path||"")).filter(Boolean);if(s.length===0)return null;let i=s.length===1?s[0]:`${s.slice(0,2).join(", ")}${s.length>2?` (+${s.length-2})`:""}`;return {timestamp:t,type:"tool_use",toolName:"Edit",toolInput:i}}return null}function Sl(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||""),o=e.input,s=Fe(o);return r==="Bash"&&xe(s)?Le(t,s):{timestamp:t,type:"tool_use",toolName:r,toolInput:s}}return null}var _l,gl,so=S(()=>{d();ze();Zt();sn();Nt();vt();Vr();Ot();rn();Je();lt();_l=new Set(["turn.started","turn.completed","item.updated"]),gl="cli/codex";({command:"codex",meta:{displayName:"Codex",models:Si(),capabilities:{resume:true}},buildArgs(t,e,n){let{model:r,effort:o}=ut(e.model),s=e.effort??o,i=e.resumeSessionId?Ii(e.mode):Ai(e.mode),a=bi(s),c=r?["-m",r]:[],u=hl(e.additionalArgs??[]),f=u.includes("--json")||u.includes("--experimental-json")?[]:["--json"];return e.resumeSessionId?{args:["exec","resume",...f,...i,...a,...c,...u,e.resumeSessionId,"-"],stdinMessage:t}:{args:["exec",...f,...i,...a,...c,...u],stdinMessage:t}},extractText(t){let e=ml(t);if(e)throw new W(e,gl);let n=Vi(t);if(n)return n;let r=t.trim();return ct(r,"codex")?"":r},extractPartialText(t){return Vi(t)},parseResultMeta(t){let e=on(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(),o=[],s;try{JSON.parse(t),s=[t];}catch{s=fl(t),s.length>1&&console.warn("[codex] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let[i,a]of s.entries()){let c;try{c=JSON.parse(a);}catch{continue}if(!Xe(c))continue;let u=c.type;if(!u)continue;let _=Ge(c,r);if(Yi(c)){let g=Ji(c);o.push({timestamp:_,type:"error",content:g,errorMessage:g});continue}if(!u.startsWith("item.")&&!u.startsWith("turn.")&&!u.startsWith("thread.")||Kr(c))continue;u==="thread.started"&&n&&n.state.delete("codex.pending");let f=c.item;if(f){if(u==="item.started"){o.push(...yl(_,f,zi(f,u,n,i)));continue}if(u==="item.completed"){let g=kl(_,f,zi(f,u,n,i));g&&o.push(g);continue}}}return o},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?_l.has(r):!1}catch{return false}}});});var Qi=S(()=>{d();});var Zi=S(()=>{d();});function Rl(t){let e=t.match(/(?:^|[^0-9])([0-9]{1,5})(?![0-9])/);if(!e)return null;let n=Number(e[1]);return Number.isInteger(n)&&n>0&&n<=65535?n:null}function El(){return new Promise(t=>{let e=false,n,r=o=>{e||(e=true,n&&clearTimeout(n),t(o));};n=setTimeout(()=>r(null),ea),n.unref();try{execFile("chcp.com",[],{encoding:"ascii",timeout:ea,windowsHide:!0},(s,i)=>{if(s){r(null);return}r(Rl(String(i)));}).once("error",()=>r(null));}catch{r(null);}})}function Tl(){return process.platform!=="win32"?Promise.resolve(null):(qn||(qn=El(),qn.then(t=>{},()=>{})),qn)}function Al(){process.platform==="win32"&&Tl();}var ea,qn,na=S(()=>{d();ea=1e3;Al();});var io=S(()=>{d();});var ra=S(()=>{d();});var ao=S(()=>{d();ze();io();ra();});var oa=S(()=>{d();co();Zi();na();io();ao();Je();});var uo=S(()=>{d();ze();Qi();sn();vt();lt();oa();ao();});var sa=S(()=>{d();});function Pt(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function Ll(t,e){return t&&ia.has(t)||Pt(e,"--dangerously-skip-permissions")?true:e.some((n,r)=>{let o=n==="--mode"?e[r+1]:n.startsWith("--mode=")?n.slice(7):void 0;return typeof o=="string"&&ia.has(o)})}function Ml(t,e){let n=[];for(let r=0;r<t.length;r+=1){let o=t[r],s=[...e].find(i=>o===i||o.startsWith(`${i}=`));s?o===s&&r+1<t.length&&(r+=1):n.push(o);}return n}function Fl(t){let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],o=r.indexOf("="),s=o>0?r.slice(0,o):r;if(!Pl.has(s)){e.push(r);continue}r===s&&n+1<t.length&&!t[n+1].startsWith("-")&&(n+=1);}return e}function ye(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Ul(t,e){if(!(t?Dl.has(t)||Ye(lo).some(s=>s.id===t):false)||!t)return e;let r=nn(lo,t),o=Zr(lo)[t]?.defaultEffort;if(r.length!==0)return e?r.includes(e)?e:o&&r.includes(o)?o:void 0:o}function je(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0?t:void 0}function go(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 fo(t){return t.step.step_index}function G(t){if(typeof t!="string")return;let e=t.split(/\r?\n/,1)[0]?.trim();return e&&Pn(e)?.slice(0,500).trim()||void 0}function ql(t,e){let n=(t??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&xl.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)/,/invalid (?:flag|option)/].some(s=>s.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 Bl(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 ca(t){let e=ye(t)?t:void 0,n=e&&ye(e.error)?e.error:void 0,r=e?G(e.code)??G(e.error_code)??G(n?.code)??G(n?.error_code):void 0,o=typeof t=="string"?G(t):e?G(e.message)??G(e.error)??G(e.reason)??G(n?.message)??G(n?.error)??G(n?.reason):void 0,s=ql(r,o),i=e?je(e.retry_after_ms)??je(e.retryAfterMs)??je(n?.retry_after_ms)??je(n?.retryAfterMs):void 0;return {code:s,kind:Bl(s),message:o??"Antigravity reported a terminal error.",...i===void 0?{}:{retryAfterMs:i}}}function Hn(t){let e=ca(t);return new W(e.message,"cli/antigravity",{code:e.code,kind:e.kind,...e.retryAfterMs===void 0?{}:{retryAfterMs:e.retryAfterMs}})}function ho(t){return new W(t,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function Hl(t){let e=new TextEncoder().encode(t).byteLength;if(!(e<=_o))throw new W(`Input is too large: final provider initial input is ${e} UTF-8 bytes; budget is ${_o} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function po(){return new W("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 $n(t){if(t.kind==="result"||t.kind==="legacy_result")return t.result}function Gn(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 $l(t){let e=Gn(t);if(!e||e.event.kind==="agy_error"||e.index!==t.length-1||$n(e.event)?.status!=="SUCCESS"||Bn(t))return false;let r=new Map;for(let o of t){if(o.kind!=="step_update"||o.step.step_type!=="agent_response")continue;let s=go(o),i=fo(o);!s||!Number.isSafeInteger(i)||r.set(JSON.stringify([s,i]),o.step);}if(r.size===0)return false;for(let o of r.values())if(o.state!=="DONE"||!ye(o.usage)||je(o.usage.input_tokens)===void 0||je(o.usage.output_tokens)===void 0)return false;return true}function Gl(t,e){for(let n=e-1;n>=0;n-=1){let r=t[n];if(r?.kind==="agy_error")return r.error}}function jl(t,e){return ye(t)&&ye(e)?{...e,...t}:ye(t)&&typeof e=="string"?{...t,message:e}:typeof t=="string"&&ye(e)?{...e,message:t}:t??e}function Wl(t){let e=Array.isArray(t.denied_actions)?t.denied_actions:[],n=[];for(let i of e){let a=ye(i)?i:void 0,c=typeof i=="string"?G(i):G(a?.display_name)??G(a?.action);c&&!n.includes(c)&&n.length<5&&n.push(c.slice(0,80));}let r=Math.max(0,e.length-n.length),o=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"",s=`Permission denied: Antigravity blocked ${e.length} requested action${e.length===1?"":"s"}${o}.`;return new W("\uAD8C\uD55C \uB54C\uBB38\uC5D0 \uC2E4\uD589\uD558\uC9C0 \uBABB\uD588\uC5B4\uC694","cli/antigravity",{code:"UNKNOWN",kind:"permanent",providerReason:s})}function Bn(t){let e=Gn(t);if(!e)return;if(e.event.kind==="agy_error")return Hn(e.event.error);let n=$n(e.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return Wl(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return ho("Antigravity returned a result with an unsupported status.");let r=n.error,o=jl(r==null||r===""?n:r,Gl(t,e.index));return Hn(o)}function ua(t){if(typeof t=="string")return t;if(t!=null)try{return JSON.stringify(t)}catch{return}}function Kl(t){return `agy:${String(t.conversation_id)}:${String(t.step_index)}`}function Vl(t,e){let n=typeof e?.name=="string"?e.name:t.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function la(t){let e=ua(t);if(e)return e.length<=2e3?e:`${e.slice(0,1999)}\u2026`}function zl(t){let e=ye(t)?t:void 0,n=e&&ye(e.error)?e.error:void 0,r=typeof t=="string"?t.trim().match(/^([A-Z][A-Z0-9_]*)(?:[:\s]|$)/)?.[1]:void 0,o=(G(e?.type)??G(e?.code)??G(e?.error_type)??G(n?.type)??G(n?.code)??G(n?.error_type)??G(r)??"TOOL_ERROR").slice(0,60),s=ca(t).message.slice(0,250);return la({type:o,message:s})??"Antigravity reported a tool error."}function aa(t,e){return t?t.state.has(e)?true:(t.state.set(e,true),false):false}function da(t,e){return {timestamp:t,type:"error",content:e.message,errorMessage:e.message,isError:true}}var lo,Dl,Pl,ia,_o,xl,mo=S(()=>{d();ze();sa();jr();en();Je();rn();Ln();to();lo="antigravity",Dl=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),Pl=new Set(["--conversation","--resume","--continue"]),ia=new Set(["bypassPermissions","agent-full-access","yolo"]),_o=18e4,xl=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"]);({command:"agy",maxInitialInputBytes:_o,meta:{displayName:"Antigravity",models:Ri(),defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(t){let e=Qt(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){Hl(t);let{model:r,effort:o}=ut(e.model),s=Xr(r),i=s.model,a=e.effort??o??s.effort,c=Ul(i,a),u=e.additionalArgs??[],_=Fl(Ml(u,new Set(["--input-format","--output-format"]))),f=i&&!Pt(u,"--model")?["--model",i]:[],g=Pt(u,"--effort")?[]:vi(c),w=Pt(u,"--mode")||Pt(u,"--dangerously-skip-permissions")?[]:Oi(e.mode),R=Ll(e.mode,u)||Pt(u,"--settings")?[]:["--settings",JSON.stringify({permissions:{allow:Fi(e.builtinAllow)}})],T=typeof e.resumeSessionId=="string"&&e.resumeSessionId.trim().length>0?["--conversation",e.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...f,...g,...w,...T,...R,..._],stdinMessage:`${JSON.stringify({event:"user",message:{content:t}})}
65
+ `),a=typeof e.error=="string"?e.error:Xe(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 o=String(e.name||e.tool_name||""),s=e.input,i=Fe(s);return o==="Bash"&&xe(i)?Le(t,i):{timestamp:t,type:"tool_use",toolName:o,toolInput:i}}if(r==="tool_result"){let o=!!e.is_error,s=String(e.output||e.content||"");return {timestamp:t,type:"tool_result",...Me(s,o)}}if(r==="web_search"){let o=e.action,s;if(o?.type==="search"){let i=o.queries;s=String(o.query||"")||(i?.length?i.join(", "):"")||String(e.query||"");}else s=e.query?"open: "+String(e.query):"";return !s&&!(Xe(o)&&o.type==="other"&&e.query==="")?null:{timestamp:t,type:"tool_use",toolName:"WebSearch",toolInput:s}}if(r==="file_change"){let o=e.changes;if(!Array.isArray(o)||o.length===0)return null;let s=o.map(a=>String(a.path||"")).filter(Boolean);if(s.length===0)return null;let i=s.length===1?s[0]:`${s.slice(0,2).join(", ")}${s.length>2?` (+${s.length-2})`:""}`;return {timestamp:t,type:"tool_use",toolName:"Edit",toolInput:i}}return null}function Sl(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||""),o=e.input,s=Fe(o);return r==="Bash"&&xe(s)?Le(t,s):{timestamp:t,type:"tool_use",toolName:r,toolInput:s}}return null}var _l,gl,so=S(()=>{d();ze();Zt();sn();Nt();vt();Vr();Ot();rn();Je();lt();_l=new Set(["turn.started","turn.completed","item.updated"]),gl="cli/codex";({command:"codex",meta:{displayName:"Codex",models:Si(),capabilities:{resume:true}},buildArgs(t,e,n){let{model:r,effort:o}=ut(e.model),s=e.effort??o,i=e.resumeSessionId?Ii(e.mode):Ai(e.mode),a=bi(s),c=r?["-m",r]:[],u=hl(e.additionalArgs??[]),f=u.includes("--json")||u.includes("--experimental-json")?[]:["--json"];return e.resumeSessionId?{args:["exec","resume",...f,...i,...a,...c,...u,e.resumeSessionId,"-"],stdinMessage:t}:{args:["exec",...f,...i,...a,...c,...u],stdinMessage:t}},extractText(t){let e=ml(t);if(e)throw new W(e,gl);let n=Vi(t);if(n)return n;let r=t.trim();return ct(r,"codex")?"":r},extractPartialText(t){return Vi(t)},parseResultMeta(t){let e=on(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(),o=[],s;try{JSON.parse(t),s=[t];}catch{s=fl(t),s.length>1&&console.warn("[codex] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let[i,a]of s.entries()){let c;try{c=JSON.parse(a);}catch{continue}if(!Xe(c))continue;let u=c.type;if(!u)continue;let _=Ge(c,r);if(Yi(c)){let g=Ji(c);o.push({timestamp:_,type:"error",content:g,errorMessage:g});continue}if(!u.startsWith("item.")&&!u.startsWith("turn.")&&!u.startsWith("thread.")||Kr(c))continue;u==="thread.started"&&n&&n.state.delete("codex.pending");let f=c.item;if(f){if(u==="item.started"){o.push(...yl(_,f,zi(f,u,n,i)));continue}if(u==="item.completed"){let g=kl(_,f,zi(f,u,n,i));g&&o.push(g);continue}}}return o},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?_l.has(r):!1}catch{return false}}});});var Qi=S(()=>{d();});var Zi=S(()=>{d();});function Rl(t){let e=t.match(/(?:^|[^0-9])([0-9]{1,5})(?![0-9])/);if(!e)return null;let n=Number(e[1]);return Number.isInteger(n)&&n>0&&n<=65535?n:null}function El(){return new Promise(t=>{let e=false,n,r=o=>{e||(e=true,n&&clearTimeout(n),t(o));};n=setTimeout(()=>r(null),ea),n.unref();try{execFile("chcp.com",[],{encoding:"ascii",timeout:ea,windowsHide:!0},(s,i)=>{if(s){r(null);return}r(Rl(String(i)));}).once("error",()=>r(null));}catch{r(null);}})}function Tl(){return process.platform!=="win32"?Promise.resolve(null):(qn||(qn=El(),qn.then(t=>{},()=>{})),qn)}function Al(){process.platform==="win32"&&Tl();}var ea,qn,na=S(()=>{d();ea=1e3;Al();});var io=S(()=>{d();});var ra=S(()=>{d();});var ao=S(()=>{d();ze();io();ra();});var oa=S(()=>{d();co();Zi();na();io();ao();Je();});var uo=S(()=>{d();ze();Qi();sn();vt();lt();oa();ao();});var sa=S(()=>{d();});function Pt(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function Ll(t,e){return t&&ia.has(t)||Pt(e,"--dangerously-skip-permissions")?true:e.some((n,r)=>{let o=n==="--mode"?e[r+1]:n.startsWith("--mode=")?n.slice(7):void 0;return typeof o=="string"&&ia.has(o)})}function Ml(t,e){let n=[];for(let r=0;r<t.length;r+=1){let o=t[r],s=[...e].find(i=>o===i||o.startsWith(`${i}=`));s?o===s&&r+1<t.length&&(r+=1):n.push(o);}return n}function Fl(t){let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],o=r.indexOf("="),s=o>0?r.slice(0,o):r;if(!Pl.has(s)){e.push(r);continue}r===s&&n+1<t.length&&!t[n+1].startsWith("-")&&(n+=1);}return e}function ye(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Ul(t,e){if(!(t?Dl.has(t)||Ye(lo).some(s=>s.id===t):false)||!t)return e;let r=nn(lo,t),o=Zr(lo)[t]?.defaultEffort;if(r.length!==0)return e?r.includes(e)?e:o&&r.includes(o)?o:void 0:o}function je(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0?t:void 0}function go(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 fo(t){return t.step.step_index}function G(t){if(typeof t!="string")return;let e=t.split(/\r?\n/,1)[0]?.trim();return e&&Pn(e)?.slice(0,500).trim()||void 0}function ql(t,e){let n=(t??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&xl.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)/,/invalid (?:flag|option)/].some(s=>s.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 Bl(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 ca(t){let e=ye(t)?t:void 0,n=e&&ye(e.error)?e.error:void 0,r=e?G(e.code)??G(e.error_code)??G(n?.code)??G(n?.error_code):void 0,o=typeof t=="string"?G(t):e?G(e.message)??G(e.error)??G(e.reason)??G(n?.message)??G(n?.error)??G(n?.reason):void 0,s=ql(r,o),i=e?je(e.retry_after_ms)??je(e.retryAfterMs)??je(n?.retry_after_ms)??je(n?.retryAfterMs):void 0;return {code:s,kind:Bl(s),message:o??"Antigravity reported a terminal error.",...i===void 0?{}:{retryAfterMs:i}}}function Hn(t){let e=ca(t);return new W(e.message,"cli/antigravity",{code:e.code,kind:e.kind,...e.retryAfterMs===void 0?{}:{retryAfterMs:e.retryAfterMs}})}function ho(t){return new W(t,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function Hl(t){let e=new TextEncoder().encode(t).byteLength;if(!(e<=_o))throw new W(`Input is too large: final provider initial input is ${e} UTF-8 bytes; budget is ${_o} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function po(){return new W("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 $n(t){if(t.kind==="result"||t.kind==="legacy_result")return t.result}function Gn(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 $l(t){let e=Gn(t);if(!e||e.event.kind==="agy_error"||e.index!==t.length-1||$n(e.event)?.status!=="SUCCESS"||Bn(t))return false;let r=new Map;for(let o of t){if(o.kind!=="step_update"||o.step.step_type!=="agent_response")continue;let s=go(o),i=fo(o);!s||!Number.isSafeInteger(i)||r.set(JSON.stringify([s,i]),o.step);}if(r.size===0)return false;for(let o of r.values())if(o.state!=="DONE"||!ye(o.usage)||je(o.usage.input_tokens)===void 0||je(o.usage.output_tokens)===void 0)return false;return true}function Gl(t,e){for(let n=e-1;n>=0;n-=1){let r=t[n];if(r?.kind==="agy_error")return r.error}}function jl(t,e){return ye(t)&&ye(e)?{...e,...t}:ye(t)&&typeof e=="string"?{...t,message:e}:typeof t=="string"&&ye(e)?{...e,message:t}:t??e}function Wl(t){let e=Array.isArray(t.denied_actions)?t.denied_actions:[],n=[];for(let i of e){let a=ye(i)?i:void 0,c=typeof i=="string"?G(i):G(a?.display_name)??G(a?.action);c&&!n.includes(c)&&n.length<5&&n.push(c.slice(0,80));}let r=Math.max(0,e.length-n.length),o=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"",s=`Permission denied: Antigravity blocked ${e.length} requested action${e.length===1?"":"s"}${o}.`;return new W("Could not run because of permissions.","cli/antigravity",{code:"UNKNOWN",kind:"permanent",providerReason:s})}function Bn(t){let e=Gn(t);if(!e)return;if(e.event.kind==="agy_error")return Hn(e.event.error);let n=$n(e.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return Wl(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return ho("Antigravity returned a result with an unsupported status.");let r=n.error,o=jl(r==null||r===""?n:r,Gl(t,e.index));return Hn(o)}function ua(t){if(typeof t=="string")return t;if(t!=null)try{return JSON.stringify(t)}catch{return}}function Kl(t){return `agy:${String(t.conversation_id)}:${String(t.step_index)}`}function Vl(t,e){let n=typeof e?.name=="string"?e.name:t.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function la(t){let e=ua(t);if(e)return e.length<=2e3?e:`${e.slice(0,1999)}\u2026`}function zl(t){let e=ye(t)?t:void 0,n=e&&ye(e.error)?e.error:void 0,r=typeof t=="string"?t.trim().match(/^([A-Z][A-Z0-9_]*)(?:[:\s]|$)/)?.[1]:void 0,o=(G(e?.type)??G(e?.code)??G(e?.error_type)??G(n?.type)??G(n?.code)??G(n?.error_type)??G(r)??"TOOL_ERROR").slice(0,60),s=ca(t).message.slice(0,250);return la({type:o,message:s})??"Antigravity reported a tool error."}function aa(t,e){return t?t.state.has(e)?true:(t.state.set(e,true),false):false}function da(t,e){return {timestamp:t,type:"error",content:e.message,errorMessage:e.message,isError:true}}var lo,Dl,Pl,ia,_o,xl,mo=S(()=>{d();ze();sa();jr();en();Je();rn();Ln();to();lo="antigravity",Dl=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),Pl=new Set(["--conversation","--resume","--continue"]),ia=new Set(["bypassPermissions","agent-full-access","yolo"]),_o=18e4,xl=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"]);({command:"agy",maxInitialInputBytes:_o,meta:{displayName:"Antigravity",models:Ri(),defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(t){let e=Qt(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){Hl(t);let{model:r,effort:o}=ut(e.model),s=Xr(r),i=s.model,a=e.effort??o??s.effort,c=Ul(i,a),u=e.additionalArgs??[],_=Fl(Ml(u,new Set(["--input-format","--output-format"]))),f=i&&!Pt(u,"--model")?["--model",i]:[],g=Pt(u,"--effort")?[]:vi(c),w=Pt(u,"--mode")||Pt(u,"--dangerously-skip-permissions")?[]:Oi(e.mode),R=Ll(e.mode,u)||Pt(u,"--settings")?[]:["--settings",JSON.stringify({permissions:{allow:Fi(e.builtinAllow)}})],T=typeof e.resumeSessionId=="string"&&e.resumeSessionId.trim().length>0?["--conversation",e.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...f,...g,...w,...T,...R,..._],stdinMessage:`${JSON.stringify({event:"user",message:{content:t}})}
66
66
  `,env:{AGY_CLI_DISABLE_AUTO_UPDATE:"true"}}},extractText(t){let e=Ct(t),n=Gn(e)?.event,r=Bn(e);if(r)throw r;let o=n?$n(n):void 0;if(o){if(o.status!=="SUCCESS")throw ho("Antigravity returned a result with an unsupported status.");if(typeof o.response!="string")throw ho("Antigravity returned a successful result without a response string.");if(!o.response.trim())throw po();return o.response}if(e.length>0)throw po();let s=t.trim();if(!s)throw po();return s},extractPartialText(t){let e=Ct(t),n=Gn(e)?.event;if(!n||n.kind==="agy_error")return;let r=$n(n);return r&&typeof r.response=="string"&&r.response.trim()?r.response:void 0},interpretExit(t,e,n){let r=Ct(n??""),o=Bn(r);return o||(t!==0&&e.trim()?Hn(e):null)},parseResultMeta(t){let e=Ct(t),n=0,r=0,o=0,s=0,i=new Set;for(let c of e){if(c.kind!=="step_update"||c.step.state!=="DONE"||!ye(c.step.usage))continue;let u=go(c),_=fo(c);if(!u||!Number.isSafeInteger(_))continue;let f=JSON.stringify([u,_]);if(i.has(f))continue;let g=c.step.usage,w=je(g.input_tokens),R=je(g.output_tokens);if(w===void 0||R===void 0)continue;i.add(f);let T=je(g.cache_read_tokens)??0;n+=w+T,r+=R,o+=T,s+=1;}return {usage:s===0?null:{inputTokens:n,outputTokens:r,cachedInputTokens:o,costUsd:0,complete:$l(e)},model:null}},parseEvent(t,e,n){let r=Qt(t);if(!r)return [];let o=e??new Date().toISOString();if(r.kind==="agy_error")return [da(o,Hn(r.error))];if(r.kind==="legacy_result"||r.kind==="result"){let w=Bn([r]);return w?[da(o,w)]:[]}if(r.kind!=="step_update")return [];let{step:s}=r,i=go(r)??"unknown",a=fo(r),c=`${i}:${a}`;if((s.state==="DONE"||s.state==="ERROR")&&aa(n,`antigravity:terminal:${c}`))return [];if(s.step_type==="agent_response")return typeof s.text_delta=="string"&&s.text_delta.length>0?[{timestamp:o,type:"text",content:s.text_delta}]:[];if(s.step_type!=="tool")return [];let u=ye(s.tool_info)?s.tool_info:void 0,_=Vl(s,u);if(!_)return [];let f=Kl(s);if(s.state==="ACTIVE"){if(aa(n,`antigravity:active:${c}`))return [];let w=ua(u?.parameters);return [{timestamp:o,type:"tool_use",toolName:_,toolUseId:f,...w===void 0?{}:{toolInput:w}}]}let g=s.state==="ERROR"?zl(u?.error):la(u?.output);return [{timestamp:o,type:"tool_result",toolName:_,toolUseId:f,...g===void 0?{}:{resultPreview:g},...s.state==="ERROR"?{isError:true}:{}}]}});});var _a=S(()=>{d();Nt();vt();Ot();lt();});var yo=S(()=>{d();ze();Gr();Je();Ot();rn();lt();});var co=S(()=>{d();ro();oo();so();uo();mo();_a();yo();ro();oo();so();uo();mo();yo();Nt();});var ga=S(()=>{d();di();co();});var ko=S(()=>{d();ga();vn();});var an,pt=S(()=>{d();an=["success","completed","done","failed","error","stopped","runner_lost"];});var dn=S(()=>{d();});var wo=S(()=>{d();$r();dn();});var cp,xt=S(()=>{d();x();F();B();M();U();At();vn();Hr();$r();Dn();Ur();ko();pt();dn();wo();dn();At();cp="0.8.9-rc.13",parseInt(cp.split("rc.")[1]),new Set(an);});d();d();d();var A="workout-log",Qe="workout-log.records.v1",_t=500,Vn=100,zn=4096,Mt=6e4,Yn=200,Ft=20,cn=6e4;d();var Ut=class{epoch=0;activeSession=null;grantControllers=new Map;get activeAccountKey(){return this.activeSession?.accountKey??null}get activeSessionEpoch(){let e=this.activeSession;return e&&!e.controller.signal.aborted?e.epoch:null}currentToken(e){let n=this.activeSession;return !n||n.accountKey!==e||n.controller.signal.aborted?null:this.toSessionToken(n)}activate(e){if(!/^[0-9a-f]{64}$/.test(e))throw new Error("INVALID_ACCOUNT_KEY");if(this.activeSession?.accountKey===e&&!this.activeSession.controller.signal.aborted)return this.toSessionToken(this.activeSession);this.abortActiveSession();let n={accountKey:e,epoch:++this.epoch,controller:new AbortController};return this.activeSession=n,this.toSessionToken(n)}captureGrant(e,n,r){if(!this.isCurrent(e))throw new Error("APP_SYNC_SESSION_STALE");if(!n||!Number.isSafeInteger(r)||r<1)throw new Error("INVALID_GRANT_FENCE");let o=new AbortController,s=this.grantKey(e.accountKey,n,r),i=()=>o.abort(e.signal.reason);e.signal.aborted?i():e.signal.addEventListener("abort",i,{once:true});let a=this.grantControllers.get(s)??new Set;return a.add({controller:o,sessionSignal:e.signal,onSessionAbort:i}),this.grantControllers.set(s,a),{accountKey:e.accountKey,epoch:e.epoch,grantId:n,generation:r,signal:o.signal}}isCurrent(e){let n=this.activeSession;return n!==null&&n.accountKey===e.accountKey&&n.epoch===e.epoch&&!n.controller.signal.aborted&&!e.signal.aborted}release(e){let n=this.grantKey(e.accountKey,e.grantId,e.generation),r=this.grantControllers.get(n);if(r){for(let o of r)o.controller.signal===e.signal&&(o.sessionSignal.removeEventListener("abort",o.onSessionAbort),r.delete(o));r.size===0&&this.grantControllers.delete(n);}}cancelGrant(e,n,r){let o=this.grantKey(e,n,r),s=this.grantControllers.get(o);if(s){for(let i of s)i.sessionSignal.removeEventListener("abort",i.onSessionAbort),i.controller.abort("grant_invalidated");this.grantControllers.delete(o);}}suspend(e){this.activeSession&&(e===void 0||this.activeSession.accountKey===e)&&(this.abortActiveSession(),this.epoch+=1);}toSessionToken(e){return {accountKey:e.accountKey,epoch:e.epoch,signal:e.controller.signal}}abortActiveSession(){let e=this.activeSession;if(e){e.controller.abort("session_suspended");for(let[n,r]of this.grantControllers)if(n.startsWith(`${e.accountKey}:${e.epoch}:`)){for(let o of r)o.sessionSignal.removeEventListener("abort",o.onSessionAbort),o.controller.abort("session_suspended");this.grantControllers.delete(n);}this.activeSession=null;}}grantKey(e,n,r){return `${e}:${this.activeSession?.epoch??this.epoch}:${n}:${r}`}};d();var Fa=Qe,ge=Object.freeze({root:"docs/apps/workout-log",include:Object.freeze(["exercises.md","routines/<id>.md","workouts/<YYYY-MM-DD>-<id>.md"]),idPattern:"^[A-Za-z0-9_-]{1,40}$",exclude:Object.freeze(["migration/**","*.json","app-state/**",".*","*~","*.tmp","*.swp","*.part",".env*","auth.json","*.key","*.pem"])}),Jn=Object.freeze({exactFiles:Object.freeze(["exercises.md"]),directFolders:Object.freeze(["routines","workouts"]),suffix:".md",maxDepth:1}),Ua=/^[A-Za-z0-9_-]{1,40}$/,Oo=["root","include","idPattern","exclude"];function vo(t,e){return Array.isArray(t)&&t.length===e.length&&t.every((n,r)=>n===e[r])}function qa(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function Ba(t){if(t==="exercises.md")return "exercises";if(/^routines\/[A-Za-z0-9_-]{1,40}\.md$/.test(t))return "routine";let e=/^workouts\/(\d{4})-(\d{2})-(\d{2})-([A-Za-z0-9_-]{1,40})\.md$/.exec(t);if(!e||!Ua.test(e[4]))return null;let[,n,r,o]=e,s=Number(n),i=Number(r),a=Number(o);if(s<1||i<1||i>12||a<1||a>31)return null;let c=new Date(0);return c.setUTCHours(0,0,0,0),c.setUTCFullYear(s,i-1,a),c.getUTCFullYear()!==s||c.getUTCMonth()!==i-1||c.getUTCDate()!==a?null:"workout"}function Ha(t){let n=t.trim().replace(/[ \t]+#.*$/,"").trim();return /^[A-Za-z0-9_-]+$/.test(n)?n:/^"[A-Za-z0-9_-]+"$/.test(n)||/^'[A-Za-z0-9_-]+'$/.test(n)?n.slice(1,-1):null}function $a(t){if(typeof t!="string")return null;let e=t.indexOf(`
67
67
  `);if((e<0?t:t.slice(0,e)).replace(/\r$/,"")!=="---")return null;let r=new Map,o=e<0?t.length:e+1;for(;o<=t.length;){let s=t.indexOf(`
68
68
  `,o),i=s<0?t.length:s,a=t.slice(o,i);a.endsWith("\r")&&(a=a.slice(0,-1));let c=s<0?i:s+1;if(Buffer.byteLength(t.slice(0,c),"utf8")>4096)return null;if(a==="---")return r.has("crewx_app")&&r.has("kind")?r:null;let u=/^(crewx_app|kind):[ \t]*(.*)$/.exec(a);if(u){let _=u[1];if(r.has(_))return null;let f=Ha(u[2]);if(f===null)return null;r.set(_,f);}if(s<0)break;o=s+1;}return null}var qt=class{scopeVersion=Qe;definition=ge;matchesDefinition(e,n){return e!==Fa||!qa(n)||Object.keys(n).length!==Oo.length||!Oo.every(r=>Object.hasOwn(n,r))?false:n.root===ge.root&&n.idPattern===ge.idPattern&&vo(n.include,ge.include)&&vo(n.exclude,ge.exclude)}validateRef(e){if(typeof e!="string"||e.length===0||e.length>256)return {valid:false,reason:"out_of_scope"};if(e.includes("\0")||e.includes("\\")||e.startsWith("/")||e.startsWith("~"))return {valid:false,reason:"out_of_scope"};if(e.split("/").some(o=>o===""||o==="."||o===".."))return {valid:false,reason:"out_of_scope"};if(e.startsWith(".")||/(?:^|\/)\./.test(e)||/(?:^|\/)[^/]*(?:~|\.tmp|\.swp|\.part)$/.test(e))return {valid:false,reason:"out_of_scope"};if(/(?:^|\/)(?:auth\.json|[^/]*\.key|[^/]*\.pem)$/.test(e)||/\.env[^/]*$/.test(e))return {valid:false,reason:"out_of_scope"};let r=Ba(e);return r===null?{valid:false,reason:"out_of_scope"}:{valid:true,kind:r}}validateFrontMatter(e,n){let r=this.validateRef(e);if(!r.valid)return {valid:false,reason:"invalid_front_matter"};let o=$a(n);return o?o.get("crewx_app")!==A?{valid:false,reason:"app_mismatch"}:o.get("kind")!==r.kind?{valid:false,reason:"kind_mismatch"}:{valid:true,kind:r.kind}:{valid:false,reason:"invalid_front_matter"}}};function q(t){return `sha256:${createHash("sha256").update(t,"utf8").digest("hex")}`}function gt(t){if(!Array.isArray(t)||t.length===0||t.length>64)return null;let e=[];for(let n of t){if(typeof n!="string"||n.length===0)return null;let r=n.normalize("NFC");if(r==="."||r===".."||r.includes("/")||r.includes("\\")||r.includes("\0")||/^[A-Za-z]:$/.test(r)||r.startsWith("~"))return null;e.push(r);}return e}d();d();var ja=10*6e4,Wa=5e3,We=class extends Error{constructor(n){if(!Number.isSafeInteger(n)||n<0)throw new Error("INVALID_APP_SYNC_BUDGET_RETRY_AT");super("APP_SYNC_BUDGET_DEFERRED");this.retryAt=n;this.name="AppSyncBudgetDeferredError";}retryAt;code="APP_SYNC_BUDGET_DEFERRED"},Xn=class{constructor(e){this.sqlite=e;if(!e||typeof e.prepare!="function"||typeof e.transaction!="function")throw new Error("INVALID_DOC_CREATE_LEDGER_DATABASE")}sqlite;peek(e,n){Qn(e),un(n),this.deleteExpired(n);let r=this.readWindow(e,n);return r.count<20?{available:true,remaining:20-r.count}:{available:false,retryAt:Do(r,n)}}reserve(e){return Po(e),this.sqlite.transaction(r=>{this.deleteExpired(r.now);let o=this.readWindow(r.accountKey,r.now);return o.count>=20?{ok:false,retryAt:Do(o,r.now)}:(this.insert(r),{ok:true})}).immediate(e)}reserveForced(e){Po(e),this.deleteExpired(e.now),this.insert(e);}prune(e){return un(e),this.deleteExpired(e)}readWindow(e,n){let r=this.sqlite.prepare(`
package/dist/esm/index.js CHANGED
@@ -38,7 +38,7 @@ import*as Gt from'path';import Gt__default,{join,isAbsolute,dirname,resolve,base
38
38
  time_updated = excluded.time_updated
39
39
  `);r.transaction(s=>{for(let a of s)o.run(a);})(n);}finally{r.close();}}function gY(e){if(!e)return [];let t=[];for(let n=0;n<e.length;n+=1){let r=e[n];if(r==="-s"||r==="--session"){let o=e[n+1],i=o!==void 0&&!o.startsWith("-");t.push({sessionId:i?o:void 0}),i&&(n+=1);continue}(r.startsWith("--session=")||r.startsWith("-s="))&&t.push({sessionId:r.slice(r.indexOf("=")+1)||void 0});}return t}function hY(e){if(!e)return;let t=[];for(let n=0;n<e.length;n+=1){let r=e[n];if(r==="-s"||r==="--session"){e[n+1]!==void 0&&!e[n+1].startsWith("-")&&(n+=1);continue}r.startsWith("--session=")||r.startsWith("-s=")||t.push(r);}return t}function Zy(e){let t=hY(e.additionalArgs);return {...e,...t===void 0?{}:{additionalArgs:t},resumeSessionId:void 0}}function mY(e,t){try{return !!e.prepare("SELECT id FROM session_v2 WHERE id = ?").get(t)}catch(n){if(n instanceof Error&&/no such table: session_v2/i.test(n.message))return false;throw n}}function yY(e,t,n){let r=new e(t,{readonly:true,fileMustExist:true});try{return mY(r,n)}finally{r.close();}}async function e_(e,t={}){let n;try{n=await(t.loadSqlite??aY)();}catch{throw new W("OpenCode isolation requires the optional better-sqlite3 dependency. Install it and retry.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}let r=t.crewxHome??Vt(),o=Lc(r),i=Du(r),s=dY(i),a=cY(t.userDataHome),d=uY(n,a);if(d.length>0){if(!HD(n,s))try{await(t.initializeDatabase??pY)(o);}catch{throw new W("Could not initialize the isolated OpenCode credential database.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}if(!HD(n,s))throw new W("The isolated OpenCode credential database is unavailable.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"});try{fY(n,s,d);}catch{throw new W("Could not copy API-key credentials into the isolated OpenCode database.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}}let c=gY(e.additionalArgs),l=c.map(p=>p.sessionId),u=c.length>0?l[l.length-1]:e.resumeSessionId;if(!u)return c.length>0?Zy(e):e;if(l.some(p=>p!==u)||!existsSync(s))return Zy(e);try{return yY(n,s,u)?{...e,resumeSessionId:u}:Zy(e)}catch{throw new W("Could not read the isolated OpenCode session database safely.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}}var t_=U(()=>{h();gs();fs();Yo();});function IY(e){return e.charAt(0).toUpperCase()+e.slice(1)}function kR(e){if(typeof e!="object"||e===null)return "execution_failed";let t=e;return t.code==="ENOENT"?"command_not_found":t.code==="ERR_CHILD_PROCESS_STDIO_MAXBUFFER"?"execution_failed":t.code==="ETIMEDOUT"||t.killed===true?"timeout":typeof t.code=="number"&&t.code!==0?"nonzero_exit":"execution_failed"}function $D(e){let t=new n_(e);return console.warn("[opencode] model query failed",{code:t.code,reason:t.reason,stage:t.stage}),t}function TY(e,t){let n=$D(t);if(e)throw n;return []}async function VD(e={}){let t=e.throwOnError===true;try{await e_({});}catch{return TY(t,"preparation_failed")}return new Promise((n,r)=>{let o=false,i=s=>{if(o)return;o=true;let a=$D(s);t?r(a):n([]);};try{execFile("opencode",["models","--standalone"],{timeout:5e3,maxBuffer:1048576,encoding:null,env:{...cr(process.env),...Lc()}},(a,d)=>{if(!o){if(a){i(kR(a));return}Promise.resolve().then(()=>cR(d)).then(c=>{if(o)return;let l=c.split(`
40
40
  `).map(u=>u.trim()).filter(u=>u.length>0).map(u=>({id:u}));o=!0,n(l);}).catch(()=>i("decode_failed"));}}).on("error",a=>i(kR(a)));}catch(s){i(kR(s));}})}function Mc(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}async function r_(){let e;try{let n=(await import('better-sqlite3')).default,r=join(Du(),"opencode.db");e=new n(r,{readonly:!0,fileMustExist:!0});let o=e.prepare("SELECT value FROM kv WHERE key = ?").get("models-dev:v2:catalog");if(!o||typeof o.value!="string")throw new Error("OpenCode model catalog row is unavailable");let i=JSON.parse(o.value);if(!Mc(i))throw new Error("OpenCode model catalog shape is unavailable");let s=typeof i.body=="string"?JSON.parse(i.body):i.body;if(!Mc(s))throw new Error("OpenCode model catalog body shape is unavailable");let a=new Map;for(let[d,c]of Object.entries(s)){if(!d||!Mc(c)||!Mc(c.models))throw new Error("OpenCode model provider shape is unavailable");for(let[l,u]of Object.entries(c.models)){if(!l||!Mc(u))throw new Error("OpenCode model shape is unavailable");let p=u.capabilities;if(p===void 0)continue;if(!Mc(p))throw new Error("OpenCode model capability shape is unavailable");let f=p.reasoning;if(f===void 0)continue;if(!Mc(f))throw new Error("OpenCode reasoning capability shape is unavailable");let g=f.effort;(g===void 0||Array.isArray(g)&&g.every(y=>typeof y=="string"))&&a.set(`${d}/${l}`,Array.isArray(g)?g:[]);}}return a}catch{return console.debug("[opencode] could not read private model effort catalog; omitting effort choices"),new Map}finally{try{e?.close();}catch{}}}function wY(e,t,n){if(!t.meta)return null;let r=t.meta.capabilities??{},o=Ri(e),i=o.length>0?o:t.meta.models??[],s=n!==void 0?Qf(n,i):i,a=nd(`cli/${e}`),d=lo(e).providerOptions??[];return {id:`cli/${e}`,name:t.meta.displayName??IY(e),modes:yc(e),effort:zr(e),models:Zf(s),modelOverrides:rd(e),...d.length>0?{providerOptions:d}:{},...a!==void 0?{defaults:a}:{},capabilities:{loadSession:r.loadSession??false,resume:r.resume??false,image:r.image??false,audio:r.audio??false,mcp:r.mcp??false}}}async function RY(e={}){let t=e.includeOpencodeRuntimeModels?await VD():void 0,n=[];for(let[r,o]of Object.entries(ri)){let s=wY(r,o,r==="opencode"?t:void 0);s&&n.push(s);}return n.sort((r,o)=>fg(r.id,o.id))}var EY,n_,SR=U(()=>{h();gd();Qy();ad();fs();t_();uo();EY={preparation_failed:{code:"OPENCODE_MODELS_PREPARATION_FAILED",stage:"prepare",message:"OpenCode model query preparation failed."},command_not_found:{code:"OPENCODE_MODELS_COMMAND_NOT_FOUND",stage:"execute",message:"OpenCode CLI could not be started."},timeout:{code:"OPENCODE_MODELS_TIMEOUT",stage:"execute",message:"OpenCode model query timed out."},nonzero_exit:{code:"OPENCODE_MODELS_EXECUTION_FAILED",stage:"execute",message:"OpenCode model query failed."},execution_failed:{code:"OPENCODE_MODELS_EXECUTION_FAILED",stage:"execute",message:"OpenCode model query failed."},decode_failed:{code:"OPENCODE_MODELS_DECODE_FAILED",stage:"decode",message:"OpenCode model output could not be decoded."}},n_=class extends Error{code;reason;stage;constructor(t){let n=EY[t];super(n.message),this.name="OpenCodeModelQueryError",this.code=n.code,this.reason=t,this.stage=n.stage;}};});function OY(e){return e?CY[e]??{agent:"build",autoApprove:false}:{agent:void 0,autoApprove:false}}function oi(e,t){return e.some(n=>n===t||n.startsWith(`${t}=`))}function CR(){let e;try{e=Du();}catch{return r_().catch(()=>new Map)}let t=Date.now();if(qD===e&&o_&&o_.expiresAt>t)return o_.result;qD=e;let n=r_().catch(()=>new Map);return o_={expiresAt:t+vY,result:n},n}async function PY(e){let t=await e_(e),n=e.additionalArgs??[],r=oi(n,"--model")||oi(n,"-m");if(!e.model||!e.effort||r)return t;let o=(await CR()).get(e.model);return !o||o.includes(e.effort)?t:(console.debug("[opencode] requested effort is not listed for this model; using OpenCode default"),{...t,effort:void 0})}function KD(e){let t=[],n=0,r=false,o=false,i=0;for(let a=0;a<e.length;a++){let d=e[a];if(o){o=false;continue}if(d==="\\"&&r){o=true;continue}if(d==='"'){r=!r;continue}if(!r){if(d==="{")n++;else if(d==="}"&&(n--,n===0)){let c=e.slice(i,a+1).trim();c&&t.push(c),i=a+1;}}}let s=e.slice(i).trim();return s&&t.push(s),t}function vn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function XD(e){let t=vn(e.part)?e.part:void 0;return e.type==="reasoning"||t?.type==="reasoning"}function NY(e){let t=vn(e.part)?e.part:void 0;return (typeof t?.text=="string"?t.text:typeof e.text=="string"?e.text:void 0)?.trim()||void 0}function xY(e){let t=[],n=false;for(let r of e.split(/\r?\n/)){let o=r.trim();if(!o)continue;try{let s=JSON.parse(o);vn(s)?t.push(s):n=!0;continue}catch{}let i=KD(o);i.length>1&&console.warn("[opencode] extractText: falling back to concatenated-JSON split for a malformed line");for(let s of i)try{let a=JSON.parse(s);vn(a)?t.push(a):n=!0;}catch{n=true;}}return {events:t,malformed:n}}function OR(e){let t=vn(e.error)?e.error:void 0,n=t&&vn(t.data)?t.data:void 0,r=YD(t),o=ni(t?.name),i=ni(n?.message)??ni(t?.message)??bR(r)??ni(e.message)??ni(e.errorMessage)??ni(e.error),s=ni(e.ref),a=o&&i&&o!==i?`${o}: ${i}`:o??i??JD;return (s?`${a} (ref: ${s})`:a).slice(0,SY)}function WD(e){let t=vn(e.error)?e.error:void 0,n=typeof t?.type=="string"?t.type:void 0,r=typeof t?.status=="number"?t.status:Number(t?.status),o=OR(e),i=YD(t),s=i&&vn(i.error)?i.error:void 0,a=typeof s?.type=="string"?s.type:void 0,d=[o,bR(i)].filter(Boolean).join(`
41
- `);if(r===402||DY(d))return new W(`OpenCode subscription is required: ${o}`,Po,{code:"SUBSCRIPTION_REQUIRED",kind:"config",providerReason:xc(o)});if(r===403&&(a==="RegionError"||a==="FreeTierError"))return new W(`OpenCode account settings are required: ${o}`,Po,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:"access",providerReason:xc(o)});if(n==="provider.auth"||r===401||r===403)return new W(`OpenCode authentication is required: ${o}`,Po,{code:"AUTH_REQUIRED",kind:"config"});if(r===410||a==="ModelDeprecated")return new W(`OpenCode model has been retired: ${o}`,Po,{code:"MODEL_RETIRED",kind:"config",replacementModel:LY(i,t,e),providerReason:xc(o)});if(n==="provider.free-limit"||r===429){let c=MY(t);return new W(`OpenCode rate limit reached: ${o}`,Po,{code:"RATE_LIMITED",kind:"transient",...c===void 0?{}:{retryAfterMs:c}})}if(n==="provider.no-route")return new W(`OpenCode model or variant unavailable: ${o}`,Po,{code:"MODEL_UNAVAILABLE",kind:"config"});if(n==="provider.invalid-request"&&r===400){let c=[o,bR(i)].filter(f=>f!==void 0),l=c.find(f=>/requires global regions/i.test(f)),u=c.find(f=>/trains on request data/i.test(f)),p=l?"region":u?"training_consent":void 0;if(p)return new W(`OpenCode account settings are required: ${o}`,Po,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:p,providerReason:xc(l??u)})}return new W(`OpenCode error: ${o}`,Po,{code:"PROVIDER_CRASHED",kind:"transient"})}function YD(e){let n=(e&&vn(e.response)?e.response:void 0)?.body;if(vn(n))return n;if(typeof n=="string")try{let r=JSON.parse(n);return vn(r)?r:void 0}catch{return}}function bR(e){let t=e&&vn(e.error)?e.error:void 0;return ni(t?.message)??ni(e?.message)}function DY(e){return /insufficient\s+(?:balance|account funds)|credit\s+limit\s+exceeded|payment\s+required|account invoice is overdue|billing_error|please add or update your payment method|(?:GLM Coding Plan|enterprise) package has expired|your current subscription plan does not yet include access to/i.test(e)}function LY(e,t,n){let r=e&&vn(e.metadata)?e.metadata:void 0,o=typeof r?.replacement=="string"?r.replacement.trim():void 0;if(!o)return;let i=[r?.model,t?.model,n.model,n.modelID].find(d=>typeof d=="string"&&d.trim().length>0)?.trim(),s=i&&i.includes("/")?i.slice(0,i.indexOf("/")):"opencode-go",a=o.includes("/")?o:`${s}/${o}`;return /^[A-Za-z0-9._/-]{1,128}$/.test(a)?a:void 0}function MY(e){let t=e?.retryAfterMs;if(typeof t=="number"&&Number.isFinite(t)&&t>=0)return t;let r=(e&&vn(e.response)?e.response:void 0)?.body,o=typeof r=="string"?UY(r):vn(r)?r:void 0;if(o){let i=vR(o);if(i)return GD(i.value,i.key==="retryafterms")}if(typeof r=="string"){let i=r.match(/retry[-_]after(?:\s*[:=]\s*|\s+)["']?([^"'\s,;}]+)/i);if(i?.[1])return GD(i[1],false)}}function UY(e){try{let t=JSON.parse(e);return vn(t)?t:void 0}catch{return}}function vR(e){if(Array.isArray(e)){for(let t of e){let n=vR(t);if(n)return n}return}if(vn(e)){for(let[t,n]of Object.entries(e)){let r=t.toLowerCase().replace(/[-_]/g,"");if(r==="retryafterms"||r==="retryafter")return {value:n,key:r}}for(let t of Object.values(e)){let n=vR(t);if(n)return n}}}function GD(e,t){if(typeof e=="number"&&Number.isFinite(e)&&e>=0)return t?e:Math.round(e*1e3);if(typeof e!="string"||!e.trim())return;let n=Number(e);if(Number.isFinite(n)&&n>=0)return t?n:Math.round(n*1e3);if(t)return;let r=Date.parse(e);return Number.isFinite(r)?Math.max(0,r-Date.now()):void 0}function zD(e){let t=xY(e),n=[],r=null,o=0,i=[],s=[],a,d=false;for(let c of t.events){if(XD(c))continue;let l=typeof c.type=="string"?c.type:void 0;if(l){if(l==="text"){let u=vn(c.part)?c.part:void 0,p=typeof u?.text=="string"?u.text:void 0;p?.trim()&&n.push(p.trim());continue}if(l==="result"){typeof c.result=="string"&&(r=c.result);continue}if(l==="tool_use"){o++;continue}if(l==="error"){i.push(c),s.push(OR(c));continue}if(l==="step_finish"){d=true;let u=vn(c.part)?c.part:void 0;a=typeof u?.reason=="string"?u.reason:void 0;}}}return {...t,texts:n,resultText:r,toolUseCount:o,errorEvents:i,errorMessages:s,terminalReason:a,hasTerminal:d}}function QD(e){return (e??"unknown").trim().toLowerCase().replace(/_/g,"-")}function BY(){return new W("OpenCode returned no assistant output.",Po,{code:"EMPTY_OUTPUT",kind:"transient"})}function FY(){return new W("OpenCode emitted malformed JSON output.",Po,{code:"PROVIDER_CRASHED",kind:"transient"})}function HY(e,t){switch(QD(e)){case "length":return new W("OpenCode stopped because the context window was exceeded.",Po,{code:"UNKNOWN",kind:"permanent"});case "content-filter":return new W("OpenCode stopped because the content filter blocked the response.",Po,{code:"UNKNOWN",kind:"permanent"});case "error":return new W(`${JD} while generating a response.`,Po,{code:"PROVIDER_CRASHED",kind:"transient"});default:return null}}var kY,Po,JD,SY,bY,vY,qD,o_,CY,i_,s_=U(()=>{h();gs();ER();vc();Ou();pd();SR();t_();kY=new Set(["step_start","step_finish"]),Po="cli/opencode",JD="OpenCode provider error",SY=240,bY="Follow the instructions provided on standard input.",vY=3e5,CY={build:{agent:"build",autoApprove:false},"build-auto":{agent:"build",autoApprove:true},plan:{agent:"plan",autoApprove:false},"plan-auto":{agent:"plan",autoApprove:true}};i_={command:"opencode",prepare:PY,meta:{displayName:"OpenCode",capabilities:{resume:true}},buildArgs(e,t,n){let r=t.additionalArgs,o=r!==void 0?[...r]:["run"];oi(o,"--format")||o.push("--format","json"),oi(o,"--thinking")||o.push("--thinking"),!oi(o,"--standalone")&&!oi(o,"--server")&&o.push("--standalone"),t.resumeSessionId&&!oi(o,"-s")&&!oi(o,"--session")&&o.push("-s",t.resumeSessionId);let{agent:i,autoApprove:s}=OY(t.mode);oi(o,"--agent")||i!==void 0&&o.push("--agent",i),s&&!oi(o,"--auto")&&o.push("--auto");let a=oi(o,"--model")||oi(o,"-m");if(t.model&&!a){let d=t.effort?`${t.model}#${t.effort}`:t.model;o.push("--model",d);}else t.effort&&!t.model&&!a&&console.debug("[opencode] ignoring effort because no model is configured");return o.push(bY),{args:o,stdinMessage:e,env:Lc()}},extractText(e){let t=zD(e),n=t.errorEvents[0];if(n)throw WD(n);let r=HY(t.terminalReason??"");if(r)throw r;let o=t.texts.length>0?t.texts[t.texts.length-1]:void 0;if(o!==void 0)return o;if(t.resultText?.trim())return t.resultText;if(t.malformed)throw FY();let i=QD(t.terminalReason);if(t.hasTerminal&&i==="tool-calls"&&t.toolUseCount>0)return "";throw BY()},interpretExit(e,t,n=""){if(e===0)return null;let o=zD(n).errorEvents[0];return o?WD(o):null},parseResultMeta(e){let t=sa(e);return t?{usage:{inputTokens:t.inputTokens,outputTokens:t.outputTokens,cachedInputTokens:t.cachedInputTokens,costUsd:0},model:null}:{usage:null,model:null}},parseEvent(e,t,n){let r=t??new Date().toISOString(),o=[],i=new Map,s;try{JSON.parse(e),s=[e];}catch{s=KD(e),s.length>1&&console.warn("[opencode] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let a of s){let d;try{d=JSON.parse(a);}catch{continue}let c=fo(d,r),l=d.type;if(XD(d)){let u=NY(d);if(!u)continue;let p=vn(d.part)?d.part:void 0,f=typeof p?.id=="string"?p.id:typeof d.id=="string"?d.id:void 0,g=u;if(f){let y=`opencode.reasoning:${f}`,_=n?.state.get(y),A=typeof _=="string"?_:i.get(f);if(typeof A=="string"&&(A===u||A.startsWith(u))||typeof A=="string"&&u.startsWith(A)&&(g=u.slice(A.length).trim(),!g))continue;i.set(f,u),n?.state.set(y,u);}o.push({timestamp:c,type:"thinking",content:g});continue}if(l){if(l==="text"){let p=d.part?.text;p&&o.push({timestamp:c,type:"text",content:p});continue}if(l==="tool_use"){let u=d.part;if(!u)continue;let p=String(u.tool||""),f=String(u.callID||u.id||""),g=u.state,y=String(g?.status||""),_=g?.input,A=ti(_);if(o.push({timestamp:c,type:"tool_use",toolName:p,toolUseId:f,toolInput:A}),y==="completed"&&g?.output!==void 0){let I=g.output,w=typeof I=="string"?I:JSON.stringify(I);o.push({timestamp:c,type:"tool_result",toolUseId:f,resultPreview:w,isError:false});}else y==="error"&&o.push({timestamp:c,type:"tool_result",toolUseId:f,resultPreview:String(g?.error||"tool error"),isError:true});continue}if(l==="error"){let u=OR(d);o.push({timestamp:c,type:"error",content:u,errorMessage:u});continue}}}return o},suppressOutputLine(e){let t=e.trim();if(!t.startsWith("{")||!t.endsWith("}"))return false;try{let r=JSON.parse(t).type;return r?kY.has(r):!1}catch{return false}}};});function ZD(e,t){if(e===void 0||e==="")return t;let n=parseInt(e,10);return Number.isNaN(n)?t:n}function PR(e=process.env){let t=e.CREWX_TIMEOUT_IDLE;if(t===void 0||t==="")return;let n=parseInt(t,10);if(!(!Number.isFinite(n)||n<=0))return n}function eL(e=process.env){return {queryMs:ZD(e.CREWX_TIMEOUT_QUERY,288e5),executeMs:ZD(e.CREWX_TIMEOUT_EXECUTE,288e5),idleMs:PR(e)??6e5}}var gg=U(()=>{h();});function Lu(e,t){return e.some(n=>n===t||n.startsWith(`${t}=`))}function qY(e,t){return e&&tL.has(e)||Lu(t,"--dangerously-skip-permissions")?true:t.some((n,r)=>{let o=n==="--mode"?t[r+1]:n.startsWith("--mode=")?n.slice(7):void 0;return typeof o=="string"&&tL.has(o)})}function WY(e,t){let n=[];for(let r=0;r<e.length;r+=1){let o=e[r],i=[...t].find(s=>o===s||o.startsWith(`${s}=`));i?o===i&&r+1<e.length&&(r+=1):n.push(o);}return n}function GY(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e[n],o=r.indexOf("="),i=o>0?r.slice(0,o):r;if(!$Y.has(i)){t.push(r);continue}r===i&&n+1<e.length&&!e[n+1].startsWith("-")&&(n+=1);}return t}function ii(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function zY(e,t){if(!(e?jY.has(e)||Ri(NR).some(i=>i.id===e):false)||!e)return t;let r=zr(NR,e),o=rd(NR)[e]?.defaultEffort;if(r.length!==0)return t?r.includes(t)?t:o&&r.includes(o)?o:void 0:o}function aa(e){return typeof e=="number"&&Number.isSafeInteger(e)&&e>=0?e:void 0}function LR(e){return e.kind==="step_update"?typeof e.step.conversation_id=="string"?e.step.conversation_id:void 0:typeof e.envelope.conversation_id=="string"?e.envelope.conversation_id:void 0}function MR(e){return e.step.step_index}function kn(e){if(typeof e!="string")return;let t=e.split(/\r?\n/,1)[0]?.trim();return t&&cd(t)?.slice(0,500).trim()||void 0}function JY(e,t){let n=(e??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&VY.has(n))return n;let r=`${n} ${t??""}`.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)/,/invalid (?:flag|option)/].some(i=>i.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 KY(e){return e==="AUTH_REQUIRED"||e==="TIMEOUT_IDLE"||e==="TIMEOUT_TOTAL"||e==="TIMEOUT_RESUME"||e==="PROVIDER_CRASHED"?"permanent":e==="MODEL_UNAVAILABLE"||e==="INVALID_PROVIDER_FORMAT"||e==="PROVIDER_NOT_FOUND"?"config":"transient"}function oL(e){let t=ii(e)?e:void 0,n=t&&ii(t.error)?t.error:void 0,r=t?kn(t.code)??kn(t.error_code)??kn(n?.code)??kn(n?.error_code):void 0,o=typeof e=="string"?kn(e):t?kn(t.message)??kn(t.error)??kn(t.reason)??kn(n?.message)??kn(n?.error)??kn(n?.reason):void 0,i=JY(r,o),s=t?aa(t.retry_after_ms)??aa(t.retryAfterMs)??aa(n?.retry_after_ms)??aa(n?.retryAfterMs):void 0;return {code:i,kind:KY(i),message:o??"Antigravity reported a terminal error.",...s===void 0?{}:{retryAfterMs:s}}}function d_(e){let t=oL(e);return new W(t.message,"cli/antigravity",{code:t.code,kind:t.kind,...t.retryAfterMs===void 0?{}:{retryAfterMs:t.retryAfterMs}})}function UR(e){return new W(e,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function XY(e){let t=new TextEncoder().encode(e).byteLength;if(!(t<=DR))throw new W(`Input is too large: final provider initial input is ${t} UTF-8 bytes; budget is ${DR} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function xR(){return new W("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 c_(e){if(e.kind==="result"||e.kind==="legacy_result")return e.result}function l_(e){for(let t=e.length-1;t>=0;t-=1){let n=e[t];if(n&&(n.kind==="result"||n.kind==="legacy_result"||n.kind==="agy_error"))return {event:n,index:t}}}function YY(e){let t=l_(e);if(!t||t.event.kind==="agy_error"||t.index!==e.length-1||c_(t.event)?.status!=="SUCCESS"||a_(e))return false;let r=new Map;for(let o of e){if(o.kind!=="step_update"||o.step.step_type!=="agent_response")continue;let i=LR(o),s=MR(o);!i||!Number.isSafeInteger(s)||r.set(JSON.stringify([i,s]),o.step);}if(r.size===0)return false;for(let o of r.values())if(o.state!=="DONE"||!ii(o.usage)||aa(o.usage.input_tokens)===void 0||aa(o.usage.output_tokens)===void 0)return false;return true}function QY(e,t){for(let n=t-1;n>=0;n-=1){let r=e[n];if(r?.kind==="agy_error")return r.error}}function ZY(e,t){return ii(e)&&ii(t)?{...t,...e}:ii(e)&&typeof t=="string"?{...e,message:t}:typeof e=="string"&&ii(t)?{...t,message:e}:e??t}function e6(e){let t=Array.isArray(e.denied_actions)?e.denied_actions:[],n=[];for(let s of t){let a=ii(s)?s:void 0,d=typeof s=="string"?kn(s):kn(a?.display_name)??kn(a?.action);d&&!n.includes(d)&&n.length<5&&n.push(d.slice(0,80));}let r=Math.max(0,t.length-n.length),o=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"",i=`Permission denied: Antigravity blocked ${t.length} requested action${t.length===1?"":"s"}${o}.`;return new W("\uAD8C\uD55C \uB54C\uBB38\uC5D0 \uC2E4\uD589\uD558\uC9C0 \uBABB\uD588\uC5B4\uC694","cli/antigravity",{code:"UNKNOWN",kind:"permanent",providerReason:i})}function a_(e){let t=l_(e);if(!t)return;if(t.event.kind==="agy_error")return d_(t.event.error);let n=c_(t.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return e6(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return UR("Antigravity returned a result with an unsupported status.");let r=n.error,o=ZY(r==null||r===""?n:r,QY(e,t.index));return d_(o)}function iL(e){if(typeof e=="string")return e;if(e!=null)try{return JSON.stringify(e)}catch{return}}function t6(e){return `agy:${String(e.conversation_id)}:${String(e.step_index)}`}function n6(e,t){let n=typeof t?.name=="string"?t.name:e.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function sL(e){let t=iL(e);if(t)return t.length<=2e3?t:`${t.slice(0,1999)}\u2026`}function r6(e){let t=ii(e)?e:void 0,n=t&&ii(t.error)?t.error:void 0,r=typeof e=="string"?e.trim().match(/^([A-Z][A-Z0-9_]*)(?:[:\s]|$)/)?.[1]:void 0,o=(kn(t?.type)??kn(t?.code)??kn(t?.error_type)??kn(n?.type)??kn(n?.code)??kn(n?.error_type)??kn(r)??"TOOL_ERROR").slice(0,60),i=oL(e).message.slice(0,250);return sL({type:o,message:i})??"Antigravity reported a tool error."}function nL(e,t){return e?e.state.has(t)?true:(e.state.set(t,true),false):false}function rL(e,t){return {timestamp:e,type:"error",content:t.message,errorMessage:t.message,isError:true}}var NR,jY,$Y,tL,DR,VY,BR,FR=U(()=>{h();gs();gg();lg();ra();uo();Pu();$y();yR();NR="antigravity",jY=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),$Y=new Set(["--conversation","--resume","--continue"]),tL=new Set(["bypassPermissions","agent-full-access","yolo"]),DR=18e4,VY=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"]);BR={command:"agy",maxInitialInputBytes:DR,meta:{displayName:"Antigravity",models:Ww(),defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(e){let t=Su(e);if(t?.kind!=="init")return null;let n=t.envelope.conversation_id;return typeof n=="string"&&n.trim().length>0?n.trim():null},buildArgs(e,t,n){XY(e);let{model:r,effort:o}=ms(t.model),i=gu(r),s=i.model,a=t.effort??o??i.effort,d=zY(s,a),c=t.additionalArgs??[],l=GY(WY(c,new Set(["--input-format","--output-format"]))),u=s&&!Lu(c,"--model")?["--model",s]:[],p=Lu(c,"--effort")?[]:wD(d),f=Lu(c,"--mode")||Lu(c,"--dangerously-skip-permissions")?[]:TD(t.mode),g=qY(t.mode,c)||Lu(c,"--settings")?[]:["--settings",JSON.stringify({permissions:{allow:bD(t.builtinAllow)}})],y=typeof t.resumeSessionId=="string"&&t.resumeSessionId.trim().length>0?["--conversation",t.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...u,...p,...f,...y,...g,...l],stdinMessage:`${JSON.stringify({event:"user",message:{content:e}})}
41
+ `);if(r===402||DY(d))return new W(`OpenCode subscription is required: ${o}`,Po,{code:"SUBSCRIPTION_REQUIRED",kind:"config",providerReason:xc(o)});if(r===403&&(a==="RegionError"||a==="FreeTierError"))return new W(`OpenCode account settings are required: ${o}`,Po,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:"access",providerReason:xc(o)});if(n==="provider.auth"||r===401||r===403)return new W(`OpenCode authentication is required: ${o}`,Po,{code:"AUTH_REQUIRED",kind:"config"});if(r===410||a==="ModelDeprecated")return new W(`OpenCode model has been retired: ${o}`,Po,{code:"MODEL_RETIRED",kind:"config",replacementModel:LY(i,t,e),providerReason:xc(o)});if(n==="provider.free-limit"||r===429){let c=MY(t);return new W(`OpenCode rate limit reached: ${o}`,Po,{code:"RATE_LIMITED",kind:"transient",...c===void 0?{}:{retryAfterMs:c}})}if(n==="provider.no-route")return new W(`OpenCode model or variant unavailable: ${o}`,Po,{code:"MODEL_UNAVAILABLE",kind:"config"});if(n==="provider.invalid-request"&&r===400){let c=[o,bR(i)].filter(f=>f!==void 0),l=c.find(f=>/requires global regions/i.test(f)),u=c.find(f=>/trains on request data/i.test(f)),p=l?"region":u?"training_consent":void 0;if(p)return new W(`OpenCode account settings are required: ${o}`,Po,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:p,providerReason:xc(l??u)})}return new W(`OpenCode error: ${o}`,Po,{code:"PROVIDER_CRASHED",kind:"transient"})}function YD(e){let n=(e&&vn(e.response)?e.response:void 0)?.body;if(vn(n))return n;if(typeof n=="string")try{let r=JSON.parse(n);return vn(r)?r:void 0}catch{return}}function bR(e){let t=e&&vn(e.error)?e.error:void 0;return ni(t?.message)??ni(e?.message)}function DY(e){return /insufficient\s+(?:balance|account funds)|credit\s+limit\s+exceeded|payment\s+required|account invoice is overdue|billing_error|please add or update your payment method|(?:GLM Coding Plan|enterprise) package has expired|your current subscription plan does not yet include access to/i.test(e)}function LY(e,t,n){let r=e&&vn(e.metadata)?e.metadata:void 0,o=typeof r?.replacement=="string"?r.replacement.trim():void 0;if(!o)return;let i=[r?.model,t?.model,n.model,n.modelID].find(d=>typeof d=="string"&&d.trim().length>0)?.trim(),s=i&&i.includes("/")?i.slice(0,i.indexOf("/")):"opencode-go",a=o.includes("/")?o:`${s}/${o}`;return /^[A-Za-z0-9._/-]{1,128}$/.test(a)?a:void 0}function MY(e){let t=e?.retryAfterMs;if(typeof t=="number"&&Number.isFinite(t)&&t>=0)return t;let r=(e&&vn(e.response)?e.response:void 0)?.body,o=typeof r=="string"?UY(r):vn(r)?r:void 0;if(o){let i=vR(o);if(i)return GD(i.value,i.key==="retryafterms")}if(typeof r=="string"){let i=r.match(/retry[-_]after(?:\s*[:=]\s*|\s+)["']?([^"'\s,;}]+)/i);if(i?.[1])return GD(i[1],false)}}function UY(e){try{let t=JSON.parse(e);return vn(t)?t:void 0}catch{return}}function vR(e){if(Array.isArray(e)){for(let t of e){let n=vR(t);if(n)return n}return}if(vn(e)){for(let[t,n]of Object.entries(e)){let r=t.toLowerCase().replace(/[-_]/g,"");if(r==="retryafterms"||r==="retryafter")return {value:n,key:r}}for(let t of Object.values(e)){let n=vR(t);if(n)return n}}}function GD(e,t){if(typeof e=="number"&&Number.isFinite(e)&&e>=0)return t?e:Math.round(e*1e3);if(typeof e!="string"||!e.trim())return;let n=Number(e);if(Number.isFinite(n)&&n>=0)return t?n:Math.round(n*1e3);if(t)return;let r=Date.parse(e);return Number.isFinite(r)?Math.max(0,r-Date.now()):void 0}function zD(e){let t=xY(e),n=[],r=null,o=0,i=[],s=[],a,d=false;for(let c of t.events){if(XD(c))continue;let l=typeof c.type=="string"?c.type:void 0;if(l){if(l==="text"){let u=vn(c.part)?c.part:void 0,p=typeof u?.text=="string"?u.text:void 0;p?.trim()&&n.push(p.trim());continue}if(l==="result"){typeof c.result=="string"&&(r=c.result);continue}if(l==="tool_use"){o++;continue}if(l==="error"){i.push(c),s.push(OR(c));continue}if(l==="step_finish"){d=true;let u=vn(c.part)?c.part:void 0;a=typeof u?.reason=="string"?u.reason:void 0;}}}return {...t,texts:n,resultText:r,toolUseCount:o,errorEvents:i,errorMessages:s,terminalReason:a,hasTerminal:d}}function QD(e){return (e??"unknown").trim().toLowerCase().replace(/_/g,"-")}function BY(){return new W("OpenCode returned no assistant output.",Po,{code:"EMPTY_OUTPUT",kind:"transient"})}function FY(){return new W("OpenCode emitted malformed JSON output.",Po,{code:"PROVIDER_CRASHED",kind:"transient"})}function HY(e,t){switch(QD(e)){case "length":return new W("OpenCode stopped because the context window was exceeded.",Po,{code:"UNKNOWN",kind:"permanent"});case "content-filter":return new W("OpenCode stopped because the content filter blocked the response.",Po,{code:"UNKNOWN",kind:"permanent"});case "error":return new W(`${JD} while generating a response.`,Po,{code:"PROVIDER_CRASHED",kind:"transient"});default:return null}}var kY,Po,JD,SY,bY,vY,qD,o_,CY,i_,s_=U(()=>{h();gs();ER();vc();Ou();pd();SR();t_();kY=new Set(["step_start","step_finish"]),Po="cli/opencode",JD="OpenCode provider error",SY=240,bY="Follow the instructions provided on standard input.",vY=3e5,CY={build:{agent:"build",autoApprove:false},"build-auto":{agent:"build",autoApprove:true},plan:{agent:"plan",autoApprove:false},"plan-auto":{agent:"plan",autoApprove:true}};i_={command:"opencode",prepare:PY,meta:{displayName:"OpenCode",capabilities:{resume:true}},buildArgs(e,t,n){let r=t.additionalArgs,o=r!==void 0?[...r]:["run"];oi(o,"--format")||o.push("--format","json"),oi(o,"--thinking")||o.push("--thinking"),!oi(o,"--standalone")&&!oi(o,"--server")&&o.push("--standalone"),t.resumeSessionId&&!oi(o,"-s")&&!oi(o,"--session")&&o.push("-s",t.resumeSessionId);let{agent:i,autoApprove:s}=OY(t.mode);oi(o,"--agent")||i!==void 0&&o.push("--agent",i),s&&!oi(o,"--auto")&&o.push("--auto");let a=oi(o,"--model")||oi(o,"-m");if(t.model&&!a){let d=t.effort?`${t.model}#${t.effort}`:t.model;o.push("--model",d);}else t.effort&&!t.model&&!a&&console.debug("[opencode] ignoring effort because no model is configured");return o.push(bY),{args:o,stdinMessage:e,env:Lc()}},extractText(e){let t=zD(e),n=t.errorEvents[0];if(n)throw WD(n);let r=HY(t.terminalReason??"");if(r)throw r;let o=t.texts.length>0?t.texts[t.texts.length-1]:void 0;if(o!==void 0)return o;if(t.resultText?.trim())return t.resultText;if(t.malformed)throw FY();let i=QD(t.terminalReason);if(t.hasTerminal&&i==="tool-calls"&&t.toolUseCount>0)return "";throw BY()},interpretExit(e,t,n=""){if(e===0)return null;let o=zD(n).errorEvents[0];return o?WD(o):null},parseResultMeta(e){let t=sa(e);return t?{usage:{inputTokens:t.inputTokens,outputTokens:t.outputTokens,cachedInputTokens:t.cachedInputTokens,costUsd:0},model:null}:{usage:null,model:null}},parseEvent(e,t,n){let r=t??new Date().toISOString(),o=[],i=new Map,s;try{JSON.parse(e),s=[e];}catch{s=KD(e),s.length>1&&console.warn("[opencode] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let a of s){let d;try{d=JSON.parse(a);}catch{continue}let c=fo(d,r),l=d.type;if(XD(d)){let u=NY(d);if(!u)continue;let p=vn(d.part)?d.part:void 0,f=typeof p?.id=="string"?p.id:typeof d.id=="string"?d.id:void 0,g=u;if(f){let y=`opencode.reasoning:${f}`,_=n?.state.get(y),A=typeof _=="string"?_:i.get(f);if(typeof A=="string"&&(A===u||A.startsWith(u))||typeof A=="string"&&u.startsWith(A)&&(g=u.slice(A.length).trim(),!g))continue;i.set(f,u),n?.state.set(y,u);}o.push({timestamp:c,type:"thinking",content:g});continue}if(l){if(l==="text"){let p=d.part?.text;p&&o.push({timestamp:c,type:"text",content:p});continue}if(l==="tool_use"){let u=d.part;if(!u)continue;let p=String(u.tool||""),f=String(u.callID||u.id||""),g=u.state,y=String(g?.status||""),_=g?.input,A=ti(_);if(o.push({timestamp:c,type:"tool_use",toolName:p,toolUseId:f,toolInput:A}),y==="completed"&&g?.output!==void 0){let I=g.output,w=typeof I=="string"?I:JSON.stringify(I);o.push({timestamp:c,type:"tool_result",toolUseId:f,resultPreview:w,isError:false});}else y==="error"&&o.push({timestamp:c,type:"tool_result",toolUseId:f,resultPreview:String(g?.error||"tool error"),isError:true});continue}if(l==="error"){let u=OR(d);o.push({timestamp:c,type:"error",content:u,errorMessage:u});continue}}}return o},suppressOutputLine(e){let t=e.trim();if(!t.startsWith("{")||!t.endsWith("}"))return false;try{let r=JSON.parse(t).type;return r?kY.has(r):!1}catch{return false}}};});function ZD(e,t){if(e===void 0||e==="")return t;let n=parseInt(e,10);return Number.isNaN(n)?t:n}function PR(e=process.env){let t=e.CREWX_TIMEOUT_IDLE;if(t===void 0||t==="")return;let n=parseInt(t,10);if(!(!Number.isFinite(n)||n<=0))return n}function eL(e=process.env){return {queryMs:ZD(e.CREWX_TIMEOUT_QUERY,288e5),executeMs:ZD(e.CREWX_TIMEOUT_EXECUTE,288e5),idleMs:PR(e)??6e5}}var gg=U(()=>{h();});function Lu(e,t){return e.some(n=>n===t||n.startsWith(`${t}=`))}function qY(e,t){return e&&tL.has(e)||Lu(t,"--dangerously-skip-permissions")?true:t.some((n,r)=>{let o=n==="--mode"?t[r+1]:n.startsWith("--mode=")?n.slice(7):void 0;return typeof o=="string"&&tL.has(o)})}function WY(e,t){let n=[];for(let r=0;r<e.length;r+=1){let o=e[r],i=[...t].find(s=>o===s||o.startsWith(`${s}=`));i?o===i&&r+1<e.length&&(r+=1):n.push(o);}return n}function GY(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e[n],o=r.indexOf("="),i=o>0?r.slice(0,o):r;if(!$Y.has(i)){t.push(r);continue}r===i&&n+1<e.length&&!e[n+1].startsWith("-")&&(n+=1);}return t}function ii(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function zY(e,t){if(!(e?jY.has(e)||Ri(NR).some(i=>i.id===e):false)||!e)return t;let r=zr(NR,e),o=rd(NR)[e]?.defaultEffort;if(r.length!==0)return t?r.includes(t)?t:o&&r.includes(o)?o:void 0:o}function aa(e){return typeof e=="number"&&Number.isSafeInteger(e)&&e>=0?e:void 0}function LR(e){return e.kind==="step_update"?typeof e.step.conversation_id=="string"?e.step.conversation_id:void 0:typeof e.envelope.conversation_id=="string"?e.envelope.conversation_id:void 0}function MR(e){return e.step.step_index}function kn(e){if(typeof e!="string")return;let t=e.split(/\r?\n/,1)[0]?.trim();return t&&cd(t)?.slice(0,500).trim()||void 0}function JY(e,t){let n=(e??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&VY.has(n))return n;let r=`${n} ${t??""}`.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)/,/invalid (?:flag|option)/].some(i=>i.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 KY(e){return e==="AUTH_REQUIRED"||e==="TIMEOUT_IDLE"||e==="TIMEOUT_TOTAL"||e==="TIMEOUT_RESUME"||e==="PROVIDER_CRASHED"?"permanent":e==="MODEL_UNAVAILABLE"||e==="INVALID_PROVIDER_FORMAT"||e==="PROVIDER_NOT_FOUND"?"config":"transient"}function oL(e){let t=ii(e)?e:void 0,n=t&&ii(t.error)?t.error:void 0,r=t?kn(t.code)??kn(t.error_code)??kn(n?.code)??kn(n?.error_code):void 0,o=typeof e=="string"?kn(e):t?kn(t.message)??kn(t.error)??kn(t.reason)??kn(n?.message)??kn(n?.error)??kn(n?.reason):void 0,i=JY(r,o),s=t?aa(t.retry_after_ms)??aa(t.retryAfterMs)??aa(n?.retry_after_ms)??aa(n?.retryAfterMs):void 0;return {code:i,kind:KY(i),message:o??"Antigravity reported a terminal error.",...s===void 0?{}:{retryAfterMs:s}}}function d_(e){let t=oL(e);return new W(t.message,"cli/antigravity",{code:t.code,kind:t.kind,...t.retryAfterMs===void 0?{}:{retryAfterMs:t.retryAfterMs}})}function UR(e){return new W(e,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function XY(e){let t=new TextEncoder().encode(e).byteLength;if(!(t<=DR))throw new W(`Input is too large: final provider initial input is ${t} UTF-8 bytes; budget is ${DR} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function xR(){return new W("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 c_(e){if(e.kind==="result"||e.kind==="legacy_result")return e.result}function l_(e){for(let t=e.length-1;t>=0;t-=1){let n=e[t];if(n&&(n.kind==="result"||n.kind==="legacy_result"||n.kind==="agy_error"))return {event:n,index:t}}}function YY(e){let t=l_(e);if(!t||t.event.kind==="agy_error"||t.index!==e.length-1||c_(t.event)?.status!=="SUCCESS"||a_(e))return false;let r=new Map;for(let o of e){if(o.kind!=="step_update"||o.step.step_type!=="agent_response")continue;let i=LR(o),s=MR(o);!i||!Number.isSafeInteger(s)||r.set(JSON.stringify([i,s]),o.step);}if(r.size===0)return false;for(let o of r.values())if(o.state!=="DONE"||!ii(o.usage)||aa(o.usage.input_tokens)===void 0||aa(o.usage.output_tokens)===void 0)return false;return true}function QY(e,t){for(let n=t-1;n>=0;n-=1){let r=e[n];if(r?.kind==="agy_error")return r.error}}function ZY(e,t){return ii(e)&&ii(t)?{...t,...e}:ii(e)&&typeof t=="string"?{...e,message:t}:typeof e=="string"&&ii(t)?{...t,message:e}:e??t}function e6(e){let t=Array.isArray(e.denied_actions)?e.denied_actions:[],n=[];for(let s of t){let a=ii(s)?s:void 0,d=typeof s=="string"?kn(s):kn(a?.display_name)??kn(a?.action);d&&!n.includes(d)&&n.length<5&&n.push(d.slice(0,80));}let r=Math.max(0,t.length-n.length),o=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"",i=`Permission denied: Antigravity blocked ${t.length} requested action${t.length===1?"":"s"}${o}.`;return new W("Could not run because of permissions.","cli/antigravity",{code:"UNKNOWN",kind:"permanent",providerReason:i})}function a_(e){let t=l_(e);if(!t)return;if(t.event.kind==="agy_error")return d_(t.event.error);let n=c_(t.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return e6(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return UR("Antigravity returned a result with an unsupported status.");let r=n.error,o=ZY(r==null||r===""?n:r,QY(e,t.index));return d_(o)}function iL(e){if(typeof e=="string")return e;if(e!=null)try{return JSON.stringify(e)}catch{return}}function t6(e){return `agy:${String(e.conversation_id)}:${String(e.step_index)}`}function n6(e,t){let n=typeof t?.name=="string"?t.name:e.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function sL(e){let t=iL(e);if(t)return t.length<=2e3?t:`${t.slice(0,1999)}\u2026`}function r6(e){let t=ii(e)?e:void 0,n=t&&ii(t.error)?t.error:void 0,r=typeof e=="string"?e.trim().match(/^([A-Z][A-Z0-9_]*)(?:[:\s]|$)/)?.[1]:void 0,o=(kn(t?.type)??kn(t?.code)??kn(t?.error_type)??kn(n?.type)??kn(n?.code)??kn(n?.error_type)??kn(r)??"TOOL_ERROR").slice(0,60),i=oL(e).message.slice(0,250);return sL({type:o,message:i})??"Antigravity reported a tool error."}function nL(e,t){return e?e.state.has(t)?true:(e.state.set(t,true),false):false}function rL(e,t){return {timestamp:e,type:"error",content:t.message,errorMessage:t.message,isError:true}}var NR,jY,$Y,tL,DR,VY,BR,FR=U(()=>{h();gs();gg();lg();ra();uo();Pu();$y();yR();NR="antigravity",jY=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),$Y=new Set(["--conversation","--resume","--continue"]),tL=new Set(["bypassPermissions","agent-full-access","yolo"]),DR=18e4,VY=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"]);BR={command:"agy",maxInitialInputBytes:DR,meta:{displayName:"Antigravity",models:Ww(),defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(e){let t=Su(e);if(t?.kind!=="init")return null;let n=t.envelope.conversation_id;return typeof n=="string"&&n.trim().length>0?n.trim():null},buildArgs(e,t,n){XY(e);let{model:r,effort:o}=ms(t.model),i=gu(r),s=i.model,a=t.effort??o??i.effort,d=zY(s,a),c=t.additionalArgs??[],l=GY(WY(c,new Set(["--input-format","--output-format"]))),u=s&&!Lu(c,"--model")?["--model",s]:[],p=Lu(c,"--effort")?[]:wD(d),f=Lu(c,"--mode")||Lu(c,"--dangerously-skip-permissions")?[]:TD(t.mode),g=qY(t.mode,c)||Lu(c,"--settings")?[]:["--settings",JSON.stringify({permissions:{allow:bD(t.builtinAllow)}})],y=typeof t.resumeSessionId=="string"&&t.resumeSessionId.trim().length>0?["--conversation",t.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...u,...p,...f,...y,...g,...l],stdinMessage:`${JSON.stringify({event:"user",message:{content:e}})}
42
42
  `,env:{AGY_CLI_DISABLE_AUTO_UPDATE:"true"}}},extractText(e){let t=bu(e),n=l_(t)?.event,r=a_(t);if(r)throw r;let o=n?c_(n):void 0;if(o){if(o.status!=="SUCCESS")throw UR("Antigravity returned a result with an unsupported status.");if(typeof o.response!="string")throw UR("Antigravity returned a successful result without a response string.");if(!o.response.trim())throw xR();return o.response}if(t.length>0)throw xR();let i=e.trim();if(!i)throw xR();return i},extractPartialText(e){let t=bu(e),n=l_(t)?.event;if(!n||n.kind==="agy_error")return;let r=c_(n);return r&&typeof r.response=="string"&&r.response.trim()?r.response:void 0},interpretExit(e,t,n){let r=bu(n??""),o=a_(r);return o||(e!==0&&t.trim()?d_(t):null)},parseResultMeta(e){let t=bu(e),n=0,r=0,o=0,i=0,s=new Set;for(let d of t){if(d.kind!=="step_update"||d.step.state!=="DONE"||!ii(d.step.usage))continue;let c=LR(d),l=MR(d);if(!c||!Number.isSafeInteger(l))continue;let u=JSON.stringify([c,l]);if(s.has(u))continue;let p=d.step.usage,f=aa(p.input_tokens),g=aa(p.output_tokens);if(f===void 0||g===void 0)continue;s.add(u);let y=aa(p.cache_read_tokens)??0;n+=f+y,r+=g,o+=y,i+=1;}return {usage:i===0?null:{inputTokens:n,outputTokens:r,cachedInputTokens:o,costUsd:0,complete:YY(t)},model:null}},parseEvent(e,t,n){let r=Su(e);if(!r)return [];let o=t??new Date().toISOString();if(r.kind==="agy_error")return [rL(o,d_(r.error))];if(r.kind==="legacy_result"||r.kind==="result"){let f=a_([r]);return f?[rL(o,f)]:[]}if(r.kind!=="step_update")return [];let{step:i}=r,s=LR(r)??"unknown",a=MR(r),d=`${s}:${a}`;if((i.state==="DONE"||i.state==="ERROR")&&nL(n,`antigravity:terminal:${d}`))return [];if(i.step_type==="agent_response")return typeof i.text_delta=="string"&&i.text_delta.length>0?[{timestamp:o,type:"text",content:i.text_delta}]:[];if(i.step_type!=="tool")return [];let c=ii(i.tool_info)?i.tool_info:void 0,l=n6(i,c);if(!l)return [];let u=t6(i);if(i.state==="ACTIVE"){if(nL(n,`antigravity:active:${d}`))return [];let f=iL(c?.parameters);return [{timestamp:o,type:"tool_use",toolName:l,toolUseId:u,...f===void 0?{}:{toolInput:f}}]}let p=i.state==="ERROR"?r6(c?.error):sL(c?.output);return [{timestamp:o,type:"tool_result",toolName:l,toolUseId:u,...p===void 0?{}:{resultPreview:p},...i.state==="ERROR"?{isError:true}:{}}]}};});var aL,dL=U(()=>{h();Cu();Ou();ud();pd();aL={parseEvent(e,t){let n;try{n=JSON.parse(e);}catch{return []}let r=n.type;if(!r)return [];if(r!=="message"&&r!=="tool_use"&&r!=="tool_result")return [];let o=fo(n,t??new Date().toISOString());if(r==="message"){if(n.role!=="assistant")return [];let s=n.content;return s?[{timestamp:o,type:"text",content:s}]:[]}if(r==="tool_use"){let i=String(n.tool_name||""),s=n.tool_id,a=n.parameters,d=ti(a);return /^bash$/i.test(i)&&ki(d)?[Si(o,d,s)]:[{timestamp:o,type:"tool_use",toolName:i,toolUseId:s,toolInput:d}]}if(r==="tool_result"){let i=n.tool_id,s=String(n.output??""),a=n.status!=="success";return [{timestamp:o,type:"tool_result",toolUseId:i,...Oo(s,a)}]}return []}};});function Mu(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Uu(e){return Mu(e)?e:void 0}function go(e){return typeof e=="string"?e:void 0}function Fc(e){let t=typeof e=="number"?e:Number(e??0);return Number.isFinite(t)?t:0}function p6(e){let t=[],n=-1,r=0,o=false,i=false;for(let s=0;s<e.length;s+=1){let a=e[s];if(n===-1){(a==="{"||a==="[")&&(n=s,r=1);continue}if(i){i=false;continue}if(a==="\\"&&o){i=true;continue}if(a==='"'){o=!o;continue}o||(a==="{"||a==="["?r+=1:(a==="}"||a==="]")&&(r-=1,r===0&&(t.push(e.slice(n,s+1)),n=-1)));}return n!==-1&&t.push(e.slice(n)),t}function hg(e){let t=e.trim();if(!t)return [];try{let n=JSON.parse(t);return Mu(n)?[n]:[]}catch{return p6(t).flatMap(n=>{try{let r=JSON.parse(n);return Mu(r)?[r]:[]}catch{return []}})}}function hL(e){let t=JSON.stringify(e);return t===void 0?String(e):t}function Bc(e){if(typeof e=="string")return e;if(Array.isArray(e)){let t=e.map(Bc).filter(n=>n!==void 0);return t.length>0?t.join(`
43
43
  `):void 0}if(Mu(e)){if(typeof e.text=="string")return e.text;if(typeof e.message=="string")return e.message;if(typeof e.error=="string")return e.error;if(e.type==="text"&&typeof e.data=="string")return e.data;for(let t of ["content","FileContent","rawOutput"]){let n=Bc(e[t]);if(n!==void 0)return n}}}function f6(e){let t=s=>Array.isArray(s)&&s.every(a=>Number.isInteger(a)&&a>=0&&a<=255),n=s=>typeof s=="string"&&s.trim().length>0?s:void 0,r=s=>new TextDecoder("utf-8",{fatal:false}).decode(Uint8Array.from(s)),o=s=>{let a=JSON.stringify(s,(d,c)=>t(c)?`<bytes:${c.length}>`:c);return a===void 0?String(s):a},i=e.rawOutput;if(i!=null){let s=Uu(i);if(!s)return n(Bc(i))??o(i);let a;if(t(s.output)&&s.output.length>0&&(a=n(r(s.output))),!a&&t(s.stdout)&&s.stdout.length>0&&(a=n(r(s.stdout))),!a){let l=Uu(s.Result);a=n(s.output)??n(l?.output)??n(Bc(i));}let d=t(s.stderr)&&s.stderr.length>0?r(s.stderr):void 0;if(d!==void 0)if(a){let l=a.endsWith(`
44
44
  `)||a.endsWith("\r")?"":`
@@ -81,7 +81,7 @@ ${r.join(`
81
81
  time_created = excluded.time_created,
82
82
  time_updated = excluded.time_updated
83
83
  `);r.transaction(i=>{for(let c of i)o.run(c);})(n);}finally{r.close();}}function gh(t){if(!t)return [];let e=[];for(let n=0;n<t.length;n+=1){let r=t[n];if(r==="-s"||r==="--session"){let o=t[n+1],s=o!==void 0&&!o.startsWith("-");e.push({sessionId:s?o:void 0}),s&&(n+=1);continue}(r.startsWith("--session=")||r.startsWith("-s="))&&e.push({sessionId:r.slice(r.indexOf("=")+1)||void 0});}return e}function hh(t){if(!t)return;let e=[];for(let n=0;n<t.length;n+=1){let r=t[n];if(r==="-s"||r==="--session"){t[n+1]!==void 0&&!t[n+1].startsWith("-")&&(n+=1);continue}r.startsWith("--session=")||r.startsWith("-s=")||e.push(r);}return e}function Po(t){let e=hh(t.additionalArgs);return {...t,...e===void 0?{}:{additionalArgs:e},resumeSessionId:void 0}}function mh(t,e){try{return !!t.prepare("SELECT id FROM session_v2 WHERE id = ?").get(e)}catch(n){if(n instanceof Error&&/no such table: session_v2/i.test(n.message))return false;throw n}}function kh(t,e,n){let r=new t(e,{readonly:true,fileMustExist:true});try{return mh(r,n)}finally{r.close();}}async function gi(t,e={}){let n;try{n=await(e.loadSqlite??dh)();}catch{throw new G("OpenCode isolation requires the optional better-sqlite3 dependency. Install it and retry.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}let r=e.crewxHome??Do(),o=br(r),s=Cr(r),i=ch(s),c=uh(e.userDataHome),d=ph(n,c);if(d.length>0){if(!Ou(n,i))try{await(e.initializeDatabase??_h)(o);}catch{throw new G("Could not initialize the isolated OpenCode credential database.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}if(!Ou(n,i))throw new G("The isolated OpenCode credential database is unavailable.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"});try{fh(n,i,d);}catch{throw new G("Could not copy API-key credentials into the isolated OpenCode database.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}}let u=gh(t.additionalArgs),l=u.map(_=>_.sessionId),p=u.length>0?l[l.length-1]:t.resumeSessionId;if(!p)return u.length>0?Po(t):t;if(l.some(_=>_!==p)||!existsSync(i))return Po(t);try{return kh(n,i,p)?{...t,resumeSessionId:p}:Po(t)}catch{throw new G("Could not read the isolated OpenCode session database safely.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}}var hi=C(()=>{g();Xt();_i();Nu();});function yn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}async function mi(){let t;try{let n=(await import('better-sqlite3')).default,r=join(Cr(),"opencode.db");t=new n(r,{readonly:!0,fileMustExist:!0});let o=t.prepare("SELECT value FROM kv WHERE key = ?").get("models-dev:v2:catalog");if(!o||typeof o.value!="string")throw new Error("OpenCode model catalog row is unavailable");let s=JSON.parse(o.value);if(!yn(s))throw new Error("OpenCode model catalog shape is unavailable");let i=typeof s.body=="string"?JSON.parse(s.body):s.body;if(!yn(i))throw new Error("OpenCode model catalog body shape is unavailable");let c=new Map;for(let[d,u]of Object.entries(i)){if(!d||!yn(u)||!yn(u.models))throw new Error("OpenCode model provider shape is unavailable");for(let[l,p]of Object.entries(u.models)){if(!l||!yn(p))throw new Error("OpenCode model shape is unavailable");let _=p.capabilities;if(_===void 0)continue;if(!yn(_))throw new Error("OpenCode model capability shape is unavailable");let h=_.reasoning;if(h===void 0)continue;if(!yn(h))throw new Error("OpenCode reasoning capability shape is unavailable");let m=h.effort;(m===void 0||Array.isArray(m)&&m.every(k=>typeof k=="string"))&&c.set(`${d}/${l}`,Array.isArray(m)?m:[]);}}return c}catch{return console.debug("[opencode] could not read private model effort catalog; omitting effort choices"),new Map}finally{try{t?.close();}catch{}}}var bu=C(()=>{g();yi();wu();Su();_i();hi();Yt();});function Ih(t){return t?Sh[t]??{agent:"build",autoApprove:false}:{agent:void 0,autoApprove:false}}function Qe(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function Ah(){let t;try{t=Cr();}catch{return mi().catch(()=>new Map)}let e=Date.now();if(Cu===t&&Lo&&Lo.expiresAt>e)return Lo.result;Cu=t;let n=mi().catch(()=>new Map);return Lo={expiresAt:e+Rh,result:n},n}async function Nh(t){let e=await gi(t),n=t.additionalArgs??[],r=Qe(n,"--model")||Qe(n,"-m");if(!t.model||!t.effort||r)return e;let o=(await Ah()).get(t.model);return !o||o.includes(t.effort)?e:(console.debug("[opencode] requested effort is not listed for this model; using OpenCode default"),{...e,effort:void 0})}function Mu(t){let e=[],n=0,r=false,o=false,s=0;for(let c=0;c<t.length;c++){let d=t[c];if(o){o=false;continue}if(d==="\\"&&r){o=true;continue}if(d==='"'){r=!r;continue}if(!r){if(d==="{")n++;else if(d==="}"&&(n--,n===0)){let u=t.slice(s,c+1).trim();u&&e.push(u),s=c+1;}}}let i=t.slice(s).trim();return i&&e.push(i),e}function ce(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function $u(t){let e=ce(t.part)?t.part:void 0;return t.type==="reasoning"||e?.type==="reasoning"}function Oh(t){let e=ce(t.part)?t.part:void 0;return (typeof e?.text=="string"?e.text:typeof t.text=="string"?t.text:void 0)?.trim()||void 0}function vh(t){let e=[],n=false;for(let r of t.split(/\r?\n/)){let o=r.trim();if(!o)continue;try{let i=JSON.parse(o);ce(i)?e.push(i):n=!0;continue}catch{}let s=Mu(o);s.length>1&&console.warn("[opencode] extractText: falling back to concatenated-JSON split for a malformed line");for(let i of s)try{let c=JSON.parse(i);ce(c)?e.push(c):n=!0;}catch{n=true;}}return {events:e,malformed:n}}function Ei(t){let e=ce(t.error)?t.error:void 0,n=e&&ce(e.data)?e.data:void 0,r=Hu(e),o=Ye(e?.name),s=Ye(n?.message)??Ye(e?.message)??Ti(r)??Ye(t.message)??Ye(t.errorMessage)??Ye(t.error),i=Ye(t.ref),c=o&&s&&o!==s?`${o}: ${s}`:o??s??Lu;return (i?`${c} (ref: ${i})`:c).slice(0,wh)}function xu(t){let e=ce(t.error)?t.error:void 0,n=typeof e?.type=="string"?e.type:void 0,r=typeof e?.status=="number"?e.status:Number(e?.status),o=Ei(t),s=Hu(e),i=s&&ce(s.error)?s.error:void 0,c=typeof i?.type=="string"?i.type:void 0,d=[o,Ti(s)].filter(Boolean).join(`
84
- `);if(r===402||bh(d))return new G(`OpenCode subscription is required: ${o}`,je,{code:"SUBSCRIPTION_REQUIRED",kind:"config",providerReason:Or(o)});if(r===403&&(c==="RegionError"||c==="FreeTierError"))return new G(`OpenCode account settings are required: ${o}`,je,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:"access",providerReason:Or(o)});if(n==="provider.auth"||r===401||r===403)return new G(`OpenCode authentication is required: ${o}`,je,{code:"AUTH_REQUIRED",kind:"config"});if(r===410||c==="ModelDeprecated")return new G(`OpenCode model has been retired: ${o}`,je,{code:"MODEL_RETIRED",kind:"config",replacementModel:Ch(s,e,t),providerReason:Or(o)});if(n==="provider.free-limit"||r===429){let u=xh(e);return new G(`OpenCode rate limit reached: ${o}`,je,{code:"RATE_LIMITED",kind:"transient",...u===void 0?{}:{retryAfterMs:u}})}if(n==="provider.no-route")return new G(`OpenCode model or variant unavailable: ${o}`,je,{code:"MODEL_UNAVAILABLE",kind:"config"});if(n==="provider.invalid-request"&&r===400){let u=[o,Ti(s)].filter(h=>h!==void 0),l=u.find(h=>/requires global regions/i.test(h)),p=u.find(h=>/trains on request data/i.test(h)),_=l?"region":p?"training_consent":void 0;if(_)return new G(`OpenCode account settings are required: ${o}`,je,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:_,providerReason:Or(l??p)})}return new G(`OpenCode error: ${o}`,je,{code:"PROVIDER_CRASHED",kind:"transient"})}function Hu(t){let n=(t&&ce(t.response)?t.response:void 0)?.body;if(ce(n))return n;if(typeof n=="string")try{let r=JSON.parse(n);return ce(r)?r:void 0}catch{return}}function Ti(t){let e=t&&ce(t.error)?t.error:void 0;return Ye(e?.message)??Ye(t?.message)}function bh(t){return /insufficient\s+(?:balance|account funds)|credit\s+limit\s+exceeded|payment\s+required|account invoice is overdue|billing_error|please add or update your payment method|(?:GLM Coding Plan|enterprise) package has expired|your current subscription plan does not yet include access to/i.test(t)}function Ch(t,e,n){let r=t&&ce(t.metadata)?t.metadata:void 0,o=typeof r?.replacement=="string"?r.replacement.trim():void 0;if(!o)return;let s=[r?.model,e?.model,n.model,n.modelID].find(d=>typeof d=="string"&&d.trim().length>0)?.trim(),i=s&&s.includes("/")?s.slice(0,s.indexOf("/")):"opencode-go",c=o.includes("/")?o:`${i}/${o}`;return /^[A-Za-z0-9._/-]{1,128}$/.test(c)?c:void 0}function xh(t){let e=t?.retryAfterMs;if(typeof e=="number"&&Number.isFinite(e)&&e>=0)return e;let r=(t&&ce(t.response)?t.response:void 0)?.body,o=typeof r=="string"?Dh(r):ce(r)?r:void 0;if(o){let s=wi(o);if(s)return Du(s.value,s.key==="retryafterms")}if(typeof r=="string"){let s=r.match(/retry[-_]after(?:\s*[:=]\s*|\s+)["']?([^"'\s,;}]+)/i);if(s?.[1])return Du(s[1],false)}}function Dh(t){try{let e=JSON.parse(t);return ce(e)?e:void 0}catch{return}}function wi(t){if(Array.isArray(t)){for(let e of t){let n=wi(e);if(n)return n}return}if(ce(t)){for(let[e,n]of Object.entries(t)){let r=e.toLowerCase().replace(/[-_]/g,"");if(r==="retryafterms"||r==="retryafter")return {value:n,key:r}}for(let e of Object.values(t)){let n=wi(e);if(n)return n}}}function Du(t,e){if(typeof t=="number"&&Number.isFinite(t)&&t>=0)return e?t:Math.round(t*1e3);if(typeof t!="string"||!t.trim())return;let n=Number(t);if(Number.isFinite(n)&&n>=0)return e?n:Math.round(n*1e3);if(e)return;let r=Date.parse(t);return Number.isFinite(r)?Math.max(0,r-Date.now()):void 0}function Pu(t){let e=vh(t),n=[],r=null,o=0,s=[],i=[],c,d=false;for(let u of e.events){if($u(u))continue;let l=typeof u.type=="string"?u.type:void 0;if(l){if(l==="text"){let p=ce(u.part)?u.part:void 0,_=typeof p?.text=="string"?p.text:void 0;_?.trim()&&n.push(_.trim());continue}if(l==="result"){typeof u.result=="string"&&(r=u.result);continue}if(l==="tool_use"){o++;continue}if(l==="error"){s.push(u),i.push(Ei(u));continue}if(l==="step_finish"){d=true;let p=ce(u.part)?u.part:void 0;c=typeof p?.reason=="string"?p.reason:void 0;}}}return {...e,texts:n,resultText:r,toolUseCount:o,errorEvents:s,errorMessages:i,terminalReason:c,hasTerminal:d}}function Uu(t){return (t??"unknown").trim().toLowerCase().replace(/_/g,"-")}function Ph(){return new G("OpenCode returned no assistant output.",je,{code:"EMPTY_OUTPUT",kind:"transient"})}function Lh(){return new G("OpenCode emitted malformed JSON output.",je,{code:"PROVIDER_CRASHED",kind:"transient"})}function Mh(t,e){switch(Uu(t)){case "length":return new G("OpenCode stopped because the context window was exceeded.",je,{code:"UNKNOWN",kind:"permanent"});case "content-filter":return new G("OpenCode stopped because the content filter blocked the response.",je,{code:"UNKNOWN",kind:"permanent"});case "error":return new G(`${Lu} while generating a response.`,je,{code:"PROVIDER_CRASHED",kind:"transient"});default:return null}}var Th,je,Lu,wh,Eh,Rh,Cu,Lo,Sh,Ri,Si=C(()=>{g();Xt();Tu();Nr();Bn();mn();bu();hi();Th=new Set(["step_start","step_finish"]),je="cli/opencode",Lu="OpenCode provider error",wh=240,Eh="Follow the instructions provided on standard input.",Rh=3e5,Sh={build:{agent:"build",autoApprove:false},"build-auto":{agent:"build",autoApprove:true},plan:{agent:"plan",autoApprove:false},"plan-auto":{agent:"plan",autoApprove:true}};Ri={command:"opencode",prepare:Nh,meta:{displayName:"OpenCode",capabilities:{resume:true}},buildArgs(t,e,n){let r=e.additionalArgs,o=r!==void 0?[...r]:["run"];Qe(o,"--format")||o.push("--format","json"),Qe(o,"--thinking")||o.push("--thinking"),!Qe(o,"--standalone")&&!Qe(o,"--server")&&o.push("--standalone"),e.resumeSessionId&&!Qe(o,"-s")&&!Qe(o,"--session")&&o.push("-s",e.resumeSessionId);let{agent:s,autoApprove:i}=Ih(e.mode);Qe(o,"--agent")||s!==void 0&&o.push("--agent",s),i&&!Qe(o,"--auto")&&o.push("--auto");let c=Qe(o,"--model")||Qe(o,"-m");if(e.model&&!c){let d=e.effort?`${e.model}#${e.effort}`:e.model;o.push("--model",d);}else e.effort&&!e.model&&!c&&console.debug("[opencode] ignoring effort because no model is configured");return o.push(Eh),{args:o,stdinMessage:t,env:br()}},extractText(t){let e=Pu(t),n=e.errorEvents[0];if(n)throw xu(n);let r=Mh(e.terminalReason??"");if(r)throw r;let o=e.texts.length>0?e.texts[e.texts.length-1]:void 0;if(o!==void 0)return o;if(e.resultText?.trim())return e.resultText;if(e.malformed)throw Lh();let s=Uu(e.terminalReason);if(e.hasTerminal&&s==="tool-calls"&&e.toolUseCount>0)return "";throw Ph()},interpretExit(t,e,n=""){if(t===0)return null;let o=Pu(n).errorEvents[0];return o?xu(o):null},parseResultMeta(t){let e=Wn(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(),o=[],s=new Map,i;try{JSON.parse(t),i=[t];}catch{i=Mu(t),i.length>1&&console.warn("[opencode] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let c of i){let d;try{d=JSON.parse(c);}catch{continue}let u=at(d,r),l=d.type;if($u(d)){let p=Oh(d);if(!p)continue;let _=ce(d.part)?d.part:void 0,h=typeof _?.id=="string"?_.id:typeof d.id=="string"?d.id:void 0,m=p;if(h){let k=`opencode.reasoning:${h}`,w=n?.state.get(k),x=typeof w=="string"?w:s.get(h);if(typeof x=="string"&&(x===p||x.startsWith(p))||typeof x=="string"&&p.startsWith(x)&&(m=p.slice(x.length).trim(),!m))continue;s.set(h,p),n?.state.set(k,p);}o.push({timestamp:u,type:"thinking",content:m});continue}if(l){if(l==="text"){let _=d.part?.text;_&&o.push({timestamp:u,type:"text",content:_});continue}if(l==="tool_use"){let p=d.part;if(!p)continue;let _=String(p.tool||""),h=String(p.callID||p.id||""),m=p.state,k=String(m?.status||""),w=m?.input,x=it(w);if(o.push({timestamp:u,type:"tool_use",toolName:_,toolUseId:h,toolInput:x}),k==="completed"&&m?.output!==void 0){let T=m.output,L=typeof T=="string"?T:JSON.stringify(T);o.push({timestamp:u,type:"tool_result",toolUseId:h,resultPreview:L,isError:false});}else k==="error"&&o.push({timestamp:u,type:"tool_result",toolUseId:h,resultPreview:String(m?.error||"tool error"),isError:true});continue}if(l==="error"){let p=Ei(d);o.push({timestamp:u,type:"error",content:p,errorMessage:p});continue}}}return o},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?Th.has(r):!1}catch{return false}}};});var qu=C(()=>{g();});function jn(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function Bh(t,e){return t&&Bu.has(t)||jn(e,"--dangerously-skip-permissions")?true:e.some((n,r)=>{let o=n==="--mode"?e[r+1]:n.startsWith("--mode=")?n.slice(7):void 0;return typeof o=="string"&&Bu.has(o)})}function Fh(t,e){let n=[];for(let r=0;r<t.length;r+=1){let o=t[r],s=[...e].find(i=>o===i||o.startsWith(`${i}=`));s?o===s&&r+1<t.length&&(r+=1):n.push(o);}return n}function Wh(t){let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],o=r.indexOf("="),s=o>0?r.slice(0,o):r;if(!Uh.has(s)){e.push(r);continue}r===s&&n+1<t.length&&!t[n+1].startsWith("-")&&(n+=1);}return e}function Ze(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Gh(t,e){if(!(t?Hh.has(t)||Pt(Ii).some(s=>s.id===t):false)||!t)return e;let r=Fn(Ii,t),o=si(Ii)[t]?.defaultEffort;if(r.length!==0)return e?r.includes(e)?e:o&&r.includes(o)?o:void 0:o}function Lt(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0?t:void 0}function Oi(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 vi(t){return t.step.step_index}function de(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 jh(t,e){let n=(t??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&qh.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)/,/invalid (?:flag|option)/].some(s=>s.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 zh(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 Gu(t){let e=Ze(t)?t:void 0,n=e&&Ze(e.error)?e.error:void 0,r=e?de(e.code)??de(e.error_code)??de(n?.code)??de(n?.error_code):void 0,o=typeof t=="string"?de(t):e?de(e.message)??de(e.error)??de(e.reason)??de(n?.message)??de(n?.error)??de(n?.reason):void 0,s=jh(r,o),i=e?Lt(e.retry_after_ms)??Lt(e.retryAfterMs)??Lt(n?.retry_after_ms)??Lt(n?.retryAfterMs):void 0;return {code:s,kind:zh(s),message:o??"Antigravity reported a terminal error.",...i===void 0?{}:{retryAfterMs:i}}}function $o(t){let e=Gu(t);return new G(e.message,"cli/antigravity",{code:e.code,kind:e.kind,...e.retryAfterMs===void 0?{}:{retryAfterMs:e.retryAfterMs}})}function bi(t){return new G(t,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function Kh(t){let e=new TextEncoder().encode(t).byteLength;if(!(e<=Ni))throw new G(`Input is too large: final provider initial input is ${e} UTF-8 bytes; budget is ${Ni} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function Ai(){return new G("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 Ho(t){if(t.kind==="result"||t.kind==="legacy_result")return t.result}function Uo(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 Jh(t){let e=Uo(t);if(!e||e.event.kind==="agy_error"||e.index!==t.length-1||Ho(e.event)?.status!=="SUCCESS"||Mo(t))return false;let r=new Map;for(let o of t){if(o.kind!=="step_update"||o.step.step_type!=="agent_response")continue;let s=Oi(o),i=vi(o);!s||!Number.isSafeInteger(i)||r.set(JSON.stringify([s,i]),o.step);}if(r.size===0)return false;for(let o of r.values())if(o.state!=="DONE"||!Ze(o.usage)||Lt(o.usage.input_tokens)===void 0||Lt(o.usage.output_tokens)===void 0)return false;return true}function Vh(t,e){for(let n=e-1;n>=0;n-=1){let r=t[n];if(r?.kind==="agy_error")return r.error}}function Xh(t,e){return Ze(t)&&Ze(e)?{...e,...t}:Ze(t)&&typeof e=="string"?{...t,message:e}:typeof t=="string"&&Ze(e)?{...e,message:t}:t??e}function Yh(t){let e=Array.isArray(t.denied_actions)?t.denied_actions:[],n=[];for(let i of e){let c=Ze(i)?i:void 0,d=typeof i=="string"?de(i):de(c?.display_name)??de(c?.action);d&&!n.includes(d)&&n.length<5&&n.push(d.slice(0,80));}let r=Math.max(0,e.length-n.length),o=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"",s=`Permission denied: Antigravity blocked ${e.length} requested action${e.length===1?"":"s"}${o}.`;return new G("\uAD8C\uD55C \uB54C\uBB38\uC5D0 \uC2E4\uD589\uD558\uC9C0 \uBABB\uD588\uC5B4\uC694","cli/antigravity",{code:"UNKNOWN",kind:"permanent",providerReason:s})}function Mo(t){let e=Uo(t);if(!e)return;if(e.event.kind==="agy_error")return $o(e.event.error);let n=Ho(e.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return Yh(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return bi("Antigravity returned a result with an unsupported status.");let r=n.error,o=Xh(r==null||r===""?n:r,Vh(t,e.index));return $o(o)}function ju(t){if(typeof t=="string")return t;if(t!=null)try{return JSON.stringify(t)}catch{return}}function Qh(t){return `agy:${String(t.conversation_id)}:${String(t.step_index)}`}function Zh(t,e){let n=typeof e?.name=="string"?e.name:t.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function zu(t){let e=ju(t);if(e)return e.length<=2e3?e:`${e.slice(0,1999)}\u2026`}function em(t){let e=Ze(t)?t:void 0,n=e&&Ze(e.error)?e.error:void 0,r=typeof t=="string"?t.trim().match(/^([A-Z][A-Z0-9_]*)(?:[:\s]|$)/)?.[1]:void 0,o=(de(e?.type)??de(e?.code)??de(e?.error_type)??de(n?.type)??de(n?.code)??de(n?.error_type)??de(r)??"TOOL_ERROR").slice(0,60),s=Gu(t).message.slice(0,250);return zu({type:o,message:s})??"Antigravity reported a tool error."}function Fu(t,e){return t?t.state.has(e)?true:(t.state.set(e,true),false):false}function Wu(t,e){return {timestamp:t,type:"error",content:e.message,errorMessage:e.message,isError:true}}var Ii,Hh,Uh,Bu,Ni,qh,Ci,xi=C(()=>{g();Xt();qu();Vs();Sr();Yt();Ar();ei();ii();Ii="antigravity",Hh=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),Uh=new Set(["--conversation","--resume","--continue"]),Bu=new Set(["bypassPermissions","agent-full-access","yolo"]),Ni=18e4,qh=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"]);Ci={command:"agy",maxInitialInputBytes:Ni,meta:{displayName:"Antigravity",models:Fc(),defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(t){let e=Er(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){Kh(t);let{model:r,effort:o}=Qt(e.model),s=ri(r),i=s.model,c=e.effort??o??s.effort,d=Gh(i,c),u=e.additionalArgs??[],l=Wh(Fh(u,new Set(["--input-format","--output-format"]))),p=i&&!jn(u,"--model")?["--model",i]:[],_=jn(u,"--effort")?[]:tu(d),h=jn(u,"--mode")||jn(u,"--dangerously-skip-permissions")?[]:eu(e.mode),m=Bh(e.mode,u)||jn(u,"--settings")?[]:["--settings",JSON.stringify({permissions:{allow:au(e.builtinAllow)}})],k=typeof e.resumeSessionId=="string"&&e.resumeSessionId.trim().length>0?["--conversation",e.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...p,..._,...h,...k,...m,...l],stdinMessage:`${JSON.stringify({event:"user",message:{content:t}})}
84
+ `);if(r===402||bh(d))return new G(`OpenCode subscription is required: ${o}`,je,{code:"SUBSCRIPTION_REQUIRED",kind:"config",providerReason:Or(o)});if(r===403&&(c==="RegionError"||c==="FreeTierError"))return new G(`OpenCode account settings are required: ${o}`,je,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:"access",providerReason:Or(o)});if(n==="provider.auth"||r===401||r===403)return new G(`OpenCode authentication is required: ${o}`,je,{code:"AUTH_REQUIRED",kind:"config"});if(r===410||c==="ModelDeprecated")return new G(`OpenCode model has been retired: ${o}`,je,{code:"MODEL_RETIRED",kind:"config",replacementModel:Ch(s,e,t),providerReason:Or(o)});if(n==="provider.free-limit"||r===429){let u=xh(e);return new G(`OpenCode rate limit reached: ${o}`,je,{code:"RATE_LIMITED",kind:"transient",...u===void 0?{}:{retryAfterMs:u}})}if(n==="provider.no-route")return new G(`OpenCode model or variant unavailable: ${o}`,je,{code:"MODEL_UNAVAILABLE",kind:"config"});if(n==="provider.invalid-request"&&r===400){let u=[o,Ti(s)].filter(h=>h!==void 0),l=u.find(h=>/requires global regions/i.test(h)),p=u.find(h=>/trains on request data/i.test(h)),_=l?"region":p?"training_consent":void 0;if(_)return new G(`OpenCode account settings are required: ${o}`,je,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:_,providerReason:Or(l??p)})}return new G(`OpenCode error: ${o}`,je,{code:"PROVIDER_CRASHED",kind:"transient"})}function Hu(t){let n=(t&&ce(t.response)?t.response:void 0)?.body;if(ce(n))return n;if(typeof n=="string")try{let r=JSON.parse(n);return ce(r)?r:void 0}catch{return}}function Ti(t){let e=t&&ce(t.error)?t.error:void 0;return Ye(e?.message)??Ye(t?.message)}function bh(t){return /insufficient\s+(?:balance|account funds)|credit\s+limit\s+exceeded|payment\s+required|account invoice is overdue|billing_error|please add or update your payment method|(?:GLM Coding Plan|enterprise) package has expired|your current subscription plan does not yet include access to/i.test(t)}function Ch(t,e,n){let r=t&&ce(t.metadata)?t.metadata:void 0,o=typeof r?.replacement=="string"?r.replacement.trim():void 0;if(!o)return;let s=[r?.model,e?.model,n.model,n.modelID].find(d=>typeof d=="string"&&d.trim().length>0)?.trim(),i=s&&s.includes("/")?s.slice(0,s.indexOf("/")):"opencode-go",c=o.includes("/")?o:`${i}/${o}`;return /^[A-Za-z0-9._/-]{1,128}$/.test(c)?c:void 0}function xh(t){let e=t?.retryAfterMs;if(typeof e=="number"&&Number.isFinite(e)&&e>=0)return e;let r=(t&&ce(t.response)?t.response:void 0)?.body,o=typeof r=="string"?Dh(r):ce(r)?r:void 0;if(o){let s=wi(o);if(s)return Du(s.value,s.key==="retryafterms")}if(typeof r=="string"){let s=r.match(/retry[-_]after(?:\s*[:=]\s*|\s+)["']?([^"'\s,;}]+)/i);if(s?.[1])return Du(s[1],false)}}function Dh(t){try{let e=JSON.parse(t);return ce(e)?e:void 0}catch{return}}function wi(t){if(Array.isArray(t)){for(let e of t){let n=wi(e);if(n)return n}return}if(ce(t)){for(let[e,n]of Object.entries(t)){let r=e.toLowerCase().replace(/[-_]/g,"");if(r==="retryafterms"||r==="retryafter")return {value:n,key:r}}for(let e of Object.values(t)){let n=wi(e);if(n)return n}}}function Du(t,e){if(typeof t=="number"&&Number.isFinite(t)&&t>=0)return e?t:Math.round(t*1e3);if(typeof t!="string"||!t.trim())return;let n=Number(t);if(Number.isFinite(n)&&n>=0)return e?n:Math.round(n*1e3);if(e)return;let r=Date.parse(t);return Number.isFinite(r)?Math.max(0,r-Date.now()):void 0}function Pu(t){let e=vh(t),n=[],r=null,o=0,s=[],i=[],c,d=false;for(let u of e.events){if($u(u))continue;let l=typeof u.type=="string"?u.type:void 0;if(l){if(l==="text"){let p=ce(u.part)?u.part:void 0,_=typeof p?.text=="string"?p.text:void 0;_?.trim()&&n.push(_.trim());continue}if(l==="result"){typeof u.result=="string"&&(r=u.result);continue}if(l==="tool_use"){o++;continue}if(l==="error"){s.push(u),i.push(Ei(u));continue}if(l==="step_finish"){d=true;let p=ce(u.part)?u.part:void 0;c=typeof p?.reason=="string"?p.reason:void 0;}}}return {...e,texts:n,resultText:r,toolUseCount:o,errorEvents:s,errorMessages:i,terminalReason:c,hasTerminal:d}}function Uu(t){return (t??"unknown").trim().toLowerCase().replace(/_/g,"-")}function Ph(){return new G("OpenCode returned no assistant output.",je,{code:"EMPTY_OUTPUT",kind:"transient"})}function Lh(){return new G("OpenCode emitted malformed JSON output.",je,{code:"PROVIDER_CRASHED",kind:"transient"})}function Mh(t,e){switch(Uu(t)){case "length":return new G("OpenCode stopped because the context window was exceeded.",je,{code:"UNKNOWN",kind:"permanent"});case "content-filter":return new G("OpenCode stopped because the content filter blocked the response.",je,{code:"UNKNOWN",kind:"permanent"});case "error":return new G(`${Lu} while generating a response.`,je,{code:"PROVIDER_CRASHED",kind:"transient"});default:return null}}var Th,je,Lu,wh,Eh,Rh,Cu,Lo,Sh,Ri,Si=C(()=>{g();Xt();Tu();Nr();Bn();mn();bu();hi();Th=new Set(["step_start","step_finish"]),je="cli/opencode",Lu="OpenCode provider error",wh=240,Eh="Follow the instructions provided on standard input.",Rh=3e5,Sh={build:{agent:"build",autoApprove:false},"build-auto":{agent:"build",autoApprove:true},plan:{agent:"plan",autoApprove:false},"plan-auto":{agent:"plan",autoApprove:true}};Ri={command:"opencode",prepare:Nh,meta:{displayName:"OpenCode",capabilities:{resume:true}},buildArgs(t,e,n){let r=e.additionalArgs,o=r!==void 0?[...r]:["run"];Qe(o,"--format")||o.push("--format","json"),Qe(o,"--thinking")||o.push("--thinking"),!Qe(o,"--standalone")&&!Qe(o,"--server")&&o.push("--standalone"),e.resumeSessionId&&!Qe(o,"-s")&&!Qe(o,"--session")&&o.push("-s",e.resumeSessionId);let{agent:s,autoApprove:i}=Ih(e.mode);Qe(o,"--agent")||s!==void 0&&o.push("--agent",s),i&&!Qe(o,"--auto")&&o.push("--auto");let c=Qe(o,"--model")||Qe(o,"-m");if(e.model&&!c){let d=e.effort?`${e.model}#${e.effort}`:e.model;o.push("--model",d);}else e.effort&&!e.model&&!c&&console.debug("[opencode] ignoring effort because no model is configured");return o.push(Eh),{args:o,stdinMessage:t,env:br()}},extractText(t){let e=Pu(t),n=e.errorEvents[0];if(n)throw xu(n);let r=Mh(e.terminalReason??"");if(r)throw r;let o=e.texts.length>0?e.texts[e.texts.length-1]:void 0;if(o!==void 0)return o;if(e.resultText?.trim())return e.resultText;if(e.malformed)throw Lh();let s=Uu(e.terminalReason);if(e.hasTerminal&&s==="tool-calls"&&e.toolUseCount>0)return "";throw Ph()},interpretExit(t,e,n=""){if(t===0)return null;let o=Pu(n).errorEvents[0];return o?xu(o):null},parseResultMeta(t){let e=Wn(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(),o=[],s=new Map,i;try{JSON.parse(t),i=[t];}catch{i=Mu(t),i.length>1&&console.warn("[opencode] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let c of i){let d;try{d=JSON.parse(c);}catch{continue}let u=at(d,r),l=d.type;if($u(d)){let p=Oh(d);if(!p)continue;let _=ce(d.part)?d.part:void 0,h=typeof _?.id=="string"?_.id:typeof d.id=="string"?d.id:void 0,m=p;if(h){let k=`opencode.reasoning:${h}`,w=n?.state.get(k),x=typeof w=="string"?w:s.get(h);if(typeof x=="string"&&(x===p||x.startsWith(p))||typeof x=="string"&&p.startsWith(x)&&(m=p.slice(x.length).trim(),!m))continue;s.set(h,p),n?.state.set(k,p);}o.push({timestamp:u,type:"thinking",content:m});continue}if(l){if(l==="text"){let _=d.part?.text;_&&o.push({timestamp:u,type:"text",content:_});continue}if(l==="tool_use"){let p=d.part;if(!p)continue;let _=String(p.tool||""),h=String(p.callID||p.id||""),m=p.state,k=String(m?.status||""),w=m?.input,x=it(w);if(o.push({timestamp:u,type:"tool_use",toolName:_,toolUseId:h,toolInput:x}),k==="completed"&&m?.output!==void 0){let T=m.output,L=typeof T=="string"?T:JSON.stringify(T);o.push({timestamp:u,type:"tool_result",toolUseId:h,resultPreview:L,isError:false});}else k==="error"&&o.push({timestamp:u,type:"tool_result",toolUseId:h,resultPreview:String(m?.error||"tool error"),isError:true});continue}if(l==="error"){let p=Ei(d);o.push({timestamp:u,type:"error",content:p,errorMessage:p});continue}}}return o},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?Th.has(r):!1}catch{return false}}};});var qu=C(()=>{g();});function jn(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function Bh(t,e){return t&&Bu.has(t)||jn(e,"--dangerously-skip-permissions")?true:e.some((n,r)=>{let o=n==="--mode"?e[r+1]:n.startsWith("--mode=")?n.slice(7):void 0;return typeof o=="string"&&Bu.has(o)})}function Fh(t,e){let n=[];for(let r=0;r<t.length;r+=1){let o=t[r],s=[...e].find(i=>o===i||o.startsWith(`${i}=`));s?o===s&&r+1<t.length&&(r+=1):n.push(o);}return n}function Wh(t){let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],o=r.indexOf("="),s=o>0?r.slice(0,o):r;if(!Uh.has(s)){e.push(r);continue}r===s&&n+1<t.length&&!t[n+1].startsWith("-")&&(n+=1);}return e}function Ze(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Gh(t,e){if(!(t?Hh.has(t)||Pt(Ii).some(s=>s.id===t):false)||!t)return e;let r=Fn(Ii,t),o=si(Ii)[t]?.defaultEffort;if(r.length!==0)return e?r.includes(e)?e:o&&r.includes(o)?o:void 0:o}function Lt(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0?t:void 0}function Oi(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 vi(t){return t.step.step_index}function de(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 jh(t,e){let n=(t??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&qh.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)/,/invalid (?:flag|option)/].some(s=>s.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 zh(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 Gu(t){let e=Ze(t)?t:void 0,n=e&&Ze(e.error)?e.error:void 0,r=e?de(e.code)??de(e.error_code)??de(n?.code)??de(n?.error_code):void 0,o=typeof t=="string"?de(t):e?de(e.message)??de(e.error)??de(e.reason)??de(n?.message)??de(n?.error)??de(n?.reason):void 0,s=jh(r,o),i=e?Lt(e.retry_after_ms)??Lt(e.retryAfterMs)??Lt(n?.retry_after_ms)??Lt(n?.retryAfterMs):void 0;return {code:s,kind:zh(s),message:o??"Antigravity reported a terminal error.",...i===void 0?{}:{retryAfterMs:i}}}function $o(t){let e=Gu(t);return new G(e.message,"cli/antigravity",{code:e.code,kind:e.kind,...e.retryAfterMs===void 0?{}:{retryAfterMs:e.retryAfterMs}})}function bi(t){return new G(t,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function Kh(t){let e=new TextEncoder().encode(t).byteLength;if(!(e<=Ni))throw new G(`Input is too large: final provider initial input is ${e} UTF-8 bytes; budget is ${Ni} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function Ai(){return new G("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 Ho(t){if(t.kind==="result"||t.kind==="legacy_result")return t.result}function Uo(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 Jh(t){let e=Uo(t);if(!e||e.event.kind==="agy_error"||e.index!==t.length-1||Ho(e.event)?.status!=="SUCCESS"||Mo(t))return false;let r=new Map;for(let o of t){if(o.kind!=="step_update"||o.step.step_type!=="agent_response")continue;let s=Oi(o),i=vi(o);!s||!Number.isSafeInteger(i)||r.set(JSON.stringify([s,i]),o.step);}if(r.size===0)return false;for(let o of r.values())if(o.state!=="DONE"||!Ze(o.usage)||Lt(o.usage.input_tokens)===void 0||Lt(o.usage.output_tokens)===void 0)return false;return true}function Vh(t,e){for(let n=e-1;n>=0;n-=1){let r=t[n];if(r?.kind==="agy_error")return r.error}}function Xh(t,e){return Ze(t)&&Ze(e)?{...e,...t}:Ze(t)&&typeof e=="string"?{...t,message:e}:typeof t=="string"&&Ze(e)?{...e,message:t}:t??e}function Yh(t){let e=Array.isArray(t.denied_actions)?t.denied_actions:[],n=[];for(let i of e){let c=Ze(i)?i:void 0,d=typeof i=="string"?de(i):de(c?.display_name)??de(c?.action);d&&!n.includes(d)&&n.length<5&&n.push(d.slice(0,80));}let r=Math.max(0,e.length-n.length),o=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"",s=`Permission denied: Antigravity blocked ${e.length} requested action${e.length===1?"":"s"}${o}.`;return new G("Could not run because of permissions.","cli/antigravity",{code:"UNKNOWN",kind:"permanent",providerReason:s})}function Mo(t){let e=Uo(t);if(!e)return;if(e.event.kind==="agy_error")return $o(e.event.error);let n=Ho(e.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return Yh(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return bi("Antigravity returned a result with an unsupported status.");let r=n.error,o=Xh(r==null||r===""?n:r,Vh(t,e.index));return $o(o)}function ju(t){if(typeof t=="string")return t;if(t!=null)try{return JSON.stringify(t)}catch{return}}function Qh(t){return `agy:${String(t.conversation_id)}:${String(t.step_index)}`}function Zh(t,e){let n=typeof e?.name=="string"?e.name:t.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function zu(t){let e=ju(t);if(e)return e.length<=2e3?e:`${e.slice(0,1999)}\u2026`}function em(t){let e=Ze(t)?t:void 0,n=e&&Ze(e.error)?e.error:void 0,r=typeof t=="string"?t.trim().match(/^([A-Z][A-Z0-9_]*)(?:[:\s]|$)/)?.[1]:void 0,o=(de(e?.type)??de(e?.code)??de(e?.error_type)??de(n?.type)??de(n?.code)??de(n?.error_type)??de(r)??"TOOL_ERROR").slice(0,60),s=Gu(t).message.slice(0,250);return zu({type:o,message:s})??"Antigravity reported a tool error."}function Fu(t,e){return t?t.state.has(e)?true:(t.state.set(e,true),false):false}function Wu(t,e){return {timestamp:t,type:"error",content:e.message,errorMessage:e.message,isError:true}}var Ii,Hh,Uh,Bu,Ni,qh,Ci,xi=C(()=>{g();Xt();qu();Vs();Sr();Yt();Ar();ei();ii();Ii="antigravity",Hh=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),Uh=new Set(["--conversation","--resume","--continue"]),Bu=new Set(["bypassPermissions","agent-full-access","yolo"]),Ni=18e4,qh=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"]);Ci={command:"agy",maxInitialInputBytes:Ni,meta:{displayName:"Antigravity",models:Fc(),defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(t){let e=Er(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){Kh(t);let{model:r,effort:o}=Qt(e.model),s=ri(r),i=s.model,c=e.effort??o??s.effort,d=Gh(i,c),u=e.additionalArgs??[],l=Wh(Fh(u,new Set(["--input-format","--output-format"]))),p=i&&!jn(u,"--model")?["--model",i]:[],_=jn(u,"--effort")?[]:tu(d),h=jn(u,"--mode")||jn(u,"--dangerously-skip-permissions")?[]:eu(e.mode),m=Bh(e.mode,u)||jn(u,"--settings")?[]:["--settings",JSON.stringify({permissions:{allow:au(e.builtinAllow)}})],k=typeof e.resumeSessionId=="string"&&e.resumeSessionId.trim().length>0?["--conversation",e.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...p,..._,...h,...k,...m,...l],stdinMessage:`${JSON.stringify({event:"user",message:{content:t}})}
85
85
  `,env:{AGY_CLI_DISABLE_AUTO_UPDATE:"true"}}},extractText(t){let e=Rr(t),n=Uo(e)?.event,r=Mo(e);if(r)throw r;let o=n?Ho(n):void 0;if(o){if(o.status!=="SUCCESS")throw bi("Antigravity returned a result with an unsupported status.");if(typeof o.response!="string")throw bi("Antigravity returned a successful result without a response string.");if(!o.response.trim())throw Ai();return o.response}if(e.length>0)throw Ai();let s=t.trim();if(!s)throw Ai();return s},extractPartialText(t){let e=Rr(t),n=Uo(e)?.event;if(!n||n.kind==="agy_error")return;let r=Ho(n);return r&&typeof r.response=="string"&&r.response.trim()?r.response:void 0},interpretExit(t,e,n){let r=Rr(n??""),o=Mo(r);return o||(t!==0&&e.trim()?$o(e):null)},parseResultMeta(t){let e=Rr(t),n=0,r=0,o=0,s=0,i=new Set;for(let d of e){if(d.kind!=="step_update"||d.step.state!=="DONE"||!Ze(d.step.usage))continue;let u=Oi(d),l=vi(d);if(!u||!Number.isSafeInteger(l))continue;let p=JSON.stringify([u,l]);if(i.has(p))continue;let _=d.step.usage,h=Lt(_.input_tokens),m=Lt(_.output_tokens);if(h===void 0||m===void 0)continue;i.add(p);let k=Lt(_.cache_read_tokens)??0;n+=h+k,r+=m,o+=k,s+=1;}return {usage:s===0?null:{inputTokens:n,outputTokens:r,cachedInputTokens:o,costUsd:0,complete:Jh(e)},model:null}},parseEvent(t,e,n){let r=Er(t);if(!r)return [];let o=e??new Date().toISOString();if(r.kind==="agy_error")return [Wu(o,$o(r.error))];if(r.kind==="legacy_result"||r.kind==="result"){let h=Mo([r]);return h?[Wu(o,h)]:[]}if(r.kind!=="step_update")return [];let{step:s}=r,i=Oi(r)??"unknown",c=vi(r),d=`${i}:${c}`;if((s.state==="DONE"||s.state==="ERROR")&&Fu(n,`antigravity:terminal:${d}`))return [];if(s.step_type==="agent_response")return typeof s.text_delta=="string"&&s.text_delta.length>0?[{timestamp:o,type:"text",content:s.text_delta}]:[];if(s.step_type!=="tool")return [];let u=Ze(s.tool_info)?s.tool_info:void 0,l=Zh(s,u);if(!l)return [];let p=Qh(s);if(s.state==="ACTIVE"){if(Fu(n,`antigravity:active:${d}`))return [];let h=ju(u?.parameters);return [{timestamp:o,type:"tool_use",toolName:l,toolUseId:p,...h===void 0?{}:{toolInput:h}}]}let _=s.state==="ERROR"?em(u?.error):zu(u?.output);return [{timestamp:o,type:"tool_result",toolName:l,toolUseId:p,..._===void 0?{}:{resultPreview:_},...s.state==="ERROR"?{isError:true}:{}}]}};});var Ku=C(()=>{g();Un();Bn();qn();mn();});function zn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Kn(t){return zn(t)?t:void 0}function He(t){return typeof t=="string"?t:void 0}function wn(t){let e=typeof t=="number"?t:Number(t??0);return Number.isFinite(e)?e:0}function cm(t){let e=[],n=-1,r=0,o=false,s=false;for(let i=0;i<t.length;i+=1){let c=t[i];if(n===-1){(c==="{"||c==="[")&&(n=i,r=1);continue}if(s){s=false;continue}if(c==="\\"&&o){s=true;continue}if(c==='"'){o=!o;continue}o||(c==="{"||c==="["?r+=1:(c==="}"||c==="]")&&(r-=1,r===0&&(e.push(t.slice(n,i+1)),n=-1)));}return n!==-1&&e.push(t.slice(n)),e}function xr(t){let e=t.trim();if(!e)return [];try{let n=JSON.parse(e);return zn(n)?[n]:[]}catch{return cm(e).flatMap(n=>{try{let r=JSON.parse(n);return zn(r)?[r]:[]}catch{return []}})}}function el(t){let e=JSON.stringify(t);return e===void 0?String(t):e}function Tn(t){if(typeof t=="string")return t;if(Array.isArray(t)){let e=t.map(Tn).filter(n=>n!==void 0);return e.length>0?e.join(`
86
86
  `):void 0}if(zn(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=Tn(t[e]);if(n!==void 0)return n}}}function um(t){let e=i=>Array.isArray(i)&&i.every(c=>Number.isInteger(c)&&c>=0&&c<=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)),o=i=>{let c=JSON.stringify(i,(d,u)=>e(u)?`<bytes:${u.length}>`:u);return c===void 0?String(i):c},s=t.rawOutput;if(s!=null){let i=Kn(s);if(!i)return n(Tn(s))??o(s);let c;if(e(i.output)&&i.output.length>0&&(c=n(r(i.output))),!c&&e(i.stdout)&&i.stdout.length>0&&(c=n(r(i.stdout))),!c){let l=Kn(i.Result);c=n(i.output)??n(l?.output)??n(Tn(s));}let d=e(i.stderr)&&i.stderr.length>0?r(i.stderr):void 0;if(d!==void 0)if(c){let l=c.endsWith(`
87
87
  `)||c.endsWith("\r")?"":`
@@ -81,7 +81,7 @@ ${r.join(`
81
81
  time_created = excluded.time_created,
82
82
  time_updated = excluded.time_updated
83
83
  `);r.transaction(i=>{for(let a of i)o.run(a);})(n);}finally{r.close();}}function ow(t){if(!t)return [];let e=[];for(let n=0;n<t.length;n+=1){let r=t[n];if(r==="-s"||r==="--session"){let o=t[n+1],s=o!==void 0&&!o.startsWith("-");e.push({sessionId:s?o:void 0}),s&&(n+=1);continue}(r.startsWith("--session=")||r.startsWith("-s="))&&e.push({sessionId:r.slice(r.indexOf("=")+1)||void 0});}return e}function sw(t){if(!t)return;let e=[];for(let n=0;n<t.length;n+=1){let r=t[n];if(r==="-s"||r==="--session"){t[n+1]!==void 0&&!t[n+1].startsWith("-")&&(n+=1);continue}r.startsWith("--session=")||r.startsWith("-s=")||e.push(r);}return e}function ei(t){let e=sw(t.additionalArgs);return {...t,...e===void 0?{}:{additionalArgs:e},resumeSessionId:void 0}}function iw(t,e){try{return !!t.prepare("SELECT id FROM session_v2 WHERE id = ?").get(e)}catch(n){if(n instanceof Error&&/no such table: session_v2/i.test(n.message))return false;throw n}}function aw(t,e,n){let r=new t(e,{readonly:true,fileMustExist:true});try{return iw(r,n)}finally{r.close();}}async function cd(t,e={}){let n;try{n=await(e.loadSqlite??YT)();}catch{throw new J("OpenCode isolation requires the optional better-sqlite3 dependency. Install it and retry.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}let r=e.crewxHome??Zs(),o=qo(r),s=Fo(r),i=QT(s),a=ZT(e.userDataHome),c=tw(n,a);if(c.length>0){if(!u_(n,i))try{await(e.initializeDatabase??nw)(o);}catch{throw new J("Could not initialize the isolated OpenCode credential database.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}if(!u_(n,i))throw new J("The isolated OpenCode credential database is unavailable.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"});try{rw(n,i,c);}catch{throw new J("Could not copy API-key credentials into the isolated OpenCode database.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}}let u=ow(t.additionalArgs),p=u.map(f=>f.sessionId),l=u.length>0?p[p.length-1]:t.resumeSessionId;if(!l)return u.length>0?ei(t):t;if(p.some(f=>f!==l)||!existsSync(i))return ei(t);try{return aw(n,i,l)?{...t,resumeSessionId:l}:ei(t)}catch{throw new J("Could not read the isolated OpenCode session database safely.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}}var ud=x(()=>{h();Cn();ad();c_();});function tr(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}async function ld(){let t;try{let n=(await import('better-sqlite3')).default,r=join(Fo(),"opencode.db");t=new n(r,{readonly:!0,fileMustExist:!0});let o=t.prepare("SELECT value FROM kv WHERE key = ?").get("models-dev:v2:catalog");if(!o||typeof o.value!="string")throw new Error("OpenCode model catalog row is unavailable");let s=JSON.parse(o.value);if(!tr(s))throw new Error("OpenCode model catalog shape is unavailable");let i=typeof s.body=="string"?JSON.parse(s.body):s.body;if(!tr(i))throw new Error("OpenCode model catalog body shape is unavailable");let a=new Map;for(let[c,u]of Object.entries(i)){if(!c||!tr(u)||!tr(u.models))throw new Error("OpenCode model provider shape is unavailable");for(let[p,l]of Object.entries(u.models)){if(!p||!tr(l))throw new Error("OpenCode model shape is unavailable");let f=l.capabilities;if(f===void 0)continue;if(!tr(f))throw new Error("OpenCode model capability shape is unavailable");let g=f.reasoning;if(g===void 0)continue;if(!tr(g))throw new Error("OpenCode reasoning capability shape is unavailable");let m=g.effort;(m===void 0||Array.isArray(m)&&m.every(k=>typeof k=="string"))&&a.set(`${c}/${p}`,Array.isArray(m)?m:[]);}}return a}catch{return console.debug("[opencode] could not read private model effort catalog; omitting effort choices"),new Map}finally{try{t?.close();}catch{}}}var p_=x(()=>{h();_d();r_();i_();ad();ud();Dn();});function fw(t){return t?_w[t]??{agent:"build",autoApprove:false}:{agent:void 0,autoApprove:false}}function Ot(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function gw(){let t;try{t=Fo();}catch{return ld().catch(()=>new Map)}let e=Date.now();if(__===t&&ti&&ti.expiresAt>e)return ti.result;__=t;let n=ld().catch(()=>new Map);return ti={expiresAt:e+pw,result:n},n}async function hw(t){let e=await cd(t),n=t.additionalArgs??[],r=Ot(n,"--model")||Ot(n,"-m");if(!t.model||!t.effort||r)return e;let o=(await gw()).get(t.model);return !o||o.includes(t.effort)?e:(console.debug("[opencode] requested effort is not listed for this model; using OpenCode default"),{...e,effort:void 0})}function k_(t){let e=[],n=0,r=false,o=false,s=0;for(let a=0;a<t.length;a++){let c=t[a];if(o){o=false;continue}if(c==="\\"&&r){o=true;continue}if(c==='"'){r=!r;continue}if(!r){if(c==="{")n++;else if(c==="}"&&(n--,n===0)){let u=t.slice(s,a+1).trim();u&&e.push(u),s=a+1;}}}let i=t.slice(s).trim();return i&&e.push(i),e}function Ie(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function y_(t){let e=Ie(t.part)?t.part:void 0;return t.type==="reasoning"||e?.type==="reasoning"}function mw(t){let e=Ie(t.part)?t.part:void 0;return (typeof e?.text=="string"?e.text:typeof t.text=="string"?t.text:void 0)?.trim()||void 0}function kw(t){let e=[],n=false;for(let r of t.split(/\r?\n/)){let o=r.trim();if(!o)continue;try{let i=JSON.parse(o);Ie(i)?e.push(i):n=!0;continue}catch{}let s=k_(o);s.length>1&&console.warn("[opencode] extractText: falling back to concatenated-JSON split for a malformed line");for(let i of s)try{let a=JSON.parse(i);Ie(a)?e.push(a):n=!0;}catch{n=true;}}return {events:e,malformed:n}}function hd(t){let e=Ie(t.error)?t.error:void 0,n=e&&Ie(e.data)?e.data:void 0,r=T_(e),o=Nt(e?.name),s=Nt(n?.message)??Nt(e?.message)??fd(r)??Nt(t.message)??Nt(t.errorMessage)??Nt(t.error),i=Nt(t.ref),a=o&&s&&o!==s?`${o}: ${s}`:o??s??m_;return (i?`${a} (ref: ${i})`:a).slice(0,uw)}function f_(t){let e=Ie(t.error)?t.error:void 0,n=typeof e?.type=="string"?e.type:void 0,r=typeof e?.status=="number"?e.status:Number(e?.status),o=hd(t),s=T_(e),i=s&&Ie(s.error)?s.error:void 0,a=typeof i?.type=="string"?i.type:void 0,c=[o,fd(s)].filter(Boolean).join(`
84
- `);if(r===402||yw(c))return new J(`OpenCode subscription is required: ${o}`,kt,{code:"SUBSCRIPTION_REQUIRED",kind:"config",providerReason:Uo(o)});if(r===403&&(a==="RegionError"||a==="FreeTierError"))return new J(`OpenCode account settings are required: ${o}`,kt,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:"access",providerReason:Uo(o)});if(n==="provider.auth"||r===401||r===403)return new J(`OpenCode authentication is required: ${o}`,kt,{code:"AUTH_REQUIRED",kind:"config"});if(r===410||a==="ModelDeprecated")return new J(`OpenCode model has been retired: ${o}`,kt,{code:"MODEL_RETIRED",kind:"config",replacementModel:Tw(s,e,t),providerReason:Uo(o)});if(n==="provider.free-limit"||r===429){let u=ww(e);return new J(`OpenCode rate limit reached: ${o}`,kt,{code:"RATE_LIMITED",kind:"transient",...u===void 0?{}:{retryAfterMs:u}})}if(n==="provider.no-route")return new J(`OpenCode model or variant unavailable: ${o}`,kt,{code:"MODEL_UNAVAILABLE",kind:"config"});if(n==="provider.invalid-request"&&r===400){let u=[o,fd(s)].filter(g=>g!==void 0),p=u.find(g=>/requires global regions/i.test(g)),l=u.find(g=>/trains on request data/i.test(g)),f=p?"region":l?"training_consent":void 0;if(f)return new J(`OpenCode account settings are required: ${o}`,kt,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:f,providerReason:Uo(p??l)})}return new J(`OpenCode error: ${o}`,kt,{code:"PROVIDER_CRASHED",kind:"transient"})}function T_(t){let n=(t&&Ie(t.response)?t.response:void 0)?.body;if(Ie(n))return n;if(typeof n=="string")try{let r=JSON.parse(n);return Ie(r)?r:void 0}catch{return}}function fd(t){let e=t&&Ie(t.error)?t.error:void 0;return Nt(e?.message)??Nt(t?.message)}function yw(t){return /insufficient\s+(?:balance|account funds)|credit\s+limit\s+exceeded|payment\s+required|account invoice is overdue|billing_error|please add or update your payment method|(?:GLM Coding Plan|enterprise) package has expired|your current subscription plan does not yet include access to/i.test(t)}function Tw(t,e,n){let r=t&&Ie(t.metadata)?t.metadata:void 0,o=typeof r?.replacement=="string"?r.replacement.trim():void 0;if(!o)return;let s=[r?.model,e?.model,n.model,n.modelID].find(c=>typeof c=="string"&&c.trim().length>0)?.trim(),i=s&&s.includes("/")?s.slice(0,s.indexOf("/")):"opencode-go",a=o.includes("/")?o:`${i}/${o}`;return /^[A-Za-z0-9._/-]{1,128}$/.test(a)?a:void 0}function ww(t){let e=t?.retryAfterMs;if(typeof e=="number"&&Number.isFinite(e)&&e>=0)return e;let r=(t&&Ie(t.response)?t.response:void 0)?.body,o=typeof r=="string"?Rw(r):Ie(r)?r:void 0;if(o){let s=gd(o);if(s)return g_(s.value,s.key==="retryafterms")}if(typeof r=="string"){let s=r.match(/retry[-_]after(?:\s*[:=]\s*|\s+)["']?([^"'\s,;}]+)/i);if(s?.[1])return g_(s[1],false)}}function Rw(t){try{let e=JSON.parse(t);return Ie(e)?e:void 0}catch{return}}function gd(t){if(Array.isArray(t)){for(let e of t){let n=gd(e);if(n)return n}return}if(Ie(t)){for(let[e,n]of Object.entries(t)){let r=e.toLowerCase().replace(/[-_]/g,"");if(r==="retryafterms"||r==="retryafter")return {value:n,key:r}}for(let e of Object.values(t)){let n=gd(e);if(n)return n}}}function g_(t,e){if(typeof t=="number"&&Number.isFinite(t)&&t>=0)return e?t:Math.round(t*1e3);if(typeof t!="string"||!t.trim())return;let n=Number(t);if(Number.isFinite(n)&&n>=0)return e?n:Math.round(n*1e3);if(e)return;let r=Date.parse(t);return Number.isFinite(r)?Math.max(0,r-Date.now()):void 0}function h_(t){let e=kw(t),n=[],r=null,o=0,s=[],i=[],a,c=false;for(let u of e.events){if(y_(u))continue;let p=typeof u.type=="string"?u.type:void 0;if(p){if(p==="text"){let l=Ie(u.part)?u.part:void 0,f=typeof l?.text=="string"?l.text:void 0;f?.trim()&&n.push(f.trim());continue}if(p==="result"){typeof u.result=="string"&&(r=u.result);continue}if(p==="tool_use"){o++;continue}if(p==="error"){s.push(u),i.push(hd(u));continue}if(p==="step_finish"){c=true;let l=Ie(u.part)?u.part:void 0;a=typeof l?.reason=="string"?l.reason:void 0;}}}return {...e,texts:n,resultText:r,toolUseCount:o,errorEvents:s,errorMessages:i,terminalReason:a,hasTerminal:c}}function w_(t){return (t??"unknown").trim().toLowerCase().replace(/_/g,"-")}function Ew(){return new J("OpenCode returned no assistant output.",kt,{code:"EMPTY_OUTPUT",kind:"transient"})}function Sw(){return new J("OpenCode emitted malformed JSON output.",kt,{code:"PROVIDER_CRASHED",kind:"transient"})}function bw(t,e){switch(w_(t)){case "length":return new J("OpenCode stopped because the context window was exceeded.",kt,{code:"UNKNOWN",kind:"permanent"});case "content-filter":return new J("OpenCode stopped because the content filter blocked the response.",kt,{code:"UNKNOWN",kind:"permanent"});case "error":return new J(`${m_} while generating a response.`,kt,{code:"PROVIDER_CRASHED",kind:"transient"});default:return null}}var cw,kt,m_,uw,lw,pw,__,ti,_w,md,kd=x(()=>{h();Cn();n_();Ho();Hr();Zn();p_();ud();cw=new Set(["step_start","step_finish"]),kt="cli/opencode",m_="OpenCode provider error",uw=240,lw="Follow the instructions provided on standard input.",pw=3e5,_w={build:{agent:"build",autoApprove:false},"build-auto":{agent:"build",autoApprove:true},plan:{agent:"plan",autoApprove:false},"plan-auto":{agent:"plan",autoApprove:true}};md={command:"opencode",prepare:hw,meta:{displayName:"OpenCode",capabilities:{resume:true}},buildArgs(t,e,n){let r=e.additionalArgs,o=r!==void 0?[...r]:["run"];Ot(o,"--format")||o.push("--format","json"),Ot(o,"--thinking")||o.push("--thinking"),!Ot(o,"--standalone")&&!Ot(o,"--server")&&o.push("--standalone"),e.resumeSessionId&&!Ot(o,"-s")&&!Ot(o,"--session")&&o.push("-s",e.resumeSessionId);let{agent:s,autoApprove:i}=fw(e.mode);Ot(o,"--agent")||s!==void 0&&o.push("--agent",s),i&&!Ot(o,"--auto")&&o.push("--auto");let a=Ot(o,"--model")||Ot(o,"-m");if(e.model&&!a){let c=e.effort?`${e.model}#${e.effort}`:e.model;o.push("--model",c);}else e.effort&&!e.model&&!a&&console.debug("[opencode] ignoring effort because no model is configured");return o.push(lw),{args:o,stdinMessage:t,env:qo()}},extractText(t){let e=h_(t),n=e.errorEvents[0];if(n)throw f_(n);let r=bw(e.terminalReason??"");if(r)throw r;let o=e.texts.length>0?e.texts[e.texts.length-1]:void 0;if(o!==void 0)return o;if(e.resultText?.trim())return e.resultText;if(e.malformed)throw Sw();let s=w_(e.terminalReason);if(e.hasTerminal&&s==="tool-calls"&&e.toolUseCount>0)return "";throw Ew()},interpretExit(t,e,n=""){if(t===0)return null;let o=h_(n).errorEvents[0];return o?f_(o):null},parseResultMeta(t){let e=Br(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(),o=[],s=new Map,i;try{JSON.parse(t),i=[t];}catch{i=k_(t),i.length>1&&console.warn("[opencode] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let a of i){let c;try{c=JSON.parse(a);}catch{continue}let u=qt(c,r),p=c.type;if(y_(c)){let l=mw(c);if(!l)continue;let f=Ie(c.part)?c.part:void 0,g=typeof f?.id=="string"?f.id:typeof c.id=="string"?c.id:void 0,m=l;if(g){let k=`opencode.reasoning:${g}`,T=n?.state.get(k),S=typeof T=="string"?T:s.get(g);if(typeof S=="string"&&(S===l||S.startsWith(l))||typeof S=="string"&&l.startsWith(S)&&(m=l.slice(S.length).trim(),!m))continue;s.set(g,l),n?.state.set(k,l);}o.push({timestamp:u,type:"thinking",content:m});continue}if(p){if(p==="text"){let f=c.part?.text;f&&o.push({timestamp:u,type:"text",content:f});continue}if(p==="tool_use"){let l=c.part;if(!l)continue;let f=String(l.tool||""),g=String(l.callID||l.id||""),m=l.state,k=String(m?.status||""),T=m?.input,S=Bt(T);if(o.push({timestamp:u,type:"tool_use",toolName:f,toolUseId:g,toolInput:S}),k==="completed"&&m?.output!==void 0){let w=m.output,L=typeof w=="string"?w:JSON.stringify(w);o.push({timestamp:u,type:"tool_result",toolUseId:g,resultPreview:L,isError:false});}else k==="error"&&o.push({timestamp:u,type:"tool_result",toolUseId:g,resultPreview:String(m?.error||"tool error"),isError:true});continue}if(p==="error"){let l=hd(c);o.push({timestamp:u,type:"error",content:l,errorMessage:l});continue}}}return o},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?cw.has(r):!1}catch{return false}}};});var R_=x(()=>{h();});function Fr(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function vw(t,e){return t&&E_.has(t)||Fr(e,"--dangerously-skip-permissions")?true:e.some((n,r)=>{let o=n==="--mode"?e[r+1]:n.startsWith("--mode=")?n.slice(7):void 0;return typeof o=="string"&&E_.has(o)})}function Cw(t,e){let n=[];for(let r=0;r<t.length;r+=1){let o=t[r],s=[...e].find(i=>o===i||o.startsWith(`${i}=`));s?o===s&&r+1<t.length&&(r+=1):n.push(o);}return n}function Dw(t){let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],o=r.indexOf("="),s=o>0?r.slice(0,o):r;if(!Nw.has(s)){e.push(r);continue}r===s&&n+1<t.length&&!t[n+1].startsWith("-")&&(n+=1);}return e}function vt(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function xw(t,e){if(!(t?Iw.has(t)||yn(yd).some(s=>s.id===t):false)||!t)return e;let r=Ur(yd,t),o=Za(yd)[t]?.defaultEffort;if(r.length!==0)return e?r.includes(e)?e:o&&r.includes(o)?o:void 0:o}function Tn(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0?t:void 0}function Rd(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 Ed(t){return t.step.step_index}function be(t){if(typeof t!="string")return;let e=t.split(/\r?\n/,1)[0]?.trim();return e&&Ws(e)?.slice(0,500).trim()||void 0}function Pw(t,e){let n=(t??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&Ow.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)/,/invalid (?:flag|option)/].some(s=>s.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 Lw(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 A_(t){let e=vt(t)?t:void 0,n=e&&vt(e.error)?e.error:void 0,r=e?be(e.code)??be(e.error_code)??be(n?.code)??be(n?.error_code):void 0,o=typeof t=="string"?be(t):e?be(e.message)??be(e.error)??be(e.reason)??be(n?.message)??be(n?.error)??be(n?.reason):void 0,s=Pw(r,o),i=e?Tn(e.retry_after_ms)??Tn(e.retryAfterMs)??Tn(n?.retry_after_ms)??Tn(n?.retryAfterMs):void 0;return {code:s,kind:Lw(s),message:o??"Antigravity reported a terminal error.",...i===void 0?{}:{retryAfterMs:i}}}function ri(t){let e=A_(t);return new J(e.message,"cli/antigravity",{code:e.code,kind:e.kind,...e.retryAfterMs===void 0?{}:{retryAfterMs:e.retryAfterMs}})}function Sd(t){return new J(t,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function Mw(t){let e=new TextEncoder().encode(t).byteLength;if(!(e<=wd))throw new J(`Input is too large: final provider initial input is ${e} UTF-8 bytes; budget is ${wd} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function Td(){return new J("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 oi(t){if(t.kind==="result"||t.kind==="legacy_result")return t.result}function si(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 $w(t){let e=si(t);if(!e||e.event.kind==="agy_error"||e.index!==t.length-1||oi(e.event)?.status!=="SUCCESS"||ni(t))return false;let r=new Map;for(let o of t){if(o.kind!=="step_update"||o.step.step_type!=="agent_response")continue;let s=Rd(o),i=Ed(o);!s||!Number.isSafeInteger(i)||r.set(JSON.stringify([s,i]),o.step);}if(r.size===0)return false;for(let o of r.values())if(o.state!=="DONE"||!vt(o.usage)||Tn(o.usage.input_tokens)===void 0||Tn(o.usage.output_tokens)===void 0)return false;return true}function Hw(t,e){for(let n=e-1;n>=0;n-=1){let r=t[n];if(r?.kind==="agy_error")return r.error}}function Uw(t,e){return vt(t)&&vt(e)?{...e,...t}:vt(t)&&typeof e=="string"?{...t,message:e}:typeof t=="string"&&vt(e)?{...e,message:t}:t??e}function Bw(t){let e=Array.isArray(t.denied_actions)?t.denied_actions:[],n=[];for(let i of e){let a=vt(i)?i:void 0,c=typeof i=="string"?be(i):be(a?.display_name)??be(a?.action);c&&!n.includes(c)&&n.length<5&&n.push(c.slice(0,80));}let r=Math.max(0,e.length-n.length),o=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"",s=`Permission denied: Antigravity blocked ${e.length} requested action${e.length===1?"":"s"}${o}.`;return new J("\uAD8C\uD55C \uB54C\uBB38\uC5D0 \uC2E4\uD589\uD558\uC9C0 \uBABB\uD588\uC5B4\uC694","cli/antigravity",{code:"UNKNOWN",kind:"permanent",providerReason:s})}function ni(t){let e=si(t);if(!e)return;if(e.event.kind==="agy_error")return ri(e.event.error);let n=oi(e.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return Bw(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return Sd("Antigravity returned a result with an unsupported status.");let r=n.error,o=Uw(r==null||r===""?n:r,Hw(t,e.index));return ri(o)}function I_(t){if(typeof t=="string")return t;if(t!=null)try{return JSON.stringify(t)}catch{return}}function qw(t){return `agy:${String(t.conversation_id)}:${String(t.step_index)}`}function Fw(t,e){let n=typeof e?.name=="string"?e.name:t.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function N_(t){let e=I_(t);if(e)return e.length<=2e3?e:`${e.slice(0,1999)}\u2026`}function jw(t){let e=vt(t)?t:void 0,n=e&&vt(e.error)?e.error:void 0,r=typeof t=="string"?t.trim().match(/^([A-Z][A-Z0-9_]*)(?:[:\s]|$)/)?.[1]:void 0,o=(be(e?.type)??be(e?.code)??be(e?.error_type)??be(n?.type)??be(n?.code)??be(n?.error_type)??be(r)??"TOOL_ERROR").slice(0,60),s=A_(t).message.slice(0,250);return N_({type:o,message:s})??"Antigravity reported a tool error."}function S_(t,e){return t?t.state.has(e)?true:(t.state.set(e,true),false):false}function b_(t,e){return {timestamp:t,type:"error",content:e.message,errorMessage:e.message,isError:true}}var yd,Iw,Nw,E_,wd,Ow,bd,Ad=x(()=>{h();Cn();R_();Wa();Lo();Dn();$o();zs();ed();yd="antigravity",Iw=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),Nw=new Set(["--conversation","--resume","--continue"]),E_=new Set(["bypassPermissions","agent-full-access","yolo"]),wd=18e4,Ow=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"]);bd={command:"agy",maxInitialInputBytes:wd,meta:{displayName:"Antigravity",models:Sp(),defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(t){let e=xo(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){Mw(t);let{model:r,effort:o}=xn(e.model),s=Ya(r),i=s.model,a=e.effort??o??s.effort,c=xw(i,a),u=e.additionalArgs??[],p=Dw(Cw(u,new Set(["--input-format","--output-format"]))),l=i&&!Fr(u,"--model")?["--model",i]:[],f=Fr(u,"--effort")?[]:$p(c),g=Fr(u,"--mode")||Fr(u,"--dangerously-skip-permissions")?[]:Mp(e.mode),m=vw(e.mode,u)||Fr(u,"--settings")?[]:["--settings",JSON.stringify({permissions:{allow:jp(e.builtinAllow)}})],k=typeof e.resumeSessionId=="string"&&e.resumeSessionId.trim().length>0?["--conversation",e.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...l,...f,...g,...k,...m,...p],stdinMessage:`${JSON.stringify({event:"user",message:{content:t}})}
84
+ `);if(r===402||yw(c))return new J(`OpenCode subscription is required: ${o}`,kt,{code:"SUBSCRIPTION_REQUIRED",kind:"config",providerReason:Uo(o)});if(r===403&&(a==="RegionError"||a==="FreeTierError"))return new J(`OpenCode account settings are required: ${o}`,kt,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:"access",providerReason:Uo(o)});if(n==="provider.auth"||r===401||r===403)return new J(`OpenCode authentication is required: ${o}`,kt,{code:"AUTH_REQUIRED",kind:"config"});if(r===410||a==="ModelDeprecated")return new J(`OpenCode model has been retired: ${o}`,kt,{code:"MODEL_RETIRED",kind:"config",replacementModel:Tw(s,e,t),providerReason:Uo(o)});if(n==="provider.free-limit"||r===429){let u=ww(e);return new J(`OpenCode rate limit reached: ${o}`,kt,{code:"RATE_LIMITED",kind:"transient",...u===void 0?{}:{retryAfterMs:u}})}if(n==="provider.no-route")return new J(`OpenCode model or variant unavailable: ${o}`,kt,{code:"MODEL_UNAVAILABLE",kind:"config"});if(n==="provider.invalid-request"&&r===400){let u=[o,fd(s)].filter(g=>g!==void 0),p=u.find(g=>/requires global regions/i.test(g)),l=u.find(g=>/trains on request data/i.test(g)),f=p?"region":l?"training_consent":void 0;if(f)return new J(`OpenCode account settings are required: ${o}`,kt,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:f,providerReason:Uo(p??l)})}return new J(`OpenCode error: ${o}`,kt,{code:"PROVIDER_CRASHED",kind:"transient"})}function T_(t){let n=(t&&Ie(t.response)?t.response:void 0)?.body;if(Ie(n))return n;if(typeof n=="string")try{let r=JSON.parse(n);return Ie(r)?r:void 0}catch{return}}function fd(t){let e=t&&Ie(t.error)?t.error:void 0;return Nt(e?.message)??Nt(t?.message)}function yw(t){return /insufficient\s+(?:balance|account funds)|credit\s+limit\s+exceeded|payment\s+required|account invoice is overdue|billing_error|please add or update your payment method|(?:GLM Coding Plan|enterprise) package has expired|your current subscription plan does not yet include access to/i.test(t)}function Tw(t,e,n){let r=t&&Ie(t.metadata)?t.metadata:void 0,o=typeof r?.replacement=="string"?r.replacement.trim():void 0;if(!o)return;let s=[r?.model,e?.model,n.model,n.modelID].find(c=>typeof c=="string"&&c.trim().length>0)?.trim(),i=s&&s.includes("/")?s.slice(0,s.indexOf("/")):"opencode-go",a=o.includes("/")?o:`${i}/${o}`;return /^[A-Za-z0-9._/-]{1,128}$/.test(a)?a:void 0}function ww(t){let e=t?.retryAfterMs;if(typeof e=="number"&&Number.isFinite(e)&&e>=0)return e;let r=(t&&Ie(t.response)?t.response:void 0)?.body,o=typeof r=="string"?Rw(r):Ie(r)?r:void 0;if(o){let s=gd(o);if(s)return g_(s.value,s.key==="retryafterms")}if(typeof r=="string"){let s=r.match(/retry[-_]after(?:\s*[:=]\s*|\s+)["']?([^"'\s,;}]+)/i);if(s?.[1])return g_(s[1],false)}}function Rw(t){try{let e=JSON.parse(t);return Ie(e)?e:void 0}catch{return}}function gd(t){if(Array.isArray(t)){for(let e of t){let n=gd(e);if(n)return n}return}if(Ie(t)){for(let[e,n]of Object.entries(t)){let r=e.toLowerCase().replace(/[-_]/g,"");if(r==="retryafterms"||r==="retryafter")return {value:n,key:r}}for(let e of Object.values(t)){let n=gd(e);if(n)return n}}}function g_(t,e){if(typeof t=="number"&&Number.isFinite(t)&&t>=0)return e?t:Math.round(t*1e3);if(typeof t!="string"||!t.trim())return;let n=Number(t);if(Number.isFinite(n)&&n>=0)return e?n:Math.round(n*1e3);if(e)return;let r=Date.parse(t);return Number.isFinite(r)?Math.max(0,r-Date.now()):void 0}function h_(t){let e=kw(t),n=[],r=null,o=0,s=[],i=[],a,c=false;for(let u of e.events){if(y_(u))continue;let p=typeof u.type=="string"?u.type:void 0;if(p){if(p==="text"){let l=Ie(u.part)?u.part:void 0,f=typeof l?.text=="string"?l.text:void 0;f?.trim()&&n.push(f.trim());continue}if(p==="result"){typeof u.result=="string"&&(r=u.result);continue}if(p==="tool_use"){o++;continue}if(p==="error"){s.push(u),i.push(hd(u));continue}if(p==="step_finish"){c=true;let l=Ie(u.part)?u.part:void 0;a=typeof l?.reason=="string"?l.reason:void 0;}}}return {...e,texts:n,resultText:r,toolUseCount:o,errorEvents:s,errorMessages:i,terminalReason:a,hasTerminal:c}}function w_(t){return (t??"unknown").trim().toLowerCase().replace(/_/g,"-")}function Ew(){return new J("OpenCode returned no assistant output.",kt,{code:"EMPTY_OUTPUT",kind:"transient"})}function Sw(){return new J("OpenCode emitted malformed JSON output.",kt,{code:"PROVIDER_CRASHED",kind:"transient"})}function bw(t,e){switch(w_(t)){case "length":return new J("OpenCode stopped because the context window was exceeded.",kt,{code:"UNKNOWN",kind:"permanent"});case "content-filter":return new J("OpenCode stopped because the content filter blocked the response.",kt,{code:"UNKNOWN",kind:"permanent"});case "error":return new J(`${m_} while generating a response.`,kt,{code:"PROVIDER_CRASHED",kind:"transient"});default:return null}}var cw,kt,m_,uw,lw,pw,__,ti,_w,md,kd=x(()=>{h();Cn();n_();Ho();Hr();Zn();p_();ud();cw=new Set(["step_start","step_finish"]),kt="cli/opencode",m_="OpenCode provider error",uw=240,lw="Follow the instructions provided on standard input.",pw=3e5,_w={build:{agent:"build",autoApprove:false},"build-auto":{agent:"build",autoApprove:true},plan:{agent:"plan",autoApprove:false},"plan-auto":{agent:"plan",autoApprove:true}};md={command:"opencode",prepare:hw,meta:{displayName:"OpenCode",capabilities:{resume:true}},buildArgs(t,e,n){let r=e.additionalArgs,o=r!==void 0?[...r]:["run"];Ot(o,"--format")||o.push("--format","json"),Ot(o,"--thinking")||o.push("--thinking"),!Ot(o,"--standalone")&&!Ot(o,"--server")&&o.push("--standalone"),e.resumeSessionId&&!Ot(o,"-s")&&!Ot(o,"--session")&&o.push("-s",e.resumeSessionId);let{agent:s,autoApprove:i}=fw(e.mode);Ot(o,"--agent")||s!==void 0&&o.push("--agent",s),i&&!Ot(o,"--auto")&&o.push("--auto");let a=Ot(o,"--model")||Ot(o,"-m");if(e.model&&!a){let c=e.effort?`${e.model}#${e.effort}`:e.model;o.push("--model",c);}else e.effort&&!e.model&&!a&&console.debug("[opencode] ignoring effort because no model is configured");return o.push(lw),{args:o,stdinMessage:t,env:qo()}},extractText(t){let e=h_(t),n=e.errorEvents[0];if(n)throw f_(n);let r=bw(e.terminalReason??"");if(r)throw r;let o=e.texts.length>0?e.texts[e.texts.length-1]:void 0;if(o!==void 0)return o;if(e.resultText?.trim())return e.resultText;if(e.malformed)throw Sw();let s=w_(e.terminalReason);if(e.hasTerminal&&s==="tool-calls"&&e.toolUseCount>0)return "";throw Ew()},interpretExit(t,e,n=""){if(t===0)return null;let o=h_(n).errorEvents[0];return o?f_(o):null},parseResultMeta(t){let e=Br(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(),o=[],s=new Map,i;try{JSON.parse(t),i=[t];}catch{i=k_(t),i.length>1&&console.warn("[opencode] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let a of i){let c;try{c=JSON.parse(a);}catch{continue}let u=qt(c,r),p=c.type;if(y_(c)){let l=mw(c);if(!l)continue;let f=Ie(c.part)?c.part:void 0,g=typeof f?.id=="string"?f.id:typeof c.id=="string"?c.id:void 0,m=l;if(g){let k=`opencode.reasoning:${g}`,T=n?.state.get(k),S=typeof T=="string"?T:s.get(g);if(typeof S=="string"&&(S===l||S.startsWith(l))||typeof S=="string"&&l.startsWith(S)&&(m=l.slice(S.length).trim(),!m))continue;s.set(g,l),n?.state.set(k,l);}o.push({timestamp:u,type:"thinking",content:m});continue}if(p){if(p==="text"){let f=c.part?.text;f&&o.push({timestamp:u,type:"text",content:f});continue}if(p==="tool_use"){let l=c.part;if(!l)continue;let f=String(l.tool||""),g=String(l.callID||l.id||""),m=l.state,k=String(m?.status||""),T=m?.input,S=Bt(T);if(o.push({timestamp:u,type:"tool_use",toolName:f,toolUseId:g,toolInput:S}),k==="completed"&&m?.output!==void 0){let w=m.output,L=typeof w=="string"?w:JSON.stringify(w);o.push({timestamp:u,type:"tool_result",toolUseId:g,resultPreview:L,isError:false});}else k==="error"&&o.push({timestamp:u,type:"tool_result",toolUseId:g,resultPreview:String(m?.error||"tool error"),isError:true});continue}if(p==="error"){let l=hd(c);o.push({timestamp:u,type:"error",content:l,errorMessage:l});continue}}}return o},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?cw.has(r):!1}catch{return false}}};});var R_=x(()=>{h();});function Fr(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function vw(t,e){return t&&E_.has(t)||Fr(e,"--dangerously-skip-permissions")?true:e.some((n,r)=>{let o=n==="--mode"?e[r+1]:n.startsWith("--mode=")?n.slice(7):void 0;return typeof o=="string"&&E_.has(o)})}function Cw(t,e){let n=[];for(let r=0;r<t.length;r+=1){let o=t[r],s=[...e].find(i=>o===i||o.startsWith(`${i}=`));s?o===s&&r+1<t.length&&(r+=1):n.push(o);}return n}function Dw(t){let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],o=r.indexOf("="),s=o>0?r.slice(0,o):r;if(!Nw.has(s)){e.push(r);continue}r===s&&n+1<t.length&&!t[n+1].startsWith("-")&&(n+=1);}return e}function vt(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function xw(t,e){if(!(t?Iw.has(t)||yn(yd).some(s=>s.id===t):false)||!t)return e;let r=Ur(yd,t),o=Za(yd)[t]?.defaultEffort;if(r.length!==0)return e?r.includes(e)?e:o&&r.includes(o)?o:void 0:o}function Tn(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0?t:void 0}function Rd(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 Ed(t){return t.step.step_index}function be(t){if(typeof t!="string")return;let e=t.split(/\r?\n/,1)[0]?.trim();return e&&Ws(e)?.slice(0,500).trim()||void 0}function Pw(t,e){let n=(t??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&Ow.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)/,/invalid (?:flag|option)/].some(s=>s.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 Lw(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 A_(t){let e=vt(t)?t:void 0,n=e&&vt(e.error)?e.error:void 0,r=e?be(e.code)??be(e.error_code)??be(n?.code)??be(n?.error_code):void 0,o=typeof t=="string"?be(t):e?be(e.message)??be(e.error)??be(e.reason)??be(n?.message)??be(n?.error)??be(n?.reason):void 0,s=Pw(r,o),i=e?Tn(e.retry_after_ms)??Tn(e.retryAfterMs)??Tn(n?.retry_after_ms)??Tn(n?.retryAfterMs):void 0;return {code:s,kind:Lw(s),message:o??"Antigravity reported a terminal error.",...i===void 0?{}:{retryAfterMs:i}}}function ri(t){let e=A_(t);return new J(e.message,"cli/antigravity",{code:e.code,kind:e.kind,...e.retryAfterMs===void 0?{}:{retryAfterMs:e.retryAfterMs}})}function Sd(t){return new J(t,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function Mw(t){let e=new TextEncoder().encode(t).byteLength;if(!(e<=wd))throw new J(`Input is too large: final provider initial input is ${e} UTF-8 bytes; budget is ${wd} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function Td(){return new J("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 oi(t){if(t.kind==="result"||t.kind==="legacy_result")return t.result}function si(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 $w(t){let e=si(t);if(!e||e.event.kind==="agy_error"||e.index!==t.length-1||oi(e.event)?.status!=="SUCCESS"||ni(t))return false;let r=new Map;for(let o of t){if(o.kind!=="step_update"||o.step.step_type!=="agent_response")continue;let s=Rd(o),i=Ed(o);!s||!Number.isSafeInteger(i)||r.set(JSON.stringify([s,i]),o.step);}if(r.size===0)return false;for(let o of r.values())if(o.state!=="DONE"||!vt(o.usage)||Tn(o.usage.input_tokens)===void 0||Tn(o.usage.output_tokens)===void 0)return false;return true}function Hw(t,e){for(let n=e-1;n>=0;n-=1){let r=t[n];if(r?.kind==="agy_error")return r.error}}function Uw(t,e){return vt(t)&&vt(e)?{...e,...t}:vt(t)&&typeof e=="string"?{...t,message:e}:typeof t=="string"&&vt(e)?{...e,message:t}:t??e}function Bw(t){let e=Array.isArray(t.denied_actions)?t.denied_actions:[],n=[];for(let i of e){let a=vt(i)?i:void 0,c=typeof i=="string"?be(i):be(a?.display_name)??be(a?.action);c&&!n.includes(c)&&n.length<5&&n.push(c.slice(0,80));}let r=Math.max(0,e.length-n.length),o=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"",s=`Permission denied: Antigravity blocked ${e.length} requested action${e.length===1?"":"s"}${o}.`;return new J("Could not run because of permissions.","cli/antigravity",{code:"UNKNOWN",kind:"permanent",providerReason:s})}function ni(t){let e=si(t);if(!e)return;if(e.event.kind==="agy_error")return ri(e.event.error);let n=oi(e.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return Bw(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return Sd("Antigravity returned a result with an unsupported status.");let r=n.error,o=Uw(r==null||r===""?n:r,Hw(t,e.index));return ri(o)}function I_(t){if(typeof t=="string")return t;if(t!=null)try{return JSON.stringify(t)}catch{return}}function qw(t){return `agy:${String(t.conversation_id)}:${String(t.step_index)}`}function Fw(t,e){let n=typeof e?.name=="string"?e.name:t.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function N_(t){let e=I_(t);if(e)return e.length<=2e3?e:`${e.slice(0,1999)}\u2026`}function jw(t){let e=vt(t)?t:void 0,n=e&&vt(e.error)?e.error:void 0,r=typeof t=="string"?t.trim().match(/^([A-Z][A-Z0-9_]*)(?:[:\s]|$)/)?.[1]:void 0,o=(be(e?.type)??be(e?.code)??be(e?.error_type)??be(n?.type)??be(n?.code)??be(n?.error_type)??be(r)??"TOOL_ERROR").slice(0,60),s=A_(t).message.slice(0,250);return N_({type:o,message:s})??"Antigravity reported a tool error."}function S_(t,e){return t?t.state.has(e)?true:(t.state.set(e,true),false):false}function b_(t,e){return {timestamp:t,type:"error",content:e.message,errorMessage:e.message,isError:true}}var yd,Iw,Nw,E_,wd,Ow,bd,Ad=x(()=>{h();Cn();R_();Wa();Lo();Dn();$o();zs();ed();yd="antigravity",Iw=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),Nw=new Set(["--conversation","--resume","--continue"]),E_=new Set(["bypassPermissions","agent-full-access","yolo"]),wd=18e4,Ow=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"]);bd={command:"agy",maxInitialInputBytes:wd,meta:{displayName:"Antigravity",models:Sp(),defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(t){let e=xo(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){Mw(t);let{model:r,effort:o}=xn(e.model),s=Ya(r),i=s.model,a=e.effort??o??s.effort,c=xw(i,a),u=e.additionalArgs??[],p=Dw(Cw(u,new Set(["--input-format","--output-format"]))),l=i&&!Fr(u,"--model")?["--model",i]:[],f=Fr(u,"--effort")?[]:$p(c),g=Fr(u,"--mode")||Fr(u,"--dangerously-skip-permissions")?[]:Mp(e.mode),m=vw(e.mode,u)||Fr(u,"--settings")?[]:["--settings",JSON.stringify({permissions:{allow:jp(e.builtinAllow)}})],k=typeof e.resumeSessionId=="string"&&e.resumeSessionId.trim().length>0?["--conversation",e.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...l,...f,...g,...k,...m,...p],stdinMessage:`${JSON.stringify({event:"user",message:{content:t}})}
85
85
  `,env:{AGY_CLI_DISABLE_AUTO_UPDATE:"true"}}},extractText(t){let e=Qn(t),n=si(e)?.event,r=ni(e);if(r)throw r;let o=n?oi(n):void 0;if(o){if(o.status!=="SUCCESS")throw Sd("Antigravity returned a result with an unsupported status.");if(typeof o.response!="string")throw Sd("Antigravity returned a successful result without a response string.");if(!o.response.trim())throw Td();return o.response}if(e.length>0)throw Td();let s=t.trim();if(!s)throw Td();return s},extractPartialText(t){let e=Qn(t),n=si(e)?.event;if(!n||n.kind==="agy_error")return;let r=oi(n);return r&&typeof r.response=="string"&&r.response.trim()?r.response:void 0},interpretExit(t,e,n){let r=Qn(n??""),o=ni(r);return o||(t!==0&&e.trim()?ri(e):null)},parseResultMeta(t){let e=Qn(t),n=0,r=0,o=0,s=0,i=new Set;for(let c of e){if(c.kind!=="step_update"||c.step.state!=="DONE"||!vt(c.step.usage))continue;let u=Rd(c),p=Ed(c);if(!u||!Number.isSafeInteger(p))continue;let l=JSON.stringify([u,p]);if(i.has(l))continue;let f=c.step.usage,g=Tn(f.input_tokens),m=Tn(f.output_tokens);if(g===void 0||m===void 0)continue;i.add(l);let k=Tn(f.cache_read_tokens)??0;n+=g+k,r+=m,o+=k,s+=1;}return {usage:s===0?null:{inputTokens:n,outputTokens:r,cachedInputTokens:o,costUsd:0,complete:$w(e)},model:null}},parseEvent(t,e,n){let r=xo(t);if(!r)return [];let o=e??new Date().toISOString();if(r.kind==="agy_error")return [b_(o,ri(r.error))];if(r.kind==="legacy_result"||r.kind==="result"){let g=ni([r]);return g?[b_(o,g)]:[]}if(r.kind!=="step_update")return [];let{step:s}=r,i=Rd(r)??"unknown",a=Ed(r),c=`${i}:${a}`;if((s.state==="DONE"||s.state==="ERROR")&&S_(n,`antigravity:terminal:${c}`))return [];if(s.step_type==="agent_response")return typeof s.text_delta=="string"&&s.text_delta.length>0?[{timestamp:o,type:"text",content:s.text_delta}]:[];if(s.step_type!=="tool")return [];let u=vt(s.tool_info)?s.tool_info:void 0,p=Fw(s,u);if(!p)return [];let l=qw(s);if(s.state==="ACTIVE"){if(S_(n,`antigravity:active:${c}`))return [];let g=I_(u?.parameters);return [{timestamp:o,type:"tool_use",toolName:p,toolUseId:l,...g===void 0?{}:{toolInput:g}}]}let f=s.state==="ERROR"?jw(u?.error):N_(u?.output);return [{timestamp:o,type:"tool_result",toolName:p,toolUseId:l,...f===void 0?{}:{resultPreview:f},...s.state==="ERROR"?{isError:true}:{}}]}};});var O_=x(()=>{h();Mr();Hr();$r();Zn();});function jr(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Wr(t){return jr(t)?t:void 0}function dt(t){return typeof t=="string"?t:void 0}function rr(t){let e=typeof t=="number"?t:Number(t??0);return Number.isFinite(e)?e:0}function Qw(t){let e=[],n=-1,r=0,o=false,s=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(s){s=false;continue}if(a==="\\"&&o){s=true;continue}if(a==='"'){o=!o;continue}o||(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 jo(t){let e=t.trim();if(!e)return [];try{let n=JSON.parse(e);return jr(n)?[n]:[]}catch{return Qw(e).flatMap(n=>{try{let r=JSON.parse(n);return jr(r)?[r]:[]}catch{return []}})}}function M_(t){let e=JSON.stringify(t);return e===void 0?String(t):e}function nr(t){if(typeof t=="string")return t;if(Array.isArray(t)){let e=t.map(nr).filter(n=>n!==void 0);return e.length>0?e.join(`
86
86
  `):void 0}if(jr(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=nr(t[e]);if(n!==void 0)return n}}}function Zw(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)),o=i=>{let a=JSON.stringify(i,(c,u)=>e(u)?`<bytes:${u.length}>`:u);return a===void 0?String(i):a},s=t.rawOutput;if(s!=null){let i=Wr(s);if(!i)return n(nr(s))??o(s);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=Wr(i.Result);a=n(i.output)??n(p?.output)??n(nr(s));}let c=e(i.stderr)&&i.stderr.length>0?r(i.stderr):void 0;if(c!==void 0)if(a){let p=a.endsWith(`
87
87
  `)||a.endsWith("\r")?"":`
package/dist/index.js CHANGED
@@ -38,7 +38,7 @@
38
38
  time_updated = excluded.time_updated
39
39
  `);r.transaction(s=>{for(let a of s)o.run(a);})(n);}finally{r.close();}}function cY(e){if(!e)return [];let t=[];for(let n=0;n<e.length;n+=1){let r=e[n];if(r==="-s"||r==="--session"){let o=e[n+1],i=o!==void 0&&!o.startsWith("-");t.push({sessionId:i?o:void 0}),i&&(n+=1);continue}(r.startsWith("--session=")||r.startsWith("-s="))&&t.push({sessionId:r.slice(r.indexOf("=")+1)||void 0});}return t}function lY(e){if(!e)return;let t=[];for(let n=0;n<e.length;n+=1){let r=e[n];if(r==="-s"||r==="--session"){e[n+1]!==void 0&&!e[n+1].startsWith("-")&&(n+=1);continue}r.startsWith("--session=")||r.startsWith("-s=")||t.push(r);}return t}function Qy(e){let t=lY(e.additionalArgs);return {...e,...t===void 0?{}:{additionalArgs:t},resumeSessionId:void 0}}function uY(e,t){try{return !!e.prepare("SELECT id FROM session_v2 WHERE id = ?").get(t)}catch(n){if(n instanceof Error&&/no such table: session_v2/i.test(n.message))return false;throw n}}function pY(e,t,n){let r=new e(t,{readonly:true,fileMustExist:true});try{return uY(r,n)}finally{r.close();}}async function Zy(e,t={}){let n;try{n=await(t.loadSqlite??nY)();}catch{throw new exports.ProviderError("OpenCode isolation requires the optional better-sqlite3 dependency. Install it and retry.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}let r=t.crewxHome??$t(),o=Dc(r),i=xu(r),s=rY(i),a=oY(t.userDataHome),d=sY(n,a);if(d.length>0){if(!BD(n,s))try{await(t.initializeDatabase??aY)(o);}catch{throw new exports.ProviderError("Could not initialize the isolated OpenCode credential database.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}if(!BD(n,s))throw new exports.ProviderError("The isolated OpenCode credential database is unavailable.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"});try{dY(n,s,d);}catch{throw new exports.ProviderError("Could not copy API-key credentials into the isolated OpenCode database.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}}let c=cY(e.additionalArgs),l=c.map(p=>p.sessionId),u=c.length>0?l[l.length-1]:e.resumeSessionId;if(!u)return c.length>0?Qy(e):e;if(l.some(p=>p!==u)||!mr.existsSync(s))return Qy(e);try{return pY(n,s,u)?{...e,resumeSessionId:u}:Qy(e)}catch{throw new exports.ProviderError("Could not read the isolated OpenCode session database safely.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}}var e_=M(()=>{h();fs();ps();Xo();});function hY(e){return e.charAt(0).toUpperCase()+e.slice(1)}function RR(e){if(typeof e!="object"||e===null)return "execution_failed";let t=e;return t.code==="ENOENT"?"command_not_found":t.code==="ERR_CHILD_PROCESS_STDIO_MAXBUFFER"?"execution_failed":t.code==="ETIMEDOUT"||t.killed===true?"timeout":typeof t.code=="number"&&t.code!==0?"nonzero_exit":"execution_failed"}function HD(e){let t=new exports.OpenCodeModelQueryError(e);return console.warn("[opencode] model query failed",{code:t.code,reason:t.reason,stage:t.stage}),t}function yY(e,t){let n=HD(t);if(e)throw n;return []}async function jD(e={}){let t=e.throwOnError===true;try{await Zy({});}catch{return yY(t,"preparation_failed")}return new Promise((n,r)=>{let o=false,i=s=>{if(o)return;o=true;let a=HD(s);t?r(a):n([]);};try{child_process.execFile("opencode",["models","--standalone"],{timeout:5e3,maxBuffer:1048576,encoding:null,env:{...dr(process.env),...Dc()}},(a,d)=>{if(!o){if(a){i(RR(a));return}Promise.resolve().then(()=>dR(d)).then(c=>{if(o)return;let l=c.split(`
40
40
  `).map(u=>u.trim()).filter(u=>u.length>0).map(u=>({id:u}));o=!0,n(l);}).catch(()=>i("decode_failed"));}}).on("error",a=>i(RR(a)));}catch(s){i(RR(s));}})}function Lc(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}async function n_(){let e;try{let n=(await import('better-sqlite3')).default,r=Wt.join(xu(),"opencode.db");e=new n(r,{readonly:!0,fileMustExist:!0});let o=e.prepare("SELECT value FROM kv WHERE key = ?").get("models-dev:v2:catalog");if(!o||typeof o.value!="string")throw new Error("OpenCode model catalog row is unavailable");let i=JSON.parse(o.value);if(!Lc(i))throw new Error("OpenCode model catalog shape is unavailable");let s=typeof i.body=="string"?JSON.parse(i.body):i.body;if(!Lc(s))throw new Error("OpenCode model catalog body shape is unavailable");let a=new Map;for(let[d,c]of Object.entries(s)){if(!d||!Lc(c)||!Lc(c.models))throw new Error("OpenCode model provider shape is unavailable");for(let[l,u]of Object.entries(c.models)){if(!l||!Lc(u))throw new Error("OpenCode model shape is unavailable");let p=u.capabilities;if(p===void 0)continue;if(!Lc(p))throw new Error("OpenCode model capability shape is unavailable");let f=p.reasoning;if(f===void 0)continue;if(!Lc(f))throw new Error("OpenCode reasoning capability shape is unavailable");let g=f.effort;(g===void 0||Array.isArray(g)&&g.every(y=>typeof y=="string"))&&a.set(`${d}/${l}`,Array.isArray(g)?g:[]);}}return a}catch{return console.debug("[opencode] could not read private model effort catalog; omitting effort choices"),new Map}finally{try{e?.close();}catch{}}}function _Y(e,t,n){if(!t.meta)return null;let r=t.meta.capabilities??{},o=wi(e),i=o.length>0?o:t.meta.models??[],s=n!==void 0?Yf(n,i):i,a=td(`cli/${e}`),d=co(e).providerOptions??[];return {id:`cli/${e}`,name:t.meta.displayName??hY(e),modes:mc(e),effort:Gr(e),models:Qf(s),modelOverrides:nd(e),...d.length>0?{providerOptions:d}:{},...a!==void 0?{defaults:a}:{},capabilities:{loadSession:r.loadSession??false,resume:r.resume??false,image:r.image??false,audio:r.audio??false,mcp:r.mcp??false}}}async function AY(e={}){let t=e.includeOpencodeRuntimeModels?await jD():void 0,n=[];for(let[r,o]of Object.entries(exports.BUILTIN_ADAPTERS)){let s=_Y(r,o,r==="opencode"?t:void 0);s&&n.push(s);}return n.sort((r,o)=>pg(r.id,o.id))}var mY;exports.OpenCodeModelQueryError=void 0;var kR=M(()=>{h();fd();Yy();sd();ps();e_();lo();mY={preparation_failed:{code:"OPENCODE_MODELS_PREPARATION_FAILED",stage:"prepare",message:"OpenCode model query preparation failed."},command_not_found:{code:"OPENCODE_MODELS_COMMAND_NOT_FOUND",stage:"execute",message:"OpenCode CLI could not be started."},timeout:{code:"OPENCODE_MODELS_TIMEOUT",stage:"execute",message:"OpenCode model query timed out."},nonzero_exit:{code:"OPENCODE_MODELS_EXECUTION_FAILED",stage:"execute",message:"OpenCode model query failed."},execution_failed:{code:"OPENCODE_MODELS_EXECUTION_FAILED",stage:"execute",message:"OpenCode model query failed."},decode_failed:{code:"OPENCODE_MODELS_DECODE_FAILED",stage:"decode",message:"OpenCode model output could not be decoded."}},exports.OpenCodeModelQueryError=class extends Error{code;reason;stage;constructor(t){let n=mY[t];super(n.message),this.name="OpenCodeModelQueryError",this.code=n.code,this.reason=t,this.stage=n.stage;}};});function kY(e){return e?RY[e]??{agent:"build",autoApprove:false}:{agent:void 0,autoApprove:false}}function ri(e,t){return e.some(n=>n===t||n.startsWith(`${t}=`))}function vR(){let e;try{e=xu();}catch{return n_().catch(()=>new Map)}let t=Date.now();if($D===e&&r_&&r_.expiresAt>t)return r_.result;$D=e;let n=n_().catch(()=>new Map);return r_={expiresAt:t+wY,result:n},n}async function SY(e){let t=await Zy(e),n=e.additionalArgs??[],r=ri(n,"--model")||ri(n,"-m");if(!e.model||!e.effort||r)return t;let o=(await vR()).get(e.model);return !o||o.includes(e.effort)?t:(console.debug("[opencode] requested effort is not listed for this model; using OpenCode default"),{...t,effort:void 0})}function zD(e){let t=[],n=0,r=false,o=false,i=0;for(let a=0;a<e.length;a++){let d=e[a];if(o){o=false;continue}if(d==="\\"&&r){o=true;continue}if(d==='"'){r=!r;continue}if(!r){if(d==="{")n++;else if(d==="}"&&(n--,n===0)){let c=e.slice(i,a+1).trim();c&&t.push(c),i=a+1;}}}let s=e.slice(i).trim();return s&&t.push(s),t}function bn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function JD(e){let t=bn(e.part)?e.part:void 0;return e.type==="reasoning"||t?.type==="reasoning"}function bY(e){let t=bn(e.part)?e.part:void 0;return (typeof t?.text=="string"?t.text:typeof e.text=="string"?e.text:void 0)?.trim()||void 0}function vY(e){let t=[],n=false;for(let r of e.split(/\r?\n/)){let o=r.trim();if(!o)continue;try{let s=JSON.parse(o);bn(s)?t.push(s):n=!0;continue}catch{}let i=zD(o);i.length>1&&console.warn("[opencode] extractText: falling back to concatenated-JSON split for a malformed line");for(let s of i)try{let a=JSON.parse(s);bn(a)?t.push(a):n=!0;}catch{n=true;}}return {events:t,malformed:n}}function CR(e){let t=bn(e.error)?e.error:void 0,n=t&&bn(t.data)?t.data:void 0,r=KD(t),o=ti(t?.name),i=ti(n?.message)??ti(t?.message)??SR(r)??ti(e.message)??ti(e.errorMessage)??ti(e.error),s=ti(e.ref),a=o&&i&&o!==i?`${o}: ${i}`:o??i??GD;return (s?`${a} (ref: ${s})`:a).slice(0,EY)}function VD(e){let t=bn(e.error)?e.error:void 0,n=typeof t?.type=="string"?t.type:void 0,r=typeof t?.status=="number"?t.status:Number(t?.status),o=CR(e),i=KD(t),s=i&&bn(i.error)?i.error:void 0,a=typeof s?.type=="string"?s.type:void 0,d=[o,SR(i)].filter(Boolean).join(`
41
- `);if(r===402||CY(d))return new exports.ProviderError(`OpenCode subscription is required: ${o}`,Oo,{code:"SUBSCRIPTION_REQUIRED",kind:"config",providerReason:Nc(o)});if(r===403&&(a==="RegionError"||a==="FreeTierError"))return new exports.ProviderError(`OpenCode account settings are required: ${o}`,Oo,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:"access",providerReason:Nc(o)});if(n==="provider.auth"||r===401||r===403)return new exports.ProviderError(`OpenCode authentication is required: ${o}`,Oo,{code:"AUTH_REQUIRED",kind:"config"});if(r===410||a==="ModelDeprecated")return new exports.ProviderError(`OpenCode model has been retired: ${o}`,Oo,{code:"MODEL_RETIRED",kind:"config",replacementModel:OY(i,t,e),providerReason:Nc(o)});if(n==="provider.free-limit"||r===429){let c=PY(t);return new exports.ProviderError(`OpenCode rate limit reached: ${o}`,Oo,{code:"RATE_LIMITED",kind:"transient",...c===void 0?{}:{retryAfterMs:c}})}if(n==="provider.no-route")return new exports.ProviderError(`OpenCode model or variant unavailable: ${o}`,Oo,{code:"MODEL_UNAVAILABLE",kind:"config"});if(n==="provider.invalid-request"&&r===400){let c=[o,SR(i)].filter(f=>f!==void 0),l=c.find(f=>/requires global regions/i.test(f)),u=c.find(f=>/trains on request data/i.test(f)),p=l?"region":u?"training_consent":void 0;if(p)return new exports.ProviderError(`OpenCode account settings are required: ${o}`,Oo,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:p,providerReason:Nc(l??u)})}return new exports.ProviderError(`OpenCode error: ${o}`,Oo,{code:"PROVIDER_CRASHED",kind:"transient"})}function KD(e){let n=(e&&bn(e.response)?e.response:void 0)?.body;if(bn(n))return n;if(typeof n=="string")try{let r=JSON.parse(n);return bn(r)?r:void 0}catch{return}}function SR(e){let t=e&&bn(e.error)?e.error:void 0;return ti(t?.message)??ti(e?.message)}function CY(e){return /insufficient\s+(?:balance|account funds)|credit\s+limit\s+exceeded|payment\s+required|account invoice is overdue|billing_error|please add or update your payment method|(?:GLM Coding Plan|enterprise) package has expired|your current subscription plan does not yet include access to/i.test(e)}function OY(e,t,n){let r=e&&bn(e.metadata)?e.metadata:void 0,o=typeof r?.replacement=="string"?r.replacement.trim():void 0;if(!o)return;let i=[r?.model,t?.model,n.model,n.modelID].find(d=>typeof d=="string"&&d.trim().length>0)?.trim(),s=i&&i.includes("/")?i.slice(0,i.indexOf("/")):"opencode-go",a=o.includes("/")?o:`${s}/${o}`;return /^[A-Za-z0-9._/-]{1,128}$/.test(a)?a:void 0}function PY(e){let t=e?.retryAfterMs;if(typeof t=="number"&&Number.isFinite(t)&&t>=0)return t;let r=(e&&bn(e.response)?e.response:void 0)?.body,o=typeof r=="string"?NY(r):bn(r)?r:void 0;if(o){let i=bR(o);if(i)return qD(i.value,i.key==="retryafterms")}if(typeof r=="string"){let i=r.match(/retry[-_]after(?:\s*[:=]\s*|\s+)["']?([^"'\s,;}]+)/i);if(i?.[1])return qD(i[1],false)}}function NY(e){try{let t=JSON.parse(e);return bn(t)?t:void 0}catch{return}}function bR(e){if(Array.isArray(e)){for(let t of e){let n=bR(t);if(n)return n}return}if(bn(e)){for(let[t,n]of Object.entries(e)){let r=t.toLowerCase().replace(/[-_]/g,"");if(r==="retryafterms"||r==="retryafter")return {value:n,key:r}}for(let t of Object.values(e)){let n=bR(t);if(n)return n}}}function qD(e,t){if(typeof e=="number"&&Number.isFinite(e)&&e>=0)return t?e:Math.round(e*1e3);if(typeof e!="string"||!e.trim())return;let n=Number(e);if(Number.isFinite(n)&&n>=0)return t?n:Math.round(n*1e3);if(t)return;let r=Date.parse(e);return Number.isFinite(r)?Math.max(0,r-Date.now()):void 0}function WD(e){let t=vY(e),n=[],r=null,o=0,i=[],s=[],a,d=false;for(let c of t.events){if(JD(c))continue;let l=typeof c.type=="string"?c.type:void 0;if(l){if(l==="text"){let u=bn(c.part)?c.part:void 0,p=typeof u?.text=="string"?u.text:void 0;p?.trim()&&n.push(p.trim());continue}if(l==="result"){typeof c.result=="string"&&(r=c.result);continue}if(l==="tool_use"){o++;continue}if(l==="error"){i.push(c),s.push(CR(c));continue}if(l==="step_finish"){d=true;let u=bn(c.part)?c.part:void 0;a=typeof u?.reason=="string"?u.reason:void 0;}}}return {...t,texts:n,resultText:r,toolUseCount:o,errorEvents:i,errorMessages:s,terminalReason:a,hasTerminal:d}}function XD(e){return (e??"unknown").trim().toLowerCase().replace(/_/g,"-")}function xY(){return new exports.ProviderError("OpenCode returned no assistant output.",Oo,{code:"EMPTY_OUTPUT",kind:"transient"})}function DY(){return new exports.ProviderError("OpenCode emitted malformed JSON output.",Oo,{code:"PROVIDER_CRASHED",kind:"transient"})}function LY(e,t){switch(XD(e)){case "length":return new exports.ProviderError("OpenCode stopped because the context window was exceeded.",Oo,{code:"UNKNOWN",kind:"permanent"});case "content-filter":return new exports.ProviderError("OpenCode stopped because the content filter blocked the response.",Oo,{code:"UNKNOWN",kind:"permanent"});case "error":return new exports.ProviderError(`${GD} while generating a response.`,Oo,{code:"PROVIDER_CRASHED",kind:"transient"});default:return null}}var IY,Oo,GD,EY,TY,wY,$D,r_,RY;exports.opencodeAdapter=void 0;var i_=M(()=>{h();fs();IR();bc();Cu();ud();kR();e_();IY=new Set(["step_start","step_finish"]),Oo="cli/opencode",GD="OpenCode provider error",EY=240,TY="Follow the instructions provided on standard input.",wY=3e5,RY={build:{agent:"build",autoApprove:false},"build-auto":{agent:"build",autoApprove:true},plan:{agent:"plan",autoApprove:false},"plan-auto":{agent:"plan",autoApprove:true}};exports.opencodeAdapter={command:"opencode",prepare:SY,meta:{displayName:"OpenCode",capabilities:{resume:true}},buildArgs(e,t,n){let r=t.additionalArgs,o=r!==void 0?[...r]:["run"];ri(o,"--format")||o.push("--format","json"),ri(o,"--thinking")||o.push("--thinking"),!ri(o,"--standalone")&&!ri(o,"--server")&&o.push("--standalone"),t.resumeSessionId&&!ri(o,"-s")&&!ri(o,"--session")&&o.push("-s",t.resumeSessionId);let{agent:i,autoApprove:s}=kY(t.mode);ri(o,"--agent")||i!==void 0&&o.push("--agent",i),s&&!ri(o,"--auto")&&o.push("--auto");let a=ri(o,"--model")||ri(o,"-m");if(t.model&&!a){let d=t.effort?`${t.model}#${t.effort}`:t.model;o.push("--model",d);}else t.effort&&!t.model&&!a&&console.debug("[opencode] ignoring effort because no model is configured");return o.push(TY),{args:o,stdinMessage:e,env:Dc()}},extractText(e){let t=WD(e),n=t.errorEvents[0];if(n)throw VD(n);let r=LY(t.terminalReason??"");if(r)throw r;let o=t.texts.length>0?t.texts[t.texts.length-1]:void 0;if(o!==void 0)return o;if(t.resultText?.trim())return t.resultText;if(t.malformed)throw DY();let i=XD(t.terminalReason);if(t.hasTerminal&&i==="tool-calls"&&t.toolUseCount>0)return "";throw xY()},interpretExit(e,t,n=""){if(e===0)return null;let o=WD(n).errorEvents[0];return o?VD(o):null},parseResultMeta(e){let t=ia(e);return t?{usage:{inputTokens:t.inputTokens,outputTokens:t.outputTokens,cachedInputTokens:t.cachedInputTokens,costUsd:0},model:null}:{usage:null,model:null}},parseEvent(e,t,n){let r=t??new Date().toISOString(),o=[],i=new Map,s;try{JSON.parse(e),s=[e];}catch{s=zD(e),s.length>1&&console.warn("[opencode] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let a of s){let d;try{d=JSON.parse(a);}catch{continue}let c=po(d,r),l=d.type;if(JD(d)){let u=bY(d);if(!u)continue;let p=bn(d.part)?d.part:void 0,f=typeof p?.id=="string"?p.id:typeof d.id=="string"?d.id:void 0,g=u;if(f){let y=`opencode.reasoning:${f}`,_=n?.state.get(y),A=typeof _=="string"?_:i.get(f);if(typeof A=="string"&&(A===u||A.startsWith(u))||typeof A=="string"&&u.startsWith(A)&&(g=u.slice(A.length).trim(),!g))continue;i.set(f,u),n?.state.set(y,u);}o.push({timestamp:c,type:"thinking",content:g});continue}if(l){if(l==="text"){let p=d.part?.text;p&&o.push({timestamp:c,type:"text",content:p});continue}if(l==="tool_use"){let u=d.part;if(!u)continue;let p=String(u.tool||""),f=String(u.callID||u.id||""),g=u.state,y=String(g?.status||""),_=g?.input,A=ei(_);if(o.push({timestamp:c,type:"tool_use",toolName:p,toolUseId:f,toolInput:A}),y==="completed"&&g?.output!==void 0){let I=g.output,w=typeof I=="string"?I:JSON.stringify(I);o.push({timestamp:c,type:"tool_result",toolUseId:f,resultPreview:w,isError:false});}else y==="error"&&o.push({timestamp:c,type:"tool_result",toolUseId:f,resultPreview:String(g?.error||"tool error"),isError:true});continue}if(l==="error"){let u=CR(d);o.push({timestamp:c,type:"error",content:u,errorMessage:u});continue}}}return o},suppressOutputLine(e){let t=e.trim();if(!t.startsWith("{")||!t.endsWith("}"))return false;try{let r=JSON.parse(t).type;return r?IY.has(r):!1}catch{return false}}};});function YD(e,t){if(e===void 0||e==="")return t;let n=parseInt(e,10);return Number.isNaN(n)?t:n}function OR(e=process.env){let t=e.CREWX_TIMEOUT_IDLE;if(t===void 0||t==="")return;let n=parseInt(t,10);if(!(!Number.isFinite(n)||n<=0))return n}function QD(e=process.env){return {queryMs:YD(e.CREWX_TIMEOUT_QUERY,288e5),executeMs:YD(e.CREWX_TIMEOUT_EXECUTE,288e5),idleMs:OR(e)??6e5}}var fg=M(()=>{h();});function Du(e,t){return e.some(n=>n===t||n.startsWith(`${t}=`))}function FY(e,t){return e&&ZD.has(e)||Du(t,"--dangerously-skip-permissions")?true:t.some((n,r)=>{let o=n==="--mode"?t[r+1]:n.startsWith("--mode=")?n.slice(7):void 0;return typeof o=="string"&&ZD.has(o)})}function HY(e,t){let n=[];for(let r=0;r<e.length;r+=1){let o=e[r],i=[...t].find(s=>o===s||o.startsWith(`${s}=`));i?o===i&&r+1<e.length&&(r+=1):n.push(o);}return n}function jY(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e[n],o=r.indexOf("="),i=o>0?r.slice(0,o):r;if(!UY.has(i)){t.push(r);continue}r===i&&n+1<e.length&&!e[n+1].startsWith("-")&&(n+=1);}return t}function oi(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function $Y(e,t){if(!(e?MY.has(e)||wi(PR).some(i=>i.id===e):false)||!e)return t;let r=Gr(PR,e),o=nd(PR)[e]?.defaultEffort;if(r.length!==0)return t?r.includes(t)?t:o&&r.includes(o)?o:void 0:o}function sa(e){return typeof e=="number"&&Number.isSafeInteger(e)&&e>=0?e:void 0}function DR(e){return e.kind==="step_update"?typeof e.step.conversation_id=="string"?e.step.conversation_id:void 0:typeof e.envelope.conversation_id=="string"?e.envelope.conversation_id:void 0}function LR(e){return e.step.step_index}function Rn(e){if(typeof e!="string")return;let t=e.split(/\r?\n/,1)[0]?.trim();return t&&dd(t)?.slice(0,500).trim()||void 0}function VY(e,t){let n=(e??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&BY.has(n))return n;let r=`${n} ${t??""}`.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)/,/invalid (?:flag|option)/].some(i=>i.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 qY(e){return e==="AUTH_REQUIRED"||e==="TIMEOUT_IDLE"||e==="TIMEOUT_TOTAL"||e==="TIMEOUT_RESUME"||e==="PROVIDER_CRASHED"?"permanent":e==="MODEL_UNAVAILABLE"||e==="INVALID_PROVIDER_FORMAT"||e==="PROVIDER_NOT_FOUND"?"config":"transient"}function nL(e){let t=oi(e)?e:void 0,n=t&&oi(t.error)?t.error:void 0,r=t?Rn(t.code)??Rn(t.error_code)??Rn(n?.code)??Rn(n?.error_code):void 0,o=typeof e=="string"?Rn(e):t?Rn(t.message)??Rn(t.error)??Rn(t.reason)??Rn(n?.message)??Rn(n?.error)??Rn(n?.reason):void 0,i=VY(r,o),s=t?sa(t.retry_after_ms)??sa(t.retryAfterMs)??sa(n?.retry_after_ms)??sa(n?.retryAfterMs):void 0;return {code:i,kind:qY(i),message:o??"Antigravity reported a terminal error.",...s===void 0?{}:{retryAfterMs:s}}}function a_(e){let t=nL(e);return new exports.ProviderError(t.message,"cli/antigravity",{code:t.code,kind:t.kind,...t.retryAfterMs===void 0?{}:{retryAfterMs:t.retryAfterMs}})}function MR(e){return new exports.ProviderError(e,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function WY(e){let t=new TextEncoder().encode(e).byteLength;if(!(t<=xR))throw new exports.ProviderError(`Input is too large: final provider initial input is ${t} UTF-8 bytes; budget is ${xR} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function NR(){return new exports.ProviderError("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 d_(e){if(e.kind==="result"||e.kind==="legacy_result")return e.result}function c_(e){for(let t=e.length-1;t>=0;t-=1){let n=e[t];if(n&&(n.kind==="result"||n.kind==="legacy_result"||n.kind==="agy_error"))return {event:n,index:t}}}function GY(e){let t=c_(e);if(!t||t.event.kind==="agy_error"||t.index!==e.length-1||d_(t.event)?.status!=="SUCCESS"||s_(e))return false;let r=new Map;for(let o of e){if(o.kind!=="step_update"||o.step.step_type!=="agent_response")continue;let i=DR(o),s=LR(o);!i||!Number.isSafeInteger(s)||r.set(JSON.stringify([i,s]),o.step);}if(r.size===0)return false;for(let o of r.values())if(o.state!=="DONE"||!oi(o.usage)||sa(o.usage.input_tokens)===void 0||sa(o.usage.output_tokens)===void 0)return false;return true}function zY(e,t){for(let n=t-1;n>=0;n-=1){let r=e[n];if(r?.kind==="agy_error")return r.error}}function JY(e,t){return oi(e)&&oi(t)?{...t,...e}:oi(e)&&typeof t=="string"?{...e,message:t}:typeof e=="string"&&oi(t)?{...t,message:e}:e??t}function KY(e){let t=Array.isArray(e.denied_actions)?e.denied_actions:[],n=[];for(let s of t){let a=oi(s)?s:void 0,d=typeof s=="string"?Rn(s):Rn(a?.display_name)??Rn(a?.action);d&&!n.includes(d)&&n.length<5&&n.push(d.slice(0,80));}let r=Math.max(0,t.length-n.length),o=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"",i=`Permission denied: Antigravity blocked ${t.length} requested action${t.length===1?"":"s"}${o}.`;return new exports.ProviderError("\uAD8C\uD55C \uB54C\uBB38\uC5D0 \uC2E4\uD589\uD558\uC9C0 \uBABB\uD588\uC5B4\uC694","cli/antigravity",{code:"UNKNOWN",kind:"permanent",providerReason:i})}function s_(e){let t=c_(e);if(!t)return;if(t.event.kind==="agy_error")return a_(t.event.error);let n=d_(t.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return KY(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return MR("Antigravity returned a result with an unsupported status.");let r=n.error,o=JY(r==null||r===""?n:r,zY(e,t.index));return a_(o)}function rL(e){if(typeof e=="string")return e;if(e!=null)try{return JSON.stringify(e)}catch{return}}function XY(e){return `agy:${String(e.conversation_id)}:${String(e.step_index)}`}function YY(e,t){let n=typeof t?.name=="string"?t.name:e.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function oL(e){let t=rL(e);if(t)return t.length<=2e3?t:`${t.slice(0,1999)}\u2026`}function QY(e){let t=oi(e)?e:void 0,n=t&&oi(t.error)?t.error:void 0,r=typeof e=="string"?e.trim().match(/^([A-Z][A-Z0-9_]*)(?:[:\s]|$)/)?.[1]:void 0,o=(Rn(t?.type)??Rn(t?.code)??Rn(t?.error_type)??Rn(n?.type)??Rn(n?.code)??Rn(n?.error_type)??Rn(r)??"TOOL_ERROR").slice(0,60),i=nL(e).message.slice(0,250);return oL({type:o,message:i})??"Antigravity reported a tool error."}function eL(e,t){return e?e.state.has(t)?true:(e.state.set(t,true),false):false}function tL(e,t){return {timestamp:e,type:"error",content:t.message,errorMessage:t.message,isError:true}}var PR,MY,UY,ZD,xR,BY,UR,BR=M(()=>{h();fs();fg();cg();na();lo();Ou();jy();mR();PR="antigravity",MY=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),UY=new Set(["--conversation","--resume","--continue"]),ZD=new Set(["bypassPermissions","agent-full-access","yolo"]),xR=18e4,BY=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"]);UR={command:"agy",maxInitialInputBytes:xR,meta:{displayName:"Antigravity",models:qw(),defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(e){let t=ku(e);if(t?.kind!=="init")return null;let n=t.envelope.conversation_id;return typeof n=="string"&&n.trim().length>0?n.trim():null},buildArgs(e,t,n){WY(e);let{model:r,effort:o}=hs(t.model),i=fu(r),s=i.model,a=t.effort??o??i.effort,d=$Y(s,a),c=t.additionalArgs??[],l=jY(HY(c,new Set(["--input-format","--output-format"]))),u=s&&!Du(c,"--model")?["--model",s]:[],p=Du(c,"--effort")?[]:ED(d),f=Du(c,"--mode")||Du(c,"--dangerously-skip-permissions")?[]:ID(t.mode),g=FY(t.mode,c)||Du(c,"--settings")?[]:["--settings",JSON.stringify({permissions:{allow:kD(t.builtinAllow)}})],y=typeof t.resumeSessionId=="string"&&t.resumeSessionId.trim().length>0?["--conversation",t.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...u,...p,...f,...y,...g,...l],stdinMessage:`${JSON.stringify({event:"user",message:{content:e}})}
41
+ `);if(r===402||CY(d))return new exports.ProviderError(`OpenCode subscription is required: ${o}`,Oo,{code:"SUBSCRIPTION_REQUIRED",kind:"config",providerReason:Nc(o)});if(r===403&&(a==="RegionError"||a==="FreeTierError"))return new exports.ProviderError(`OpenCode account settings are required: ${o}`,Oo,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:"access",providerReason:Nc(o)});if(n==="provider.auth"||r===401||r===403)return new exports.ProviderError(`OpenCode authentication is required: ${o}`,Oo,{code:"AUTH_REQUIRED",kind:"config"});if(r===410||a==="ModelDeprecated")return new exports.ProviderError(`OpenCode model has been retired: ${o}`,Oo,{code:"MODEL_RETIRED",kind:"config",replacementModel:OY(i,t,e),providerReason:Nc(o)});if(n==="provider.free-limit"||r===429){let c=PY(t);return new exports.ProviderError(`OpenCode rate limit reached: ${o}`,Oo,{code:"RATE_LIMITED",kind:"transient",...c===void 0?{}:{retryAfterMs:c}})}if(n==="provider.no-route")return new exports.ProviderError(`OpenCode model or variant unavailable: ${o}`,Oo,{code:"MODEL_UNAVAILABLE",kind:"config"});if(n==="provider.invalid-request"&&r===400){let c=[o,SR(i)].filter(f=>f!==void 0),l=c.find(f=>/requires global regions/i.test(f)),u=c.find(f=>/trains on request data/i.test(f)),p=l?"region":u?"training_consent":void 0;if(p)return new exports.ProviderError(`OpenCode account settings are required: ${o}`,Oo,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:p,providerReason:Nc(l??u)})}return new exports.ProviderError(`OpenCode error: ${o}`,Oo,{code:"PROVIDER_CRASHED",kind:"transient"})}function KD(e){let n=(e&&bn(e.response)?e.response:void 0)?.body;if(bn(n))return n;if(typeof n=="string")try{let r=JSON.parse(n);return bn(r)?r:void 0}catch{return}}function SR(e){let t=e&&bn(e.error)?e.error:void 0;return ti(t?.message)??ti(e?.message)}function CY(e){return /insufficient\s+(?:balance|account funds)|credit\s+limit\s+exceeded|payment\s+required|account invoice is overdue|billing_error|please add or update your payment method|(?:GLM Coding Plan|enterprise) package has expired|your current subscription plan does not yet include access to/i.test(e)}function OY(e,t,n){let r=e&&bn(e.metadata)?e.metadata:void 0,o=typeof r?.replacement=="string"?r.replacement.trim():void 0;if(!o)return;let i=[r?.model,t?.model,n.model,n.modelID].find(d=>typeof d=="string"&&d.trim().length>0)?.trim(),s=i&&i.includes("/")?i.slice(0,i.indexOf("/")):"opencode-go",a=o.includes("/")?o:`${s}/${o}`;return /^[A-Za-z0-9._/-]{1,128}$/.test(a)?a:void 0}function PY(e){let t=e?.retryAfterMs;if(typeof t=="number"&&Number.isFinite(t)&&t>=0)return t;let r=(e&&bn(e.response)?e.response:void 0)?.body,o=typeof r=="string"?NY(r):bn(r)?r:void 0;if(o){let i=bR(o);if(i)return qD(i.value,i.key==="retryafterms")}if(typeof r=="string"){let i=r.match(/retry[-_]after(?:\s*[:=]\s*|\s+)["']?([^"'\s,;}]+)/i);if(i?.[1])return qD(i[1],false)}}function NY(e){try{let t=JSON.parse(e);return bn(t)?t:void 0}catch{return}}function bR(e){if(Array.isArray(e)){for(let t of e){let n=bR(t);if(n)return n}return}if(bn(e)){for(let[t,n]of Object.entries(e)){let r=t.toLowerCase().replace(/[-_]/g,"");if(r==="retryafterms"||r==="retryafter")return {value:n,key:r}}for(let t of Object.values(e)){let n=bR(t);if(n)return n}}}function qD(e,t){if(typeof e=="number"&&Number.isFinite(e)&&e>=0)return t?e:Math.round(e*1e3);if(typeof e!="string"||!e.trim())return;let n=Number(e);if(Number.isFinite(n)&&n>=0)return t?n:Math.round(n*1e3);if(t)return;let r=Date.parse(e);return Number.isFinite(r)?Math.max(0,r-Date.now()):void 0}function WD(e){let t=vY(e),n=[],r=null,o=0,i=[],s=[],a,d=false;for(let c of t.events){if(JD(c))continue;let l=typeof c.type=="string"?c.type:void 0;if(l){if(l==="text"){let u=bn(c.part)?c.part:void 0,p=typeof u?.text=="string"?u.text:void 0;p?.trim()&&n.push(p.trim());continue}if(l==="result"){typeof c.result=="string"&&(r=c.result);continue}if(l==="tool_use"){o++;continue}if(l==="error"){i.push(c),s.push(CR(c));continue}if(l==="step_finish"){d=true;let u=bn(c.part)?c.part:void 0;a=typeof u?.reason=="string"?u.reason:void 0;}}}return {...t,texts:n,resultText:r,toolUseCount:o,errorEvents:i,errorMessages:s,terminalReason:a,hasTerminal:d}}function XD(e){return (e??"unknown").trim().toLowerCase().replace(/_/g,"-")}function xY(){return new exports.ProviderError("OpenCode returned no assistant output.",Oo,{code:"EMPTY_OUTPUT",kind:"transient"})}function DY(){return new exports.ProviderError("OpenCode emitted malformed JSON output.",Oo,{code:"PROVIDER_CRASHED",kind:"transient"})}function LY(e,t){switch(XD(e)){case "length":return new exports.ProviderError("OpenCode stopped because the context window was exceeded.",Oo,{code:"UNKNOWN",kind:"permanent"});case "content-filter":return new exports.ProviderError("OpenCode stopped because the content filter blocked the response.",Oo,{code:"UNKNOWN",kind:"permanent"});case "error":return new exports.ProviderError(`${GD} while generating a response.`,Oo,{code:"PROVIDER_CRASHED",kind:"transient"});default:return null}}var IY,Oo,GD,EY,TY,wY,$D,r_,RY;exports.opencodeAdapter=void 0;var i_=M(()=>{h();fs();IR();bc();Cu();ud();kR();e_();IY=new Set(["step_start","step_finish"]),Oo="cli/opencode",GD="OpenCode provider error",EY=240,TY="Follow the instructions provided on standard input.",wY=3e5,RY={build:{agent:"build",autoApprove:false},"build-auto":{agent:"build",autoApprove:true},plan:{agent:"plan",autoApprove:false},"plan-auto":{agent:"plan",autoApprove:true}};exports.opencodeAdapter={command:"opencode",prepare:SY,meta:{displayName:"OpenCode",capabilities:{resume:true}},buildArgs(e,t,n){let r=t.additionalArgs,o=r!==void 0?[...r]:["run"];ri(o,"--format")||o.push("--format","json"),ri(o,"--thinking")||o.push("--thinking"),!ri(o,"--standalone")&&!ri(o,"--server")&&o.push("--standalone"),t.resumeSessionId&&!ri(o,"-s")&&!ri(o,"--session")&&o.push("-s",t.resumeSessionId);let{agent:i,autoApprove:s}=kY(t.mode);ri(o,"--agent")||i!==void 0&&o.push("--agent",i),s&&!ri(o,"--auto")&&o.push("--auto");let a=ri(o,"--model")||ri(o,"-m");if(t.model&&!a){let d=t.effort?`${t.model}#${t.effort}`:t.model;o.push("--model",d);}else t.effort&&!t.model&&!a&&console.debug("[opencode] ignoring effort because no model is configured");return o.push(TY),{args:o,stdinMessage:e,env:Dc()}},extractText(e){let t=WD(e),n=t.errorEvents[0];if(n)throw VD(n);let r=LY(t.terminalReason??"");if(r)throw r;let o=t.texts.length>0?t.texts[t.texts.length-1]:void 0;if(o!==void 0)return o;if(t.resultText?.trim())return t.resultText;if(t.malformed)throw DY();let i=XD(t.terminalReason);if(t.hasTerminal&&i==="tool-calls"&&t.toolUseCount>0)return "";throw xY()},interpretExit(e,t,n=""){if(e===0)return null;let o=WD(n).errorEvents[0];return o?VD(o):null},parseResultMeta(e){let t=ia(e);return t?{usage:{inputTokens:t.inputTokens,outputTokens:t.outputTokens,cachedInputTokens:t.cachedInputTokens,costUsd:0},model:null}:{usage:null,model:null}},parseEvent(e,t,n){let r=t??new Date().toISOString(),o=[],i=new Map,s;try{JSON.parse(e),s=[e];}catch{s=zD(e),s.length>1&&console.warn("[opencode] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let a of s){let d;try{d=JSON.parse(a);}catch{continue}let c=po(d,r),l=d.type;if(JD(d)){let u=bY(d);if(!u)continue;let p=bn(d.part)?d.part:void 0,f=typeof p?.id=="string"?p.id:typeof d.id=="string"?d.id:void 0,g=u;if(f){let y=`opencode.reasoning:${f}`,_=n?.state.get(y),A=typeof _=="string"?_:i.get(f);if(typeof A=="string"&&(A===u||A.startsWith(u))||typeof A=="string"&&u.startsWith(A)&&(g=u.slice(A.length).trim(),!g))continue;i.set(f,u),n?.state.set(y,u);}o.push({timestamp:c,type:"thinking",content:g});continue}if(l){if(l==="text"){let p=d.part?.text;p&&o.push({timestamp:c,type:"text",content:p});continue}if(l==="tool_use"){let u=d.part;if(!u)continue;let p=String(u.tool||""),f=String(u.callID||u.id||""),g=u.state,y=String(g?.status||""),_=g?.input,A=ei(_);if(o.push({timestamp:c,type:"tool_use",toolName:p,toolUseId:f,toolInput:A}),y==="completed"&&g?.output!==void 0){let I=g.output,w=typeof I=="string"?I:JSON.stringify(I);o.push({timestamp:c,type:"tool_result",toolUseId:f,resultPreview:w,isError:false});}else y==="error"&&o.push({timestamp:c,type:"tool_result",toolUseId:f,resultPreview:String(g?.error||"tool error"),isError:true});continue}if(l==="error"){let u=CR(d);o.push({timestamp:c,type:"error",content:u,errorMessage:u});continue}}}return o},suppressOutputLine(e){let t=e.trim();if(!t.startsWith("{")||!t.endsWith("}"))return false;try{let r=JSON.parse(t).type;return r?IY.has(r):!1}catch{return false}}};});function YD(e,t){if(e===void 0||e==="")return t;let n=parseInt(e,10);return Number.isNaN(n)?t:n}function OR(e=process.env){let t=e.CREWX_TIMEOUT_IDLE;if(t===void 0||t==="")return;let n=parseInt(t,10);if(!(!Number.isFinite(n)||n<=0))return n}function QD(e=process.env){return {queryMs:YD(e.CREWX_TIMEOUT_QUERY,288e5),executeMs:YD(e.CREWX_TIMEOUT_EXECUTE,288e5),idleMs:OR(e)??6e5}}var fg=M(()=>{h();});function Du(e,t){return e.some(n=>n===t||n.startsWith(`${t}=`))}function FY(e,t){return e&&ZD.has(e)||Du(t,"--dangerously-skip-permissions")?true:t.some((n,r)=>{let o=n==="--mode"?t[r+1]:n.startsWith("--mode=")?n.slice(7):void 0;return typeof o=="string"&&ZD.has(o)})}function HY(e,t){let n=[];for(let r=0;r<e.length;r+=1){let o=e[r],i=[...t].find(s=>o===s||o.startsWith(`${s}=`));i?o===i&&r+1<e.length&&(r+=1):n.push(o);}return n}function jY(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e[n],o=r.indexOf("="),i=o>0?r.slice(0,o):r;if(!UY.has(i)){t.push(r);continue}r===i&&n+1<e.length&&!e[n+1].startsWith("-")&&(n+=1);}return t}function oi(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function $Y(e,t){if(!(e?MY.has(e)||wi(PR).some(i=>i.id===e):false)||!e)return t;let r=Gr(PR,e),o=nd(PR)[e]?.defaultEffort;if(r.length!==0)return t?r.includes(t)?t:o&&r.includes(o)?o:void 0:o}function sa(e){return typeof e=="number"&&Number.isSafeInteger(e)&&e>=0?e:void 0}function DR(e){return e.kind==="step_update"?typeof e.step.conversation_id=="string"?e.step.conversation_id:void 0:typeof e.envelope.conversation_id=="string"?e.envelope.conversation_id:void 0}function LR(e){return e.step.step_index}function Rn(e){if(typeof e!="string")return;let t=e.split(/\r?\n/,1)[0]?.trim();return t&&dd(t)?.slice(0,500).trim()||void 0}function VY(e,t){let n=(e??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&BY.has(n))return n;let r=`${n} ${t??""}`.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)/,/invalid (?:flag|option)/].some(i=>i.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 qY(e){return e==="AUTH_REQUIRED"||e==="TIMEOUT_IDLE"||e==="TIMEOUT_TOTAL"||e==="TIMEOUT_RESUME"||e==="PROVIDER_CRASHED"?"permanent":e==="MODEL_UNAVAILABLE"||e==="INVALID_PROVIDER_FORMAT"||e==="PROVIDER_NOT_FOUND"?"config":"transient"}function nL(e){let t=oi(e)?e:void 0,n=t&&oi(t.error)?t.error:void 0,r=t?Rn(t.code)??Rn(t.error_code)??Rn(n?.code)??Rn(n?.error_code):void 0,o=typeof e=="string"?Rn(e):t?Rn(t.message)??Rn(t.error)??Rn(t.reason)??Rn(n?.message)??Rn(n?.error)??Rn(n?.reason):void 0,i=VY(r,o),s=t?sa(t.retry_after_ms)??sa(t.retryAfterMs)??sa(n?.retry_after_ms)??sa(n?.retryAfterMs):void 0;return {code:i,kind:qY(i),message:o??"Antigravity reported a terminal error.",...s===void 0?{}:{retryAfterMs:s}}}function a_(e){let t=nL(e);return new exports.ProviderError(t.message,"cli/antigravity",{code:t.code,kind:t.kind,...t.retryAfterMs===void 0?{}:{retryAfterMs:t.retryAfterMs}})}function MR(e){return new exports.ProviderError(e,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function WY(e){let t=new TextEncoder().encode(e).byteLength;if(!(t<=xR))throw new exports.ProviderError(`Input is too large: final provider initial input is ${t} UTF-8 bytes; budget is ${xR} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function NR(){return new exports.ProviderError("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 d_(e){if(e.kind==="result"||e.kind==="legacy_result")return e.result}function c_(e){for(let t=e.length-1;t>=0;t-=1){let n=e[t];if(n&&(n.kind==="result"||n.kind==="legacy_result"||n.kind==="agy_error"))return {event:n,index:t}}}function GY(e){let t=c_(e);if(!t||t.event.kind==="agy_error"||t.index!==e.length-1||d_(t.event)?.status!=="SUCCESS"||s_(e))return false;let r=new Map;for(let o of e){if(o.kind!=="step_update"||o.step.step_type!=="agent_response")continue;let i=DR(o),s=LR(o);!i||!Number.isSafeInteger(s)||r.set(JSON.stringify([i,s]),o.step);}if(r.size===0)return false;for(let o of r.values())if(o.state!=="DONE"||!oi(o.usage)||sa(o.usage.input_tokens)===void 0||sa(o.usage.output_tokens)===void 0)return false;return true}function zY(e,t){for(let n=t-1;n>=0;n-=1){let r=e[n];if(r?.kind==="agy_error")return r.error}}function JY(e,t){return oi(e)&&oi(t)?{...t,...e}:oi(e)&&typeof t=="string"?{...e,message:t}:typeof e=="string"&&oi(t)?{...t,message:e}:e??t}function KY(e){let t=Array.isArray(e.denied_actions)?e.denied_actions:[],n=[];for(let s of t){let a=oi(s)?s:void 0,d=typeof s=="string"?Rn(s):Rn(a?.display_name)??Rn(a?.action);d&&!n.includes(d)&&n.length<5&&n.push(d.slice(0,80));}let r=Math.max(0,t.length-n.length),o=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"",i=`Permission denied: Antigravity blocked ${t.length} requested action${t.length===1?"":"s"}${o}.`;return new exports.ProviderError("Could not run because of permissions.","cli/antigravity",{code:"UNKNOWN",kind:"permanent",providerReason:i})}function s_(e){let t=c_(e);if(!t)return;if(t.event.kind==="agy_error")return a_(t.event.error);let n=d_(t.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return KY(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return MR("Antigravity returned a result with an unsupported status.");let r=n.error,o=JY(r==null||r===""?n:r,zY(e,t.index));return a_(o)}function rL(e){if(typeof e=="string")return e;if(e!=null)try{return JSON.stringify(e)}catch{return}}function XY(e){return `agy:${String(e.conversation_id)}:${String(e.step_index)}`}function YY(e,t){let n=typeof t?.name=="string"?t.name:e.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function oL(e){let t=rL(e);if(t)return t.length<=2e3?t:`${t.slice(0,1999)}\u2026`}function QY(e){let t=oi(e)?e:void 0,n=t&&oi(t.error)?t.error:void 0,r=typeof e=="string"?e.trim().match(/^([A-Z][A-Z0-9_]*)(?:[:\s]|$)/)?.[1]:void 0,o=(Rn(t?.type)??Rn(t?.code)??Rn(t?.error_type)??Rn(n?.type)??Rn(n?.code)??Rn(n?.error_type)??Rn(r)??"TOOL_ERROR").slice(0,60),i=nL(e).message.slice(0,250);return oL({type:o,message:i})??"Antigravity reported a tool error."}function eL(e,t){return e?e.state.has(t)?true:(e.state.set(t,true),false):false}function tL(e,t){return {timestamp:e,type:"error",content:t.message,errorMessage:t.message,isError:true}}var PR,MY,UY,ZD,xR,BY,UR,BR=M(()=>{h();fs();fg();cg();na();lo();Ou();jy();mR();PR="antigravity",MY=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),UY=new Set(["--conversation","--resume","--continue"]),ZD=new Set(["bypassPermissions","agent-full-access","yolo"]),xR=18e4,BY=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"]);UR={command:"agy",maxInitialInputBytes:xR,meta:{displayName:"Antigravity",models:qw(),defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(e){let t=ku(e);if(t?.kind!=="init")return null;let n=t.envelope.conversation_id;return typeof n=="string"&&n.trim().length>0?n.trim():null},buildArgs(e,t,n){WY(e);let{model:r,effort:o}=hs(t.model),i=fu(r),s=i.model,a=t.effort??o??i.effort,d=$Y(s,a),c=t.additionalArgs??[],l=jY(HY(c,new Set(["--input-format","--output-format"]))),u=s&&!Du(c,"--model")?["--model",s]:[],p=Du(c,"--effort")?[]:ED(d),f=Du(c,"--mode")||Du(c,"--dangerously-skip-permissions")?[]:ID(t.mode),g=FY(t.mode,c)||Du(c,"--settings")?[]:["--settings",JSON.stringify({permissions:{allow:kD(t.builtinAllow)}})],y=typeof t.resumeSessionId=="string"&&t.resumeSessionId.trim().length>0?["--conversation",t.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...u,...p,...f,...y,...g,...l],stdinMessage:`${JSON.stringify({event:"user",message:{content:e}})}
42
42
  `,env:{AGY_CLI_DISABLE_AUTO_UPDATE:"true"}}},extractText(e){let t=Su(e),n=c_(t)?.event,r=s_(t);if(r)throw r;let o=n?d_(n):void 0;if(o){if(o.status!=="SUCCESS")throw MR("Antigravity returned a result with an unsupported status.");if(typeof o.response!="string")throw MR("Antigravity returned a successful result without a response string.");if(!o.response.trim())throw NR();return o.response}if(t.length>0)throw NR();let i=e.trim();if(!i)throw NR();return i},extractPartialText(e){let t=Su(e),n=c_(t)?.event;if(!n||n.kind==="agy_error")return;let r=d_(n);return r&&typeof r.response=="string"&&r.response.trim()?r.response:void 0},interpretExit(e,t,n){let r=Su(n??""),o=s_(r);return o||(e!==0&&t.trim()?a_(t):null)},parseResultMeta(e){let t=Su(e),n=0,r=0,o=0,i=0,s=new Set;for(let d of t){if(d.kind!=="step_update"||d.step.state!=="DONE"||!oi(d.step.usage))continue;let c=DR(d),l=LR(d);if(!c||!Number.isSafeInteger(l))continue;let u=JSON.stringify([c,l]);if(s.has(u))continue;let p=d.step.usage,f=sa(p.input_tokens),g=sa(p.output_tokens);if(f===void 0||g===void 0)continue;s.add(u);let y=sa(p.cache_read_tokens)??0;n+=f+y,r+=g,o+=y,i+=1;}return {usage:i===0?null:{inputTokens:n,outputTokens:r,cachedInputTokens:o,costUsd:0,complete:GY(t)},model:null}},parseEvent(e,t,n){let r=ku(e);if(!r)return [];let o=t??new Date().toISOString();if(r.kind==="agy_error")return [tL(o,a_(r.error))];if(r.kind==="legacy_result"||r.kind==="result"){let f=s_([r]);return f?[tL(o,f)]:[]}if(r.kind!=="step_update")return [];let{step:i}=r,s=DR(r)??"unknown",a=LR(r),d=`${s}:${a}`;if((i.state==="DONE"||i.state==="ERROR")&&eL(n,`antigravity:terminal:${d}`))return [];if(i.step_type==="agent_response")return typeof i.text_delta=="string"&&i.text_delta.length>0?[{timestamp:o,type:"text",content:i.text_delta}]:[];if(i.step_type!=="tool")return [];let c=oi(i.tool_info)?i.tool_info:void 0,l=YY(i,c);if(!l)return [];let u=XY(i);if(i.state==="ACTIVE"){if(eL(n,`antigravity:active:${d}`))return [];let f=rL(c?.parameters);return [{timestamp:o,type:"tool_use",toolName:l,toolUseId:u,...f===void 0?{}:{toolInput:f}}]}let p=i.state==="ERROR"?QY(c?.error):oL(c?.output);return [{timestamp:o,type:"tool_result",toolName:l,toolUseId:u,...p===void 0?{}:{resultPreview:p},...i.state==="ERROR"?{isError:true}:{}}]}};});var iL,sL=M(()=>{h();vu();Cu();ld();ud();iL={parseEvent(e,t){let n;try{n=JSON.parse(e);}catch{return []}let r=n.type;if(!r)return [];if(r!=="message"&&r!=="tool_use"&&r!=="tool_result")return [];let o=po(n,t??new Date().toISOString());if(r==="message"){if(n.role!=="assistant")return [];let s=n.content;return s?[{timestamp:o,type:"text",content:s}]:[]}if(r==="tool_use"){let i=String(n.tool_name||""),s=n.tool_id,a=n.parameters,d=ei(a);return /^bash$/i.test(i)&&Ri(d)?[ki(o,d,s)]:[{timestamp:o,type:"tool_use",toolName:i,toolUseId:s,toolInput:d}]}if(r==="tool_result"){let i=n.tool_id,s=String(n.output??""),a=n.status!=="success";return [{timestamp:o,type:"tool_result",toolUseId:i,...Co(s,a)}]}return []}};});function Lu(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Mu(e){return Lu(e)?e:void 0}function fo(e){return typeof e=="string"?e:void 0}function Bc(e){let t=typeof e=="number"?e:Number(e??0);return Number.isFinite(t)?t:0}function a6(e){let t=[],n=-1,r=0,o=false,i=false;for(let s=0;s<e.length;s+=1){let a=e[s];if(n===-1){(a==="{"||a==="[")&&(n=s,r=1);continue}if(i){i=false;continue}if(a==="\\"&&o){i=true;continue}if(a==='"'){o=!o;continue}o||(a==="{"||a==="["?r+=1:(a==="}"||a==="]")&&(r-=1,r===0&&(t.push(e.slice(n,s+1)),n=-1)));}return n!==-1&&t.push(e.slice(n)),t}function gg(e){let t=e.trim();if(!t)return [];try{let n=JSON.parse(t);return Lu(n)?[n]:[]}catch{return a6(t).flatMap(n=>{try{let r=JSON.parse(n);return Lu(r)?[r]:[]}catch{return []}})}}function fL(e){let t=JSON.stringify(e);return t===void 0?String(e):t}function Uc(e){if(typeof e=="string")return e;if(Array.isArray(e)){let t=e.map(Uc).filter(n=>n!==void 0);return t.length>0?t.join(`
43
43
  `):void 0}if(Lu(e)){if(typeof e.text=="string")return e.text;if(typeof e.message=="string")return e.message;if(typeof e.error=="string")return e.error;if(e.type==="text"&&typeof e.data=="string")return e.data;for(let t of ["content","FileContent","rawOutput"]){let n=Uc(e[t]);if(n!==void 0)return n}}}function d6(e){let t=s=>Array.isArray(s)&&s.every(a=>Number.isInteger(a)&&a>=0&&a<=255),n=s=>typeof s=="string"&&s.trim().length>0?s:void 0,r=s=>new TextDecoder("utf-8",{fatal:false}).decode(Uint8Array.from(s)),o=s=>{let a=JSON.stringify(s,(d,c)=>t(c)?`<bytes:${c.length}>`:c);return a===void 0?String(s):a},i=e.rawOutput;if(i!=null){let s=Mu(i);if(!s)return n(Uc(i))??o(i);let a;if(t(s.output)&&s.output.length>0&&(a=n(r(s.output))),!a&&t(s.stdout)&&s.stdout.length>0&&(a=n(r(s.stdout))),!a){let l=Mu(s.Result);a=n(s.output)??n(l?.output)??n(Uc(i));}let d=t(s.stderr)&&s.stderr.length>0?r(s.stderr):void 0;if(d!==void 0)if(a){let l=a.endsWith(`
44
44
  `)||a.endsWith("\r")?"":`
@@ -81,7 +81,7 @@ ${r.join(`
81
81
  time_created = excluded.time_created,
82
82
  time_updated = excluded.time_updated
83
83
  `);r.transaction(i=>{for(let c of i)o.run(c);})(n);}finally{r.close();}}function uh(t){if(!t)return [];let e=[];for(let n=0;n<t.length;n+=1){let r=t[n];if(r==="-s"||r==="--session"){let o=t[n+1],s=o!==void 0&&!o.startsWith("-");e.push({sessionId:s?o:void 0}),s&&(n+=1);continue}(r.startsWith("--session=")||r.startsWith("-s="))&&e.push({sessionId:r.slice(r.indexOf("=")+1)||void 0});}return e}function lh(t){if(!t)return;let e=[];for(let n=0;n<t.length;n+=1){let r=t[n];if(r==="-s"||r==="--session"){t[n+1]!==void 0&&!t[n+1].startsWith("-")&&(n+=1);continue}r.startsWith("--session=")||r.startsWith("-s=")||e.push(r);}return e}function Do(t){let e=lh(t.additionalArgs);return {...t,...e===void 0?{}:{additionalArgs:e},resumeSessionId:void 0}}function ph(t,e){try{return !!t.prepare("SELECT id FROM session_v2 WHERE id = ?").get(e)}catch(n){if(n instanceof Error&&/no such table: session_v2/i.test(n.message))return false;throw n}}function _h(t,e,n){let r=new t(e,{readonly:true,fileMustExist:true});try{return ph(r,n)}finally{r.close();}}async function fi(t,e={}){let n;try{n=await(e.loadSqlite??rh)();}catch{throw new W("OpenCode isolation requires the optional better-sqlite3 dependency. Install it and retry.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}let r=e.crewxHome??xo(),o=vr(r),s=br(r),i=oh(s),c=sh(e.userDataHome),d=ah(n,c);if(d.length>0){if(!Nu(n,i))try{await(e.initializeDatabase??dh)(o);}catch{throw new W("Could not initialize the isolated OpenCode credential database.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}if(!Nu(n,i))throw new W("The isolated OpenCode credential database is unavailable.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"});try{ch(n,i,d);}catch{throw new W("Could not copy API-key credentials into the isolated OpenCode database.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}}let u=uh(t.additionalArgs),l=u.map(_=>_.sessionId),p=u.length>0?l[l.length-1]:t.resumeSessionId;if(!p)return u.length>0?Do(t):t;if(l.some(_=>_!==p)||!Iu.existsSync(i))return Do(t);try{return _h(n,i,p)?{...t,resumeSessionId:p}:Do(t)}catch{throw new W("Could not read the isolated OpenCode session database safely.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}}var gi=b(()=>{g();Vt();pi();Au();});function kn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}async function hi(){let t;try{let n=(await import('better-sqlite3')).default,r=Ne.join(br(),"opencode.db");t=new n(r,{readonly:!0,fileMustExist:!0});let o=t.prepare("SELECT value FROM kv WHERE key = ?").get("models-dev:v2:catalog");if(!o||typeof o.value!="string")throw new Error("OpenCode model catalog row is unavailable");let s=JSON.parse(o.value);if(!kn(s))throw new Error("OpenCode model catalog shape is unavailable");let i=typeof s.body=="string"?JSON.parse(s.body):s.body;if(!kn(i))throw new Error("OpenCode model catalog body shape is unavailable");let c=new Map;for(let[d,u]of Object.entries(i)){if(!d||!kn(u)||!kn(u.models))throw new Error("OpenCode model provider shape is unavailable");for(let[l,p]of Object.entries(u.models)){if(!l||!kn(p))throw new Error("OpenCode model shape is unavailable");let _=p.capabilities;if(_===void 0)continue;if(!kn(_))throw new Error("OpenCode model capability shape is unavailable");let h=_.reasoning;if(h===void 0)continue;if(!kn(h))throw new Error("OpenCode reasoning capability shape is unavailable");let m=h.effort;(m===void 0||Array.isArray(m)&&m.every(k=>typeof k=="string"))&&c.set(`${d}/${l}`,Array.isArray(m)?m:[]);}}return c}catch{return console.debug("[opencode] could not read private model effort catalog; omitting effort choices"),new Map}finally{try{t?.close();}catch{}}}var vu=b(()=>{g();ki();Tu();Ru();pi();gi();Xt();});function Th(t){return t?yh[t]??{agent:"build",autoApprove:false}:{agent:void 0,autoApprove:false}}function Ye(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function wh(){let t;try{t=br();}catch{return hi().catch(()=>new Map)}let e=Date.now();if(bu===t&&Po&&Po.expiresAt>e)return Po.result;bu=t;let n=hi().catch(()=>new Map);return Po={expiresAt:e+kh,result:n},n}async function Eh(t){let e=await fi(t),n=t.additionalArgs??[],r=Ye(n,"--model")||Ye(n,"-m");if(!t.model||!t.effort||r)return e;let o=(await wh()).get(t.model);return !o||o.includes(t.effort)?e:(console.debug("[opencode] requested effort is not listed for this model; using OpenCode default"),{...e,effort:void 0})}function Lu(t){let e=[],n=0,r=false,o=false,s=0;for(let c=0;c<t.length;c++){let d=t[c];if(o){o=false;continue}if(d==="\\"&&r){o=true;continue}if(d==='"'){r=!r;continue}if(!r){if(d==="{")n++;else if(d==="}"&&(n--,n===0)){let u=t.slice(s,c+1).trim();u&&e.push(u),s=c+1;}}}let i=t.slice(s).trim();return i&&e.push(i),e}function de(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Mu(t){let e=de(t.part)?t.part:void 0;return t.type==="reasoning"||e?.type==="reasoning"}function Rh(t){let e=de(t.part)?t.part:void 0;return (typeof e?.text=="string"?e.text:typeof t.text=="string"?t.text:void 0)?.trim()||void 0}function Sh(t){let e=[],n=false;for(let r of t.split(/\r?\n/)){let o=r.trim();if(!o)continue;try{let i=JSON.parse(o);de(i)?e.push(i):n=!0;continue}catch{}let s=Lu(o);s.length>1&&console.warn("[opencode] extractText: falling back to concatenated-JSON split for a malformed line");for(let i of s)try{let c=JSON.parse(i);de(c)?e.push(c):n=!0;}catch{n=true;}}return {events:e,malformed:n}}function wi(t){let e=de(t.error)?t.error:void 0,n=e&&de(e.data)?e.data:void 0,r=$u(e),o=Xe(e?.name),s=Xe(n?.message)??Xe(e?.message)??yi(r)??Xe(t.message)??Xe(t.errorMessage)??Xe(t.error),i=Xe(t.ref),c=o&&s&&o!==s?`${o}: ${s}`:o??s??Pu;return (i?`${c} (ref: ${i})`:c).slice(0,hh)}function Cu(t){let e=de(t.error)?t.error:void 0,n=typeof e?.type=="string"?e.type:void 0,r=typeof e?.status=="number"?e.status:Number(e?.status),o=wi(t),s=$u(e),i=s&&de(s.error)?s.error:void 0,c=typeof i?.type=="string"?i.type:void 0,d=[o,yi(s)].filter(Boolean).join(`
84
- `);if(r===402||Ih(d))return new W(`OpenCode subscription is required: ${o}`,Ge,{code:"SUBSCRIPTION_REQUIRED",kind:"config",providerReason:Nr(o)});if(r===403&&(c==="RegionError"||c==="FreeTierError"))return new W(`OpenCode account settings are required: ${o}`,Ge,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:"access",providerReason:Nr(o)});if(n==="provider.auth"||r===401||r===403)return new W(`OpenCode authentication is required: ${o}`,Ge,{code:"AUTH_REQUIRED",kind:"config"});if(r===410||c==="ModelDeprecated")return new W(`OpenCode model has been retired: ${o}`,Ge,{code:"MODEL_RETIRED",kind:"config",replacementModel:Ah(s,e,t),providerReason:Nr(o)});if(n==="provider.free-limit"||r===429){let u=Nh(e);return new W(`OpenCode rate limit reached: ${o}`,Ge,{code:"RATE_LIMITED",kind:"transient",...u===void 0?{}:{retryAfterMs:u}})}if(n==="provider.no-route")return new W(`OpenCode model or variant unavailable: ${o}`,Ge,{code:"MODEL_UNAVAILABLE",kind:"config"});if(n==="provider.invalid-request"&&r===400){let u=[o,yi(s)].filter(h=>h!==void 0),l=u.find(h=>/requires global regions/i.test(h)),p=u.find(h=>/trains on request data/i.test(h)),_=l?"region":p?"training_consent":void 0;if(_)return new W(`OpenCode account settings are required: ${o}`,Ge,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:_,providerReason:Nr(l??p)})}return new W(`OpenCode error: ${o}`,Ge,{code:"PROVIDER_CRASHED",kind:"transient"})}function $u(t){let n=(t&&de(t.response)?t.response:void 0)?.body;if(de(n))return n;if(typeof n=="string")try{let r=JSON.parse(n);return de(r)?r:void 0}catch{return}}function yi(t){let e=t&&de(t.error)?t.error:void 0;return Xe(e?.message)??Xe(t?.message)}function Ih(t){return /insufficient\s+(?:balance|account funds)|credit\s+limit\s+exceeded|payment\s+required|account invoice is overdue|billing_error|please add or update your payment method|(?:GLM Coding Plan|enterprise) package has expired|your current subscription plan does not yet include access to/i.test(t)}function Ah(t,e,n){let r=t&&de(t.metadata)?t.metadata:void 0,o=typeof r?.replacement=="string"?r.replacement.trim():void 0;if(!o)return;let s=[r?.model,e?.model,n.model,n.modelID].find(d=>typeof d=="string"&&d.trim().length>0)?.trim(),i=s&&s.includes("/")?s.slice(0,s.indexOf("/")):"opencode-go",c=o.includes("/")?o:`${i}/${o}`;return /^[A-Za-z0-9._/-]{1,128}$/.test(c)?c:void 0}function Nh(t){let e=t?.retryAfterMs;if(typeof e=="number"&&Number.isFinite(e)&&e>=0)return e;let r=(t&&de(t.response)?t.response:void 0)?.body,o=typeof r=="string"?Oh(r):de(r)?r:void 0;if(o){let s=Ti(o);if(s)return xu(s.value,s.key==="retryafterms")}if(typeof r=="string"){let s=r.match(/retry[-_]after(?:\s*[:=]\s*|\s+)["']?([^"'\s,;}]+)/i);if(s?.[1])return xu(s[1],false)}}function Oh(t){try{let e=JSON.parse(t);return de(e)?e:void 0}catch{return}}function Ti(t){if(Array.isArray(t)){for(let e of t){let n=Ti(e);if(n)return n}return}if(de(t)){for(let[e,n]of Object.entries(t)){let r=e.toLowerCase().replace(/[-_]/g,"");if(r==="retryafterms"||r==="retryafter")return {value:n,key:r}}for(let e of Object.values(t)){let n=Ti(e);if(n)return n}}}function xu(t,e){if(typeof t=="number"&&Number.isFinite(t)&&t>=0)return e?t:Math.round(t*1e3);if(typeof t!="string"||!t.trim())return;let n=Number(t);if(Number.isFinite(n)&&n>=0)return e?n:Math.round(n*1e3);if(e)return;let r=Date.parse(t);return Number.isFinite(r)?Math.max(0,r-Date.now()):void 0}function Du(t){let e=Sh(t),n=[],r=null,o=0,s=[],i=[],c,d=false;for(let u of e.events){if(Mu(u))continue;let l=typeof u.type=="string"?u.type:void 0;if(l){if(l==="text"){let p=de(u.part)?u.part:void 0,_=typeof p?.text=="string"?p.text:void 0;_?.trim()&&n.push(_.trim());continue}if(l==="result"){typeof u.result=="string"&&(r=u.result);continue}if(l==="tool_use"){o++;continue}if(l==="error"){s.push(u),i.push(wi(u));continue}if(l==="step_finish"){d=true;let p=de(u.part)?u.part:void 0;c=typeof p?.reason=="string"?p.reason:void 0;}}}return {...e,texts:n,resultText:r,toolUseCount:o,errorEvents:s,errorMessages:i,terminalReason:c,hasTerminal:d}}function Hu(t){return (t??"unknown").trim().toLowerCase().replace(/_/g,"-")}function vh(){return new W("OpenCode returned no assistant output.",Ge,{code:"EMPTY_OUTPUT",kind:"transient"})}function bh(){return new W("OpenCode emitted malformed JSON output.",Ge,{code:"PROVIDER_CRASHED",kind:"transient"})}function Ch(t,e){switch(Hu(t)){case "length":return new W("OpenCode stopped because the context window was exceeded.",Ge,{code:"UNKNOWN",kind:"permanent"});case "content-filter":return new W("OpenCode stopped because the content filter blocked the response.",Ge,{code:"UNKNOWN",kind:"permanent"});case "error":return new W(`${Pu} while generating a response.`,Ge,{code:"PROVIDER_CRASHED",kind:"transient"});default:return null}}var gh,Ge,Pu,hh,mh,kh,bu,Po,yh,Ei,Ri=b(()=>{g();Vt();yu();Ar();qn();hn();vu();gi();gh=new Set(["step_start","step_finish"]),Ge="cli/opencode",Pu="OpenCode provider error",hh=240,mh="Follow the instructions provided on standard input.",kh=3e5,yh={build:{agent:"build",autoApprove:false},"build-auto":{agent:"build",autoApprove:true},plan:{agent:"plan",autoApprove:false},"plan-auto":{agent:"plan",autoApprove:true}};Ei={command:"opencode",prepare:Eh,meta:{displayName:"OpenCode",capabilities:{resume:true}},buildArgs(t,e,n){let r=e.additionalArgs,o=r!==void 0?[...r]:["run"];Ye(o,"--format")||o.push("--format","json"),Ye(o,"--thinking")||o.push("--thinking"),!Ye(o,"--standalone")&&!Ye(o,"--server")&&o.push("--standalone"),e.resumeSessionId&&!Ye(o,"-s")&&!Ye(o,"--session")&&o.push("-s",e.resumeSessionId);let{agent:s,autoApprove:i}=Th(e.mode);Ye(o,"--agent")||s!==void 0&&o.push("--agent",s),i&&!Ye(o,"--auto")&&o.push("--auto");let c=Ye(o,"--model")||Ye(o,"-m");if(e.model&&!c){let d=e.effort?`${e.model}#${e.effort}`:e.model;o.push("--model",d);}else e.effort&&!e.model&&!c&&console.debug("[opencode] ignoring effort because no model is configured");return o.push(mh),{args:o,stdinMessage:t,env:vr()}},extractText(t){let e=Du(t),n=e.errorEvents[0];if(n)throw Cu(n);let r=Ch(e.terminalReason??"");if(r)throw r;let o=e.texts.length>0?e.texts[e.texts.length-1]:void 0;if(o!==void 0)return o;if(e.resultText?.trim())return e.resultText;if(e.malformed)throw bh();let s=Hu(e.terminalReason);if(e.hasTerminal&&s==="tool-calls"&&e.toolUseCount>0)return "";throw vh()},interpretExit(t,e,n=""){if(t===0)return null;let o=Du(n).errorEvents[0];return o?Cu(o):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,n){let r=e??new Date().toISOString(),o=[],s=new Map,i;try{JSON.parse(t),i=[t];}catch{i=Lu(t),i.length>1&&console.warn("[opencode] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let c of i){let d;try{d=JSON.parse(c);}catch{continue}let u=it(d,r),l=d.type;if(Mu(d)){let p=Rh(d);if(!p)continue;let _=de(d.part)?d.part:void 0,h=typeof _?.id=="string"?_.id:typeof d.id=="string"?d.id:void 0,m=p;if(h){let k=`opencode.reasoning:${h}`,w=n?.state.get(k),C=typeof w=="string"?w:s.get(h);if(typeof C=="string"&&(C===p||C.startsWith(p))||typeof C=="string"&&p.startsWith(C)&&(m=p.slice(C.length).trim(),!m))continue;s.set(h,p),n?.state.set(k,p);}o.push({timestamp:u,type:"thinking",content:m});continue}if(l){if(l==="text"){let _=d.part?.text;_&&o.push({timestamp:u,type:"text",content:_});continue}if(l==="tool_use"){let p=d.part;if(!p)continue;let _=String(p.tool||""),h=String(p.callID||p.id||""),m=p.state,k=String(m?.status||""),w=m?.input,C=st(w);if(o.push({timestamp:u,type:"tool_use",toolName:_,toolUseId:h,toolInput:C}),k==="completed"&&m?.output!==void 0){let T=m.output,P=typeof T=="string"?T:JSON.stringify(T);o.push({timestamp:u,type:"tool_result",toolUseId:h,resultPreview:P,isError:false});}else k==="error"&&o.push({timestamp:u,type:"tool_result",toolUseId:h,resultPreview:String(m?.error||"tool error"),isError:true});continue}if(l==="error"){let p=wi(d);o.push({timestamp:u,type:"error",content:p,errorMessage:p});continue}}}return o},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?gh.has(r):!1}catch{return false}}};});var Uu=b(()=>{g();});function Gn(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function Mh(t,e){return t&&qu.has(t)||Gn(e,"--dangerously-skip-permissions")?true:e.some((n,r)=>{let o=n==="--mode"?e[r+1]:n.startsWith("--mode=")?n.slice(7):void 0;return typeof o=="string"&&qu.has(o)})}function $h(t,e){let n=[];for(let r=0;r<t.length;r+=1){let o=t[r],s=[...e].find(i=>o===i||o.startsWith(`${i}=`));s?o===s&&r+1<t.length&&(r+=1):n.push(o);}return n}function Hh(t){let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],o=r.indexOf("="),s=o>0?r.slice(0,o):r;if(!Ph.has(s)){e.push(r);continue}r===s&&n+1<t.length&&!t[n+1].startsWith("-")&&(n+=1);}return e}function Qe(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Uh(t,e){if(!(t?Dh.has(t)||Dt(Si).some(s=>s.id===t):false)||!t)return e;let r=Bn(Si,t),o=oi(Si)[t]?.defaultEffort;if(r.length!==0)return e?r.includes(e)?e:o&&r.includes(o)?o:void 0:o}function Pt(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0?t:void 0}function Ni(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 Oi(t){return t.step.step_index}function ae(t){if(typeof t!="string")return;let e=t.split(/\r?\n/,1)[0]?.trim();return e&&So(e)?.slice(0,500).trim()||void 0}function qh(t,e){let n=(t??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&Lh.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)/,/invalid (?:flag|option)/].some(s=>s.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 Bh(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 Wu(t){let e=Qe(t)?t:void 0,n=e&&Qe(e.error)?e.error:void 0,r=e?ae(e.code)??ae(e.error_code)??ae(n?.code)??ae(n?.error_code):void 0,o=typeof t=="string"?ae(t):e?ae(e.message)??ae(e.error)??ae(e.reason)??ae(n?.message)??ae(n?.error)??ae(n?.reason):void 0,s=qh(r,o),i=e?Pt(e.retry_after_ms)??Pt(e.retryAfterMs)??Pt(n?.retry_after_ms)??Pt(n?.retryAfterMs):void 0;return {code:s,kind:Bh(s),message:o??"Antigravity reported a terminal error.",...i===void 0?{}:{retryAfterMs:i}}}function Mo(t){let e=Wu(t);return new W(e.message,"cli/antigravity",{code:e.code,kind:e.kind,...e.retryAfterMs===void 0?{}:{retryAfterMs:e.retryAfterMs}})}function vi(t){return new W(t,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function Fh(t){let e=new TextEncoder().encode(t).byteLength;if(!(e<=Ai))throw new W(`Input is too large: final provider initial input is ${e} UTF-8 bytes; budget is ${Ai} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function Ii(){return new W("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 $o(t){if(t.kind==="result"||t.kind==="legacy_result")return t.result}function Ho(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 Wh(t){let e=Ho(t);if(!e||e.event.kind==="agy_error"||e.index!==t.length-1||$o(e.event)?.status!=="SUCCESS"||Lo(t))return false;let r=new Map;for(let o of t){if(o.kind!=="step_update"||o.step.step_type!=="agent_response")continue;let s=Ni(o),i=Oi(o);!s||!Number.isSafeInteger(i)||r.set(JSON.stringify([s,i]),o.step);}if(r.size===0)return false;for(let o of r.values())if(o.state!=="DONE"||!Qe(o.usage)||Pt(o.usage.input_tokens)===void 0||Pt(o.usage.output_tokens)===void 0)return false;return true}function Gh(t,e){for(let n=e-1;n>=0;n-=1){let r=t[n];if(r?.kind==="agy_error")return r.error}}function jh(t,e){return Qe(t)&&Qe(e)?{...e,...t}:Qe(t)&&typeof e=="string"?{...t,message:e}:typeof t=="string"&&Qe(e)?{...e,message:t}:t??e}function zh(t){let e=Array.isArray(t.denied_actions)?t.denied_actions:[],n=[];for(let i of e){let c=Qe(i)?i:void 0,d=typeof i=="string"?ae(i):ae(c?.display_name)??ae(c?.action);d&&!n.includes(d)&&n.length<5&&n.push(d.slice(0,80));}let r=Math.max(0,e.length-n.length),o=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"",s=`Permission denied: Antigravity blocked ${e.length} requested action${e.length===1?"":"s"}${o}.`;return new W("\uAD8C\uD55C \uB54C\uBB38\uC5D0 \uC2E4\uD589\uD558\uC9C0 \uBABB\uD588\uC5B4\uC694","cli/antigravity",{code:"UNKNOWN",kind:"permanent",providerReason:s})}function Lo(t){let e=Ho(t);if(!e)return;if(e.event.kind==="agy_error")return Mo(e.event.error);let n=$o(e.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return zh(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return vi("Antigravity returned a result with an unsupported status.");let r=n.error,o=jh(r==null||r===""?n:r,Gh(t,e.index));return Mo(o)}function Gu(t){if(typeof t=="string")return t;if(t!=null)try{return JSON.stringify(t)}catch{return}}function Kh(t){return `agy:${String(t.conversation_id)}:${String(t.step_index)}`}function Jh(t,e){let n=typeof e?.name=="string"?e.name:t.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function ju(t){let e=Gu(t);if(e)return e.length<=2e3?e:`${e.slice(0,1999)}\u2026`}function Vh(t){let e=Qe(t)?t:void 0,n=e&&Qe(e.error)?e.error:void 0,r=typeof t=="string"?t.trim().match(/^([A-Z][A-Z0-9_]*)(?:[:\s]|$)/)?.[1]:void 0,o=(ae(e?.type)??ae(e?.code)??ae(e?.error_type)??ae(n?.type)??ae(n?.code)??ae(n?.error_type)??ae(r)??"TOOL_ERROR").slice(0,60),s=Wu(t).message.slice(0,250);return ju({type:o,message:s})??"Antigravity reported a tool error."}function Bu(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 Si,Dh,Ph,qu,Ai,Lh,bi,Ci=b(()=>{g();Vt();Uu();Js();Rr();Xt();Ir();Zs();si();Si="antigravity",Dh=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),Ph=new Set(["--conversation","--resume","--continue"]),qu=new Set(["bypassPermissions","agent-full-access","yolo"]),Ai=18e4,Lh=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"]);bi={command:"agy",maxInitialInputBytes:Ai,meta:{displayName:"Antigravity",models:Bc(),defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(t){let e=wr(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){Fh(t);let{model:r,effort:o}=Yt(e.model),s=ni(r),i=s.model,c=e.effort??o??s.effort,d=Uh(i,c),u=e.additionalArgs??[],l=Hh($h(u,new Set(["--input-format","--output-format"]))),p=i&&!Gn(u,"--model")?["--model",i]:[],_=Gn(u,"--effort")?[]:eu(d),h=Gn(u,"--mode")||Gn(u,"--dangerously-skip-permissions")?[]:Zc(e.mode),m=Mh(e.mode,u)||Gn(u,"--settings")?[]:["--settings",JSON.stringify({permissions:{allow:iu(e.builtinAllow)}})],k=typeof e.resumeSessionId=="string"&&e.resumeSessionId.trim().length>0?["--conversation",e.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...p,..._,...h,...k,...m,...l],stdinMessage:`${JSON.stringify({event:"user",message:{content:t}})}
84
+ `);if(r===402||Ih(d))return new W(`OpenCode subscription is required: ${o}`,Ge,{code:"SUBSCRIPTION_REQUIRED",kind:"config",providerReason:Nr(o)});if(r===403&&(c==="RegionError"||c==="FreeTierError"))return new W(`OpenCode account settings are required: ${o}`,Ge,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:"access",providerReason:Nr(o)});if(n==="provider.auth"||r===401||r===403)return new W(`OpenCode authentication is required: ${o}`,Ge,{code:"AUTH_REQUIRED",kind:"config"});if(r===410||c==="ModelDeprecated")return new W(`OpenCode model has been retired: ${o}`,Ge,{code:"MODEL_RETIRED",kind:"config",replacementModel:Ah(s,e,t),providerReason:Nr(o)});if(n==="provider.free-limit"||r===429){let u=Nh(e);return new W(`OpenCode rate limit reached: ${o}`,Ge,{code:"RATE_LIMITED",kind:"transient",...u===void 0?{}:{retryAfterMs:u}})}if(n==="provider.no-route")return new W(`OpenCode model or variant unavailable: ${o}`,Ge,{code:"MODEL_UNAVAILABLE",kind:"config"});if(n==="provider.invalid-request"&&r===400){let u=[o,yi(s)].filter(h=>h!==void 0),l=u.find(h=>/requires global regions/i.test(h)),p=u.find(h=>/trains on request data/i.test(h)),_=l?"region":p?"training_consent":void 0;if(_)return new W(`OpenCode account settings are required: ${o}`,Ge,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:_,providerReason:Nr(l??p)})}return new W(`OpenCode error: ${o}`,Ge,{code:"PROVIDER_CRASHED",kind:"transient"})}function $u(t){let n=(t&&de(t.response)?t.response:void 0)?.body;if(de(n))return n;if(typeof n=="string")try{let r=JSON.parse(n);return de(r)?r:void 0}catch{return}}function yi(t){let e=t&&de(t.error)?t.error:void 0;return Xe(e?.message)??Xe(t?.message)}function Ih(t){return /insufficient\s+(?:balance|account funds)|credit\s+limit\s+exceeded|payment\s+required|account invoice is overdue|billing_error|please add or update your payment method|(?:GLM Coding Plan|enterprise) package has expired|your current subscription plan does not yet include access to/i.test(t)}function Ah(t,e,n){let r=t&&de(t.metadata)?t.metadata:void 0,o=typeof r?.replacement=="string"?r.replacement.trim():void 0;if(!o)return;let s=[r?.model,e?.model,n.model,n.modelID].find(d=>typeof d=="string"&&d.trim().length>0)?.trim(),i=s&&s.includes("/")?s.slice(0,s.indexOf("/")):"opencode-go",c=o.includes("/")?o:`${i}/${o}`;return /^[A-Za-z0-9._/-]{1,128}$/.test(c)?c:void 0}function Nh(t){let e=t?.retryAfterMs;if(typeof e=="number"&&Number.isFinite(e)&&e>=0)return e;let r=(t&&de(t.response)?t.response:void 0)?.body,o=typeof r=="string"?Oh(r):de(r)?r:void 0;if(o){let s=Ti(o);if(s)return xu(s.value,s.key==="retryafterms")}if(typeof r=="string"){let s=r.match(/retry[-_]after(?:\s*[:=]\s*|\s+)["']?([^"'\s,;}]+)/i);if(s?.[1])return xu(s[1],false)}}function Oh(t){try{let e=JSON.parse(t);return de(e)?e:void 0}catch{return}}function Ti(t){if(Array.isArray(t)){for(let e of t){let n=Ti(e);if(n)return n}return}if(de(t)){for(let[e,n]of Object.entries(t)){let r=e.toLowerCase().replace(/[-_]/g,"");if(r==="retryafterms"||r==="retryafter")return {value:n,key:r}}for(let e of Object.values(t)){let n=Ti(e);if(n)return n}}}function xu(t,e){if(typeof t=="number"&&Number.isFinite(t)&&t>=0)return e?t:Math.round(t*1e3);if(typeof t!="string"||!t.trim())return;let n=Number(t);if(Number.isFinite(n)&&n>=0)return e?n:Math.round(n*1e3);if(e)return;let r=Date.parse(t);return Number.isFinite(r)?Math.max(0,r-Date.now()):void 0}function Du(t){let e=Sh(t),n=[],r=null,o=0,s=[],i=[],c,d=false;for(let u of e.events){if(Mu(u))continue;let l=typeof u.type=="string"?u.type:void 0;if(l){if(l==="text"){let p=de(u.part)?u.part:void 0,_=typeof p?.text=="string"?p.text:void 0;_?.trim()&&n.push(_.trim());continue}if(l==="result"){typeof u.result=="string"&&(r=u.result);continue}if(l==="tool_use"){o++;continue}if(l==="error"){s.push(u),i.push(wi(u));continue}if(l==="step_finish"){d=true;let p=de(u.part)?u.part:void 0;c=typeof p?.reason=="string"?p.reason:void 0;}}}return {...e,texts:n,resultText:r,toolUseCount:o,errorEvents:s,errorMessages:i,terminalReason:c,hasTerminal:d}}function Hu(t){return (t??"unknown").trim().toLowerCase().replace(/_/g,"-")}function vh(){return new W("OpenCode returned no assistant output.",Ge,{code:"EMPTY_OUTPUT",kind:"transient"})}function bh(){return new W("OpenCode emitted malformed JSON output.",Ge,{code:"PROVIDER_CRASHED",kind:"transient"})}function Ch(t,e){switch(Hu(t)){case "length":return new W("OpenCode stopped because the context window was exceeded.",Ge,{code:"UNKNOWN",kind:"permanent"});case "content-filter":return new W("OpenCode stopped because the content filter blocked the response.",Ge,{code:"UNKNOWN",kind:"permanent"});case "error":return new W(`${Pu} while generating a response.`,Ge,{code:"PROVIDER_CRASHED",kind:"transient"});default:return null}}var gh,Ge,Pu,hh,mh,kh,bu,Po,yh,Ei,Ri=b(()=>{g();Vt();yu();Ar();qn();hn();vu();gi();gh=new Set(["step_start","step_finish"]),Ge="cli/opencode",Pu="OpenCode provider error",hh=240,mh="Follow the instructions provided on standard input.",kh=3e5,yh={build:{agent:"build",autoApprove:false},"build-auto":{agent:"build",autoApprove:true},plan:{agent:"plan",autoApprove:false},"plan-auto":{agent:"plan",autoApprove:true}};Ei={command:"opencode",prepare:Eh,meta:{displayName:"OpenCode",capabilities:{resume:true}},buildArgs(t,e,n){let r=e.additionalArgs,o=r!==void 0?[...r]:["run"];Ye(o,"--format")||o.push("--format","json"),Ye(o,"--thinking")||o.push("--thinking"),!Ye(o,"--standalone")&&!Ye(o,"--server")&&o.push("--standalone"),e.resumeSessionId&&!Ye(o,"-s")&&!Ye(o,"--session")&&o.push("-s",e.resumeSessionId);let{agent:s,autoApprove:i}=Th(e.mode);Ye(o,"--agent")||s!==void 0&&o.push("--agent",s),i&&!Ye(o,"--auto")&&o.push("--auto");let c=Ye(o,"--model")||Ye(o,"-m");if(e.model&&!c){let d=e.effort?`${e.model}#${e.effort}`:e.model;o.push("--model",d);}else e.effort&&!e.model&&!c&&console.debug("[opencode] ignoring effort because no model is configured");return o.push(mh),{args:o,stdinMessage:t,env:vr()}},extractText(t){let e=Du(t),n=e.errorEvents[0];if(n)throw Cu(n);let r=Ch(e.terminalReason??"");if(r)throw r;let o=e.texts.length>0?e.texts[e.texts.length-1]:void 0;if(o!==void 0)return o;if(e.resultText?.trim())return e.resultText;if(e.malformed)throw bh();let s=Hu(e.terminalReason);if(e.hasTerminal&&s==="tool-calls"&&e.toolUseCount>0)return "";throw vh()},interpretExit(t,e,n=""){if(t===0)return null;let o=Du(n).errorEvents[0];return o?Cu(o):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,n){let r=e??new Date().toISOString(),o=[],s=new Map,i;try{JSON.parse(t),i=[t];}catch{i=Lu(t),i.length>1&&console.warn("[opencode] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let c of i){let d;try{d=JSON.parse(c);}catch{continue}let u=it(d,r),l=d.type;if(Mu(d)){let p=Rh(d);if(!p)continue;let _=de(d.part)?d.part:void 0,h=typeof _?.id=="string"?_.id:typeof d.id=="string"?d.id:void 0,m=p;if(h){let k=`opencode.reasoning:${h}`,w=n?.state.get(k),C=typeof w=="string"?w:s.get(h);if(typeof C=="string"&&(C===p||C.startsWith(p))||typeof C=="string"&&p.startsWith(C)&&(m=p.slice(C.length).trim(),!m))continue;s.set(h,p),n?.state.set(k,p);}o.push({timestamp:u,type:"thinking",content:m});continue}if(l){if(l==="text"){let _=d.part?.text;_&&o.push({timestamp:u,type:"text",content:_});continue}if(l==="tool_use"){let p=d.part;if(!p)continue;let _=String(p.tool||""),h=String(p.callID||p.id||""),m=p.state,k=String(m?.status||""),w=m?.input,C=st(w);if(o.push({timestamp:u,type:"tool_use",toolName:_,toolUseId:h,toolInput:C}),k==="completed"&&m?.output!==void 0){let T=m.output,P=typeof T=="string"?T:JSON.stringify(T);o.push({timestamp:u,type:"tool_result",toolUseId:h,resultPreview:P,isError:false});}else k==="error"&&o.push({timestamp:u,type:"tool_result",toolUseId:h,resultPreview:String(m?.error||"tool error"),isError:true});continue}if(l==="error"){let p=wi(d);o.push({timestamp:u,type:"error",content:p,errorMessage:p});continue}}}return o},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?gh.has(r):!1}catch{return false}}};});var Uu=b(()=>{g();});function Gn(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function Mh(t,e){return t&&qu.has(t)||Gn(e,"--dangerously-skip-permissions")?true:e.some((n,r)=>{let o=n==="--mode"?e[r+1]:n.startsWith("--mode=")?n.slice(7):void 0;return typeof o=="string"&&qu.has(o)})}function $h(t,e){let n=[];for(let r=0;r<t.length;r+=1){let o=t[r],s=[...e].find(i=>o===i||o.startsWith(`${i}=`));s?o===s&&r+1<t.length&&(r+=1):n.push(o);}return n}function Hh(t){let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],o=r.indexOf("="),s=o>0?r.slice(0,o):r;if(!Ph.has(s)){e.push(r);continue}r===s&&n+1<t.length&&!t[n+1].startsWith("-")&&(n+=1);}return e}function Qe(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Uh(t,e){if(!(t?Dh.has(t)||Dt(Si).some(s=>s.id===t):false)||!t)return e;let r=Bn(Si,t),o=oi(Si)[t]?.defaultEffort;if(r.length!==0)return e?r.includes(e)?e:o&&r.includes(o)?o:void 0:o}function Pt(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0?t:void 0}function Ni(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 Oi(t){return t.step.step_index}function ae(t){if(typeof t!="string")return;let e=t.split(/\r?\n/,1)[0]?.trim();return e&&So(e)?.slice(0,500).trim()||void 0}function qh(t,e){let n=(t??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&Lh.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)/,/invalid (?:flag|option)/].some(s=>s.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 Bh(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 Wu(t){let e=Qe(t)?t:void 0,n=e&&Qe(e.error)?e.error:void 0,r=e?ae(e.code)??ae(e.error_code)??ae(n?.code)??ae(n?.error_code):void 0,o=typeof t=="string"?ae(t):e?ae(e.message)??ae(e.error)??ae(e.reason)??ae(n?.message)??ae(n?.error)??ae(n?.reason):void 0,s=qh(r,o),i=e?Pt(e.retry_after_ms)??Pt(e.retryAfterMs)??Pt(n?.retry_after_ms)??Pt(n?.retryAfterMs):void 0;return {code:s,kind:Bh(s),message:o??"Antigravity reported a terminal error.",...i===void 0?{}:{retryAfterMs:i}}}function Mo(t){let e=Wu(t);return new W(e.message,"cli/antigravity",{code:e.code,kind:e.kind,...e.retryAfterMs===void 0?{}:{retryAfterMs:e.retryAfterMs}})}function vi(t){return new W(t,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function Fh(t){let e=new TextEncoder().encode(t).byteLength;if(!(e<=Ai))throw new W(`Input is too large: final provider initial input is ${e} UTF-8 bytes; budget is ${Ai} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function Ii(){return new W("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 $o(t){if(t.kind==="result"||t.kind==="legacy_result")return t.result}function Ho(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 Wh(t){let e=Ho(t);if(!e||e.event.kind==="agy_error"||e.index!==t.length-1||$o(e.event)?.status!=="SUCCESS"||Lo(t))return false;let r=new Map;for(let o of t){if(o.kind!=="step_update"||o.step.step_type!=="agent_response")continue;let s=Ni(o),i=Oi(o);!s||!Number.isSafeInteger(i)||r.set(JSON.stringify([s,i]),o.step);}if(r.size===0)return false;for(let o of r.values())if(o.state!=="DONE"||!Qe(o.usage)||Pt(o.usage.input_tokens)===void 0||Pt(o.usage.output_tokens)===void 0)return false;return true}function Gh(t,e){for(let n=e-1;n>=0;n-=1){let r=t[n];if(r?.kind==="agy_error")return r.error}}function jh(t,e){return Qe(t)&&Qe(e)?{...e,...t}:Qe(t)&&typeof e=="string"?{...t,message:e}:typeof t=="string"&&Qe(e)?{...e,message:t}:t??e}function zh(t){let e=Array.isArray(t.denied_actions)?t.denied_actions:[],n=[];for(let i of e){let c=Qe(i)?i:void 0,d=typeof i=="string"?ae(i):ae(c?.display_name)??ae(c?.action);d&&!n.includes(d)&&n.length<5&&n.push(d.slice(0,80));}let r=Math.max(0,e.length-n.length),o=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"",s=`Permission denied: Antigravity blocked ${e.length} requested action${e.length===1?"":"s"}${o}.`;return new W("Could not run because of permissions.","cli/antigravity",{code:"UNKNOWN",kind:"permanent",providerReason:s})}function Lo(t){let e=Ho(t);if(!e)return;if(e.event.kind==="agy_error")return Mo(e.event.error);let n=$o(e.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return zh(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return vi("Antigravity returned a result with an unsupported status.");let r=n.error,o=jh(r==null||r===""?n:r,Gh(t,e.index));return Mo(o)}function Gu(t){if(typeof t=="string")return t;if(t!=null)try{return JSON.stringify(t)}catch{return}}function Kh(t){return `agy:${String(t.conversation_id)}:${String(t.step_index)}`}function Jh(t,e){let n=typeof e?.name=="string"?e.name:t.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function ju(t){let e=Gu(t);if(e)return e.length<=2e3?e:`${e.slice(0,1999)}\u2026`}function Vh(t){let e=Qe(t)?t:void 0,n=e&&Qe(e.error)?e.error:void 0,r=typeof t=="string"?t.trim().match(/^([A-Z][A-Z0-9_]*)(?:[:\s]|$)/)?.[1]:void 0,o=(ae(e?.type)??ae(e?.code)??ae(e?.error_type)??ae(n?.type)??ae(n?.code)??ae(n?.error_type)??ae(r)??"TOOL_ERROR").slice(0,60),s=Wu(t).message.slice(0,250);return ju({type:o,message:s})??"Antigravity reported a tool error."}function Bu(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 Si,Dh,Ph,qu,Ai,Lh,bi,Ci=b(()=>{g();Vt();Uu();Js();Rr();Xt();Ir();Zs();si();Si="antigravity",Dh=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),Ph=new Set(["--conversation","--resume","--continue"]),qu=new Set(["bypassPermissions","agent-full-access","yolo"]),Ai=18e4,Lh=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"]);bi={command:"agy",maxInitialInputBytes:Ai,meta:{displayName:"Antigravity",models:Bc(),defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(t){let e=wr(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){Fh(t);let{model:r,effort:o}=Yt(e.model),s=ni(r),i=s.model,c=e.effort??o??s.effort,d=Uh(i,c),u=e.additionalArgs??[],l=Hh($h(u,new Set(["--input-format","--output-format"]))),p=i&&!Gn(u,"--model")?["--model",i]:[],_=Gn(u,"--effort")?[]:eu(d),h=Gn(u,"--mode")||Gn(u,"--dangerously-skip-permissions")?[]:Zc(e.mode),m=Mh(e.mode,u)||Gn(u,"--settings")?[]:["--settings",JSON.stringify({permissions:{allow:iu(e.builtinAllow)}})],k=typeof e.resumeSessionId=="string"&&e.resumeSessionId.trim().length>0?["--conversation",e.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...p,..._,...h,...k,...m,...l],stdinMessage:`${JSON.stringify({event:"user",message:{content:t}})}
85
85
  `,env:{AGY_CLI_DISABLE_AUTO_UPDATE:"true"}}},extractText(t){let e=Er(t),n=Ho(e)?.event,r=Lo(e);if(r)throw r;let o=n?$o(n):void 0;if(o){if(o.status!=="SUCCESS")throw vi("Antigravity returned a result with an unsupported status.");if(typeof o.response!="string")throw vi("Antigravity returned a successful result without a response string.");if(!o.response.trim())throw Ii();return o.response}if(e.length>0)throw Ii();let s=t.trim();if(!s)throw Ii();return s},extractPartialText(t){let e=Er(t),n=Ho(e)?.event;if(!n||n.kind==="agy_error")return;let r=$o(n);return r&&typeof r.response=="string"&&r.response.trim()?r.response:void 0},interpretExit(t,e,n){let r=Er(n??""),o=Lo(r);return o||(t!==0&&e.trim()?Mo(e):null)},parseResultMeta(t){let e=Er(t),n=0,r=0,o=0,s=0,i=new Set;for(let d of e){if(d.kind!=="step_update"||d.step.state!=="DONE"||!Qe(d.step.usage))continue;let u=Ni(d),l=Oi(d);if(!u||!Number.isSafeInteger(l))continue;let p=JSON.stringify([u,l]);if(i.has(p))continue;let _=d.step.usage,h=Pt(_.input_tokens),m=Pt(_.output_tokens);if(h===void 0||m===void 0)continue;i.add(p);let k=Pt(_.cache_read_tokens)??0;n+=h+k,r+=m,o+=k,s+=1;}return {usage:s===0?null:{inputTokens:n,outputTokens:r,cachedInputTokens:o,costUsd:0,complete:Wh(e)},model:null}},parseEvent(t,e,n){let r=wr(t);if(!r)return [];let o=e??new Date().toISOString();if(r.kind==="agy_error")return [Fu(o,Mo(r.error))];if(r.kind==="legacy_result"||r.kind==="result"){let h=Lo([r]);return h?[Fu(o,h)]:[]}if(r.kind!=="step_update")return [];let{step:s}=r,i=Ni(r)??"unknown",c=Oi(r),d=`${i}:${c}`;if((s.state==="DONE"||s.state==="ERROR")&&Bu(n,`antigravity:terminal:${d}`))return [];if(s.step_type==="agent_response")return typeof s.text_delta=="string"&&s.text_delta.length>0?[{timestamp:o,type:"text",content:s.text_delta}]:[];if(s.step_type!=="tool")return [];let u=Qe(s.tool_info)?s.tool_info:void 0,l=Jh(s,u);if(!l)return [];let p=Kh(s);if(s.state==="ACTIVE"){if(Bu(n,`antigravity:active:${d}`))return [];let h=Gu(u?.parameters);return [{timestamp:o,type:"tool_use",toolName:l,toolUseId:p,...h===void 0?{}:{toolInput:h}}]}let _=s.state==="ERROR"?Vh(u?.error):ju(u?.output);return [{timestamp:o,type:"tool_result",toolName:l,toolUseId:p,..._===void 0?{}:{resultPreview:_},...s.state==="ERROR"?{isError:true}:{}}]}};});var zu=b(()=>{g();Hn();qn();Un();hn();});function jn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function zn(t){return jn(t)?t:void 0}function $e(t){return typeof t=="string"?t:void 0}function Tn(t){let e=typeof t=="number"?t:Number(t??0);return Number.isFinite(e)?e:0}function om(t){let e=[],n=-1,r=0,o=false,s=false;for(let i=0;i<t.length;i+=1){let c=t[i];if(n===-1){(c==="{"||c==="[")&&(n=i,r=1);continue}if(s){s=false;continue}if(c==="\\"&&o){s=true;continue}if(c==='"'){o=!o;continue}o||(c==="{"||c==="["?r+=1:(c==="}"||c==="]")&&(r-=1,r===0&&(e.push(t.slice(n,i+1)),n=-1)));}return n!==-1&&e.push(t.slice(n)),e}function Cr(t){let e=t.trim();if(!e)return [];try{let n=JSON.parse(e);return jn(n)?[n]:[]}catch{return om(e).flatMap(n=>{try{let r=JSON.parse(n);return jn(r)?[r]:[]}catch{return []}})}}function Zu(t){let e=JSON.stringify(t);return e===void 0?String(t):e}function yn(t){if(typeof t=="string")return t;if(Array.isArray(t)){let e=t.map(yn).filter(n=>n!==void 0);return e.length>0?e.join(`
86
86
  `):void 0}if(jn(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=yn(t[e]);if(n!==void 0)return n}}}function sm(t){let e=i=>Array.isArray(i)&&i.every(c=>Number.isInteger(c)&&c>=0&&c<=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)),o=i=>{let c=JSON.stringify(i,(d,u)=>e(u)?`<bytes:${u.length}>`:u);return c===void 0?String(i):c},s=t.rawOutput;if(s!=null){let i=zn(s);if(!i)return n(yn(s))??o(s);let c;if(e(i.output)&&i.output.length>0&&(c=n(r(i.output))),!c&&e(i.stdout)&&i.stdout.length>0&&(c=n(r(i.stdout))),!c){let l=zn(i.Result);c=n(i.output)??n(l?.output)??n(yn(s));}let d=e(i.stderr)&&i.stderr.length>0?r(i.stderr):void 0;if(d!==void 0)if(c){let l=c.endsWith(`
87
87
  `)||c.endsWith("\r")?"":`
@@ -81,7 +81,7 @@ ${r.join(`
81
81
  time_created = excluded.time_created,
82
82
  time_updated = excluded.time_updated
83
83
  `);r.transaction(i=>{for(let a of i)o.run(a);})(n);}finally{r.close();}}function ZT(t){if(!t)return [];let e=[];for(let n=0;n<t.length;n+=1){let r=t[n];if(r==="-s"||r==="--session"){let o=t[n+1],s=o!==void 0&&!o.startsWith("-");e.push({sessionId:s?o:void 0}),s&&(n+=1);continue}(r.startsWith("--session=")||r.startsWith("-s="))&&e.push({sessionId:r.slice(r.indexOf("=")+1)||void 0});}return e}function ew(t){if(!t)return;let e=[];for(let n=0;n<t.length;n+=1){let r=t[n];if(r==="-s"||r==="--session"){t[n+1]!==void 0&&!t[n+1].startsWith("-")&&(n+=1);continue}r.startsWith("--session=")||r.startsWith("-s=")||e.push(r);}return e}function Zs(t){let e=ew(t.additionalArgs);return {...t,...e===void 0?{}:{additionalArgs:e},resumeSessionId:void 0}}function tw(t,e){try{return !!t.prepare("SELECT id FROM session_v2 WHERE id = ?").get(e)}catch(n){if(n instanceof Error&&/no such table: session_v2/i.test(n.message))return false;throw n}}function nw(t,e,n){let r=new t(e,{readonly:true,fileMustExist:true});try{return tw(r,n)}finally{r.close();}}async function dd(t,e={}){let n;try{n=await(e.loadSqlite??zT)();}catch{throw new V("OpenCode isolation requires the optional better-sqlite3 dependency. Install it and retry.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}let r=e.crewxHome??Qs(),o=Bo(r),s=qo(r),i=KT(s),a=VT(e.userDataHome),c=XT(n,a);if(c.length>0){if(!c_(n,i))try{await(e.initializeDatabase??YT)(o);}catch{throw new V("Could not initialize the isolated OpenCode credential database.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}if(!c_(n,i))throw new V("The isolated OpenCode credential database is unavailable.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"});try{QT(n,i,c);}catch{throw new V("Could not copy API-key credentials into the isolated OpenCode database.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}}let u=ZT(t.additionalArgs),p=u.map(f=>f.sessionId),l=u.length>0?p[p.length-1]:t.resumeSessionId;if(!l)return u.length>0?Zs(t):t;if(p.some(f=>f!==l)||!Bl.existsSync(i))return Zs(t);try{return nw(n,i,l)?{...t,resumeSessionId:l}:Zs(t)}catch{throw new V("Could not read the isolated OpenCode session database safely.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}}var cd=D(()=>{h();vn();id();d_();});function er(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}async function ud(){let t;try{let n=(await import('better-sqlite3')).default,r=Ye.join(qo(),"opencode.db");t=new n(r,{readonly:!0,fileMustExist:!0});let o=t.prepare("SELECT value FROM kv WHERE key = ?").get("models-dev:v2:catalog");if(!o||typeof o.value!="string")throw new Error("OpenCode model catalog row is unavailable");let s=JSON.parse(o.value);if(!er(s))throw new Error("OpenCode model catalog shape is unavailable");let i=typeof s.body=="string"?JSON.parse(s.body):s.body;if(!er(i))throw new Error("OpenCode model catalog body shape is unavailable");let a=new Map;for(let[c,u]of Object.entries(i)){if(!c||!er(u)||!er(u.models))throw new Error("OpenCode model provider shape is unavailable");for(let[p,l]of Object.entries(u.models)){if(!p||!er(l))throw new Error("OpenCode model shape is unavailable");let f=l.capabilities;if(f===void 0)continue;if(!er(f))throw new Error("OpenCode model capability shape is unavailable");let g=f.reasoning;if(g===void 0)continue;if(!er(g))throw new Error("OpenCode reasoning capability shape is unavailable");let m=g.effort;(m===void 0||Array.isArray(m)&&m.every(k=>typeof k=="string"))&&a.set(`${c}/${p}`,Array.isArray(m)?m:[]);}}return a}catch{return console.debug("[opencode] could not read private model effort catalog; omitting effort choices"),new Map}finally{try{t?.close();}catch{}}}var l_=D(()=>{h();pd();n_();s_();id();cd();Cn();});function cw(t){return t?dw[t]??{agent:"build",autoApprove:false}:{agent:void 0,autoApprove:false}}function Nt(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function uw(){let t;try{t=qo();}catch{return ud().catch(()=>new Map)}let e=Date.now();if(p_===t&&ei&&ei.expiresAt>e)return ei.result;p_=t;let n=ud().catch(()=>new Map);return ei={expiresAt:e+aw,result:n},n}async function lw(t){let e=await dd(t),n=t.additionalArgs??[],r=Nt(n,"--model")||Nt(n,"-m");if(!t.model||!t.effort||r)return e;let o=(await uw()).get(t.model);return !o||o.includes(t.effort)?e:(console.debug("[opencode] requested effort is not listed for this model; using OpenCode default"),{...e,effort:void 0})}function m_(t){let e=[],n=0,r=false,o=false,s=0;for(let a=0;a<t.length;a++){let c=t[a];if(o){o=false;continue}if(c==="\\"&&r){o=true;continue}if(c==='"'){r=!r;continue}if(!r){if(c==="{")n++;else if(c==="}"&&(n--,n===0)){let u=t.slice(s,a+1).trim();u&&e.push(u),s=a+1;}}}let i=t.slice(s).trim();return i&&e.push(i),e}function Ae(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function k_(t){let e=Ae(t.part)?t.part:void 0;return t.type==="reasoning"||e?.type==="reasoning"}function pw(t){let e=Ae(t.part)?t.part:void 0;return (typeof e?.text=="string"?e.text:typeof t.text=="string"?t.text:void 0)?.trim()||void 0}function _w(t){let e=[],n=false;for(let r of t.split(/\r?\n/)){let o=r.trim();if(!o)continue;try{let i=JSON.parse(o);Ae(i)?e.push(i):n=!0;continue}catch{}let s=m_(o);s.length>1&&console.warn("[opencode] extractText: falling back to concatenated-JSON split for a malformed line");for(let i of s)try{let a=JSON.parse(i);Ae(a)?e.push(a):n=!0;}catch{n=true;}}return {events:e,malformed:n}}function gd(t){let e=Ae(t.error)?t.error:void 0,n=e&&Ae(e.data)?e.data:void 0,r=y_(e),o=It(e?.name),s=It(n?.message)??It(e?.message)??_d(r)??It(t.message)??It(t.errorMessage)??It(t.error),i=It(t.ref),a=o&&s&&o!==s?`${o}: ${s}`:o??s??h_;return (i?`${a} (ref: ${i})`:a).slice(0,sw)}function __(t){let e=Ae(t.error)?t.error:void 0,n=typeof e?.type=="string"?e.type:void 0,r=typeof e?.status=="number"?e.status:Number(e?.status),o=gd(t),s=y_(e),i=s&&Ae(s.error)?s.error:void 0,a=typeof i?.type=="string"?i.type:void 0,c=[o,_d(s)].filter(Boolean).join(`
84
- `);if(r===402||fw(c))return new V(`OpenCode subscription is required: ${o}`,mt,{code:"SUBSCRIPTION_REQUIRED",kind:"config",providerReason:Ho(o)});if(r===403&&(a==="RegionError"||a==="FreeTierError"))return new V(`OpenCode account settings are required: ${o}`,mt,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:"access",providerReason:Ho(o)});if(n==="provider.auth"||r===401||r===403)return new V(`OpenCode authentication is required: ${o}`,mt,{code:"AUTH_REQUIRED",kind:"config"});if(r===410||a==="ModelDeprecated")return new V(`OpenCode model has been retired: ${o}`,mt,{code:"MODEL_RETIRED",kind:"config",replacementModel:gw(s,e,t),providerReason:Ho(o)});if(n==="provider.free-limit"||r===429){let u=hw(e);return new V(`OpenCode rate limit reached: ${o}`,mt,{code:"RATE_LIMITED",kind:"transient",...u===void 0?{}:{retryAfterMs:u}})}if(n==="provider.no-route")return new V(`OpenCode model or variant unavailable: ${o}`,mt,{code:"MODEL_UNAVAILABLE",kind:"config"});if(n==="provider.invalid-request"&&r===400){let u=[o,_d(s)].filter(g=>g!==void 0),p=u.find(g=>/requires global regions/i.test(g)),l=u.find(g=>/trains on request data/i.test(g)),f=p?"region":l?"training_consent":void 0;if(f)return new V(`OpenCode account settings are required: ${o}`,mt,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:f,providerReason:Ho(p??l)})}return new V(`OpenCode error: ${o}`,mt,{code:"PROVIDER_CRASHED",kind:"transient"})}function y_(t){let n=(t&&Ae(t.response)?t.response:void 0)?.body;if(Ae(n))return n;if(typeof n=="string")try{let r=JSON.parse(n);return Ae(r)?r:void 0}catch{return}}function _d(t){let e=t&&Ae(t.error)?t.error:void 0;return It(e?.message)??It(t?.message)}function fw(t){return /insufficient\s+(?:balance|account funds)|credit\s+limit\s+exceeded|payment\s+required|account invoice is overdue|billing_error|please add or update your payment method|(?:GLM Coding Plan|enterprise) package has expired|your current subscription plan does not yet include access to/i.test(t)}function gw(t,e,n){let r=t&&Ae(t.metadata)?t.metadata:void 0,o=typeof r?.replacement=="string"?r.replacement.trim():void 0;if(!o)return;let s=[r?.model,e?.model,n.model,n.modelID].find(c=>typeof c=="string"&&c.trim().length>0)?.trim(),i=s&&s.includes("/")?s.slice(0,s.indexOf("/")):"opencode-go",a=o.includes("/")?o:`${i}/${o}`;return /^[A-Za-z0-9._/-]{1,128}$/.test(a)?a:void 0}function hw(t){let e=t?.retryAfterMs;if(typeof e=="number"&&Number.isFinite(e)&&e>=0)return e;let r=(t&&Ae(t.response)?t.response:void 0)?.body,o=typeof r=="string"?mw(r):Ae(r)?r:void 0;if(o){let s=fd(o);if(s)return f_(s.value,s.key==="retryafterms")}if(typeof r=="string"){let s=r.match(/retry[-_]after(?:\s*[:=]\s*|\s+)["']?([^"'\s,;}]+)/i);if(s?.[1])return f_(s[1],false)}}function mw(t){try{let e=JSON.parse(t);return Ae(e)?e:void 0}catch{return}}function fd(t){if(Array.isArray(t)){for(let e of t){let n=fd(e);if(n)return n}return}if(Ae(t)){for(let[e,n]of Object.entries(t)){let r=e.toLowerCase().replace(/[-_]/g,"");if(r==="retryafterms"||r==="retryafter")return {value:n,key:r}}for(let e of Object.values(t)){let n=fd(e);if(n)return n}}}function f_(t,e){if(typeof t=="number"&&Number.isFinite(t)&&t>=0)return e?t:Math.round(t*1e3);if(typeof t!="string"||!t.trim())return;let n=Number(t);if(Number.isFinite(n)&&n>=0)return e?n:Math.round(n*1e3);if(e)return;let r=Date.parse(t);return Number.isFinite(r)?Math.max(0,r-Date.now()):void 0}function g_(t){let e=_w(t),n=[],r=null,o=0,s=[],i=[],a,c=false;for(let u of e.events){if(k_(u))continue;let p=typeof u.type=="string"?u.type:void 0;if(p){if(p==="text"){let l=Ae(u.part)?u.part:void 0,f=typeof l?.text=="string"?l.text:void 0;f?.trim()&&n.push(f.trim());continue}if(p==="result"){typeof u.result=="string"&&(r=u.result);continue}if(p==="tool_use"){o++;continue}if(p==="error"){s.push(u),i.push(gd(u));continue}if(p==="step_finish"){c=true;let l=Ae(u.part)?u.part:void 0;a=typeof l?.reason=="string"?l.reason:void 0;}}}return {...e,texts:n,resultText:r,toolUseCount:o,errorEvents:s,errorMessages:i,terminalReason:a,hasTerminal:c}}function T_(t){return (t??"unknown").trim().toLowerCase().replace(/_/g,"-")}function kw(){return new V("OpenCode returned no assistant output.",mt,{code:"EMPTY_OUTPUT",kind:"transient"})}function yw(){return new V("OpenCode emitted malformed JSON output.",mt,{code:"PROVIDER_CRASHED",kind:"transient"})}function Tw(t,e){switch(T_(t)){case "length":return new V("OpenCode stopped because the context window was exceeded.",mt,{code:"UNKNOWN",kind:"permanent"});case "content-filter":return new V("OpenCode stopped because the content filter blocked the response.",mt,{code:"UNKNOWN",kind:"permanent"});case "error":return new V(`${h_} while generating a response.`,mt,{code:"PROVIDER_CRASHED",kind:"transient"});default:return null}}var ow,mt,h_,sw,iw,aw,p_,ei,dw,hd,md=D(()=>{h();vn();t_();$o();$r();Qn();l_();cd();ow=new Set(["step_start","step_finish"]),mt="cli/opencode",h_="OpenCode provider error",sw=240,iw="Follow the instructions provided on standard input.",aw=3e5,dw={build:{agent:"build",autoApprove:false},"build-auto":{agent:"build",autoApprove:true},plan:{agent:"plan",autoApprove:false},"plan-auto":{agent:"plan",autoApprove:true}};hd={command:"opencode",prepare:lw,meta:{displayName:"OpenCode",capabilities:{resume:true}},buildArgs(t,e,n){let r=e.additionalArgs,o=r!==void 0?[...r]:["run"];Nt(o,"--format")||o.push("--format","json"),Nt(o,"--thinking")||o.push("--thinking"),!Nt(o,"--standalone")&&!Nt(o,"--server")&&o.push("--standalone"),e.resumeSessionId&&!Nt(o,"-s")&&!Nt(o,"--session")&&o.push("-s",e.resumeSessionId);let{agent:s,autoApprove:i}=cw(e.mode);Nt(o,"--agent")||s!==void 0&&o.push("--agent",s),i&&!Nt(o,"--auto")&&o.push("--auto");let a=Nt(o,"--model")||Nt(o,"-m");if(e.model&&!a){let c=e.effort?`${e.model}#${e.effort}`:e.model;o.push("--model",c);}else e.effort&&!e.model&&!a&&console.debug("[opencode] ignoring effort because no model is configured");return o.push(iw),{args:o,stdinMessage:t,env:Bo()}},extractText(t){let e=g_(t),n=e.errorEvents[0];if(n)throw __(n);let r=Tw(e.terminalReason??"");if(r)throw r;let o=e.texts.length>0?e.texts[e.texts.length-1]:void 0;if(o!==void 0)return o;if(e.resultText?.trim())return e.resultText;if(e.malformed)throw yw();let s=T_(e.terminalReason);if(e.hasTerminal&&s==="tool-calls"&&e.toolUseCount>0)return "";throw kw()},interpretExit(t,e,n=""){if(t===0)return null;let o=g_(n).errorEvents[0];return o?__(o):null},parseResultMeta(t){let e=Ur(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(),o=[],s=new Map,i;try{JSON.parse(t),i=[t];}catch{i=m_(t),i.length>1&&console.warn("[opencode] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let a of i){let c;try{c=JSON.parse(a);}catch{continue}let u=Bt(c,r),p=c.type;if(k_(c)){let l=pw(c);if(!l)continue;let f=Ae(c.part)?c.part:void 0,g=typeof f?.id=="string"?f.id:typeof c.id=="string"?c.id:void 0,m=l;if(g){let k=`opencode.reasoning:${g}`,T=n?.state.get(k),E=typeof T=="string"?T:s.get(g);if(typeof E=="string"&&(E===l||E.startsWith(l))||typeof E=="string"&&l.startsWith(E)&&(m=l.slice(E.length).trim(),!m))continue;s.set(g,l),n?.state.set(k,l);}o.push({timestamp:u,type:"thinking",content:m});continue}if(p){if(p==="text"){let f=c.part?.text;f&&o.push({timestamp:u,type:"text",content:f});continue}if(p==="tool_use"){let l=c.part;if(!l)continue;let f=String(l.tool||""),g=String(l.callID||l.id||""),m=l.state,k=String(m?.status||""),T=m?.input,E=Ut(T);if(o.push({timestamp:u,type:"tool_use",toolName:f,toolUseId:g,toolInput:E}),k==="completed"&&m?.output!==void 0){let w=m.output,P=typeof w=="string"?w:JSON.stringify(w);o.push({timestamp:u,type:"tool_result",toolUseId:g,resultPreview:P,isError:false});}else k==="error"&&o.push({timestamp:u,type:"tool_result",toolUseId:g,resultPreview:String(m?.error||"tool error"),isError:true});continue}if(p==="error"){let l=gd(c);o.push({timestamp:u,type:"error",content:l,errorMessage:l});continue}}}return o},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?ow.has(r):!1}catch{return false}}};});var w_=D(()=>{h();});function qr(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function bw(t,e){return t&&R_.has(t)||qr(e,"--dangerously-skip-permissions")?true:e.some((n,r)=>{let o=n==="--mode"?e[r+1]:n.startsWith("--mode=")?n.slice(7):void 0;return typeof o=="string"&&R_.has(o)})}function Aw(t,e){let n=[];for(let r=0;r<t.length;r+=1){let o=t[r],s=[...e].find(i=>o===i||o.startsWith(`${i}=`));s?o===s&&r+1<t.length&&(r+=1):n.push(o);}return n}function Iw(t){let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],o=r.indexOf("="),s=o>0?r.slice(0,o):r;if(!Ew.has(s)){e.push(r);continue}r===s&&n+1<t.length&&!t[n+1].startsWith("-")&&(n+=1);}return e}function Ot(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Nw(t,e){if(!(t?Rw.has(t)||kn(kd).some(s=>s.id===t):false)||!t)return e;let r=Hr(kd,t),o=Qa(kd)[t]?.defaultEffort;if(r.length!==0)return e?r.includes(e)?e:o&&r.includes(o)?o:void 0:o}function yn(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0?t:void 0}function wd(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 Rd(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&&js(e)?.slice(0,500).trim()||void 0}function Ow(t,e){let n=(t??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&Sw.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)/,/invalid (?:flag|option)/].some(s=>s.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 vw(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 b_(t){let e=Ot(t)?t:void 0,n=e&&Ot(e.error)?e.error:void 0,r=e?Se(e.code)??Se(e.error_code)??Se(n?.code)??Se(n?.error_code):void 0,o=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,s=Ow(r,o),i=e?yn(e.retry_after_ms)??yn(e.retryAfterMs)??yn(n?.retry_after_ms)??yn(n?.retryAfterMs):void 0;return {code:s,kind:vw(s),message:o??"Antigravity reported a terminal error.",...i===void 0?{}:{retryAfterMs:i}}}function ni(t){let e=b_(t);return new V(e.message,"cli/antigravity",{code:e.code,kind:e.kind,...e.retryAfterMs===void 0?{}:{retryAfterMs:e.retryAfterMs}})}function Ed(t){return new V(t,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function Cw(t){let e=new TextEncoder().encode(t).byteLength;if(!(e<=Td))throw new V(`Input is too large: final provider initial input is ${e} UTF-8 bytes; budget is ${Td} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function yd(){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 ri(t){if(t.kind==="result"||t.kind==="legacy_result")return t.result}function oi(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 Dw(t){let e=oi(t);if(!e||e.event.kind==="agy_error"||e.index!==t.length-1||ri(e.event)?.status!=="SUCCESS"||ti(t))return false;let r=new Map;for(let o of t){if(o.kind!=="step_update"||o.step.step_type!=="agent_response")continue;let s=wd(o),i=Rd(o);!s||!Number.isSafeInteger(i)||r.set(JSON.stringify([s,i]),o.step);}if(r.size===0)return false;for(let o of r.values())if(o.state!=="DONE"||!Ot(o.usage)||yn(o.usage.input_tokens)===void 0||yn(o.usage.output_tokens)===void 0)return false;return true}function xw(t,e){for(let n=e-1;n>=0;n-=1){let r=t[n];if(r?.kind==="agy_error")return r.error}}function Pw(t,e){return Ot(t)&&Ot(e)?{...e,...t}:Ot(t)&&typeof e=="string"?{...t,message:e}:typeof t=="string"&&Ot(e)?{...e,message:t}:t??e}function Lw(t){let e=Array.isArray(t.denied_actions)?t.denied_actions:[],n=[];for(let i of e){let a=Ot(i)?i:void 0,c=typeof i=="string"?Se(i):Se(a?.display_name)??Se(a?.action);c&&!n.includes(c)&&n.length<5&&n.push(c.slice(0,80));}let r=Math.max(0,e.length-n.length),o=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"",s=`Permission denied: Antigravity blocked ${e.length} requested action${e.length===1?"":"s"}${o}.`;return new V("\uAD8C\uD55C \uB54C\uBB38\uC5D0 \uC2E4\uD589\uD558\uC9C0 \uBABB\uD588\uC5B4\uC694","cli/antigravity",{code:"UNKNOWN",kind:"permanent",providerReason:s})}function ti(t){let e=oi(t);if(!e)return;if(e.event.kind==="agy_error")return ni(e.event.error);let n=ri(e.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return Lw(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return Ed("Antigravity returned a result with an unsupported status.");let r=n.error,o=Pw(r==null||r===""?n:r,xw(t,e.index));return ni(o)}function A_(t){if(typeof t=="string")return t;if(t!=null)try{return JSON.stringify(t)}catch{return}}function Mw(t){return `agy:${String(t.conversation_id)}:${String(t.step_index)}`}function $w(t,e){let n=typeof e?.name=="string"?e.name:t.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function I_(t){let e=A_(t);if(e)return e.length<=2e3?e:`${e.slice(0,1999)}\u2026`}function Hw(t){let e=Ot(t)?t:void 0,n=e&&Ot(e.error)?e.error:void 0,r=typeof t=="string"?t.trim().match(/^([A-Z][A-Z0-9_]*)(?:[:\s]|$)/)?.[1]:void 0,o=(Se(e?.type)??Se(e?.code)??Se(e?.error_type)??Se(n?.type)??Se(n?.code)??Se(n?.error_type)??Se(r)??"TOOL_ERROR").slice(0,60),s=b_(t).message.slice(0,250);return I_({type:o,message:s})??"Antigravity reported a tool error."}function E_(t,e){return t?t.state.has(e)?true:(t.state.set(e,true),false):false}function S_(t,e){return {timestamp:t,type:"error",content:e.message,errorMessage:e.message,isError:true}}var kd,Rw,Ew,R_,Td,Sw,Sd,bd=D(()=>{h();vn();w_();ja();Po();Cn();Mo();Gs();Za();kd="antigravity",Rw=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),Ew=new Set(["--conversation","--resume","--continue"]),R_=new Set(["bypassPermissions","agent-full-access","yolo"]),Td=18e4,Sw=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"]);Sd={command:"agy",maxInitialInputBytes:Td,meta:{displayName:"Antigravity",models:Ep(),defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(t){let e=Do(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){Cw(t);let{model:r,effort:o}=Dn(e.model),s=Xa(r),i=s.model,a=e.effort??o??s.effort,c=Nw(i,a),u=e.additionalArgs??[],p=Iw(Aw(u,new Set(["--input-format","--output-format"]))),l=i&&!qr(u,"--model")?["--model",i]:[],f=qr(u,"--effort")?[]:Mp(c),g=qr(u,"--mode")||qr(u,"--dangerously-skip-permissions")?[]:Lp(e.mode),m=bw(e.mode,u)||qr(u,"--settings")?[]:["--settings",JSON.stringify({permissions:{allow:Fp(e.builtinAllow)}})],k=typeof e.resumeSessionId=="string"&&e.resumeSessionId.trim().length>0?["--conversation",e.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...l,...f,...g,...k,...m,...p],stdinMessage:`${JSON.stringify({event:"user",message:{content:t}})}
84
+ `);if(r===402||fw(c))return new V(`OpenCode subscription is required: ${o}`,mt,{code:"SUBSCRIPTION_REQUIRED",kind:"config",providerReason:Ho(o)});if(r===403&&(a==="RegionError"||a==="FreeTierError"))return new V(`OpenCode account settings are required: ${o}`,mt,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:"access",providerReason:Ho(o)});if(n==="provider.auth"||r===401||r===403)return new V(`OpenCode authentication is required: ${o}`,mt,{code:"AUTH_REQUIRED",kind:"config"});if(r===410||a==="ModelDeprecated")return new V(`OpenCode model has been retired: ${o}`,mt,{code:"MODEL_RETIRED",kind:"config",replacementModel:gw(s,e,t),providerReason:Ho(o)});if(n==="provider.free-limit"||r===429){let u=hw(e);return new V(`OpenCode rate limit reached: ${o}`,mt,{code:"RATE_LIMITED",kind:"transient",...u===void 0?{}:{retryAfterMs:u}})}if(n==="provider.no-route")return new V(`OpenCode model or variant unavailable: ${o}`,mt,{code:"MODEL_UNAVAILABLE",kind:"config"});if(n==="provider.invalid-request"&&r===400){let u=[o,_d(s)].filter(g=>g!==void 0),p=u.find(g=>/requires global regions/i.test(g)),l=u.find(g=>/trains on request data/i.test(g)),f=p?"region":l?"training_consent":void 0;if(f)return new V(`OpenCode account settings are required: ${o}`,mt,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:f,providerReason:Ho(p??l)})}return new V(`OpenCode error: ${o}`,mt,{code:"PROVIDER_CRASHED",kind:"transient"})}function y_(t){let n=(t&&Ae(t.response)?t.response:void 0)?.body;if(Ae(n))return n;if(typeof n=="string")try{let r=JSON.parse(n);return Ae(r)?r:void 0}catch{return}}function _d(t){let e=t&&Ae(t.error)?t.error:void 0;return It(e?.message)??It(t?.message)}function fw(t){return /insufficient\s+(?:balance|account funds)|credit\s+limit\s+exceeded|payment\s+required|account invoice is overdue|billing_error|please add or update your payment method|(?:GLM Coding Plan|enterprise) package has expired|your current subscription plan does not yet include access to/i.test(t)}function gw(t,e,n){let r=t&&Ae(t.metadata)?t.metadata:void 0,o=typeof r?.replacement=="string"?r.replacement.trim():void 0;if(!o)return;let s=[r?.model,e?.model,n.model,n.modelID].find(c=>typeof c=="string"&&c.trim().length>0)?.trim(),i=s&&s.includes("/")?s.slice(0,s.indexOf("/")):"opencode-go",a=o.includes("/")?o:`${i}/${o}`;return /^[A-Za-z0-9._/-]{1,128}$/.test(a)?a:void 0}function hw(t){let e=t?.retryAfterMs;if(typeof e=="number"&&Number.isFinite(e)&&e>=0)return e;let r=(t&&Ae(t.response)?t.response:void 0)?.body,o=typeof r=="string"?mw(r):Ae(r)?r:void 0;if(o){let s=fd(o);if(s)return f_(s.value,s.key==="retryafterms")}if(typeof r=="string"){let s=r.match(/retry[-_]after(?:\s*[:=]\s*|\s+)["']?([^"'\s,;}]+)/i);if(s?.[1])return f_(s[1],false)}}function mw(t){try{let e=JSON.parse(t);return Ae(e)?e:void 0}catch{return}}function fd(t){if(Array.isArray(t)){for(let e of t){let n=fd(e);if(n)return n}return}if(Ae(t)){for(let[e,n]of Object.entries(t)){let r=e.toLowerCase().replace(/[-_]/g,"");if(r==="retryafterms"||r==="retryafter")return {value:n,key:r}}for(let e of Object.values(t)){let n=fd(e);if(n)return n}}}function f_(t,e){if(typeof t=="number"&&Number.isFinite(t)&&t>=0)return e?t:Math.round(t*1e3);if(typeof t!="string"||!t.trim())return;let n=Number(t);if(Number.isFinite(n)&&n>=0)return e?n:Math.round(n*1e3);if(e)return;let r=Date.parse(t);return Number.isFinite(r)?Math.max(0,r-Date.now()):void 0}function g_(t){let e=_w(t),n=[],r=null,o=0,s=[],i=[],a,c=false;for(let u of e.events){if(k_(u))continue;let p=typeof u.type=="string"?u.type:void 0;if(p){if(p==="text"){let l=Ae(u.part)?u.part:void 0,f=typeof l?.text=="string"?l.text:void 0;f?.trim()&&n.push(f.trim());continue}if(p==="result"){typeof u.result=="string"&&(r=u.result);continue}if(p==="tool_use"){o++;continue}if(p==="error"){s.push(u),i.push(gd(u));continue}if(p==="step_finish"){c=true;let l=Ae(u.part)?u.part:void 0;a=typeof l?.reason=="string"?l.reason:void 0;}}}return {...e,texts:n,resultText:r,toolUseCount:o,errorEvents:s,errorMessages:i,terminalReason:a,hasTerminal:c}}function T_(t){return (t??"unknown").trim().toLowerCase().replace(/_/g,"-")}function kw(){return new V("OpenCode returned no assistant output.",mt,{code:"EMPTY_OUTPUT",kind:"transient"})}function yw(){return new V("OpenCode emitted malformed JSON output.",mt,{code:"PROVIDER_CRASHED",kind:"transient"})}function Tw(t,e){switch(T_(t)){case "length":return new V("OpenCode stopped because the context window was exceeded.",mt,{code:"UNKNOWN",kind:"permanent"});case "content-filter":return new V("OpenCode stopped because the content filter blocked the response.",mt,{code:"UNKNOWN",kind:"permanent"});case "error":return new V(`${h_} while generating a response.`,mt,{code:"PROVIDER_CRASHED",kind:"transient"});default:return null}}var ow,mt,h_,sw,iw,aw,p_,ei,dw,hd,md=D(()=>{h();vn();t_();$o();$r();Qn();l_();cd();ow=new Set(["step_start","step_finish"]),mt="cli/opencode",h_="OpenCode provider error",sw=240,iw="Follow the instructions provided on standard input.",aw=3e5,dw={build:{agent:"build",autoApprove:false},"build-auto":{agent:"build",autoApprove:true},plan:{agent:"plan",autoApprove:false},"plan-auto":{agent:"plan",autoApprove:true}};hd={command:"opencode",prepare:lw,meta:{displayName:"OpenCode",capabilities:{resume:true}},buildArgs(t,e,n){let r=e.additionalArgs,o=r!==void 0?[...r]:["run"];Nt(o,"--format")||o.push("--format","json"),Nt(o,"--thinking")||o.push("--thinking"),!Nt(o,"--standalone")&&!Nt(o,"--server")&&o.push("--standalone"),e.resumeSessionId&&!Nt(o,"-s")&&!Nt(o,"--session")&&o.push("-s",e.resumeSessionId);let{agent:s,autoApprove:i}=cw(e.mode);Nt(o,"--agent")||s!==void 0&&o.push("--agent",s),i&&!Nt(o,"--auto")&&o.push("--auto");let a=Nt(o,"--model")||Nt(o,"-m");if(e.model&&!a){let c=e.effort?`${e.model}#${e.effort}`:e.model;o.push("--model",c);}else e.effort&&!e.model&&!a&&console.debug("[opencode] ignoring effort because no model is configured");return o.push(iw),{args:o,stdinMessage:t,env:Bo()}},extractText(t){let e=g_(t),n=e.errorEvents[0];if(n)throw __(n);let r=Tw(e.terminalReason??"");if(r)throw r;let o=e.texts.length>0?e.texts[e.texts.length-1]:void 0;if(o!==void 0)return o;if(e.resultText?.trim())return e.resultText;if(e.malformed)throw yw();let s=T_(e.terminalReason);if(e.hasTerminal&&s==="tool-calls"&&e.toolUseCount>0)return "";throw kw()},interpretExit(t,e,n=""){if(t===0)return null;let o=g_(n).errorEvents[0];return o?__(o):null},parseResultMeta(t){let e=Ur(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(),o=[],s=new Map,i;try{JSON.parse(t),i=[t];}catch{i=m_(t),i.length>1&&console.warn("[opencode] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let a of i){let c;try{c=JSON.parse(a);}catch{continue}let u=Bt(c,r),p=c.type;if(k_(c)){let l=pw(c);if(!l)continue;let f=Ae(c.part)?c.part:void 0,g=typeof f?.id=="string"?f.id:typeof c.id=="string"?c.id:void 0,m=l;if(g){let k=`opencode.reasoning:${g}`,T=n?.state.get(k),E=typeof T=="string"?T:s.get(g);if(typeof E=="string"&&(E===l||E.startsWith(l))||typeof E=="string"&&l.startsWith(E)&&(m=l.slice(E.length).trim(),!m))continue;s.set(g,l),n?.state.set(k,l);}o.push({timestamp:u,type:"thinking",content:m});continue}if(p){if(p==="text"){let f=c.part?.text;f&&o.push({timestamp:u,type:"text",content:f});continue}if(p==="tool_use"){let l=c.part;if(!l)continue;let f=String(l.tool||""),g=String(l.callID||l.id||""),m=l.state,k=String(m?.status||""),T=m?.input,E=Ut(T);if(o.push({timestamp:u,type:"tool_use",toolName:f,toolUseId:g,toolInput:E}),k==="completed"&&m?.output!==void 0){let w=m.output,P=typeof w=="string"?w:JSON.stringify(w);o.push({timestamp:u,type:"tool_result",toolUseId:g,resultPreview:P,isError:false});}else k==="error"&&o.push({timestamp:u,type:"tool_result",toolUseId:g,resultPreview:String(m?.error||"tool error"),isError:true});continue}if(p==="error"){let l=gd(c);o.push({timestamp:u,type:"error",content:l,errorMessage:l});continue}}}return o},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?ow.has(r):!1}catch{return false}}};});var w_=D(()=>{h();});function qr(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function bw(t,e){return t&&R_.has(t)||qr(e,"--dangerously-skip-permissions")?true:e.some((n,r)=>{let o=n==="--mode"?e[r+1]:n.startsWith("--mode=")?n.slice(7):void 0;return typeof o=="string"&&R_.has(o)})}function Aw(t,e){let n=[];for(let r=0;r<t.length;r+=1){let o=t[r],s=[...e].find(i=>o===i||o.startsWith(`${i}=`));s?o===s&&r+1<t.length&&(r+=1):n.push(o);}return n}function Iw(t){let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],o=r.indexOf("="),s=o>0?r.slice(0,o):r;if(!Ew.has(s)){e.push(r);continue}r===s&&n+1<t.length&&!t[n+1].startsWith("-")&&(n+=1);}return e}function Ot(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Nw(t,e){if(!(t?Rw.has(t)||kn(kd).some(s=>s.id===t):false)||!t)return e;let r=Hr(kd,t),o=Qa(kd)[t]?.defaultEffort;if(r.length!==0)return e?r.includes(e)?e:o&&r.includes(o)?o:void 0:o}function yn(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0?t:void 0}function wd(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 Rd(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&&js(e)?.slice(0,500).trim()||void 0}function Ow(t,e){let n=(t??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&Sw.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)/,/invalid (?:flag|option)/].some(s=>s.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 vw(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 b_(t){let e=Ot(t)?t:void 0,n=e&&Ot(e.error)?e.error:void 0,r=e?Se(e.code)??Se(e.error_code)??Se(n?.code)??Se(n?.error_code):void 0,o=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,s=Ow(r,o),i=e?yn(e.retry_after_ms)??yn(e.retryAfterMs)??yn(n?.retry_after_ms)??yn(n?.retryAfterMs):void 0;return {code:s,kind:vw(s),message:o??"Antigravity reported a terminal error.",...i===void 0?{}:{retryAfterMs:i}}}function ni(t){let e=b_(t);return new V(e.message,"cli/antigravity",{code:e.code,kind:e.kind,...e.retryAfterMs===void 0?{}:{retryAfterMs:e.retryAfterMs}})}function Ed(t){return new V(t,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function Cw(t){let e=new TextEncoder().encode(t).byteLength;if(!(e<=Td))throw new V(`Input is too large: final provider initial input is ${e} UTF-8 bytes; budget is ${Td} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function yd(){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 ri(t){if(t.kind==="result"||t.kind==="legacy_result")return t.result}function oi(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 Dw(t){let e=oi(t);if(!e||e.event.kind==="agy_error"||e.index!==t.length-1||ri(e.event)?.status!=="SUCCESS"||ti(t))return false;let r=new Map;for(let o of t){if(o.kind!=="step_update"||o.step.step_type!=="agent_response")continue;let s=wd(o),i=Rd(o);!s||!Number.isSafeInteger(i)||r.set(JSON.stringify([s,i]),o.step);}if(r.size===0)return false;for(let o of r.values())if(o.state!=="DONE"||!Ot(o.usage)||yn(o.usage.input_tokens)===void 0||yn(o.usage.output_tokens)===void 0)return false;return true}function xw(t,e){for(let n=e-1;n>=0;n-=1){let r=t[n];if(r?.kind==="agy_error")return r.error}}function Pw(t,e){return Ot(t)&&Ot(e)?{...e,...t}:Ot(t)&&typeof e=="string"?{...t,message:e}:typeof t=="string"&&Ot(e)?{...e,message:t}:t??e}function Lw(t){let e=Array.isArray(t.denied_actions)?t.denied_actions:[],n=[];for(let i of e){let a=Ot(i)?i:void 0,c=typeof i=="string"?Se(i):Se(a?.display_name)??Se(a?.action);c&&!n.includes(c)&&n.length<5&&n.push(c.slice(0,80));}let r=Math.max(0,e.length-n.length),o=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"",s=`Permission denied: Antigravity blocked ${e.length} requested action${e.length===1?"":"s"}${o}.`;return new V("Could not run because of permissions.","cli/antigravity",{code:"UNKNOWN",kind:"permanent",providerReason:s})}function ti(t){let e=oi(t);if(!e)return;if(e.event.kind==="agy_error")return ni(e.event.error);let n=ri(e.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return Lw(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return Ed("Antigravity returned a result with an unsupported status.");let r=n.error,o=Pw(r==null||r===""?n:r,xw(t,e.index));return ni(o)}function A_(t){if(typeof t=="string")return t;if(t!=null)try{return JSON.stringify(t)}catch{return}}function Mw(t){return `agy:${String(t.conversation_id)}:${String(t.step_index)}`}function $w(t,e){let n=typeof e?.name=="string"?e.name:t.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function I_(t){let e=A_(t);if(e)return e.length<=2e3?e:`${e.slice(0,1999)}\u2026`}function Hw(t){let e=Ot(t)?t:void 0,n=e&&Ot(e.error)?e.error:void 0,r=typeof t=="string"?t.trim().match(/^([A-Z][A-Z0-9_]*)(?:[:\s]|$)/)?.[1]:void 0,o=(Se(e?.type)??Se(e?.code)??Se(e?.error_type)??Se(n?.type)??Se(n?.code)??Se(n?.error_type)??Se(r)??"TOOL_ERROR").slice(0,60),s=b_(t).message.slice(0,250);return I_({type:o,message:s})??"Antigravity reported a tool error."}function E_(t,e){return t?t.state.has(e)?true:(t.state.set(e,true),false):false}function S_(t,e){return {timestamp:t,type:"error",content:e.message,errorMessage:e.message,isError:true}}var kd,Rw,Ew,R_,Td,Sw,Sd,bd=D(()=>{h();vn();w_();ja();Po();Cn();Mo();Gs();Za();kd="antigravity",Rw=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),Ew=new Set(["--conversation","--resume","--continue"]),R_=new Set(["bypassPermissions","agent-full-access","yolo"]),Td=18e4,Sw=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"]);Sd={command:"agy",maxInitialInputBytes:Td,meta:{displayName:"Antigravity",models:Ep(),defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(t){let e=Do(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){Cw(t);let{model:r,effort:o}=Dn(e.model),s=Xa(r),i=s.model,a=e.effort??o??s.effort,c=Nw(i,a),u=e.additionalArgs??[],p=Iw(Aw(u,new Set(["--input-format","--output-format"]))),l=i&&!qr(u,"--model")?["--model",i]:[],f=qr(u,"--effort")?[]:Mp(c),g=qr(u,"--mode")||qr(u,"--dangerously-skip-permissions")?[]:Lp(e.mode),m=bw(e.mode,u)||qr(u,"--settings")?[]:["--settings",JSON.stringify({permissions:{allow:Fp(e.builtinAllow)}})],k=typeof e.resumeSessionId=="string"&&e.resumeSessionId.trim().length>0?["--conversation",e.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...l,...f,...g,...k,...m,...p],stdinMessage:`${JSON.stringify({event:"user",message:{content:t}})}
85
85
  `,env:{AGY_CLI_DISABLE_AUTO_UPDATE:"true"}}},extractText(t){let e=Yn(t),n=oi(e)?.event,r=ti(e);if(r)throw r;let o=n?ri(n):void 0;if(o){if(o.status!=="SUCCESS")throw Ed("Antigravity returned a result with an unsupported status.");if(typeof o.response!="string")throw Ed("Antigravity returned a successful result without a response string.");if(!o.response.trim())throw yd();return o.response}if(e.length>0)throw yd();let s=t.trim();if(!s)throw yd();return s},extractPartialText(t){let e=Yn(t),n=oi(e)?.event;if(!n||n.kind==="agy_error")return;let r=ri(n);return r&&typeof r.response=="string"&&r.response.trim()?r.response:void 0},interpretExit(t,e,n){let r=Yn(n??""),o=ti(r);return o||(t!==0&&e.trim()?ni(e):null)},parseResultMeta(t){let e=Yn(t),n=0,r=0,o=0,s=0,i=new Set;for(let c of e){if(c.kind!=="step_update"||c.step.state!=="DONE"||!Ot(c.step.usage))continue;let u=wd(c),p=Rd(c);if(!u||!Number.isSafeInteger(p))continue;let l=JSON.stringify([u,p]);if(i.has(l))continue;let f=c.step.usage,g=yn(f.input_tokens),m=yn(f.output_tokens);if(g===void 0||m===void 0)continue;i.add(l);let k=yn(f.cache_read_tokens)??0;n+=g+k,r+=m,o+=k,s+=1;}return {usage:s===0?null:{inputTokens:n,outputTokens:r,cachedInputTokens:o,costUsd:0,complete:Dw(e)},model:null}},parseEvent(t,e,n){let r=Do(t);if(!r)return [];let o=e??new Date().toISOString();if(r.kind==="agy_error")return [S_(o,ni(r.error))];if(r.kind==="legacy_result"||r.kind==="result"){let g=ti([r]);return g?[S_(o,g)]:[]}if(r.kind!=="step_update")return [];let{step:s}=r,i=wd(r)??"unknown",a=Rd(r),c=`${i}:${a}`;if((s.state==="DONE"||s.state==="ERROR")&&E_(n,`antigravity:terminal:${c}`))return [];if(s.step_type==="agent_response")return typeof s.text_delta=="string"&&s.text_delta.length>0?[{timestamp:o,type:"text",content:s.text_delta}]:[];if(s.step_type!=="tool")return [];let u=Ot(s.tool_info)?s.tool_info:void 0,p=$w(s,u);if(!p)return [];let l=Mw(s);if(s.state==="ACTIVE"){if(E_(n,`antigravity:active:${c}`))return [];let g=A_(u?.parameters);return [{timestamp:o,type:"tool_use",toolName:p,toolUseId:l,...g===void 0?{}:{toolInput:g}}]}let f=s.state==="ERROR"?Hw(u?.error):I_(u?.output);return [{timestamp:o,type:"tool_result",toolName:p,toolUseId:l,...f===void 0?{}:{resultPreview:f},...s.state==="ERROR"?{isError:true}:{}}]}};});var N_=D(()=>{h();Lr();$r();Mr();Qn();});function Fr(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function jr(t){return Fr(t)?t:void 0}function at(t){return typeof t=="string"?t:void 0}function nr(t){let e=typeof t=="number"?t:Number(t??0);return Number.isFinite(e)?e:0}function Kw(t){let e=[],n=-1,r=0,o=false,s=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(s){s=false;continue}if(a==="\\"&&o){s=true;continue}if(a==='"'){o=!o;continue}o||(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 Fo(t){let e=t.trim();if(!e)return [];try{let n=JSON.parse(e);return Fr(n)?[n]:[]}catch{return Kw(e).flatMap(n=>{try{let r=JSON.parse(n);return Fr(r)?[r]:[]}catch{return []}})}}function L_(t){let e=JSON.stringify(t);return e===void 0?String(t):e}function tr(t){if(typeof t=="string")return t;if(Array.isArray(t)){let e=t.map(tr).filter(n=>n!==void 0);return e.length>0?e.join(`
86
86
  `):void 0}if(Fr(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=tr(t[e]);if(n!==void 0)return n}}}function Vw(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)),o=i=>{let a=JSON.stringify(i,(c,u)=>e(u)?`<bytes:${u.length}>`:u);return a===void 0?String(i):a},s=t.rawOutput;if(s!=null){let i=jr(s);if(!i)return n(tr(s))??o(s);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=jr(i.Result);a=n(i.output)??n(p?.output)??n(tr(s));}let c=e(i.stderr)&&i.stderr.length>0?r(i.stderr):void 0;if(c!==void 0)if(a){let p=a.endsWith(`
87
87
  `)||a.endsWith("\r")?"":`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crewx/sdk",
3
- "version": "0.9.0-rc.222",
3
+ "version": "0.9.0-rc.224",
4
4
  "license": "UNLICENSED",
5
5
  "engines": {
6
6
  "node": ">=20.19.0"