@abacus-ai/cli 2.5.1-canary.4 → 2.5.1-canary.5

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.
Files changed (2) hide show
  1. package/dist/index.mjs +4 -4
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -75178,12 +75178,12 @@ No matching component was found for:
75178
75178
  * This source code is licensed under the MIT license found in the
75179
75179
  * LICENSE file in the root directory of this source tree.
75180
75180
  */
75181
- var xPe=G((e=>{var t=wY().__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;e.c=function(e){return t.H.useMemoCache(e)}})),cQ=G(((e,t)=>{t.exports=xPe()}))();function $(e){let t=(0,cQ.c)(14),{color:n,backgroundColor:r,dimColor:i,bold:a,italic:o,underline:s,strikethrough:c,inverse:l,wrap:u,transform:d,children:f}=e,p=i===void 0?!1:i,m=a===void 0?!1:a,h=o===void 0?!1:o,g=s===void 0?!1:s,_=c===void 0?!1:c,v=l===void 0?!1:l,y=u===void 0?`wrap`:u;if(f==null)return null;let b;t[0]!==r||t[1]!==m||t[2]!==n||t[3]!==p||t[4]!==v||t[5]!==h||t[6]!==_||t[7]!==g||t[8]!==d?(b=e=>(p&&(e=XZ().dim().render(e)),n&&(e=YZ(e,n,`foreground`)),r&&(e=YZ(e,r,`background`)),m&&(e=XZ().bold().render(e)),h&&(e=XZ().italic().render(e)),g&&(e=XZ().underline().render(e)),_&&(e=XZ().strikethrough().render(e)),v&&(e=XZ().reverse().render(e)),d&&(e=d(e)),e),t[0]=r,t[1]=m,t[2]=n,t[3]=p,t[4]=v,t[5]=h,t[6]=_,t[7]=g,t[8]=d,t[9]=b):b=t[9];let x=b,S;return t[10]!==f||t[11]!==x||t[12]!==y?(S=(0,Z.jsx)(`jar-text`,{style:{flexGrow:0,flexShrink:0,flexDirection:`row`,textWrap:y},internal_transform:x,children:f}),t[10]=f,t[11]=x,t[12]=y,t[13]=S):S=t[13],S}const SPe=/\x1b\[[\d:]*;(\d+)/;function CPe(e){let t=SPe.exec(e);return t?(parseInt(t[1],10)-1&8)!=0:!1}const lQ={upArrow:!1,downArrow:!1,leftArrow:!1,rightArrow:!1,pageDown:!1,pageUp:!1,home:!1,end:!1,return:!1,escape:!1,ctrl:!1,shift:!1,tab:!1,backspace:!1,delete:!1,meta:!1,super:!1,paste:!1,raw:``},uQ=(e,t={})=>{let{addInputListener:n}=(0,X.use)(CZ),r=(0,X.useRef)(e);r.current=e,(0,X.useEffect)(()=>{if(t.isActive!==!1)return n(e=>{if(tX(e))return;if(e.startsWith(`\x1B[200~`)){let t=e.indexOf(`\x1B[201~`),n=t===-1?e.slice(6):e.slice(6,t);lQ.upArrow=!1,lQ.downArrow=!1,lQ.leftArrow=!1,lQ.rightArrow=!1,lQ.pageDown=!1,lQ.pageUp=!1,lQ.home=!1,lQ.end=!1,lQ.return=!1,lQ.escape=!1,lQ.ctrl=!1,lQ.shift=!1,lQ.tab=!1,lQ.backspace=!1,lQ.delete=!1,lQ.meta=!1,lQ.super=!1,lQ.paste=!0,lQ.raw=e,r.current(n,{...lQ});return}let t=AMe(e),n=t?t.split(`+`):[],i=n[n.length-1]??``,a=n.includes(`ctrl`),o=n.includes(`shift`),s=n.includes(`alt`);lQ.upArrow=i===`up`,lQ.downArrow=i===`down`,lQ.leftArrow=i===`left`,lQ.rightArrow=i===`right`,lQ.pageDown=i===`pagedown`,lQ.pageUp=i===`pageup`,lQ.home=i===`home`,lQ.end=i===`end`,lQ.return=i===`return`||i===`enter`,lQ.escape=i===`escape`,lQ.ctrl=a,lQ.shift=o,lQ.tab=i===`tab`,lQ.backspace=i===`backspace`,lQ.delete=i===`delete`,lQ.meta=s,lQ.super=CPe(e),lQ.paste=!1,lQ.raw=e;let c=lQ,l=``;if(a&&i)l=i;else if(!c.upArrow&&!c.downArrow&&!c.leftArrow&&!c.rightArrow&&!c.pageDown&&!c.pageUp&&!c.home&&!c.end&&!c.return&&!c.escape&&!c.tab&&!c.backspace&&!c.delete){let t=NMe(e);t===void 0?e.length===1?l=e:i.length===1&&(l=i):l=t}r.current(l,{...c})})},[t.isActive,n])},wPe=()=>{let e=(0,X.use)(wZ);if(!e)throw Error(`useApp must be used within a jar render context`);return{exit:e.exit,requestFullRedraw:e.requestFullRedraw}},dQ=e=>{let t=(0,cQ.c)(23),n;t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n);let{isActive:r,autoFocus:i,id:a}=n,o=r===void 0?!0:r,s=i===void 0?!1:i,{activeId:c,add:l,remove:u,activate:d,deactivate:f,focus:p}=(0,X.use)(xZ),m;t[2]===a?m=t[3]:(m=a??Math.random().toString().slice(2,7),t[2]=a,t[3]=m);let h=m,g;t[4]!==l||t[5]!==s||t[6]!==h||t[7]!==u?(g=()=>(l(h,{autoFocus:s}),()=>{u(h)}),t[4]=l,t[5]=s,t[6]=h,t[7]=u,t[8]=g):g=t[8];let _;t[9]!==s||t[10]!==h?(_=[h,s],t[9]=s,t[10]=h,t[11]=_):_=t[11],(0,X.useEffect)(g,_);let v;t[12]!==d||t[13]!==f||t[14]!==h||t[15]!==o?(v=()=>{o?d(h):f(h)},t[12]=d,t[13]=f,t[14]=h,t[15]=o,t[16]=v):v=t[16];let y;t[17]!==h||t[18]!==o?(y=[o,h],t[17]=h,t[18]=o,t[19]=y):y=t[19],(0,X.useEffect)(v,y);let b=!!h&&c===h,x;return t[20]!==p||t[21]!==b?(x={isFocused:b,focus:p},t[20]=p,t[21]=b,t[22]=x):x=t[22],x};function fQ(){return(0,X.use)(SZ)}const pQ=()=>{let e=(0,X.use)(TZ);if(!e)throw Error(`useTerminal must be used within a jar render context`);return e.output},mQ=RegExp(`[\\x1b\\x9b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><~]|\\x1b\\][\\s\\S]*?(?:\\x07|\\x1b\\\\)`,`g`);function TPe(){return new RegExp(mQ.source,`g`)}function EPe(e){return e.replace(mQ,``)}function DPe(e){return e.replace(/[\x07\x1b\x9c]/g,``)}function hQ(e){return`\x1B]2;`+DPe(e)+`\x07`}var gQ=G(((e,t)=>{t.exports={name:`@codellm/cli`,version:`2.5.1-canary.4`,private:!0,bin:{abacusai:`dist/index.mjs`},files:[`dist`,`LICENSE.txt`],type:`module`,scripts:{"prepare-publish":`bun ./scripts/prepare-publish.ts`,build:`tsdown`,"check-types":`tsgo -b --noEmit`,test:`FORCE_COLOR=1 vitest run`,"test:watch":`FORCE_COLOR=1 vitest`,"test:ui":`FORCE_COLOR=1 vitest --ui`,"test:coverage":`FORCE_COLOR=1 vitest run --coverage`},dependencies:{"@clack/prompts":`^0.11.0`,"@codellm/agent":`workspace:*`,"@codellm/api":`workspace:*`,"@codellm/auth":`workspace:*`,"@codellm/comms":`workspace:*`,"@codellm/jar":`workspace:*`,"@codellm/logging":`workspace:*`,"@codellm/product":`workspace:*`,"@logtape/logtape":`catalog:`,"@orpc/client":`catalog:`,"@orpc/contract":`catalog:`,"@orpc/server":`catalog:`,"@sentry/node-core":`catalog:`,"@slack/web-api":`^7.0.0`,"@tanstack/react-query":`catalog:`,"@vscode/ripgrep":`catalog:`,"ansi-styles":`catalog:`,"beautiful-mermaid":`^1.1.3`,"cli-boxes":`catalog:`,"cli-highlight":`^2.1.11`,conf:`catalog:`,diff:`catalog:`,fzf:`catalog:`,"gradient-string":`^3.0.0`,immer:`catalog:`,"isomorphic-git":`catalog:`,marked:`^17.0.6`,"node-notifier":`catalog:`,"patchright-core":`catalog:`,react:`catalog:react`,"react-compiler-runtime":`^1.0.0`,remend:`^1.3.0`,semver:`catalog:`,"shell-history":`^2.0.1`,"string-width":`catalog:`,"strip-ansi":`catalog:`,trash:`catalog:`,zod:`catalog:`},devDependencies:{"@babel/core":`catalog:infra`,"@codellm/configs":`workspace:*`,"@playwright/mcp":`^0.0.68`,"@rolldown/plugin-babel":`catalog:infra`,"@types/diff":`^8.0.0`,"@types/node":`catalog:`,"@types/react":`catalog:react`,"@types/semver":`^7.7.1`,"@typescript/native-preview":`catalog:infra`,"@vitejs/plugin-react":`catalog:infra`,"@vitest/coverage-v8":`^4.1.5`,"@vitest/ui":`^4.1.5`,"@xterm/addon-serialize":`^0.14.0`,"@xterm/headless":`^6.0.0`,"babel-plugin-react-compiler":`catalog:infra`,"cli-testing-library":`^3.0.1`,jsdom:`^27.4.0`,"react-devtools-core":`^6.1.5`,"svg-term-cli":`^2.1.1`,tsdown:`catalog:infra`,vite:`catalog:infra`,vitest:`catalog:infra`,zigpty:`^0.1.6`},engines:{node:`>=18`}}})),_Q=$e(gQ(),1);let vQ=null;function yQ(e){let t=(0,lY.prerelease)(e);return t&&t.length>0&&typeof t[0]==`string`?t[0]:`latest`}function bQ(e){if(!e)return``;try{return T(e)}catch{return e}}function xQ(){return{invokedPath:bQ(process.argv[1]??``),execPath:bQ(process.execPath??process.argv[0]??``)}}function SQ(e){let t=hn.configDirName.replace(/^\./,``).replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return RegExp(`[/\\\\]\\.?${t}[/\\\\]bin[/\\\\]`,`i`).test(e)}function CQ(e){return/[/\\]node_modules[/\\]/.test(e)||/[/\\]\._npx[/\\]/.test(e)||/[/\\]_npx[/\\]/.test(e)||/[/\\]\.?npm[/\\]/.test(e)||/[/\\]\.?pnpm[/\\]/.test(e)||/[/\\]\.?yarn[/\\]/.test(e)||/[/\\]\.bun[/\\]/.test(e)}function wQ(){let e=(process.env.npm_command??``).toLowerCase();if(e===`exec`||e===`dlx`)return!0;let{invokedPath:t,execPath:n}=xQ();return/[/\\]_npx[/\\]|[/\\]dlx[/\\]|[/\\]\.cache[/\\]/.test(t+`|`+n)}function TQ(){let e=process.env.npm_config_user_agent;if(e){let t=e.split(`/`)[0];if(t===`yarn`||t===`pnpm`||t===`bun`||t===`npm`)return t}let{invokedPath:t,execPath:n}=xQ(),r=`${t}|${n}`;return/[/\\]\.?yarn[/\\]/.test(r)?`yarn`:/[/\\]\.?pnpm[/\\]/.test(r)?`pnpm`:/[/\\]\.bun[/\\]/.test(r)||process.versions.bun!==void 0&&!SQ(n)?`bun`:`npm`}function OPe(){let{execPath:e,invokedPath:t}=xQ();return CQ(t)||CQ(e)?!1:SQ(e)||SQ(t)}function EQ(){let e=`${hn.internalEnvPrefix}DEV`,t=process.env[e];if(t===`1`||t===`true`)return!0;let{invokedPath:n,execPath:r}=xQ();return!(SQ(r)||SQ(n)||CQ(n)||CQ(r)||process.env.npm_config_user_agent)}function kPe(){let{execPath:e}=xQ(),t=TQ(),n=wQ();return EQ()?{installationType:`development`,packageManager:t,isEphemeral:n,execPath:e}:OPe()?{installationType:`native`,packageManager:t,isEphemeral:n,execPath:e}:{installationType:`package-manager`,packageManager:t,isEphemeral:n,execPath:e}}function APe(){return`${process.platform===`win32`?`win32`:process.platform===`darwin`?`darwin`:`linux`}-${process.arch===`arm64`?`arm64`:`x64`}`}async function jPe(e){let t=Date.now();if(vQ&&t-vQ.timestamp<6e4)return vQ.tags;let n=await fetch(`https://registry.npmjs.org/${e}`,{signal:AbortSignal.timeout(1e4),headers:{accept:`application/json`}});if(!n.ok)throw Error(`Registry returned ${n.status}`);let r=(await n.json())[`dist-tags`]??{};return vQ={tags:r,timestamp:t},r}async function MPe(e,t,n,r){let i=t??yQ(e),a=(r??`https://apps.abacus.ai`).replace(/\/$/,``),o=new URL(`${a}/api/v0/_getCodellmCliVersion`);o.searchParams.set(`channel`,i),n&&o.searchParams.set(`platform`,n),o.searchParams.set(`cli_version`,e);let s=await fetch(o.toString(),{signal:AbortSignal.timeout(1e4)});if(s.status===204)return null;if(!s.ok)throw Error(`API returned ${s.status}`);let c=await s.json(),l=c&&`result`in c&&c.result?c.result:c??{};if(!l.version||!l.channel)throw Error(`API returned invalid payload`);return{currentVersion:e,latestVersion:l.version,tag:l.channel,packageManager:TQ(),isEphemeral:wQ(),installationType:`native`,downloadUrl:l.url}}async function NPe(e,t){let n=t??yQ(e),r=TQ(),i=wQ(),a=(await jPe(gn.publishName))[n];return!a&&n!==`latest`||!a||a===e?null:{currentVersion:e,latestVersion:a,tag:n,packageManager:r,isEphemeral:i,installationType:`package-manager`}}async function DQ(e,t,n,r){let i=kPe();if(i.installationType===`native`)try{return await MPe(e,t,APe(),n)}catch{return null}return i.installationType===`development`&&!r?.includeDev?null:await NPe(e,t)}function OQ(e){if(e.installationType===`native`)return`${hn.binName} upgrade`;let t=`${gn.publishName}@${e.tag}`;switch(e.packageManager){case`yarn`:return`yarn global add ${t}`;case`pnpm`:return`pnpm add -g ${t}`;case`bun`:return`bun add -g ${t}`;default:return`npm install -g ${t}`}}function kQ(e){try{return{ok:!0,output:le(OQ(e),{stdio:`pipe`,encoding:`utf-8`}).trim()}}catch(e){return{ok:!1,output:e instanceof Error&&`stderr`in e?String(e.stderr).trim():e instanceof Error?e.message:`Unknown error`}}}function PPe(){let e=N.join(t.homedir(),hn.configDirName,`bin`);try{let n=N.dirname(bQ(process.execPath));return!n||n.toLowerCase().startsWith(t.tmpdir().toLowerCase())?e:n}catch{return e}}async function AQ(e){if(!e.downloadUrl)return{ok:!1,output:`No download URL`};let n=N.join(t.tmpdir(),`abacusai-update-${Date.now()}`),r=process.platform===`win32`,i=r?`${hn.binName}.exe`:hn.binName,a=PPe();try{await we.mkdir(n,{recursive:!0}),await we.mkdir(a,{recursive:!0});let t=N.join(n,r?`update.zip`:`update.tar.gz`),o=await fetch(e.downloadUrl);if(!o.ok)throw Error(`Download failed: ${o.status}`);let s=Buffer.from(await o.arrayBuffer());await we.writeFile(t,s),le(r?`powershell -Command "Expand-Archive -Path '${t}' -DestinationPath '${n}' -Force"`:`tar -xzf "${t}" -C "${n}"`,{stdio:`pipe`});let c=N.join(n,i),l=N.join(a,i);if(r){let e=`${l}.old`;await we.rm(e,{force:!0}).catch(()=>{}),await we.rename(l,e).catch(()=>{}),await we.copyFile(c,l),await we.rm(e,{force:!0}).catch(()=>{})}else await we.copyFile(c,l),await we.chmod(l,493);return{ok:!0,output:`Updated to ${e.latestVersion}`}}catch(e){return{ok:!1,output:e instanceof Error?e.message:`Unknown error`}}finally{await we.rm(n,{recursive:!0,force:!0}).catch(()=>{})}}function FPe(e,t){let n=e=>{let n=e.toLowerCase();if(n===t)return 1e3;if(n.startsWith(t))return 900;let r=0,i=-1;for(let e of t){let t=n.indexOf(e,i+1);if(t===-1)return 0;r+=100-(t-i),i=t}return r+=Math.max(0,50-n.length),r},r=null,i=0;for(let t of e){let e=Math.max(n(t.name??``),n(t.llmName));e>i&&(i=e,r=t.llmName)}return i>=100?r:null}async function jQ(e,t,n=nt.CLI){let r=(await e.listLLMModels({coworkV2:n===nt.COWORK}))?.result??[];return r.length||(process.stderr.write(`Error: No models available.
75181
+ var xPe=G((e=>{var t=wY().__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;e.c=function(e){return t.H.useMemoCache(e)}})),cQ=G(((e,t)=>{t.exports=xPe()}))();function $(e){let t=(0,cQ.c)(14),{color:n,backgroundColor:r,dimColor:i,bold:a,italic:o,underline:s,strikethrough:c,inverse:l,wrap:u,transform:d,children:f}=e,p=i===void 0?!1:i,m=a===void 0?!1:a,h=o===void 0?!1:o,g=s===void 0?!1:s,_=c===void 0?!1:c,v=l===void 0?!1:l,y=u===void 0?`wrap`:u;if(f==null)return null;let b;t[0]!==r||t[1]!==m||t[2]!==n||t[3]!==p||t[4]!==v||t[5]!==h||t[6]!==_||t[7]!==g||t[8]!==d?(b=e=>(p&&(e=XZ().dim().render(e)),n&&(e=YZ(e,n,`foreground`)),r&&(e=YZ(e,r,`background`)),m&&(e=XZ().bold().render(e)),h&&(e=XZ().italic().render(e)),g&&(e=XZ().underline().render(e)),_&&(e=XZ().strikethrough().render(e)),v&&(e=XZ().reverse().render(e)),d&&(e=d(e)),e),t[0]=r,t[1]=m,t[2]=n,t[3]=p,t[4]=v,t[5]=h,t[6]=_,t[7]=g,t[8]=d,t[9]=b):b=t[9];let x=b,S;return t[10]!==f||t[11]!==x||t[12]!==y?(S=(0,Z.jsx)(`jar-text`,{style:{flexGrow:0,flexShrink:0,flexDirection:`row`,textWrap:y},internal_transform:x,children:f}),t[10]=f,t[11]=x,t[12]=y,t[13]=S):S=t[13],S}const SPe=/\x1b\[[\d:]*;(\d+)/;function CPe(e){let t=SPe.exec(e);return t?(parseInt(t[1],10)-1&8)!=0:!1}const lQ={upArrow:!1,downArrow:!1,leftArrow:!1,rightArrow:!1,pageDown:!1,pageUp:!1,home:!1,end:!1,return:!1,escape:!1,ctrl:!1,shift:!1,tab:!1,backspace:!1,delete:!1,meta:!1,super:!1,paste:!1,raw:``},uQ=(e,t={})=>{let{addInputListener:n}=(0,X.use)(CZ),r=(0,X.useRef)(e);r.current=e,(0,X.useEffect)(()=>{if(t.isActive!==!1)return n(e=>{if(tX(e))return;if(e.startsWith(`\x1B[200~`)){let t=e.indexOf(`\x1B[201~`),n=t===-1?e.slice(6):e.slice(6,t);lQ.upArrow=!1,lQ.downArrow=!1,lQ.leftArrow=!1,lQ.rightArrow=!1,lQ.pageDown=!1,lQ.pageUp=!1,lQ.home=!1,lQ.end=!1,lQ.return=!1,lQ.escape=!1,lQ.ctrl=!1,lQ.shift=!1,lQ.tab=!1,lQ.backspace=!1,lQ.delete=!1,lQ.meta=!1,lQ.super=!1,lQ.paste=!0,lQ.raw=e,r.current(n,{...lQ});return}let t=AMe(e),n=t?t.split(`+`):[],i=n[n.length-1]??``,a=n.includes(`ctrl`),o=n.includes(`shift`),s=n.includes(`alt`);lQ.upArrow=i===`up`,lQ.downArrow=i===`down`,lQ.leftArrow=i===`left`,lQ.rightArrow=i===`right`,lQ.pageDown=i===`pagedown`,lQ.pageUp=i===`pageup`,lQ.home=i===`home`,lQ.end=i===`end`,lQ.return=i===`return`||i===`enter`,lQ.escape=i===`escape`,lQ.ctrl=a,lQ.shift=o,lQ.tab=i===`tab`,lQ.backspace=i===`backspace`,lQ.delete=i===`delete`,lQ.meta=s,lQ.super=CPe(e),lQ.paste=!1,lQ.raw=e;let c=lQ,l=``;if(a&&i)l=i;else if(!c.upArrow&&!c.downArrow&&!c.leftArrow&&!c.rightArrow&&!c.pageDown&&!c.pageUp&&!c.home&&!c.end&&!c.return&&!c.escape&&!c.tab&&!c.backspace&&!c.delete){let t=NMe(e);t===void 0?e.length===1?l=e:i.length===1&&(l=i):l=t}r.current(l,{...c})})},[t.isActive,n])},wPe=()=>{let e=(0,X.use)(wZ);if(!e)throw Error(`useApp must be used within a jar render context`);return{exit:e.exit,requestFullRedraw:e.requestFullRedraw}},dQ=e=>{let t=(0,cQ.c)(23),n;t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n);let{isActive:r,autoFocus:i,id:a}=n,o=r===void 0?!0:r,s=i===void 0?!1:i,{activeId:c,add:l,remove:u,activate:d,deactivate:f,focus:p}=(0,X.use)(xZ),m;t[2]===a?m=t[3]:(m=a??Math.random().toString().slice(2,7),t[2]=a,t[3]=m);let h=m,g;t[4]!==l||t[5]!==s||t[6]!==h||t[7]!==u?(g=()=>(l(h,{autoFocus:s}),()=>{u(h)}),t[4]=l,t[5]=s,t[6]=h,t[7]=u,t[8]=g):g=t[8];let _;t[9]!==s||t[10]!==h?(_=[h,s],t[9]=s,t[10]=h,t[11]=_):_=t[11],(0,X.useEffect)(g,_);let v;t[12]!==d||t[13]!==f||t[14]!==h||t[15]!==o?(v=()=>{o?d(h):f(h)},t[12]=d,t[13]=f,t[14]=h,t[15]=o,t[16]=v):v=t[16];let y;t[17]!==h||t[18]!==o?(y=[o,h],t[17]=h,t[18]=o,t[19]=y):y=t[19],(0,X.useEffect)(v,y);let b=!!h&&c===h,x;return t[20]!==p||t[21]!==b?(x={isFocused:b,focus:p},t[20]=p,t[21]=b,t[22]=x):x=t[22],x};function fQ(){return(0,X.use)(SZ)}const pQ=()=>{let e=(0,X.use)(TZ);if(!e)throw Error(`useTerminal must be used within a jar render context`);return e.output},mQ=RegExp(`[\\x1b\\x9b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><~]|\\x1b\\][\\s\\S]*?(?:\\x07|\\x1b\\\\)`,`g`);function TPe(){return new RegExp(mQ.source,`g`)}function EPe(e){return e.replace(mQ,``)}function DPe(e){return e.replace(/[\x07\x1b\x9c]/g,``)}function hQ(e){return`\x1B]2;`+DPe(e)+`\x07`}var gQ=G(((e,t)=>{t.exports={name:`@codellm/cli`,version:`2.5.1-canary.5`,private:!0,bin:{abacusai:`dist/index.mjs`},files:[`dist`,`LICENSE.txt`],type:`module`,scripts:{"prepare-publish":`bun ./scripts/prepare-publish.ts`,build:`tsdown`,"check-types":`tsgo -b --noEmit`,test:`FORCE_COLOR=1 vitest run`,"test:watch":`FORCE_COLOR=1 vitest`,"test:ui":`FORCE_COLOR=1 vitest --ui`,"test:coverage":`FORCE_COLOR=1 vitest run --coverage`},dependencies:{"@clack/prompts":`^0.11.0`,"@codellm/agent":`workspace:*`,"@codellm/api":`workspace:*`,"@codellm/auth":`workspace:*`,"@codellm/comms":`workspace:*`,"@codellm/jar":`workspace:*`,"@codellm/logging":`workspace:*`,"@codellm/product":`workspace:*`,"@logtape/logtape":`catalog:`,"@orpc/client":`catalog:`,"@orpc/contract":`catalog:`,"@orpc/server":`catalog:`,"@sentry/node-core":`catalog:`,"@slack/web-api":`^7.0.0`,"@tanstack/react-query":`catalog:`,"@vscode/ripgrep":`catalog:`,"ansi-styles":`catalog:`,"beautiful-mermaid":`^1.1.3`,"cli-boxes":`catalog:`,"cli-highlight":`^2.1.11`,conf:`catalog:`,diff:`catalog:`,fzf:`catalog:`,"gradient-string":`^3.0.0`,immer:`catalog:`,"isomorphic-git":`catalog:`,marked:`^17.0.6`,"node-notifier":`catalog:`,"patchright-core":`catalog:`,react:`catalog:react`,"react-compiler-runtime":`^1.0.0`,remend:`^1.3.0`,semver:`catalog:`,"shell-history":`^2.0.1`,"string-width":`catalog:`,"strip-ansi":`catalog:`,trash:`catalog:`,zod:`catalog:`},devDependencies:{"@babel/core":`catalog:infra`,"@codellm/configs":`workspace:*`,"@playwright/mcp":`^0.0.68`,"@rolldown/plugin-babel":`catalog:infra`,"@types/diff":`^8.0.0`,"@types/node":`catalog:`,"@types/react":`catalog:react`,"@types/semver":`^7.7.1`,"@typescript/native-preview":`catalog:infra`,"@vitejs/plugin-react":`catalog:infra`,"@vitest/coverage-v8":`^4.1.5`,"@vitest/ui":`^4.1.5`,"@xterm/addon-serialize":`^0.14.0`,"@xterm/headless":`^6.0.0`,"babel-plugin-react-compiler":`catalog:infra`,"cli-testing-library":`^3.0.1`,jsdom:`^27.4.0`,"react-devtools-core":`^6.1.5`,"svg-term-cli":`^2.1.1`,tsdown:`catalog:infra`,vite:`catalog:infra`,vitest:`catalog:infra`,zigpty:`^0.1.6`},engines:{node:`>=18`}}})),_Q=$e(gQ(),1);let vQ=null;function yQ(e){let t=(0,lY.prerelease)(e);return t&&t.length>0&&typeof t[0]==`string`?t[0]:`latest`}function bQ(e){if(!e)return``;try{return T(e)}catch{return e}}function xQ(){return{invokedPath:bQ(process.argv[1]??``),execPath:bQ(process.execPath??process.argv[0]??``)}}function SQ(e){let t=hn.configDirName.replace(/^\./,``).replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return RegExp(`[/\\\\]\\.?${t}[/\\\\]bin[/\\\\]`,`i`).test(e)}function CQ(e){return/[/\\]node_modules[/\\]/.test(e)||/[/\\]\._npx[/\\]/.test(e)||/[/\\]_npx[/\\]/.test(e)||/[/\\]\.?npm[/\\]/.test(e)||/[/\\]\.?pnpm[/\\]/.test(e)||/[/\\]\.?yarn[/\\]/.test(e)||/[/\\]\.bun[/\\]/.test(e)}function wQ(){let e=(process.env.npm_command??``).toLowerCase();if(e===`exec`||e===`dlx`)return!0;let{invokedPath:t,execPath:n}=xQ();return/[/\\]_npx[/\\]|[/\\]dlx[/\\]|[/\\]\.cache[/\\]/.test(t+`|`+n)}function TQ(){let e=process.env.npm_config_user_agent;if(e){let t=e.split(`/`)[0];if(t===`yarn`||t===`pnpm`||t===`bun`||t===`npm`)return t}let{invokedPath:t,execPath:n}=xQ(),r=`${t}|${n}`;return/[/\\]\.?yarn[/\\]/.test(r)?`yarn`:/[/\\]\.?pnpm[/\\]/.test(r)?`pnpm`:/[/\\]\.bun[/\\]/.test(r)||process.versions.bun!==void 0&&!SQ(n)?`bun`:`npm`}function OPe(){let{execPath:e,invokedPath:t}=xQ();return CQ(t)||CQ(e)?!1:SQ(e)||SQ(t)}function EQ(){let e=`${hn.internalEnvPrefix}DEV`,t=process.env[e];if(t===`1`||t===`true`)return!0;let{invokedPath:n,execPath:r}=xQ();return!(SQ(r)||SQ(n)||CQ(n)||CQ(r)||process.env.npm_config_user_agent)}function kPe(){let{execPath:e}=xQ(),t=TQ(),n=wQ();return EQ()?{installationType:`development`,packageManager:t,isEphemeral:n,execPath:e}:OPe()?{installationType:`native`,packageManager:t,isEphemeral:n,execPath:e}:{installationType:`package-manager`,packageManager:t,isEphemeral:n,execPath:e}}function APe(){return`${process.platform===`win32`?`win32`:process.platform===`darwin`?`darwin`:`linux`}-${process.arch===`arm64`?`arm64`:`x64`}`}async function jPe(e){let t=Date.now();if(vQ&&t-vQ.timestamp<6e4)return vQ.tags;let n=await fetch(`https://registry.npmjs.org/${e}`,{signal:AbortSignal.timeout(1e4),headers:{accept:`application/json`}});if(!n.ok)throw Error(`Registry returned ${n.status}`);let r=(await n.json())[`dist-tags`]??{};return vQ={tags:r,timestamp:t},r}async function MPe(e,t,n,r){let i=t??yQ(e),a=(r??`https://apps.abacus.ai`).replace(/\/$/,``),o=new URL(`${a}/api/v0/_getCodellmCliVersion`);o.searchParams.set(`channel`,i),n&&o.searchParams.set(`platform`,n),o.searchParams.set(`cli_version`,e);let s=await fetch(o.toString(),{signal:AbortSignal.timeout(1e4)});if(s.status===204)return null;if(!s.ok)throw Error(`API returned ${s.status}`);let c=await s.json(),l=c&&`result`in c&&c.result?c.result:c??{};if(!l.version||!l.channel)throw Error(`API returned invalid payload`);return{currentVersion:e,latestVersion:l.version,tag:l.channel,packageManager:TQ(),isEphemeral:wQ(),installationType:`native`,downloadUrl:l.url}}async function NPe(e,t){let n=t??yQ(e),r=TQ(),i=wQ(),a=(await jPe(gn.publishName))[n];return!a&&n!==`latest`||!a||a===e?null:{currentVersion:e,latestVersion:a,tag:n,packageManager:r,isEphemeral:i,installationType:`package-manager`}}async function DQ(e,t,n,r){let i=kPe();if(i.installationType===`native`)try{return await MPe(e,t,APe(),n)}catch{return null}return i.installationType===`development`&&!r?.includeDev?null:await NPe(e,t)}function OQ(e){if(e.installationType===`native`)return`${hn.binName} upgrade`;let t=`${gn.publishName}@${e.tag}`;switch(e.packageManager){case`yarn`:return`yarn global add ${t}`;case`pnpm`:return`pnpm add -g ${t}`;case`bun`:return`bun add -g ${t}`;default:return`npm install -g ${t}`}}function kQ(e){try{return{ok:!0,output:le(OQ(e),{stdio:`pipe`,encoding:`utf-8`}).trim()}}catch(e){return{ok:!1,output:e instanceof Error&&`stderr`in e?String(e.stderr).trim():e instanceof Error?e.message:`Unknown error`}}}function PPe(){let e=N.join(t.homedir(),hn.configDirName,`bin`);try{let n=N.dirname(bQ(process.execPath));return!n||n.toLowerCase().startsWith(t.tmpdir().toLowerCase())?e:n}catch{return e}}async function AQ(e){if(!e.downloadUrl)return{ok:!1,output:`No download URL`};let n=N.join(t.tmpdir(),`abacusai-update-${Date.now()}`),r=process.platform===`win32`,i=r?`${hn.binName}.exe`:hn.binName,a=PPe();try{await we.mkdir(n,{recursive:!0}),await we.mkdir(a,{recursive:!0});let t=N.join(n,r?`update.zip`:`update.tar.gz`),o=await fetch(e.downloadUrl);if(!o.ok)throw Error(`Download failed: ${o.status}`);let s=Buffer.from(await o.arrayBuffer());await we.writeFile(t,s),le(r?`powershell -Command "Expand-Archive -Path '${t}' -DestinationPath '${n}' -Force"`:`tar -xzf "${t}" -C "${n}"`,{stdio:`pipe`});let c=N.join(n,i),l=N.join(a,i);if(r){let e=`${l}.old`;await we.rm(e,{force:!0}).catch(()=>{}),await we.rename(l,e).catch(()=>{}),await we.copyFile(c,l),await we.rm(e,{force:!0}).catch(()=>{})}else await we.copyFile(c,l),await we.chmod(l,493);return{ok:!0,output:`Updated to ${e.latestVersion}`}}catch(e){return{ok:!1,output:e instanceof Error?e.message:`Unknown error`}}finally{await we.rm(n,{recursive:!0,force:!0}).catch(()=>{})}}function FPe(e,t){let n=e=>{let n=e.toLowerCase();if(n===t)return 1e3;if(n.startsWith(t))return 900;let r=0,i=-1;for(let e of t){let t=n.indexOf(e,i+1);if(t===-1)return 0;r+=100-(t-i),i=t}return r+=Math.max(0,50-n.length),r},r=null,i=0;for(let t of e){let e=Math.max(n(t.name??``),n(t.llmName));e>i&&(i=e,r=t.llmName)}return i>=100?r:null}async function jQ(e,t,n=nt.CLI){let r=(await e.listLLMModels({coworkV2:n===nt.COWORK}))?.result??[];return r.length||(process.stderr.write(`Error: No models available.
75182
75182
  `),process.exit(1)),t?FPe(r,t.toLowerCase())||(process.stderr.write(`Warning: Model "${t}" not found. Using default: ${r[0].llmName}\n`),r[0].llmName):r[0].llmName}const MQ=dt([`codellm`,`cli`,`exit`]),NQ=new Set,PQ=new Set,FQ=new Set;let IQ=!1,LQ=!1,RQ=null,zQ;async function IPe(e){let t=e.map(e=>new Promise(t=>{let n=`writableLength`in e?e.writableLength:0;if((`bufferSize`in e?e.bufferSize:n)===0){t();return}let r=e.write.bind(e),i=!1,a=()=>{let n=`writableLength`in e?e.writableLength:0;(`bufferSize`in e?e.bufferSize:n)===0&&!i&&(i=!0,e.write=r,t())};e.once(`drain`,a),e.write(``,`utf-8`,()=>{a()}),e.write=function(){return!1}}));await Promise.all(t)}async function BQ(e,t,n,r){if(IQ)return;r?.debug?.(`Executing exit handlers`,{shouldManuallyExit:e,isSynchronous:t,signal:n,asyncCallbacks:NQ.size,syncCallbacks:PQ.size}),IQ=!0,NQ.size>0&&t&&MQ.error`SYNCHRONOUS TERMINATION NOTICE: When explicitly exiting the process via process.exit or via a parent process, asynchronous tasks in your exitHooks will not run. Either remove these tasks, use gracefulExit() instead of process.exit(), or ensure your parent process sends a SIGINT to the process running this code.`;let i=0;n>0?i=128+n:zQ===void 0?(typeof H.exitCode==`number`||typeof H.exitCode==`string`)&&(i=Number(H.exitCode)):i=zQ;let a=(t=!1)=>{(t||e)&&(RQ?RQ.call(H,i):H.exit(i))};for(let e of PQ)try{e(i)}catch(e){MQ.error`Error in synchronous exit hook: ${e}`}if(t){a();return}let o=[],s=0;for(let[e,t]of NQ)s=Math.max(s,t),o.push(Promise.resolve(e(i)).catch(e=>{MQ.error`Error in asynchronous exit hook: ${e}`}));let c=Array.from(FQ);c.length>0&&o.push(IPe(c));let l=setTimeout(()=>{a(!0)},s);try{await Promise.all(o),clearTimeout(l),a()}catch(e){clearTimeout(l),MQ.error`Error during exit cleanup: ${e}`,a(!0)}}function LPe(){LQ||(LQ=!0,H.once(`beforeExit`,()=>{BQ(!0,!1,-128)}),H.once(`SIGINT`,()=>{BQ(!0,!1,2)}),H.once(`SIGTERM`,()=>{BQ(!0,!1,15)}),H.once(`exit`,()=>{BQ(!1,!0,0)}),H.on(`message`,e=>{e===`shutdown`&&BQ(!0,!0,-128)}),RQ||(RQ=H.exit.bind(H),H.exit=function(e){if(zQ===void 0&&(zQ=e??0),NQ.size===0&&FQ.size===0){if(RQ){RQ(e??0);return}H.exit(e??0)}BQ(!0,!1,-128).catch(e=>{MQ.error`Error during exit: ${e}`,RQ?RQ(1):H.exit(1)})}))}function VQ(e,t){if(typeof e!=`function`)throw TypeError(`callback must be a function`);if(IQ)throw Error(`Cannot install exit hook while exit handlers are running`);t?.logger?.debug?.(`Registering exit hook`,{wait:t?.wait,hasStreams:t?.streams!==void 0}),LPe();let n=t?.wait??0,r=t?.streams??[H.stdout,H.stderr];if(n>0){let t=[e,n];NQ.add(t);for(let e of r)FQ.add(e);return()=>{NQ.delete(t);for(let e of r)FQ.delete(e)}}return PQ.add(e),()=>{PQ.delete(e)}}function HQ(e){e!==void 0&&(H.exitCode=e),BQ(!0,!1,-128)}function UQ(e){process.stdout.write(JSON.stringify(e)+`
75183
75183
  `)}function RPe(e){try{return JSON.parse(e)}catch{return null}}async function zPe({agentArgs:e}){hu(`ndjson IPC host started`,`cli`);let t=await SY.create(),n=new Ou(t,Sn(),gn.userAgentNames.desktop,_Q.default.version);if(!t.isAuthenticated())try{(await n.getUserInfo())?.result?.email||(process.stderr.write(`Error: Not authenticated. Set ABACUS_DEVICE_CODE environment variable.
75184
75184
  `),process.exit(1))}catch{process.stderr.write(`Error: Not authenticated. Set ABACUS_DEVICE_CODE environment variable.
75185
75185
  `),process.exit(1)}let r=process.cwd(),i=new rJ({cwd:r,extraSources:[{read:async()=>({client:nt.CLI})}]});await i.load();let a=i.get(`baseUrl`);if(a){try{new URL(a)}catch{process.stderr.write(`Invalid baseUrl: ${a}\n`),process.exit(1)}n.setUrl(a),n.resetEndpoints(),await n.getApiEndpoint()}let o=await jQ(n,e?.model,i.get(`client`)),s=new Map,c=0,l=new eJ(async e=>{let t=`perm-${++c}`;return UQ({type:`permission_needed`,permissionId:t,request:e}),new Promise(e=>{s.set(t,{resolve:e})})}),u=Rd.Normal,d=e?.[`permission-mode`];if(d)switch(d){case`normal`:u=Rd.Normal;break;case`accept-edits`:u=Rd.AcceptEdits;break;case`plan`:u=Rd.PlanMode;break;case`yolo`:u=Rd.Yolo;break}let f=new $q({allowedDirectories:[r,...e?.[`add-dir`]?.map(e=>P.isAbsolute(e)?e:P.resolve(r,e))??[]],primaryWorkspace:r,apiClient:n,mode:u,model:o,permissionProvider:l,config:i,isPrintMode:!1,enablePromptRewrite:!1,supportsThoughtStreaming:!0,enableSkills:!0,cliAllowedTools:e?.[`allowed-tools`],cliDisallowedTools:e?.[`disallowed-tools`]});f.onAutoRestart=e=>{WQ(f,e)},VQ(async()=>{f.stop(),await new Promise(e=>setTimeout(e,200))},{wait:1e3}),UQ({type:`ready`,model:o,mode:u});let p=Jq.loadSkills(r).then(()=>{UQ({type:`skills_loaded`,skills:Jq.getAllMetadata()})}).catch(e=>{fu(e),process.stderr.write(`Failed to load skills: ${e}\n`)}),m=i.get(`autoUpdate`)!==!1;EQ()||DQ(_Q.default.version,i.get(`updateChannel`),i.get(`baseUrl`)).then(async e=>{if(!e||(UQ({type:`update_available`,currentVersion:e.currentVersion,latestVersion:e.latestVersion}),!m))return;UQ({type:`update_downloading`,latestVersion:e.latestVersion});let t=e.installationType===`native`?await AQ(e):kQ(e);t.ok?UQ({type:`update_complete`,latestVersion:e.latestVersion}):UQ({type:`update_failed`,latestVersion:e.latestVersion,error:t.output||`Update failed`})}).catch(e=>{fu(e)});let h=B.createInterface({input:process.stdin});h.on(`line`,async e=>{let t=e.trim();if(!t)return;let r=RPe(t);if(r)switch(r.type){case`send`:{let e=r.message??``,t=r.conversationId,n=Array.isArray(r.activeSkills)?r.activeSkills:void 0;t&&f.getConversationId()!==t&&await f.switchConversation(t),WQ(f,e,n);break}case`stop`:f.stop();break;case`list_skills`:p.then(()=>{UQ({type:`skills_loaded`,skills:Jq.getAllMetadata()})});break;case`switch_conversation`:{let e=r.conversationId;e&&(f.switchConversation(e),UQ({type:`event`,event:{type:`status_changed`,status:`idle`}}));break}case`reset_conversation`:f.resetConversation(),UQ({type:`event`,event:{type:`status_changed`,status:`idle`}});break;case`set_mode`:{let e=BPe(r.mode??`DEFAULT`);f.setMode(e);break}case`set_model`:{let e=r.model;if(e){let t=await jQ(n,e,i.get(`client`));f.setModel(t),UQ({type:`event`,event:{type:`model_changed`,model:t}})}break}case`set_folder`:{let e=r.folder;e&&f.setWorkspace(e);break}case`enqueue`:{let e=r.message??``,t=r.hidden??!1;f.nq(e,{hidden:t}),UQ({type:`queue_updated`,messages:f.getQueueEntries()});break}case`dequeue`:{let e=r.includeHidden??!1,t=r.id,n=f.dq({includeHidden:e,...t?{id:t}:{}});UQ({type:`queue_updated`,messages:f.getQueueEntries(),dequeued:n.map(e=>e.message)});break}case`get_queue`:{let e=r.includeHidden??!1;UQ({type:`queue_updated`,messages:f.getQueueEntries({includeHidden:e})});break}case`clear_queue`:{let e=r.includeHidden??!1;f.clearQueue({includeHidden:e}),UQ({type:`queue_updated`,messages:f.getQueueEntries()});break}case`remove_from_queue`:{let e=r.id,t=r.index;if(e)f.remove(e,{includeHidden:!0});else if(typeof t==`number`){let e=f.getQueueEntries()[t];e&&f.remove(e.id)}UQ({type:`queue_updated`,messages:f.getQueueEntries()});break}case`permission_response`:{let e=r.permissionId,t=r.decision,n=s.get(e);n&&(n.resolve(t),s.delete(e));break}}}),h.on(`close`,()=>{process.exit(0)})}async function WQ(e,t,n){try{for await(let r of e.send(t,{activeSkills:n}))UQ({type:`event`,event:r})}catch(e){fu(e),UQ({type:`event`,event:{type:`error`,error:{message:e instanceof Error?e.message:String(e)}}})}}function BPe(e){switch(e){case`DEFAULT`:return Rd.Normal;case`ACCEPTEDITS`:return Rd.AcceptEdits;case`PLAN`:return Rd.PlanMode;case`YOLO`:return Rd.Yolo;default:return Rd.Normal}}const VPe=dt([`codellm`,`cli`,`print-mode`]);async function HPe(){let e=await SY.create();return{apiClient:new Ou(e,Sn(),gn.userAgentNames.print,_Q.default.version),authManager:e}}function GQ(e){process.stdout.write(JSON.stringify(e)+`
75186
- `)}async function UPe(e,t){if(e?.resume)return e.resume;if(e?.continue)try{return((await t.getConversationsList(hn.nonInteractiveAgentType))?.result??[]).sort((e,t)=>{let n=e.lastEventCreatedAt?new Date(e.lastEventCreatedAt).getTime():0;return(t.lastEventCreatedAt?new Date(t.lastEventCreatedAt).getTime():0)-n})[0]?.deploymentConversationId}catch{}return e?.conversationId}async function WPe({agentArgs:e}){hu(`print-mode started`,`cli`);let{apiClient:t,authManager:n}=await HPe(),r=process.cwd(),i=new rJ({cwd:r,extraSources:[{read:async()=>({client:nt.CLI})}]});await i.load(),EQ()||DQ(_Q.default.version,i.get(`updateChannel`),i.get(`baseUrl`)).then(e=>{if(e){let t=e.isEphemeral?`\nUpdate available: ${e.currentVersion} → ${e.latestVersion} (${e.tag})\n`:e.installationType===`native`&&i.get(`autoUpdate`)!==!1?`\nUpdate available: ${e.currentVersion} → ${e.latestVersion} (${e.tag}). Restart to auto-update.\n`:`\nUpdate available: ${e.currentVersion} → ${e.latestVersion} (${e.tag}). Run: ${OQ(e)}\n`;process.stderr.write(t)}}).catch(e=>{fu(e)});let a=i.get(`baseUrl`);if(a){try{new URL(a)}catch{VPe.error`Invalid baseUrl: ${a}`,process.exit(1)}t.setUrl(a),t.resetEndpoints(),await t.getApiEndpoint()}!n.isAuthenticated()&&!n.isEnvAuth()&&(process.stderr.write(`Not authenticated. Set ${hn.envPrefix}API_KEY environment variable or run interactively to log in.\n`),process.exit(1));let o=e?.[`output-format`]??`text`,s=await jQ(t,e?.model),c=Rd.Yolo,l=e?.[`permission-mode`];if(l)switch(l){case`normal`:c=Rd.Normal;break;case`accept-edits`:c=Rd.AcceptEdits;break;case`plan`:c=Rd.PlanMode;break;default:c=Rd.Yolo;break}let u=new $q({allowedDirectories:[r,...e?.[`add-dir`]?.map(e=>P.isAbsolute(e)?e:P.resolve(r,e))??[]],primaryWorkspace:r,apiClient:t,mode:c,model:s,permissionProvider:new mAe,config:i,isPrintMode:!0,enablePromptRewrite:!1,supportsThoughtStreaming:!0,enableSkills:!0,cliAllowedTools:e?.[`allowed-tools`],cliDisallowedTools:e?.[`disallowed-tools`]});VQ(async()=>{u.stop(),await new Promise(e=>setTimeout(e,200))},{wait:1e3});let d=await UPe(e,t);if(d)try{let e=await u.loadConversation(d);e.llmName&&(s=e.llmName,u.setModel(e.llmName))}catch(e){throw fu(e),e}let f=e?.prompt??``;process.env.DEEPAGENT_HIGH_QUALITY===`true`&&(f=`
75186
+ `)}async function UPe(e,t){if(e?.resume)return e.resume;if(e?.continue)try{return((await t.getConversationsList(hn.nonInteractiveAgentType))?.result??[]).sort((e,t)=>{let n=e.lastEventCreatedAt?new Date(e.lastEventCreatedAt).getTime():0;return(t.lastEventCreatedAt?new Date(t.lastEventCreatedAt).getTime():0)-n})[0]?.deploymentConversationId}catch{}return e?.conversationId}async function WPe({agentArgs:e}){hu(`print-mode started`,`cli`);let{apiClient:t,authManager:n}=await HPe(),r=process.cwd(),i=new rJ({cwd:r,extraSources:[{read:async()=>({client:nt.CLI})}]});await i.load(),EQ()||DQ(_Q.default.version,i.get(`updateChannel`),i.get(`baseUrl`)).then(e=>{if(e){let t=e.isEphemeral?`\nUpdate available: ${e.currentVersion} → ${e.latestVersion} (${e.tag})\n`:e.installationType===`native`&&i.get(`autoUpdate`)!==!1?`\nUpdate available: ${e.currentVersion} → ${e.latestVersion} (${e.tag}). Restart to auto-update.\n`:`\nUpdate available: ${e.currentVersion} → ${e.latestVersion} (${e.tag}). Run: ${OQ(e)}\n`;process.stderr.write(t)}}).catch(e=>{fu(e)});let a=i.get(`baseUrl`);if(a){try{new URL(a)}catch{VPe.error`Invalid baseUrl: ${a}`,process.exit(1)}t.setUrl(a),t.resetEndpoints(),await t.getApiEndpoint()}!n.isAuthenticated()&&!n.isEnvAuth()&&(process.stderr.write(`Not authenticated. Set ${hn.envPrefix}API_KEY environment variable or run interactively to log in.\n`),process.exit(1));let o=e?.[`output-format`]??`text`,s=await jQ(t,e?.model,i.get(`client`)),c=Rd.Yolo,l=e?.[`permission-mode`];if(l)switch(l){case`normal`:c=Rd.Normal;break;case`accept-edits`:c=Rd.AcceptEdits;break;case`plan`:c=Rd.PlanMode;break;default:c=Rd.Yolo;break}let u=new $q({allowedDirectories:[r,...e?.[`add-dir`]?.map(e=>P.isAbsolute(e)?e:P.resolve(r,e))??[]],primaryWorkspace:r,apiClient:t,mode:c,model:s,permissionProvider:new mAe,config:i,isPrintMode:!0,enablePromptRewrite:!1,supportsThoughtStreaming:!0,enableSkills:!0,cliAllowedTools:e?.[`allowed-tools`],cliDisallowedTools:e?.[`disallowed-tools`]});VQ(async()=>{u.stop(),await new Promise(e=>setTimeout(e,200))},{wait:1e3});let d=await UPe(e,t);if(d)try{let e=await u.loadConversation(d);e.llmName&&(s=e.llmName,u.setModel(e.llmName))}catch(e){throw fu(e),e}let f=e?.prompt??``;process.env.DEEPAGENT_HIGH_QUALITY===`true`&&(f=`
75187
75187
  IMPORTANT INSTRUCTIONS: Your task is to follow the <task_description> EXACTLY and verify the solution within the FIXED TIME LIMIT.
75188
75188
  A few things to keep in mind (Add Relevant ONES BELOW AS TODOS):
75189
75189
  1. You are in a docker container without user interaction and fixed time limit. Assume HIGHEST permissions are available to the user.
@@ -75281,7 +75281,7 @@ https://github.com/highlightjs/highlight.js/issues/2277`),a=e,i=t);let o={code:i
75281
75281
  `,`utf8`)}function S3(e){let t=[],n=0;for(let r=0;r<e.length;r++)if(e[r]===10){let i=e.subarray(n,r).toString(`utf8`).trim();i&&t.push(i),n=r+1}return[t,e.subarray(n)]}function XUe(e,t){let n=RUe(t,{});try{p.existsSync(e)&&p.unlinkSync(e)}catch{}let r=V.createServer(e=>{let t=new JUe(t=>{!e.destroyed&&e.writable&&e.write(x3(t))}),r=Buffer.alloc(0);e.on(`data`,async e=>{r=Buffer.concat([r,e]);let[i,a]=S3(r);r=a;for(let e of i)try{await t.message(e,n)}catch(e){fu(e,{context:`rpc-deserialization`})}}),e.on(`close`,()=>{t.close()}),e.on(`error`,n=>{fu(n,{context:`socket-server`}),e.destroy(),t.close()})});return new Promise((t,n)=>{r.on(`error`,e=>{fu(e,{context:`socket-server`}),n(e)}),r.listen(e,()=>{r.removeListener(`error`,n),r.on(`error`,e=>{fu(e,{context:`socket-server`})});try{p.chmodSync(e,438)}catch{}t({getSocketPath:()=>e,dispose:()=>{r.close();try{p.existsSync(e)&&p.unlinkSync(e)}catch{}}})})})}var ZUe=class{peer;constructor(e){this.peer=e}async call(e){let t=await this.peer.request(e);return{...t,body:()=>Promise.resolve(t.body)}}},QUe=class extends MUe{constructor(e){super(new ZUe(e),{url:`orpc:/`})}};function $Ue(e,t){let n=t?.timeoutMs??2e3;return new Promise((t,r)=>{let i=V.connect(e),a=setTimeout(()=>{i.destroy(),r(Error(`Connection to ${e} timed out after ${n}ms`))},n);i.on(`connect`,()=>{clearTimeout(a);let e=new KUe(e=>{!i.destroyed&&i.writable&&i.write(x3(e))}),n=Buffer.alloc(0);i.on(`data`,async t=>{n=Buffer.concat([n,t]);let[r,i]=S3(n);n=i;for(let t of r)try{await e.message(t)}catch(e){fu(e,{context:`rpc-deserialization`})}}),i.on(`close`,()=>e.close()),i.on(`error`,t=>{fu(t,{context:`socket-client`}),i.destroy(),e.close()}),t({link:new QUe(e),dispose:()=>{e.close(),i.destroy()}})}),i.on(`error`,e=>{clearTimeout(a),fu(e,{context:`socket-connect`}),r(e)})})}const C3=Symbol(`ORPC_LAZY_SYMBOL`);function w3(e,t={}){return{[C3]:{loader:e,meta:t}}}function T3(e){return(typeof e==`object`||typeof e==`function`)&&e!==null&&C3 in e}function E3(e){return e[C3].meta}function D3(e){return T3(e)?e[C3].loader():Promise.resolve({default:e})}function eWe(e,t){if(t.length>e.length)return!1;for(let n=0;n<e.length;n++){if(t[n]===void 0)return!0;if(e[n]!==t[n])return!1}return!0}function tWe(e,t,n){return n.dedupeLeading&&eWe(t,e)?t:[...e,...t]}function O3(e,t){return[...e,t]}var k3=class{"~orpc";constructor(e){this[`~orpc`]=e}};function A3(e){return e instanceof k3?!0:e3(e)&&`middlewares`in e[`~orpc`]&&`inputValidationIndex`in e[`~orpc`]&&`outputValidationIndex`in e[`~orpc`]&&`handler`in e[`~orpc`]}function nWe(e,t){return{...e,...t}}function rWe(e){return new Proxy(e,{get(t,n){return typeof n==`string`?(...t)=>{let r=f4(t),i=e[n];return new I4(n,{defined:!!i,status:i?.status,message:r.message??i?.message,data:r.data,cause:r.cause})}:Reflect.get(t,n)}})}function iWe(e){return{output:e,context:{}}}function j3(e,...t){let n=f4(t);return async(...[t,r])=>{let i=p4(n.path),{default:a}=await D3(e),o=r?.context??{},s=await A4(n.context??{},o),c=rWe(a[`~orpc`].errorMap),l=async e=>e instanceof I4?await TUe(a[`~orpc`].errorMap,e):e;try{let e=await y4({name:`call_procedure`,signal:r?.signal},e=>(e?.setAttribute(`procedure.path`,[...i]),T4(p4(n.interceptors),{context:s,input:t,errors:c,path:i,procedure:a,signal:r?.signal,lastEventId:r?.lastEventId},e=>sWe(e.procedure,e))));return S4(e)?e instanceof K4?e:hUe(e,Y4(w4({name:`consume_event_iterator_output`,signal:r?.signal},e),{value:e=>e,error:e=>l(e)})):e}catch(e){throw await l(e)}}}async function aWe(e,t){let n=e[`~orpc`].inputSchema;return n?y4({name:`validate_input`},async()=>{let e=await n[`~standard`].validate(t);if(e.issues)throw new I4(`BAD_REQUEST`,{message:`Input validation failed`,data:{issues:e.issues},cause:new Z4({message:`Input validation failed`,issues:e.issues,data:t})});return e.value}):t}async function oWe(e,t){let n=e[`~orpc`].outputSchema;return n?y4({name:`validate_output`},async()=>{let e=await n[`~standard`].validate(t);if(e.issues)throw new I4(`INTERNAL_SERVER_ERROR`,{message:`Output validation failed`,cause:new Z4({message:`Output validation failed`,issues:e.issues,data:t})});return e.value}):t}async function sWe(e,t){let n=e[`~orpc`].middlewares,r=Math.min(Math.max(0,e[`~orpc`].inputValidationIndex),n.length),i=Math.min(Math.max(0,e[`~orpc`].outputValidationIndex),n.length),a=async(o,s,c)=>{let l=c;o===r&&(l=await aWe(e,l));let u=n[o],d=u?await y4({name:`middleware.${u.name}`,signal:t.signal},async e=>(e?.setAttribute(`middleware.index`,o),e?.setAttribute(`middleware.name`,u.name),(await u({...t,context:s,next:async(...[e])=>{let t=e?.context??{};return{output:await a(o+1,nWe(s,t),l),context:t}}},l,iWe)).output)):await y4({name:`handler`,signal:t.signal},()=>e[`~orpc`].handler({...t,context:s,input:l}));return o===i?await oWe(e,d):d};return a(0,t.context,t.input)}const M3=Symbol(`ORPC_HIDDEN_ROUTER_CONTRACT`);function N3(e,t){return new Proxy(e,{get(e,n){return n===M3?t:Reflect.get(e,n)}})}function cWe(e){return e[M3]}function P3(e,t){let n=e;for(let e=0;e<t.length;e++){let r=t[e];if(!n||A3(n))return;if(!T3(n)){n=n[r];continue}let i=n,a=t.slice(e);return w3(async()=>D3(P3((await D3(i)).default,a)),E3(i))}return n}function F3(e){return new Proxy(e,{get(t,n){return typeof n==`string`?F3(P3(e,[n])):Reflect.get(t,n)}})}function I3(e,t){if(T3(e)){let n=E3(e),r=n?.prefix?s3(t.prefix,n?.prefix):t.prefix;return F3(w3(async()=>{let{default:n}=await D3(e);return D3(I3(n,t))},{...n,prefix:r}))}if(A3(e)){let n=tWe(t.middlewares,e[`~orpc`].middlewares,{dedupeLeading:t.dedupeLeadingMiddlewares}),r=n.length-e[`~orpc`].middlewares.length;return new k3({...e[`~orpc`],route:l3(e[`~orpc`].route,t),errorMap:Q4(t.errorMap,e[`~orpc`].errorMap),middlewares:n,inputValidationIndex:e[`~orpc`].inputValidationIndex+r,outputValidationIndex:e[`~orpc`].outputValidationIndex+r})}let n={};for(let r in e)n[r]=I3(e[r],t);return n}function L3(e,t,n=[]){let r=e.router,i=cWe(e.router);if(i!==void 0&&(r=i),T3(r))n.push({router:r,path:e.path});else if(e3(r))t({contract:r,path:e.path});else for(let i in r)L3({router:r[i],path:[...e.path,i]},t,n);return n}function lWe(e,t){return new k3({...e[`~orpc`],errorMap:t[`~orpc`].errorMap,route:t[`~orpc`].route,meta:t[`~orpc`].meta})}const uWe={initialInputValidationIndex:0,initialOutputValidationIndex:0,dedupeLeadingMiddlewares:!0};function R3(e,t){return t===void 0?uWe[e]:t}function z3(e){let t=((...t)=>e(...t));return t.mapInput=t=>z3((n,r,...i)=>e(n,t(r),...i)),t.concat=(t,n)=>{let r=n?z3(t).mapInput(n):t;return z3((t,n,i,...a)=>e({...t,next:(...[e])=>r({...t,context:{...t.context,...e?.context},next:(...[n])=>t.next({context:{...e?.context,...n?.context}})},n,i,...a)},n,i,...a))},t}function dWe(e){return async t=>{try{return[null,await e(t)]}catch(e){if(e instanceof Error&&`digest`in e&&typeof e.digest==`string`&&e.digest.startsWith(`NEXT_`)||e instanceof Response&&`options`in e&&D4(e.options)||D4(e)&&e.isNotFound===!0)throw e;return[L4(e).toJSON(),void 0]}}}var fWe=class e extends k3{errors(t){return new e({...this[`~orpc`],errorMap:Q4(this[`~orpc`].errorMap,t)})}meta(t){return new e({...this[`~orpc`],meta:a3(this[`~orpc`].meta,t)})}route(t){return new e({...this[`~orpc`],route:o3(this[`~orpc`].route,t)})}use(t,n){let r=n?z3(t).mapInput(n):t;return new e({...this[`~orpc`],middlewares:O3(this[`~orpc`].middlewares,r)})}callable(...e){let t=j3(this,...e);return new Proxy(t,{get:(e,t)=>Reflect.has(this,t)?Reflect.get(this,t):Reflect.get(e,t),has:(e,t)=>Reflect.has(this,t)||Reflect.has(e,t)})}actionable(...e){let t=dWe(j3(this,...e));return new Proxy(t,{get:(e,t)=>Reflect.has(this,t)?Reflect.get(this,t):Reflect.get(e,t),has:(e,t)=>Reflect.has(this,t)||Reflect.has(e,t)})}},B3=class e{"~orpc";constructor(e){this[`~orpc`]=e}$config(t){let n=this[`~orpc`].inputValidationIndex-R3(`initialInputValidationIndex`,this[`~orpc`].config.initialInputValidationIndex),r=this[`~orpc`].outputValidationIndex-R3(`initialOutputValidationIndex`,this[`~orpc`].config.initialOutputValidationIndex);return new e({...this[`~orpc`],config:t,dedupeLeadingMiddlewares:R3(`dedupeLeadingMiddlewares`,t.dedupeLeadingMiddlewares),inputValidationIndex:R3(`initialInputValidationIndex`,t.initialInputValidationIndex)+n,outputValidationIndex:R3(`initialOutputValidationIndex`,t.initialOutputValidationIndex)+r})}$context(){return new e({...this[`~orpc`],middlewares:[],inputValidationIndex:R3(`initialInputValidationIndex`,this[`~orpc`].config.initialInputValidationIndex),outputValidationIndex:R3(`initialOutputValidationIndex`,this[`~orpc`].config.initialOutputValidationIndex)})}$meta(t){return new e({...this[`~orpc`],meta:t})}$route(t){return new e({...this[`~orpc`],route:t})}$input(t){return new e({...this[`~orpc`],inputSchema:t})}middleware(e){return z3(e)}errors(t){return new e({...this[`~orpc`],errorMap:Q4(this[`~orpc`].errorMap,t)})}use(t,n){let r=n?z3(t).mapInput(n):t;return new e({...this[`~orpc`],middlewares:O3(this[`~orpc`].middlewares,r)})}meta(t){return new e({...this[`~orpc`],meta:a3(this[`~orpc`].meta,t)})}route(t){return new e({...this[`~orpc`],route:o3(this[`~orpc`].route,t)})}input(t){return new e({...this[`~orpc`],inputSchema:t,inputValidationIndex:R3(`initialInputValidationIndex`,this[`~orpc`].config.initialInputValidationIndex)+this[`~orpc`].middlewares.length})}output(t){return new e({...this[`~orpc`],outputSchema:t,outputValidationIndex:R3(`initialOutputValidationIndex`,this[`~orpc`].config.initialOutputValidationIndex)+this[`~orpc`].middlewares.length})}handler(e){return new fWe({...this[`~orpc`],handler:e})}prefix(t){return new e({...this[`~orpc`],prefix:s3(this[`~orpc`].prefix,t)})}tag(...t){return new e({...this[`~orpc`],tags:c3(this[`~orpc`].tags,t)})}router(e){return I3(e,this[`~orpc`])}lazy(e){return I3(w3(e),this[`~orpc`])}};new B3({config:{},route:{},meta:{},errorMap:{},inputValidationIndex:R3(`initialInputValidationIndex`),outputValidationIndex:R3(`initialOutputValidationIndex`),middlewares:[],dedupeLeadingMiddlewares:!0});function V3(e,t,n){return e3(e)?new B3({...e[`~orpc`],config:t,middlewares:n,inputValidationIndex:R3(`initialInputValidationIndex`,t?.initialInputValidationIndex)+n.length,outputValidationIndex:R3(`initialOutputValidationIndex`,t?.initialOutputValidationIndex)+n.length,dedupeLeadingMiddlewares:R3(`dedupeLeadingMiddlewares`,t.dedupeLeadingMiddlewares)}):new Proxy(e,{get:(r,i)=>{if(typeof i!=`string`)return Reflect.get(r,i);let a;i===`middleware`?a=e=>z3(e):i===`use`?a=r=>V3(e,t,O3(n,r)):i===`router`?a=r=>N3(I3(r,{middlewares:n,errorMap:{},prefix:void 0,tags:void 0,dedupeLeadingMiddlewares:R3(`dedupeLeadingMiddlewares`,t.dedupeLeadingMiddlewares)}),e):i===`lazy`&&(a=r=>N3(I3(w3(r),{middlewares:n,errorMap:{},prefix:void 0,tags:void 0,dedupeLeadingMiddlewares:R3(`dedupeLeadingMiddlewares`,t.dedupeLeadingMiddlewares)}),e));let o=FUe(r,[i]);if(!o)return a??o;let s=V3(o,t,n);return a?new Proxy(a,{get(e,t){return Reflect.get(s,t)}}):s}})}function H3(e,t={}){let n=V3(e,t,[]),r=new Proxy(n,{get:(t,n)=>{let i;n===`$context`?i=()=>r:n===`$config`&&(i=t=>H3(e,t));let a=Reflect.get(t,n);return!i||!a||typeof a!=`function`&&typeof a!=`object`?i||a:new Proxy(i,{get(e,t){return Reflect.get(a,t)}})}});return r}var pWe=class{plugins;constructor(e=[]){this.plugins=[...e].sort((e,t)=>(e.order??0)-(t.order??0))}init(e,t){for(let n of this.plugins)n.init?.(e,t)}},mWe=class{constructor(e,t,n,r){this.matcher=t,this.codec=n,new pWe(r.plugins).init(r,e),this.interceptors=p4(r.interceptors),this.clientInterceptors=p4(r.clientInterceptors),this.rootInterceptors=p4(r.rootInterceptors),this.matcher.init(e)}interceptors;clientInterceptors;rootInterceptors;async handle(e,t){let n=t.prefix?.replace(/\/$/,``)||void 0;return n&&!e.url.pathname.startsWith(`${n}/`)&&e.url.pathname!==n?{matched:!1,response:void 0}:T4(this.rootInterceptors,{...t,request:e,prefix:n},async t=>y4({name:`${e.method} ${e.url.pathname}`},async e=>{let n;try{return await T4(this.interceptors,t,async({request:t,context:r,prefix:i})=>{let a=t.method,o=t.url,s=i?o.pathname.replace(i,``):o.pathname,c=await y4({name:`find_procedure`},()=>this.matcher.match(a,`/${s.replace(/^\/|\/$/g,``)}`));if(!c)return{matched:!1,response:void 0};e?.updateName(`${m4}.${c.path.join(`/`)}`),e?.setAttribute(`rpc.system`,m4),e?.setAttribute(`rpc.method`,c.path.join(`.`)),n=`decode_input`;let l=await y4({name:`decode_input`},()=>this.codec.decode(t,c.params,c.procedure));n=void 0,S4(l)&&(l=w4({name:`consume_event_iterator_input`,signal:t.signal},l));let u=j3(c.procedure,{context:r,path:c.path,interceptors:this.clientInterceptors});n=`call_procedure`;let d=await u(l,{signal:t.signal,lastEventId:q4(t.headers[`last-event-id`])});return n=void 0,{matched:!0,response:this.codec.encode(d,c.procedure)}})}catch(t){n!==`call_procedure`&&v4(e,t);let r=n===`decode_input`&&!(t instanceof I4)?new I4(`BAD_REQUEST`,{message:`Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,cause:t}):L4(t);return{matched:!0,response:this.codec.encodeError(r)}}}))}},hWe=class{constructor(e){this.serializer=e}async decode(e,t,n){let r=e.method===`GET`?uUe(e.url.searchParams.getAll(`data`).at(-1)):await e.body();return this.serializer.deserialize(r)}encode(e,t){return{status:200,headers:{},body:this.serializer.serialize(e)}}encodeError(e){return{status:e.status,headers:{},body:this.serializer.serialize(e.toJSON())}}},gWe=class{filter;tree=new fUe;pendingRouters=[];constructor(e={}){this.filter=e.filter??!0}init(e,t=[]){let n=L3({router:e,path:t},t=>{if(!A4(this.filter,t))return;let{path:n,contract:r}=t,i=r3(n);A3(r)?this.tree[i]={path:n,contract:r,procedure:r,router:e}:this.tree[i]={path:n,contract:r,procedure:void 0,router:e}});this.pendingRouters.push(...n.map(e=>({...e,httpPathPrefix:r3(e.path)})))}async match(e,t){if(this.pendingRouters.length){let e=[];for(let n of this.pendingRouters)if(t.startsWith(n.httpPathPrefix)){let{default:e}=await D3(n.router);this.init(e,n.path)}else e.push(n);this.pendingRouters=e}let n=this.tree[t];if(n){if(!n.procedure){let{default:e}=await D3(P3(n.router,n.path));if(!A3(e))throw Error(`
75282
75282
  [Contract-First] Missing or invalid implementation for procedure at path: ${r3(n.path)}.
75283
75283
  Ensure that the procedure is correctly defined and matches the expected contract.
75284
- `);n.procedure=lWe(e,n.contract)}return{path:n.path,procedure:n.procedure}}}},_We=class extends mWe{constructor(e,t={}){let n=new i3(new n3(t)),r=new gWe(t),i=new hWe(n);super(e,r,i,t)}},vWe=class{socketServer;socketPath;editorState={file:void 0,startLine:void 0,endLine:void 0};onEditorStateCallback=null;pendingDecisions=new Map;constructor(){let e=N.join(t.homedir(),hn.configDirName,`cli`);this.socketPath=N.join(e,`${process.pid}.sock`)}getEditorState(){return{...this.editorState}}onEditorChange(e){this.onEditorStateCallback=e}waitForDecision(e,t){return new Promise((n,r)=>{if(t?.aborted){r(Error(`Aborted`));return}let i=()=>{t?.removeEventListener(`abort`,a),this.pendingDecisions.delete(e)},a=()=>{i(),r(Error(`Aborted`))};t?.addEventListener(`abort`,a,{once:!0}),this.pendingDecisions.set(e,{resolve:e=>{i(),n(e)},cleanup:i})})}async start(){let e=N.dirname(this.socketPath);p.existsSync(e)||p.mkdirSync(e,{recursive:!0});let t=H3(IUe),n=t.router({editorStateChanged:t.editorStateChanged.handler(async({input:e})=>(this.editorState={file:e.file??void 0,startLine:e.startLine,endLine:e.endLine},this.onEditorStateCallback?.(this.editorState),{ok:!0})),toolDecision:t.toolDecision.handler(async({input:e})=>{let t=this.pendingDecisions.get(e.toolId);return t&&t.resolve(e.decision),{ok:!0}})});this.socketServer=await XUe(this.socketPath,new _We(n))}dispose(){for(let[,e]of this.pendingDecisions)e.cleanup();this.pendingDecisions.clear(),this.socketServer?.dispose(),this.socketServer=void 0}},yWe=class{client=null;disposeSocket=null;currentFile=void 0;selectionStartLine=void 0;selectionEndLine=void 0;onFileChangeCallback=null;constructor(e){this.pushServer=e}findSocketPath(){let e=process.env[hn.socketEnvVar];if(e&&m.existsSync(e))return e;try{let e=P.join(n.homedir(),hn.configDirName,hn.ideDirName),t=m.readdirSync(e).filter(e=>e.endsWith(`.sock`)).map(t=>P.join(e,t)).filter(e=>m.existsSync(e));if(t.length===1)return t[0]}catch{}return null}async connect(){try{let e=this.findSocketPath();if(!e)return!1;let t=await $Ue(e,{timeoutMs:2e3});this.client=X4(t.link),this.disposeSocket=()=>t.dispose(),await this.client.register({cliSocketPath:this.pushServer.socketPath,pid:process.pid});let n=this.pushServer.getEditorState();return this.currentFile=n.file,this.selectionStartLine=n.startLine,this.selectionEndLine=n.endLine,this.pushServer.onEditorChange(e=>{this.currentFile=e.file,this.selectionStartLine=e.startLine,this.selectionEndLine=e.endLine,this.onFileChangeCallback?.(e.file,e.startLine,e.endLine)}),!0}catch{return!1}}getCurrentFile(){return this.currentFile}getSelectionRange(){return{startLine:this.selectionStartLine,endLine:this.selectionEndLine}}isConnected(){return this.client!==null}onFileChange(e){this.onFileChangeCallback=e}async showDiff(e){if(!this.client)return!1;try{return(await this.client.showDiff({...e,cliSocketPath:this.pushServer.socketPath})).success}catch{return!1}}async showToolView(e){if(!this.client)return!1;try{return(await this.client.showToolView({...e,cliSocketPath:this.pushServer.socketPath})).success}catch{return!1}}async notifyDiffDecision(e){if(!this.client)throw Error(`Not connected to extension`);await this.client.notifyDiffDecision(e)}async openPlanFile(e){if(!this.client)throw Error(`Not connected to extension`);return{opened:(await this.client.openFile({file:e})).success}}async getDiagnostics(e){if(!this.client)throw Error(`Not connected to extension`);return this.client.getDiagnostics({...e&&{files:e}})}dispose(){this.disposeSocket?.(),this.disposeSocket=null,this.client=null,this.currentFile=void 0,this.selectionStartLine=void 0,this.selectionEndLine=void 0,this.onFileChangeCallback=null}};const U3=(0,X.createContext)(null);function W3(){let e=(0,X.use)(U3);if(!e)throw Error(`useExtensionFile must be used within ExtensionFileProvider`);return e}function bWe(e){let t=(0,cQ.c)(11),{children:n,initialFile:r}=e,[i,a]=(0,X.useState)(r),[o,s]=(0,X.useState)(void 0),[c,l]=(0,X.useState)(void 0),[u,d]=(0,X.useState)(null),[f,p]=(0,X.useState)(null),m=(0,X.useRef)(null),h=(0,X.useRef)(null),g,_;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>{let e=!1;return(async()=>{let t=new vWe;try{await t.start()}catch{}if(e){t.dispose();return}h.current=t,p(t),t.onEditorChange(e=>{a(e.file),s(e.startLine),l(e.endLine)});for(let n of[0,...[500,1e3,2e3,3e3,4e3]]){if(e||(n>0&&await new Promise(e=>setTimeout(e,n)),e))return;try{let n=new yWe(t);if(await n.connect()){if(e){n.dispose();return}let r=t.getEditorState();a(r.file),s(r.startLine),l(r.endLine),n.onFileChange((e,t,n)=>{a(e),s(t),l(n)}),m.current=n,d(n);return}}catch{}}})(),()=>{e=!0,m.current&&(m.current.dispose(),m.current=null,d(null)),h.current&&(h.current.dispose(),h.current=null,p(null))}},_=[],t[0]=g,t[1]=_):(g=t[0],_=t[1]),(0,X.useEffect)(g,_);let v;t[2]!==u||t[3]!==i||t[4]!==f||t[5]!==c||t[6]!==o?(v={currentFile:i,selectionStartLine:o,selectionEndLine:c,connection:u,pushServer:f},t[2]=u,t[3]=i,t[4]=f,t[5]=c,t[6]=o,t[7]=v):v=t[7];let y;return t[8]!==n||t[9]!==v?(y=(0,Z.jsx)(U3.Provider,{value:v,children:n}),t[8]=n,t[9]=v,t[10]=y):y=t[10],y}const G3=(0,X.createContext)(null);function xWe(e){let t=(0,cQ.c)(8),{children:n}=e,[r,i]=(0,X.useState)(`idle`),a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=()=>i(`upload`),t[0]=a):a=t[0];let o=a,s;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>i(`download`),t[1]=s):s=t[1];let c=s,l;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(l=()=>i(`idle`),t[2]=l):l=t[2];let u=l,d;t[3]===r?d=t[4]:(d={activity:r,setActivity:i,startUpload:o,startDownload:c,stopActivity:u},t[3]=r,t[4]=d);let f=d,p;return t[5]!==n||t[6]!==f?(p=(0,Z.jsx)(G3.Provider,{value:f,children:n}),t[5]=n,t[6]=f,t[7]=p):p=t[7],p}function K3(){let e=(0,X.use)(G3);if(!e)throw Error(`useNetworkActivity must be used within NetworkActivityProvider`);return e}const SWe=new Set([`iterm2`,`kitty`,`wezterm`,`ghostty`]),q3=(0,X.createContext)(null),CWe=()=>{let e=(0,X.use)(q3);if(!e)throw Error(`useNotification must be used within NotificationProvider`);return e};function wWe(){if(process.platform!==`darwin`||process.env.TERM_PROGRAM!==`vscode`)return;let e=(process.env.VSCODE_GIT_IPC_HANDLE??process.env.VSCODE_IPC_HOOK_CLI??``).toLowerCase().includes(`cursor`)?`Cursor`:`Visual Studio Code`;try{return le(`osascript -e 'id of app "${e}"' 2>/dev/null`,{encoding:`utf8`,timeout:2e3}).trim()||void 0}catch{return}}const TWe=({children:e,mode:t=`full`})=>{let{isFocused:n}=fQ(),r=pQ(),i=(0,X.useRef)(n);i.current=n;let a=(0,X.useRef)(t);a.current=t;let o=(0,X.useRef)(SWe.has(gX())),s=(0,X.useRef)(wWe()),c=(0,X.useCallback)((e,t,n)=>{i.current||a.current===`off`||(a.current===`full`&&(o.current?r.notify({body:e,title:t}):EAe(t,e,n,{activateBundleId:s.current})),TAe(n))},[r]),l=(0,X.useCallback)((e,t)=>c(e,t??`Abacus AI`,`complete`),[c]),u=(0,X.useCallback)(e=>c(e,`Action Required`,`action-required`),[c]),d=(0,X.useCallback)(e=>c(e,`Task Complete`,`complete`),[c]),f=(0,X.useMemo)(()=>({notifyIfUnfocused:l,notifyActionRequired:u,notifyTaskComplete:d}),[l,u,d]);return(0,Z.jsx)(q3.Provider,{value:f,children:e})};function J3(e){return new Promise(t=>{process.platform===`darwin`?se(`open`,[e],e=>t(!e)):process.platform===`win32`?se(`explorer.exe`,[e],e=>t(!e)):se(`xdg-open`,[e],e=>t(!e))})}function Y3(e){return new Promise(t=>{let n=process.platform===`darwin`?ue(`pbcopy`):process.platform===`win32`?ue(`clip`):ue(`xclip`,[`-selection`,`clipboard`]);n.on(`error`,()=>t(!1)),n.on(`exit`,e=>t(e===0)),n.stdin?.write(e),n.stdin?.end()})}const X3=(0,X.createContext)(null),Z3=()=>{let e=(0,X.use)(X3);if(!e)throw Error(`useApiClient must be used within ApiClientProvider`);return e},Q3=(0,X.memo)(e=>{let t=(0,cQ.c)(9),{children:n,client:r,authManager:i,onAuthExpired:a}=e,[o,s]=(0,X.useState)(!1),c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=()=>s(!1),t[0]=c):c=t[0];let l=c,u;t[1]!==o||t[2]!==i||t[3]!==r||t[4]!==a?(u={apiClient:r,authManager:i,authExpired:o,setAuthExpired:s,clearAuthExpired:l,onAuthExpired:a},t[1]=o,t[2]=i,t[3]=r,t[4]=a,t[5]=u):u=t[5];let d=u,f;return t[6]!==n||t[7]!==d?(f=(0,Z.jsx)(X3.Provider,{value:d,children:n}),t[6]=n,t[7]=d,t[8]=f):f=t[8],f});Q3.displayName=`ApiClientProvider`;const $3=(0,X.createContext)(null);function e6(e,t){let n=t?new Set(t):null;return e.map(e=>{if(e.type!==`code_llm_tool_call`||e.status!==`transient`||e.toolUseResult||n&&!n.has(e.id))return e;let t=Array.isArray(e.toolUseRequest)?e.toolUseRequest[0]?.id??e.id:e.toolUseRequest?.id??e.id;return{...e,status:`completed`,isStreamingArgs:!1,toolUseResult:{id:t,content:JSON.stringify({reason:rz.INTERRUPTED}),rejected:!0}}})}function EWe(e,t){switch(t.type){case`INIT_SEND`:return[...e6(e.filter(e=>e.temp!==!0)),t.userSeg,t.spinnySeg];case`TEXT_DELTA`:{let{segId:n,content:r}=t,i=e6(e).filter(e=>!e.isSpinny);return i.find(e=>e.id===n)?i.map(e=>e.id===n?{...e,segment:(e.segment||``)+r}:e):[...i,{id:n,status:`transient`,source:`bot`,type:`text`,segment:r}]}case`THINKING_DELTA`:{let{segId:n,content:r,startTime:i}=t;return e.find(e=>e.id===n)?e.map(e=>e.id===n?{...e,segment:(e.segment||``)+r}:e):[...e,{id:n,status:`transient`,source:`bot`,type:`thinking`,isSpinny:!0,segment:r,thinkingStartTime:i}]}case`THINKING_COMPLETE`:return e.map(e=>e.id===t.segId?{...e,status:`completed`,isSpinny:!1,thinkingEndTime:t.endTime}:e);case`TOOL_DISPLAY_DATA`:return e.map(e=>e.id===t.toolCallId?{...e,toolDisplayData:{...e.toolDisplayData,...t.data}}:e);case`TOOL_REQUESTED`:{let{textSegId:n,toolSeg:r}=t,i;return i=n?e.filter(e=>!e.isSpinny).map(e=>e.id===n?{...e,status:`completed`}:e):e.filter(e=>!e.isSpinny),[...i,r]}case`TOOL_EXECUTION_COMPLETE`:{let{toolCallId:n,rawResult:r,parsedResult:i,spinnySeg:a}=t,o=e.map(e=>e.id===n?{...e,status:`completed`,toolUseResult:r,...i!==void 0&&{parsedResult:i}}:e);return a?[...o,a]:o}case`TOOL_USER_MESSAGE`:return[...e,t.seg];case`TEXT_COMPLETED`:return e.map(e=>e.id===t.segId?{...e,status:`completed`}:e);case`TURN_COMPLETE`:{let n=e6(e,t.toolCallIds);return t.textSegId&&(n=n.map(e=>e.id===t.textSegId?{...e,status:`completed`}:e)),n}case`FINALIZE`:{let n=e6(e);return t.textSegId&&(n=n.map(e=>e.id===t.textSegId?{...e,status:`completed`}:e)),n.filter(e=>!e.isSpinny)}case`ADD_NOTIFICATION`:{let n=t.seg,r=e[e.length-1];if(r&&r.type===`code_llm_notification`&&r.message===n.message&&r.severity===n.severity){let t=[...e];return t[t.length-1]={...r,flashKey:(r.flashKey??0)+1},t}return[...e,n]}case`ERROR`:return[...e6(e).filter(e=>!e.isSpinny),t.errorSeg];case`REMOVE_USER_SEG`:return e.filter(e=>e.id!==t.userSegId);case`CLEAR`:return[];case`LOAD`:return t.segments;case`REMOVE_TEMP`:return e.some(e=>e.temp===!0)?e.filter(e=>e.temp!==!0):e;case`ADD_CREDITS`:return[...e,t.seg];case`TOOL_CALL_START`:{let{toolCallId:n,toolName:r,textSegId:i}=t,a;return a=i?e.filter(e=>!e.isSpinny).map(e=>e.id===i?{...e,status:`completed`}:e):e.filter(e=>!e.isSpinny),[...a,{id:n,status:`transient`,source:`bot`,type:`code_llm_tool_call`,toolUseRequest:{id:n,name:r,input:{}},isStreamingArgs:!0,streamingArguments:``}]}case`TOOL_CALL_DELTA`:{let{toolCallId:n,argumentsDelta:r}=t;return e.map(e=>e.id===n?{...e,streamingArguments:(e.streamingArguments??``)+r}:e)}case`TOOL_CALL_STOP`:{let{toolCallId:n,toolName:r,arguments:i}=t,a={};try{a=JSON.parse(i)}catch{}return e.map(e=>e.id===n?{...e,isStreamingArgs:!1,streamingArguments:i,toolUseRequest:{id:n,name:r,input:a}}:e)}case`ADD_CONNECTOR_AUTH`:return[...e.filter(e=>!e.isSpinny),t.seg];case`UPDATE_CONNECTOR_AUTH`:{let n=[...e].reverse().find(e=>e.type===`code_llm_connector_auth`);return n?e.map(e=>e.id===n.id?{...e,connectorStatuses:{...e.connectorStatuses,...t.connectorStatuses}}:e):e}case`UPDATE_CONNECTOR_AUTH_URL`:{let n=[...e].reverse().find(e=>e.type===`code_llm_connector_auth`);return n?e.map(e=>e.id===n.id?{...e,connectorAuthUrls:{...e.connectorAuthUrls,[t.service]:t.url}}:e):e}default:return e}}function DWe(e){switch(e.type){case`text`:return{id:e.id,status:`completed`,source:e.source,type:`text`,segment:e.content};case`thinking`:return{id:e.id,status:`completed`,source:`bot`,type:`thinking`,segment:e.content,isSpinny:e.isSpinny,...e.title!==void 0&&{title:e.title}};case`tool_call`:return{id:e.id,status:`completed`,source:`bot`,type:`code_llm_tool_call`,toolUseRequest:e.toolUseRequest,toolUseResult:e.toolUseResult??{id:e.toolUseRequest.id,content:` `},...e.parsedResult!==void 0&&{parsedResult:e.parsedResult},...e.toolDisplayData!==void 0&&{toolDisplayData:e.toolDisplayData}};case`notification`:return{id:e.id,status:`completed`,source:`bot`,type:`code_llm_notification`,message:e.message,severity:e.severity,...e.actions!==void 0&&{actions:e.actions}};case`tool_group`:return{id:e.id,status:`completed`,source:`bot`,type:`text`,segment:e.summary}}}const t6=(0,X.memo)(({children:e,apiClient:t,configService:n,agentArgs:r})=>{let{agentMode:i,setAgentMode:a}=j2(),o=(0,X.useRef)(i),s=(0,X.useRef)(i),c=(0,X.useRef)(null),{notifyActionRequired:l,notifyTaskComplete:u}=CWe(),{startUpload:d,startDownload:f,stopActivity:p}=K3(),{authManager:m,setAuthExpired:h,onAuthExpired:g}=Z3(),_=pQ(),{connection:v,pushServer:y}=W3(),b=(0,X.useRef)(v),x=(0,X.useRef)(y);(0,X.useEffect)(()=>{b.current=v},[v]),(0,X.useEffect)(()=>{x.current=y},[y]);let[S,C]=(0,X.useState)(zd.Idle),[w,T]=(0,X.useReducer)(EWe,[]),E=(0,X.useRef)(new Map),[D,O]=(0,X.useState)(null),[k,A]=(0,X.useState)(null),j=(0,X.useRef)(null),M=(0,X.useRef)([]),[N,ee]=(0,X.useState)([]),[te,F]=(0,X.useState)(null),[I,L]=(0,X.useState)(null),[ne,R]=(0,X.useState)(!0),[z,re]=(0,X.useState)(!0),[ie,ae]=(0,X.useState)(0),[oe,se]=(0,X.useState)(null),[ce,le]=(0,X.useState)(null),[ue,de]=(0,X.useState)(null),[fe,B]=(0,X.useState)(null),pe=(0,X.useRef)(0),me=(0,X.useRef)(!0),he=(0,X.useRef)(null),ge=(0,X.useRef)(zd.Idle),_e=(0,X.useCallback)(e=>{ge.current=e,C(e)},[]);(0,X.useEffect)(()=>()=>{he.current&&clearTimeout(he.current),c.current&&clearTimeout(c.current)},[]);let[ve,ye]=(0,X.useState)(null),be=qF(process.cwd()),V=(0,X.useCallback)(e=>{j.current=e,A(e)},[]),xe=(0,X.useCallback)(()=>{let e=M.current.shift();if(!e){V(null);return}e.request=Ce.current?.refreshPermissionRequest(e.request)??e.request;let t=!1;(e.editorDiffFilePath||e.editorToolViewShown)&&x.current&&x.current.waitForDecision(e.request.tool.id).then(n=>{t||(t=!0,_e(n===`accept`||n===`allowAlways`||n===`allowYolo`?zd.ExecutingTool:zd.Submitted),e.resolve(n),xe())}).catch(()=>{}),V({request:e.request,resolve:n=>{t||(t=!0,_e(n===`accept`||n===`allowAlways`||n===`allowYolo`||typeof n==`object`&&n.type===`accept_with_message`||typeof n==`object`&&n.type===`question_answers`?zd.ExecutingTool:zd.Submitted),setTimeout(()=>{e.resolve(n),xe()},0).unref())}}),_e(zd.WaitingForToolPermission),l(`Abacus.AI is waiting for your input`)},[l,_e,V]),Se=(0,X.useMemo)(()=>new eJ(async e=>{let t=b.current,n=e,r=null;if(t&&x.current&&e.type===`edit_file`){let i=e.tool.id,a=E.current.get(i),o=(e.tool.input??{}).filePath??e.filePath??``,s=a?.originalContent??e.originalContent??``,c=a?.newContent??e.newContent??``;o&&(s||c)&&await t.showDiff({filePath:o,originalContent:s,modifiedContent:c,toolId:i})&&(n={...e,diffShownInEditor:!0},r=o)}if(t&&x.current&&e.type===`write_file`&&!e.isNewFile){let i=e.tool.id,a=e.filePath??``,o=e.originalContent??``,s=e.content??``;a&&(o||s)&&await t.showDiff({filePath:a,originalContent:o,modifiedContent:s,toolId:i})&&(n={...e,diffShownInEditor:!0},r=a)}let i=!1;t&&e.type===`exit_plan_mode`&&e.planFilePath&&(x.current&&await t.showToolView({filePath:e.planFilePath,toolKey:e.tool.id}).catch(()=>!1)&&(i=!0),i||await t.openPlanFile(e.planFilePath).catch(()=>{}));let a=await new Promise(e=>{let t={request:n,editorDiffFilePath:r,editorToolViewShown:i,resolve:e},a=M.current.length===0&&!j.current;M.current.push(t),a&&xe()});if(r&&t){let e=a===`reject`||typeof a==`object`&&a.type===`reject_with_message`;t.notifyDiffDecision({targetFile:r,decision:e?`reject`:`accept`}).catch(()=>{})}return a}),[xe]),Ce=(0,X.useRef)(null);function we(){return new $q({allowedDirectories:[be,...r?.[`add-dir`]?.map(e=>{let t=GF(e);return qF(P.isAbsolute(t)?t:P.resolve(be,t))})??[]],primaryWorkspace:be,apiClient:t,mode:s.current,permissionProvider:Se,config:n,diagnosticsProvider:{getDiagnostics:async e=>{let t=b.current;return t?t.getDiagnostics(e):[]}},onMcpAuthRequired:void 0,enableSkills:!0,cliAllowedTools:r?.[`allowed-tools`],cliDisallowedTools:r?.[`disallowed-tools`]})}Ce.current||=(s.current=o.current,we());let Te=Ce.current,Ee=(0,X.useCallback)(()=>{ee(Te.getQueueEntries().map(e=>({...e})))},[Te]),De=(0,X.useCallback)(e=>{s.current=e,Te.setMode(e),M.current=M.current.filter(t=>Ud(t.request.type,e)?(t.resolve(`accept`),!1):!0);let t=j.current;t&&Ud(t.request.type,e)&&t.resolve(`accept`)},[Te]);(0,X.useEffect)(()=>(o.current=i,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{De(i),c.current=null},500),c.current.unref(),()=>{c.current&&=(clearTimeout(c.current),null)}),[i,De]),(0,X.useEffect)(()=>{(async()=>{let e=!0;if(r?.conversationId)try{await Pe(r.conversationId)}catch{e=!1}e&&r?.prompt&&await Ie({message:r.prompt})})()},[]),(0,X.useEffect)(()=>{let e=!1,t=0,n=1e3,r=()=>{if(e)return;t+=n;let i=Te.mcp.listServers(),a=i.filter(e=>e.status===`auth-required`);if(a.length>0){let e=a.map(e=>e.config.name??e.config.id).join(`, `);Oe(`${a.length} MCP server(s) require auth (${e}). Use /mcp auth <name> to authenticate.`,`warning`,!0);return}t<1e4&&i.some(e=>e.status!==`connected`&&e.status!==`error`)&&setTimeout(r,n)},i=setTimeout(r,n);return()=>{e=!0,clearTimeout(i)}},[]),(0,X.useEffect)(()=>{switch(S){case zd.Submitted:case zd.Streaming:_.showProgress({state:`indeterminate`});break;case zd.ExecutingTool:_.showProgress({state:`indeterminate`});break;case zd.WaitingForToolPermission:_.hideProgress();break;case zd.Idle:_.hideProgress();break}},[S,_]);let Oe=(0,X.useCallback)((e,t=`info`,n=!1)=>{T({type:`ADD_NOTIFICATION`,seg:{id:crypto.randomUUID(),status:`completed`,source:`bot`,type:`code_llm_notification`,severity:t,message:e,temp:n}})},[]),ke=(0,X.useCallback)(()=>{T({type:`CLEAR`}),O(null),_e(zd.Idle),ye(null),B(null),E.current.clear(),c.current&&=(clearTimeout(c.current),null),s.current=o.current,Ce.current=we()},[t,be,Se]),Ae=(0,X.useCallback)(()=>{T({type:`CLEAR`})},[]),je=(0,X.useCallback)(()=>{T({type:`REMOVE_TEMP`})},[]),Me=(0,X.useCallback)(()=>{let e=Te.dq();Ee(),e.length>0&&F(e.map(e=>e.message).join(`
75284
+ `);n.procedure=lWe(e,n.contract)}return{path:n.path,procedure:n.procedure}}}},_We=class extends mWe{constructor(e,t={}){let n=new i3(new n3(t)),r=new gWe(t),i=new hWe(n);super(e,r,i,t)}},vWe=class{socketServer;socketPath;editorState={file:void 0,startLine:void 0,endLine:void 0};onEditorStateCallback=null;pendingDecisions=new Map;constructor(){let e=N.join(t.homedir(),hn.configDirName,`cli`);this.socketPath=N.join(e,`${process.pid}.sock`)}getEditorState(){return{...this.editorState}}onEditorChange(e){this.onEditorStateCallback=e}waitForDecision(e,t){return new Promise((n,r)=>{if(t?.aborted){r(Error(`Aborted`));return}let i=()=>{t?.removeEventListener(`abort`,a),this.pendingDecisions.delete(e)},a=()=>{i(),r(Error(`Aborted`))};t?.addEventListener(`abort`,a,{once:!0}),this.pendingDecisions.set(e,{resolve:e=>{i(),n(e)},cleanup:i})})}async start(){let e=N.dirname(this.socketPath);p.existsSync(e)||p.mkdirSync(e,{recursive:!0});let t=H3(IUe),n=t.router({editorStateChanged:t.editorStateChanged.handler(async({input:e})=>(this.editorState={file:e.file??void 0,startLine:e.startLine,endLine:e.endLine},this.onEditorStateCallback?.(this.editorState),{ok:!0})),toolDecision:t.toolDecision.handler(async({input:e})=>{let t=this.pendingDecisions.get(e.toolId);return t&&t.resolve(e.decision),{ok:!0}})});this.socketServer=await XUe(this.socketPath,new _We(n))}dispose(){for(let[,e]of this.pendingDecisions)e.cleanup();this.pendingDecisions.clear(),this.socketServer?.dispose(),this.socketServer=void 0}},yWe=class{client=null;disposeSocket=null;currentFile=void 0;selectionStartLine=void 0;selectionEndLine=void 0;onFileChangeCallback=null;constructor(e){this.pushServer=e}findSocketPath(){let e=process.env[hn.socketEnvVar];if(e&&m.existsSync(e))return e;try{let e=P.join(n.homedir(),hn.configDirName,hn.ideDirName),t=m.readdirSync(e).filter(e=>e.endsWith(`.sock`)).map(t=>P.join(e,t)).filter(e=>m.existsSync(e));if(t.length===1)return t[0]}catch{}return null}async connect(){try{let e=this.findSocketPath();if(!e)return!1;let t=await $Ue(e,{timeoutMs:2e3});this.client=X4(t.link),this.disposeSocket=()=>t.dispose(),await this.client.register({cliSocketPath:this.pushServer.socketPath,pid:process.pid});let n=this.pushServer.getEditorState();return this.currentFile=n.file,this.selectionStartLine=n.startLine,this.selectionEndLine=n.endLine,this.pushServer.onEditorChange(e=>{this.currentFile=e.file,this.selectionStartLine=e.startLine,this.selectionEndLine=e.endLine,this.onFileChangeCallback?.(e.file,e.startLine,e.endLine)}),!0}catch{return!1}}getCurrentFile(){return this.currentFile}getSelectionRange(){return{startLine:this.selectionStartLine,endLine:this.selectionEndLine}}isConnected(){return this.client!==null}onFileChange(e){this.onFileChangeCallback=e}async showDiff(e){if(!this.client)return!1;try{return(await this.client.showDiff({...e,cliSocketPath:this.pushServer.socketPath})).success}catch{return!1}}async showToolView(e){if(!this.client)return!1;try{return(await this.client.showToolView({...e,cliSocketPath:this.pushServer.socketPath})).success}catch{return!1}}async notifyDiffDecision(e){if(!this.client)throw Error(`Not connected to extension`);await this.client.notifyDiffDecision(e)}async openPlanFile(e){if(!this.client)throw Error(`Not connected to extension`);return{opened:(await this.client.openFile({file:e})).success}}async getDiagnostics(e){if(!this.client)throw Error(`Not connected to extension`);return this.client.getDiagnostics({...e&&{files:e}})}dispose(){this.disposeSocket?.(),this.disposeSocket=null,this.client=null,this.currentFile=void 0,this.selectionStartLine=void 0,this.selectionEndLine=void 0,this.onFileChangeCallback=null}};const U3=(0,X.createContext)(null);function W3(){let e=(0,X.use)(U3);if(!e)throw Error(`useExtensionFile must be used within ExtensionFileProvider`);return e}function bWe(e){let t=(0,cQ.c)(11),{children:n,initialFile:r}=e,[i,a]=(0,X.useState)(r),[o,s]=(0,X.useState)(void 0),[c,l]=(0,X.useState)(void 0),[u,d]=(0,X.useState)(null),[f,p]=(0,X.useState)(null),m=(0,X.useRef)(null),h=(0,X.useRef)(null),g,_;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>{let e=!1;return(async()=>{let t=new vWe;try{await t.start()}catch{}if(e){t.dispose();return}h.current=t,p(t),t.onEditorChange(e=>{a(e.file),s(e.startLine),l(e.endLine)});for(let n of[0,...[500,1e3,2e3,3e3,4e3]]){if(e||(n>0&&await new Promise(e=>setTimeout(e,n)),e))return;try{let n=new yWe(t);if(await n.connect()){if(e){n.dispose();return}let r=t.getEditorState();a(r.file),s(r.startLine),l(r.endLine),n.onFileChange((e,t,n)=>{a(e),s(t),l(n)}),m.current=n,d(n);return}}catch{}}})(),()=>{e=!0,m.current&&(m.current.dispose(),m.current=null,d(null)),h.current&&(h.current.dispose(),h.current=null,p(null))}},_=[],t[0]=g,t[1]=_):(g=t[0],_=t[1]),(0,X.useEffect)(g,_);let v;t[2]!==u||t[3]!==i||t[4]!==f||t[5]!==c||t[6]!==o?(v={currentFile:i,selectionStartLine:o,selectionEndLine:c,connection:u,pushServer:f},t[2]=u,t[3]=i,t[4]=f,t[5]=c,t[6]=o,t[7]=v):v=t[7];let y;return t[8]!==n||t[9]!==v?(y=(0,Z.jsx)(U3.Provider,{value:v,children:n}),t[8]=n,t[9]=v,t[10]=y):y=t[10],y}const G3=(0,X.createContext)(null);function xWe(e){let t=(0,cQ.c)(8),{children:n}=e,[r,i]=(0,X.useState)(`idle`),a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=()=>i(`upload`),t[0]=a):a=t[0];let o=a,s;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>i(`download`),t[1]=s):s=t[1];let c=s,l;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(l=()=>i(`idle`),t[2]=l):l=t[2];let u=l,d;t[3]===r?d=t[4]:(d={activity:r,setActivity:i,startUpload:o,startDownload:c,stopActivity:u},t[3]=r,t[4]=d);let f=d,p;return t[5]!==n||t[6]!==f?(p=(0,Z.jsx)(G3.Provider,{value:f,children:n}),t[5]=n,t[6]=f,t[7]=p):p=t[7],p}function K3(){let e=(0,X.use)(G3);if(!e)throw Error(`useNetworkActivity must be used within NetworkActivityProvider`);return e}const SWe=new Set([`iterm2`,`kitty`,`wezterm`,`ghostty`]),q3=(0,X.createContext)(null),CWe=()=>{let e=(0,X.use)(q3);if(!e)throw Error(`useNotification must be used within NotificationProvider`);return e};function wWe(){if(process.platform!==`darwin`||process.env.TERM_PROGRAM!==`vscode`)return;let e=(process.env.VSCODE_GIT_IPC_HANDLE??process.env.VSCODE_IPC_HOOK_CLI??``).toLowerCase().includes(`cursor`)?`Cursor`:`Visual Studio Code`;try{return le(`osascript -e 'id of app "${e}"' 2>/dev/null`,{encoding:`utf8`,timeout:2e3}).trim()||void 0}catch{return}}const TWe=({children:e,mode:t=`full`})=>{let{isFocused:n}=fQ(),r=pQ(),i=(0,X.useRef)(n);i.current=n;let a=(0,X.useRef)(t);a.current=t;let o=(0,X.useRef)(SWe.has(gX())),s=(0,X.useRef)(wWe()),c=(0,X.useCallback)((e,t,n)=>{i.current||a.current===`off`||(a.current===`full`&&(o.current?r.notify({body:e,title:t}):EAe(t,e,n,{activateBundleId:s.current})),TAe(n))},[r]),l=(0,X.useCallback)((e,t)=>c(e,t??`Abacus AI`,`complete`),[c]),u=(0,X.useCallback)(e=>c(e,`Action Required`,`action-required`),[c]),d=(0,X.useCallback)(e=>c(e,`Task Complete`,`complete`),[c]),f=(0,X.useMemo)(()=>({notifyIfUnfocused:l,notifyActionRequired:u,notifyTaskComplete:d}),[l,u,d]);return(0,Z.jsx)(q3.Provider,{value:f,children:e})};function J3(e){return new Promise(t=>{process.platform===`darwin`?se(`open`,[e],e=>t(!e)):process.platform===`win32`?se(`explorer.exe`,[e],e=>t(!e)):se(`xdg-open`,[e],e=>t(!e))})}function Y3(e){return new Promise(t=>{let n=process.platform===`darwin`?ue(`pbcopy`):process.platform===`win32`?ue(`clip`):ue(`xclip`,[`-selection`,`clipboard`]);n.on(`error`,()=>t(!1)),n.on(`exit`,e=>t(e===0)),n.stdin?.write(e),n.stdin?.end()})}const X3=(0,X.createContext)(null),Z3=()=>{let e=(0,X.use)(X3);if(!e)throw Error(`useApiClient must be used within ApiClientProvider`);return e},Q3=(0,X.memo)(e=>{let t=(0,cQ.c)(9),{children:n,client:r,authManager:i,onAuthExpired:a}=e,[o,s]=(0,X.useState)(!1),c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=()=>s(!1),t[0]=c):c=t[0];let l=c,u;t[1]!==o||t[2]!==i||t[3]!==r||t[4]!==a?(u={apiClient:r,authManager:i,authExpired:o,setAuthExpired:s,clearAuthExpired:l,onAuthExpired:a},t[1]=o,t[2]=i,t[3]=r,t[4]=a,t[5]=u):u=t[5];let d=u,f;return t[6]!==n||t[7]!==d?(f=(0,Z.jsx)(X3.Provider,{value:d,children:n}),t[6]=n,t[7]=d,t[8]=f):f=t[8],f});Q3.displayName=`ApiClientProvider`;const $3=(0,X.createContext)(null);function e6(e,t){let n=t?new Set(t):null;return e.map(e=>{if(e.type!==`code_llm_tool_call`||e.status!==`transient`||e.toolUseResult||n&&!n.has(e.id))return e;let t=Array.isArray(e.toolUseRequest)?e.toolUseRequest[0]?.id??e.id:e.toolUseRequest?.id??e.id;return{...e,status:`completed`,isStreamingArgs:!1,toolUseResult:{id:t,content:JSON.stringify({reason:rz.INTERRUPTED}),rejected:!0}}})}function EWe(e,t){switch(t.type){case`INIT_SEND`:return[...e6(e.filter(e=>e.temp!==!0)),t.userSeg,t.spinnySeg];case`TEXT_DELTA`:{let{segId:n,content:r}=t,i=e6(e).filter(e=>!e.isSpinny);return i.find(e=>e.id===n)?i.map(e=>e.id===n?{...e,segment:(e.segment||``)+r}:e):[...i,{id:n,status:`transient`,source:`bot`,type:`text`,segment:r}]}case`THINKING_DELTA`:{let{segId:n,content:r,startTime:i}=t;return e.find(e=>e.id===n)?e.map(e=>e.id===n?{...e,segment:(e.segment||``)+r}:e):[...e,{id:n,status:`transient`,source:`bot`,type:`thinking`,isSpinny:!0,segment:r,thinkingStartTime:i}]}case`THINKING_COMPLETE`:return e.map(e=>e.id===t.segId?{...e,status:`completed`,isSpinny:!1,thinkingEndTime:t.endTime}:e);case`TOOL_DISPLAY_DATA`:return e.map(e=>e.id===t.toolCallId?{...e,toolDisplayData:{...e.toolDisplayData,...t.data}}:e);case`TOOL_REQUESTED`:{let{textSegId:n,toolSeg:r}=t,i;return i=n?e.filter(e=>!e.isSpinny).map(e=>e.id===n?{...e,status:`completed`}:e):e.filter(e=>!e.isSpinny),[...i,r]}case`TOOL_EXECUTION_COMPLETE`:{let{toolCallId:n,rawResult:r,parsedResult:i,spinnySeg:a}=t,o=e.map(e=>e.id===n?{...e,status:`completed`,toolUseResult:r,...i!==void 0&&{parsedResult:i}}:e);return a?[...o,a]:o}case`TOOL_USER_MESSAGE`:return[...e,t.seg];case`TEXT_COMPLETED`:return e.map(e=>e.id===t.segId?{...e,status:`completed`}:e);case`TURN_COMPLETE`:{let n=e6(e,t.toolCallIds);return t.textSegId&&(n=n.map(e=>e.id===t.textSegId?{...e,status:`completed`}:e)),n}case`FINALIZE`:{let n=e6(e);return t.textSegId&&(n=n.map(e=>e.id===t.textSegId?{...e,status:`completed`}:e)),n.filter(e=>!e.isSpinny)}case`ADD_NOTIFICATION`:{let n=t.seg,r=e[e.length-1];if(r&&r.type===`code_llm_notification`&&r.message===n.message&&r.severity===n.severity){let t=[...e];return t[t.length-1]={...r,flashKey:(r.flashKey??0)+1},t}return[...e,n]}case`ERROR`:return[...e6(e).filter(e=>!e.isSpinny),t.errorSeg];case`REMOVE_USER_SEG`:return e.filter(e=>e.id!==t.userSegId);case`CLEAR`:return[];case`LOAD`:return t.segments;case`REMOVE_TEMP`:return e.some(e=>e.temp===!0)?e.filter(e=>e.temp!==!0):e;case`ADD_CREDITS`:return[...e,t.seg];case`TOOL_CALL_START`:{let{toolCallId:n,toolName:r,textSegId:i}=t,a;return a=i?e.filter(e=>!e.isSpinny).map(e=>e.id===i?{...e,status:`completed`}:e):e.filter(e=>!e.isSpinny),[...a,{id:n,status:`transient`,source:`bot`,type:`code_llm_tool_call`,toolUseRequest:{id:n,name:r,input:{}},isStreamingArgs:!0,streamingArguments:``}]}case`TOOL_CALL_DELTA`:{let{toolCallId:n,argumentsDelta:r}=t;return e.map(e=>e.id===n?{...e,streamingArguments:(e.streamingArguments??``)+r}:e)}case`TOOL_CALL_STOP`:{let{toolCallId:n,toolName:r,arguments:i}=t,a={};try{a=JSON.parse(i)}catch{}return e.map(e=>e.id===n?{...e,isStreamingArgs:!1,streamingArguments:i,toolUseRequest:{id:n,name:r,input:a}}:e)}case`ADD_CONNECTOR_AUTH`:return[...e.filter(e=>!e.isSpinny),t.seg];case`UPDATE_CONNECTOR_AUTH`:{let n=[...e].reverse().find(e=>e.type===`code_llm_connector_auth`);return n?e.map(e=>e.id===n.id?{...e,connectorStatuses:{...e.connectorStatuses,...t.connectorStatuses}}:e):e}case`UPDATE_CONNECTOR_AUTH_URL`:{let n=[...e].reverse().find(e=>e.type===`code_llm_connector_auth`);return n?e.map(e=>e.id===n.id?{...e,connectorAuthUrls:{...e.connectorAuthUrls,[t.service]:t.url}}:e):e}default:return e}}function DWe(e){switch(e.type){case`text`:return{id:e.id,status:`completed`,source:e.source,type:`text`,segment:e.content};case`thinking`:return{id:e.id,status:`completed`,source:`bot`,type:`thinking`,segment:e.content,isSpinny:e.isSpinny,...e.title!==void 0&&{title:e.title}};case`tool_call`:return{id:e.id,status:`completed`,source:`bot`,type:`code_llm_tool_call`,toolUseRequest:e.toolUseRequest,toolUseResult:e.toolUseResult??{id:e.toolUseRequest.id,content:` `},...e.parsedResult!==void 0&&{parsedResult:e.parsedResult},...e.toolDisplayData!==void 0&&{toolDisplayData:e.toolDisplayData}};case`notification`:return{id:e.id,status:`completed`,source:`bot`,type:`code_llm_notification`,message:e.message,severity:e.severity,...e.actions!==void 0&&{actions:e.actions}};case`tool_group`:return{id:e.id,status:`completed`,source:`bot`,type:`text`,segment:e.summary}}}const t6=(0,X.memo)(({children:e,apiClient:t,configService:n,agentArgs:r})=>{let{agentMode:i,setAgentMode:a}=j2(),o=(0,X.useRef)(i),s=(0,X.useRef)(i),c=(0,X.useRef)(null),{notifyActionRequired:l,notifyTaskComplete:u}=CWe(),{startUpload:d,startDownload:f,stopActivity:p}=K3(),{authManager:m,setAuthExpired:h,onAuthExpired:g}=Z3(),_=pQ(),{connection:v,pushServer:y}=W3(),b=(0,X.useRef)(v),x=(0,X.useRef)(y);(0,X.useEffect)(()=>{b.current=v},[v]),(0,X.useEffect)(()=>{x.current=y},[y]);let[S,C]=(0,X.useState)(zd.Idle),[w,T]=(0,X.useReducer)(EWe,[]),E=(0,X.useRef)(new Map),[D,O]=(0,X.useState)(null),[k,A]=(0,X.useState)(null),j=(0,X.useRef)(null),M=(0,X.useRef)([]),[N,ee]=(0,X.useState)([]),[te,F]=(0,X.useState)(null),[I,L]=(0,X.useState)(null),[ne,R]=(0,X.useState)(!0),[z,re]=(0,X.useState)(!0),[ie,ae]=(0,X.useState)(0),[oe,se]=(0,X.useState)(null),[ce,le]=(0,X.useState)(null),[ue,de]=(0,X.useState)(null),[fe,B]=(0,X.useState)(null),pe=(0,X.useRef)(0),me=(0,X.useRef)(!0),he=(0,X.useRef)(null),ge=(0,X.useRef)(zd.Idle),_e=(0,X.useCallback)(e=>{ge.current=e,C(e)},[]);(0,X.useEffect)(()=>()=>{he.current&&clearTimeout(he.current),c.current&&clearTimeout(c.current)},[]);let[ve,ye]=(0,X.useState)(null),be=qF(process.cwd()),V=(0,X.useCallback)(e=>{j.current=e,A(e)},[]),xe=(0,X.useCallback)(()=>{let e=M.current.shift();if(!e){V(null);return}e.request=Ce.current?.refreshPermissionRequest(e.request)??e.request;let t=!1;(e.editorDiffFilePath||e.editorToolViewShown)&&x.current&&x.current.waitForDecision(e.request.tool.id).then(n=>{t||(t=!0,_e(n===`accept`||n===`allowAlways`||n===`allowYolo`?zd.ExecutingTool:zd.Submitted),e.resolve(n),xe())}).catch(()=>{}),V({request:e.request,resolve:n=>{t||(t=!0,_e(n===`accept`||n===`allowAlways`||n===`allowYolo`||typeof n==`object`&&n.type===`accept_with_message`||typeof n==`object`&&n.type===`question_answers`?zd.ExecutingTool:zd.Submitted),setTimeout(()=>{e.resolve(n),xe()},0).unref())}}),_e(zd.WaitingForToolPermission),l(`Abacus.AI is waiting for your input`)},[l,_e,V]),Se=(0,X.useMemo)(()=>new eJ(async e=>{let t=b.current,n=e,r=null;if(t&&x.current&&e.type===`edit_file`){let i=e.tool.id,a=E.current.get(i),o=(e.tool.input??{}).filePath??e.filePath??``,s=a?.originalContent??e.originalContent??``,c=a?.newContent??e.newContent??``;o&&(s||c)&&await t.showDiff({filePath:o,originalContent:s,modifiedContent:c,toolId:i})&&(n={...e,diffShownInEditor:!0},r=o)}if(t&&x.current&&e.type===`write_file`&&!e.isNewFile){let i=e.tool.id,a=e.filePath??``,o=e.originalContent??``,s=e.content??``;a&&(o||s)&&await t.showDiff({filePath:a,originalContent:o,modifiedContent:s,toolId:i})&&(n={...e,diffShownInEditor:!0},r=a)}let i=!1;t&&e.type===`exit_plan_mode`&&e.planFilePath&&(x.current&&await t.showToolView({filePath:e.planFilePath,toolKey:e.tool.id}).catch(()=>!1)&&(i=!0),i||await t.openPlanFile(e.planFilePath).catch(()=>{}));let a=await new Promise(e=>{let t={request:n,editorDiffFilePath:r,editorToolViewShown:i,resolve:e},a=M.current.length===0&&!j.current;M.current.push(t),a&&xe()});if(r&&t){let e=a===`reject`||typeof a==`object`&&a.type===`reject_with_message`;t.notifyDiffDecision({targetFile:r,decision:e?`reject`:`accept`}).catch(()=>{})}return a}),[xe]),Ce=(0,X.useRef)(null);function we(){return new $q({allowedDirectories:[be,...r?.[`add-dir`]?.map(e=>{let t=GF(e);return qF(P.isAbsolute(t)?t:P.resolve(be,t))})??[]],primaryWorkspace:be,apiClient:t,mode:s.current,...r?.model&&{model:r.model},permissionProvider:Se,config:n,diagnosticsProvider:{getDiagnostics:async e=>{let t=b.current;return t?t.getDiagnostics(e):[]}},onMcpAuthRequired:void 0,enableSkills:!0,cliAllowedTools:r?.[`allowed-tools`],cliDisallowedTools:r?.[`disallowed-tools`]})}Ce.current||=(s.current=o.current,we());let Te=Ce.current,Ee=(0,X.useCallback)(()=>{ee(Te.getQueueEntries().map(e=>({...e})))},[Te]),De=(0,X.useCallback)(e=>{s.current=e,Te.setMode(e),M.current=M.current.filter(t=>Ud(t.request.type,e)?(t.resolve(`accept`),!1):!0);let t=j.current;t&&Ud(t.request.type,e)&&t.resolve(`accept`)},[Te]);(0,X.useEffect)(()=>(o.current=i,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{De(i),c.current=null},500),c.current.unref(),()=>{c.current&&=(clearTimeout(c.current),null)}),[i,De]),(0,X.useEffect)(()=>{(async()=>{let e=!0;if(r?.conversationId)try{await Pe(r.conversationId)}catch{e=!1}e&&r?.prompt&&await Ie({message:r.prompt})})()},[]),(0,X.useEffect)(()=>{let e=!1,t=0,n=1e3,r=()=>{if(e)return;t+=n;let i=Te.mcp.listServers(),a=i.filter(e=>e.status===`auth-required`);if(a.length>0){let e=a.map(e=>e.config.name??e.config.id).join(`, `);Oe(`${a.length} MCP server(s) require auth (${e}). Use /mcp auth <name> to authenticate.`,`warning`,!0);return}t<1e4&&i.some(e=>e.status!==`connected`&&e.status!==`error`)&&setTimeout(r,n)},i=setTimeout(r,n);return()=>{e=!0,clearTimeout(i)}},[]),(0,X.useEffect)(()=>{switch(S){case zd.Submitted:case zd.Streaming:_.showProgress({state:`indeterminate`});break;case zd.ExecutingTool:_.showProgress({state:`indeterminate`});break;case zd.WaitingForToolPermission:_.hideProgress();break;case zd.Idle:_.hideProgress();break}},[S,_]);let Oe=(0,X.useCallback)((e,t=`info`,n=!1)=>{T({type:`ADD_NOTIFICATION`,seg:{id:crypto.randomUUID(),status:`completed`,source:`bot`,type:`code_llm_notification`,severity:t,message:e,temp:n}})},[]),ke=(0,X.useCallback)(()=>{T({type:`CLEAR`}),O(null),_e(zd.Idle),ye(null),B(null),E.current.clear(),c.current&&=(clearTimeout(c.current),null),s.current=o.current,Ce.current=we()},[t,be,Se]),Ae=(0,X.useCallback)(()=>{T({type:`CLEAR`})},[]),je=(0,X.useCallback)(()=>{T({type:`REMOVE_TEMP`})},[]),Me=(0,X.useCallback)(()=>{let e=Te.dq();Ee(),e.length>0&&F(e.map(e=>e.message).join(`
75285
75285
  `)),Te.stop();let t=j.current;t&&t.resolve(`reject`);for(let e of M.current)e.resolve(`reject`);M.current.length=0,V(null),_e(zd.Idle)},[Te,Ee,_e,V]),Ne=(0,X.useCallback)(()=>{k&&k.resolve(`reject`)},[k]),Pe=(0,X.useCallback)(async e=>{_e(zd.LoadingConversation),T({type:`CLEAR`}),O(null),ye(e);try{let t=await Te.loadConversation(e);return t.title&&O(t.title),t.segments.length>0&&T({type:`LOAD`,segments:t.segments.map(e=>DWe(e))}),B(t.llmName??null),t.llmName&&Te.setModel(t.llmName),{llmName:t.llmName}}catch{return B(null),Oe(`Failed to load conversation`,`error`),{}}finally{_e(zd.Idle)}},[Te,Oe,_e]),Fe=(0,X.useCallback)(async(e,t)=>{await Te.mcp.refresh(),t&&Oe(`MCP tools refreshed`,`info`,!0)},[Te,Oe]),Ie=(0,X.useCallback)(async({message:e,selectedModel:t,fileAttachments:n,activeSkills:r})=>{if(!e||S===zd.LoadingConversation)return;t&&Te.setModel(t);let i=e;if(n&&n.length>0){let e=n.filter(e=>!e.mimeType.startsWith(`image/`));for(let t of e){let e=typeof t.content==`string`?t.content:t.content.toString(`utf-8`);i+=`\n\n<file path="${t.filePath}">\n${e}\n</file>`}}let o=crypto.randomUUID();T({type:`INIT_SEND`,userSeg:{id:o,status:`completed`,source:`user`,type:`text`,segment:e},spinnySeg:{id:crypto.randomUUID(),status:`transient`,source:`bot`,type:`collapsible_component`,title:`Processing request`,temp:!0,isSpinny:!0}}),_e(zd.Submitted),d();let s=null,c=null,l=[],_=new Set,v,y=b.current,x=y?.getCurrentFile(),C=y?.getSelectionRange();if(y&&x)try{let e=(await y.getDiagnostics([x])).filter(e=>e.severity===`error`||e.severity===`warning`);e.length>0&&(v=e.map(e=>`${e.file}:${e.line}:${e.column} [${e.severity}] ${e.message}`).join(`
75286
75286
  `))}catch{}try{for await(let e of Te.send(i,{diagnosticIssues:v,currentFile:x??void 0,selectionStartLine:C?.startLine,selectionEndLine:C?.endLine,activeSkills:r})){let t=()=>{c&&=(T({type:`THINKING_COMPLETE`,segId:c,endTime:Date.now()}),null)};switch(e.type){case`text_delta`:{_e(zd.Streaming),p(),f(),t();let n=e.content;s||=crypto.randomUUID(),T({type:`TEXT_DELTA`,segId:s,content:n});break}case`thinking_delta`:{let t=e.content;c||=crypto.randomUUID(),T({type:`THINKING_DELTA`,segId:c,content:t,startTime:Date.now()});break}case`thinking_complete`:t();break;case`tool_display_data`:{let{toolCallId:t,data:n}=e,r=E.current.get(t)??{};E.current.set(t,{...r,...n}),T({type:`TOOL_DISPLAY_DATA`,toolCallId:t,data:n});break}case`tool_call_start`:t(),_.add(e.toolCallId),T({type:`TOOL_CALL_START`,toolCallId:e.toolCallId,toolName:e.toolName,textSegId:s}),s=null;break;case`tool_call_delta`:T({type:`TOOL_CALL_DELTA`,toolCallId:e.toolCallId,argumentsDelta:e.argumentsDelta});break;case`tool_call_stop`:T({type:`TOOL_CALL_STOP`,toolCallId:e.toolCallId,toolName:e.toolName,arguments:e.arguments});break;case`tool_requested`:{let n=e.tool,r=!!n.server_executed;r||(ge.current!==zd.WaitingForToolPermission&&_e(zd.ExecutingTool),p(),d()),t();let i=e.tool.id;if(r||l.push(i),_.has(i)){T({type:`TOOL_CALL_STOP`,toolCallId:i,toolName:e.tool.name,arguments:JSON.stringify(e.tool.input??{})}),s=null;break}let a={id:i,status:r?`completed`:`transient`,source:`bot`,type:`code_llm_tool_call`,toolUseRequest:{id:i,name:e.tool.name,input:e.tool.input,...r&&{server_executed:!0,result:n.result}},toolDisplayData:E.current.get(i)};T({type:`TOOL_REQUESTED`,toolCallId:i,textSegId:s,toolSeg:a}),s=null;break}case`tool_execution_complete`:{p();let t=e.tool.id,{parsedResult:n,...r}=e.result;if(e.tool.server_executed){T({type:`TOOL_EXECUTION_COMPLETE`,toolCallId:t,rawResult:r,...n!==void 0&&{parsedResult:n}}),s=null;break}f();let i={id:crypto.randomUUID(),status:`transient`,source:`bot`,type:`collapsible_component`,title:`Analyzing result`,temp:!0,isSpinny:!0};T({type:`TOOL_EXECUTION_COMPLETE`,toolCallId:t,rawResult:r,...n!==void 0&&{parsedResult:n},spinnySeg:i}),s=null;break}case`notification`:T({type:`ADD_NOTIFICATION`,seg:{id:crypto.randomUUID(),status:`completed`,source:`bot`,type:`code_llm_notification`,severity:e.severity,message:e.message,...e.actions!==void 0&&{actions:e.actions}}});break;case`error`:T({type:`ERROR`,errorSeg:{id:crypto.randomUUID(),status:`completed`,source:`bot`,type:`code_llm_notification`,severity:`error`,message:e.error.message}});break;case`mode_changed`:a(e.mode);break;case`tool_user_message`:T({type:`TOOL_USER_MESSAGE`,seg:{id:crypto.randomUUID(),status:`completed`,source:`user`,type:`text`,segment:e.message}});break;case`retry`:L({attempt:e.attempt,maxAttempts:e.maxAttempts,delayMs:e.delayMs,isNetworkError:e.isNetworkError});break;case`network_status`:e.online?(he.current&&=(clearTimeout(he.current),null),me.current=!0,R(!0),re(!0),L(null),setTimeout(()=>{if(ge.current===zd.Idle&&Te.getQueueEntries().length>0){let e=Te.dq();if(e.length>0){Ee();let t=e.map(e=>e.message).join(`
75287
75287
  `),n=Jq.matchSkill(t.trim());Ie(n?{message:t,activeSkills:[n.skill.id]}:{message:t})}}},0).unref?.()):(me.current=!1,R(!1),he.current||=setTimeout(()=>{he.current=null,me.current||re(!1)},3e4));break;case`user_message_dequeued`:T({type:`INIT_SEND`,userSeg:{id:crypto.randomUUID(),status:`completed`,source:`user`,type:`text`,segment:e.content},spinnySeg:{id:crypto.randomUUID(),status:`transient`,source:`bot`,type:`collapsible_component`,title:`Processing request`,temp:!0,isSpinny:!0}}),Ee(),s=null,c=null,l.length=0;break;case`credits`:pe.current+=e.creditsUsed,ae(t=>t+e.creditsUsed);break;case`connector_auth`:{let t=e.connectorMetadata?.userLevelConnectors??{},n=e.connectorMetadata?.authUrls??{};if(Object.keys(t).length>0){T({type:`ADD_CONNECTOR_AUTH`,seg:{id:crypto.randomUUID(),status:`transient`,source:`bot`,type:`code_llm_connector_auth`,connectorMetadata:t,connectorStatuses:Object.fromEntries(Object.keys(t).map(e=>[e,`PENDING`])),connectorAuthUrls:n}});for(let e of Object.keys(t)){let t=n[e];t&&J3(t)}}break}case`connector_auth_status`:T({type:`UPDATE_CONNECTOR_AUTH`,connectorStatuses:e.connectorsStatus??{}});break;case`session_info`:se(e.contextPercent),le(e.contextTokensUsed),de(e.contextWindowMax);break;case`turn_complete`:T({type:`TURN_COMPLETE`,textSegId:s,toolCallIds:[...l]}),s=null,l.length=0,Ee();break}}}catch(e){if(e instanceof Su)m.isEnvAuth()||(h(!0),g?.()),T({type:`REMOVE_USER_SEG`,userSegId:o}),Oe(`Session expired — use /login to authenticate again.`,`error`,!0);else{let t=Eu(e)?`Unable to connect to API`:e instanceof Error?e.message:`An error occurred`;T({type:`REMOVE_USER_SEG`,userSegId:o}),Oe(t,`error`,!0)}F(i),Te.dq(),Ee()}finally{p(),L(null);let e=Te.getConversationId();e&&ye(e),T({type:`FINALIZE`,textSegId:s}),pe.current>0&&(T({type:`ADD_CREDITS`,seg:{id:`credits-${Date.now()}`,status:`completed`,source:`bot`,type:`code_llm_credits`,creditsUsed:pe.current}}),pe.current=0),_e(zd.Idle),u(`Abacus.AI completed the task`)}},[Te,S,Oe,u,d,f,p,a,m,h]);(0,X.useEffect)(()=>(Te.onAutoRestart=e=>{ge.current===zd.Idle&&Ie({message:e})},()=>{Te.onAutoRestart=null}),[Te,Ie]);let Le=(0,X.useCallback)((e,t)=>{let n=Te.nq(e,t);return Ee(),n},[Te,Ee]),Re=(0,X.useCallback)(e=>{let t=Te.dq(e);return Ee(),t},[Te,Ee]),ze=(0,X.useCallback)((e,t)=>{Te.remove(e,t),Ee()},[Te,Ee]),Be=(0,X.useCallback)((e,t)=>{let n=Te.setContent(e,t);return Ee(),n},[Te,Ee]),Ve=(0,X.useCallback)(e=>{Te.clearQueue(e),Ee()},[Te,Ee]),H=(0,X.useCallback)(()=>{F(null)},[]),He=(0,X.useCallback)(e=>Te.isDirectoryAllowed(e),[Te]),Ue=(0,X.useCallback)((e,t)=>Te.addAllowedDirectory(e,t),[Te]),U=(0,X.useCallback)(()=>Te.listTerminalSessions(),[Te]),We=(0,X.useCallback)(e=>Te.getTerminalSessionOutput(e),[Te]),Ge=(0,X.useCallback)(e=>Te.stopTerminalSession(e),[Te]),Ke=(0,X.useMemo)(()=>({conversationId:ve,conversationTitle:D,segments:w,segmentsLength:w.length,sendMessage:Ie,stop:Me,rejectPendingPermission:Ne,agentStatus:S,clearSegments:ke,clearSegmentsOnly:Ae,clearTempSegments:je,loadConversation:Pe,addNotification:Oe,mcp:Te.mcp,isDirectoryAllowed:He,addAllowedDirectory:Ue,pendingToolPermission:k,refreshMcpTools:Fe,queuedMessages:N,nq:Le,dq:Re,removeFromQueue:ze,setQueuedMessageContent:Be,clearQueue:Ve,dequeuedOnStop:te,clearDequeuedOnStop:H,retryState:I,networkOnline:ne,debouncedNetworkOnline:z,listTerminalSessions:U,getTerminalSessionOutput:We,stopTerminalSession:Ge,totalCredits:ie,contextPercent:oe,contextTokensUsed:ce,contextWindowMax:ue,resolvedConversationLlmName:fe}),[ve,D,w,Ie,Me,Ne,S,ke,Ae,je,Pe,Oe,Te,He,Ue,k,Fe,N,Le,Re,ze,Be,Ve,te,H,I,ne,z,U,We,Ge,ie,oe,ce,ue,fe]);return(0,Z.jsx)($3.Provider,{value:Ke,children:e})});t6.displayName=`AgentProvider`;function n6(){let e=(0,X.use)($3);if(!e)throw Error(`Agent context not found. Did you forget to wrap your component in <${t6.name}>?`);return e}function r6(e){return e.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)}function OWe(e){let t=(0,cQ.c)(42),{toolName:n,status:r,parsedResult:i}=e,{agentStatus:a}=n6(),o;t[0]===n?o=t[1]:(o=r6(n),t[0]=n,t[1]=o);let s=o;if(r===`interrupted`){let e;t[2]===s?e=t[3]:(e=(0,Z.jsx)(h2,{name:s,status:`interrupted`}),t[2]=s,t[3]=e);let n;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,Z.jsx)(g2,{color:`yellow`,children:`Interrupted · What should I do instead?`}),t[4]=n):n=t[4];let r;return t[5]===e?r=t[6]:(r=(0,Z.jsxs)(Q,{flexDirection:`column`,children:[e,n]}),t[5]=e,t[6]=r),r}if(r===`rejected`){if(i?.userNote){let e;t[7]===s?e=t[8]:(e=(0,Z.jsx)(h2,{name:s,status:`rejected`}),t[7]=s,t[8]=e);let n;t[9]===i.userNote?n=t[10]:(n=(0,Z.jsxs)(g2,{color:`yellow`,children:[`Rejected · `,(0,Z.jsxs)($,{italic:!0,children:[`"`,i.userNote,`"`]})]}),t[9]=i.userNote,t[10]=n);let r;return t[11]!==e||t[12]!==n?(r=(0,Z.jsxs)(Q,{flexDirection:`column`,children:[e,n]}),t[11]=e,t[12]=n,t[13]=r):r=t[13],r}let e;t[14]===s?e=t[15]:(e=(0,Z.jsx)(h2,{name:s,status:`rejected`}),t[14]=s,t[15]=e);let n;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,Z.jsx)(g2,{color:`yellow`,children:`Rejected`}),t[16]=n):n=t[16];let r;return t[17]===e?r=t[18]:(r=(0,Z.jsxs)(Q,{flexDirection:`column`,children:[e,n]}),t[17]=e,t[18]=r),r}if(r===`error`){let e;t[19]===s?e=t[20]:(e=(0,Z.jsx)(h2,{name:s,status:`error`}),t[19]=s,t[20]=e);let n=i?.errorMessage??i?.summary??`MCP tool execution failed`,r;t[21]===n?r=t[22]:(r=(0,Z.jsx)(g2,{color:`red`,children:n}),t[21]=n,t[22]=r);let a;return t[23]!==e||t[24]!==r?(a=(0,Z.jsxs)(Q,{flexDirection:`column`,children:[e,r]}),t[23]=e,t[24]=r,t[25]=a):a=t[25],a}let c=a===zd.WaitingForToolPermission&&!i,l=!i&&(a===zd.Streaming||a===zd.ExecutingTool),u=i?.phase===`error`;if(c){let e;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Z.jsx)($,{color:`yellow`,children:`●`}),t[26]=e):e=t[26];let n;return t[27]===s?n=t[28]:(n=(0,Z.jsxs)(Q,{flexDirection:`row`,gap:1,children:[e,(0,Z.jsx)($,{color:`cyan`,children:s})]}),t[27]=s,t[28]=n),n}if(l){let e;return t[29]===s?e=t[30]:(e=(0,Z.jsx)(h2,{name:s,status:`pending`,showSpinner:!0}),t[29]=s,t[30]=e),e}if(i){let e=u?`error`:`success`,n;t[31]!==s||t[32]!==e?(n=(0,Z.jsx)(h2,{name:s,status:e}),t[31]=s,t[32]=e,t[33]=n):n=t[33];let r=u?`red`:`brightblack`,a=u?`Error: ${i.errorMessage??i.summary??`Tool execution failed`}`:i.summary??`Executed successfully`,o;t[34]!==r||t[35]!==a?(o=(0,Z.jsx)(g2,{color:r,children:a}),t[34]=r,t[35]=a,t[36]=o):o=t[36];let c;return t[37]!==n||t[38]!==o?(c=(0,Z.jsxs)(Q,{flexDirection:`column`,children:[n,o]}),t[37]=n,t[38]=o,t[39]=c):c=t[39],c}let d;return t[40]===s?d=t[41]:(d=(0,Z.jsx)(Q,{flexDirection:`column`,children:(0,Z.jsx)(h2,{name:s,status:`pending`})}),t[40]=s,t[41]=d),d}function kWe(e){return{displayName:r6(e),getHeaderParams(e){return``},renderUI(t,n,r){return(0,Z.jsx)(OWe,{toolName:e,rawInput:t,status:n,parsedResult:r})}}}function i6(e){let t=[];return e.pattern&&t.push(`pattern: "${e.pattern}"`),e.path&&t.push(`path: "${e.path}"`),t.length>0?t.join(`, `):`[no pattern]`}const AWe={displayName:`Search`,getHeaderParams(e){try{return i6(e)}catch{return`[unknown]`}},renderUI(e,t,n){let r=i6(e);return t===`error`?(0,Z.jsxs)(Q,{flexDirection:`column`,children:[(0,Z.jsx)(h2,{name:`Search`,params:r,status:`error`}),(0,Z.jsx)(g2,{color:`red`,children:`Error matching files`})]}):t===`executing`?(0,Z.jsx)(h2,{name:`Search`,params:r,status:`executing`,showSpinner:!0}):n?(0,Z.jsx)(jWe,{searchParams:r,parsedResult:n}):(0,Z.jsx)(Q,{flexDirection:`column`,children:(0,Z.jsx)(h2,{name:`Search`,params:r,status:`pending`})})}};function jWe(e){let t=(0,cQ.c)(9),{searchParams:n,parsedResult:r}=e,i=(0,X.useContext)(P2),a;if(t[0]!==i||t[1]!==r.data.files||t[2]!==r.summary||t[3]!==n){let e=r.data.files??[],o=i?30:10,s=e.slice(0,o),c=e.length-s.length,l;t[5]===n?l=t[6]:(l=(0,Z.jsx)(h2,{name:`Search`,params:n,status:`success`}),t[5]=n,t[6]=l);let u;t[7]===r.summary?u=t[8]:(u=(0,Z.jsx)(g2,{children:r.summary}),t[7]=r.summary,t[8]=u),a=(0,Z.jsxs)(Q,{flexDirection:`column`,children:[l,u,e.length>0&&(0,Z.jsxs)(_2,{children:[s.map(MWe),c>0&&(0,Z.jsxs)($,{dimColor:!0,children:[`… +`,c,` more file`,c===1?``:`s`]})]})]}),t[0]=i,t[1]=r.data.files,t[2]=r.summary,t[3]=n,t[4]=a}else a=t[4];return a}function MWe(e,t){return(0,Z.jsx)($,{dimColor:!0,children:e},t)}function a6(e){let t=e,n=[];t.pattern&&n.push(`pattern: "${t.pattern}"`),t.path&&n.push(`path: "${t.path}"`);let r=t.outputMode||e.output_mode;return r&&n.push(`outputMode: "${r}"`),t.glob&&n.push(`glob: "${t.glob}"`),t[`-i`]&&n.push(`case-insensitive`),n.length>0?n.join(`, `):`[no pattern]`}const NWe={displayName:`Search`,getHeaderParams(e){try{return a6(e)}catch{return`[unknown]`}},renderUI(e,t,n){let r=a6(e);return t===`error`?(0,Z.jsxs)(Q,{flexDirection:`column`,children:[(0,Z.jsx)(h2,{name:`Search`,params:r,status:`error`}),(0,Z.jsx)(g2,{color:`red`,children:`Error searching content`})]}):t===`executing`?(0,Z.jsx)(h2,{name:`Search`,params:r,status:`executing`,showSpinner:!0}):n?(0,Z.jsx)(PWe,{searchParams:r,parsedResult:n}):(0,Z.jsx)(Q,{flexDirection:`column`,children:(0,Z.jsx)(h2,{name:`Search`,params:r,status:`pending`})})}};function PWe(e){let t=(0,cQ.c)(9),{searchParams:n,parsedResult:r}=e,i=(0,X.useContext)(P2),a;if(t[0]!==i||t[1]!==r.data.matches||t[2]!==r.summary||t[3]!==n){let e=r.data.matches??[],o=i?30:10,s=e.slice(0,o),c=e.length-s.length,l;t[5]===n?l=t[6]:(l=(0,Z.jsx)(h2,{name:`Search`,params:n,status:`success`}),t[5]=n,t[6]=l);let u;t[7]===r.summary?u=t[8]:(u=(0,Z.jsx)(g2,{children:r.summary}),t[7]=r.summary,t[8]=u),a=(0,Z.jsxs)(Q,{flexDirection:`column`,children:[l,u,e.length>0&&(0,Z.jsxs)(_2,{children:[s.map(FWe),c>0&&(0,Z.jsxs)($,{dimColor:!0,children:[`… +`,c,` more match`,c===1?``:`es`]})]})]}),t[0]=i,t[1]=r.data.matches,t[2]=r.summary,t[3]=n,t[4]=a}else a=t[4];return a}function FWe(e,t){return(0,Z.jsx)($,{dimColor:!0,children:e},t)}const IWe=PR({url:Y()}),LWe={displayName:`Web Fetch`,getHeaderParams(e){try{let t=e?.url||``;return t.length>50?t.substring(0,47)+`...`:t}catch{return`[unknown]`}},renderUI(e,t,n){let r=IWe.safeParse(w2(e));if(!r.success)return(0,Z.jsxs)(Q,{flexDirection:`column`,children:[(0,Z.jsx)(h2,{name:`Fetch`,params:``,status:`error`}),(0,Z.jsx)(g2,{color:`red`,children:`Invalid params`})]});let i=r.data.url||``,a=i.length>50?i.substring(0,47)+`...`:i;return t===`error`?(0,Z.jsxs)(Q,{flexDirection:`column`,children:[(0,Z.jsx)(h2,{name:`Fetch`,params:a,status:`error`}),(0,Z.jsx)(g2,{color:`red`,children:`Error fetching URL`})]}):t===`executing`?(0,Z.jsx)(h2,{name:`Fetch`,params:a,status:`executing`,showSpinner:!0}):n?(0,Z.jsxs)(Q,{flexDirection:`column`,children:[(0,Z.jsx)(h2,{name:`Fetch`,params:a,status:`success`}),(0,Z.jsx)(g2,{children:n.summary??`Fetched content`})]}):(0,Z.jsx)(Q,{flexDirection:`column`,children:(0,Z.jsx)(h2,{name:`Fetch`,params:a,status:`pending`})})}},RWe=PR({searchTerm:Y(),query:Y().optional(),explanation:Y().optional(),allowedDomains:MR(Y()).optional(),blockedDomains:MR(Y()).optional()}),zWe={displayName:`WebSearch`,getHeaderParams(e){try{return`"${e?.searchTerm||e?.search_term||e?.query||`[no query]`}"`}catch{return`[unknown]`}},renderUI(e,t,n){let r=RWe.safeParse(w2(e));if(!r.success)return(0,Z.jsxs)(Q,{flexDirection:`column`,children:[(0,Z.jsx)(h2,{name:`WebSearch`,params:``,status:`error`}),(0,Z.jsx)(g2,{color:`red`,children:`Invalid params`})]});let i=r.data,a=i.searchTerm||i.query||``,o=`"${a.length>40?a.substring(0,37)+`...`:a}"`;return t===`error`?(0,Z.jsxs)(Q,{flexDirection:`column`,children:[(0,Z.jsx)(h2,{name:`WebSearch`,params:o,status:`error`}),(0,Z.jsx)(g2,{color:`red`,children:`Error performing web search`})]}):t===`executing`?(0,Z.jsx)(h2,{name:`WebSearch`,params:o,status:`executing`,showSpinner:!0}):(0,Z.jsxs)(Q,{flexDirection:`column`,children:[(0,Z.jsx)(h2,{name:`WebSearch`,params:o,status:`success`}),(0,Z.jsx)(g2,{children:`Found results`})]})}},BWe=PR({shellId:Y(),filter:Y().optional()}),VWe={displayName:`BashOutput`,getHeaderParams(e){try{let t=e,n=[`id: ${t.shellId||``}`];return t.filter&&n.push(`filter: ${t.filter}`),n.join(`, `)}catch{return`[unknown]`}},renderUI(e,t,n){let r=BWe.safeParse(w2(e));if(!r.success)return(0,Z.jsxs)(Q,{flexDirection:`column`,children:[(0,Z.jsx)(h2,{name:`BashOutput`,params:``,status:`error`}),(0,Z.jsx)(g2,{color:`red`,children:`Invalid params`})]});let i=`id: ${r.data.shellId}`;return t===`interrupted`?(0,Z.jsxs)(Q,{flexDirection:`column`,children:[(0,Z.jsx)(h2,{name:`BashOutput`,params:i,status:`interrupted`}),(0,Z.jsx)(g2,{color:`yellow`,children:`Interrupted · What should I do instead?`})]}):t===`rejected`?(0,Z.jsxs)(Q,{flexDirection:`column`,children:[(0,Z.jsx)(h2,{name:`BashOutput`,params:i,status:`rejected`}),n?.userNote?(0,Z.jsxs)(g2,{color:`yellow`,children:[`Rejected · `,(0,Z.jsxs)($,{italic:!0,children:[`"`,n.userNote,`"`]})]}):(0,Z.jsx)(g2,{color:`yellow`,children:`Rejected`})]}):!n&&(t===`executing`||t===`pending`)?(0,Z.jsx)(h2,{name:`BashOutput`,params:i,status:`pending`,showSpinner:!0}):n?(0,Z.jsxs)(Q,{flexDirection:`column`,children:[(0,Z.jsx)(h2,{name:`BashOutput`,params:i,status:`success`}),(0,Z.jsx)(g2,{children:n.summary})]}):(0,Z.jsx)(Q,{flexDirection:`column`,children:(0,Z.jsx)(h2,{name:`BashOutput`,params:i,status:`pending`})})}};var HWe=class{startTime;constructor(){this.startTime=performance.now()}getElapsedSeconds(){return(performance.now()-this.startTime)/1e3}getElapsedMs(){return performance.now()-this.startTime}getFormattedDuration(){return o6(this.getElapsedMs())}reset(){this.startTime=performance.now()}};function o6(e){let t=Math.floor(e/1e3),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60,a=[];return n>0&&a.push(`${n}h`),r>0&&a.push(`${r}m`),(i>0||a.length===0)&&a.push(`${i}s`),a.join(` `)}function UWe(e,t,n){let r=n?50:t,i=e.split(`
@@ -75533,7 +75533,7 @@ ${xZe}${t.trimStart()}`),n=3+f(t.trimStart()).length)}process.stdout.write(`
75533
75533
  `);process.stdout.write(x9.cursor.move(-999,e.length-1)),process.stdout.write(x9.erase.down(e.length))},g=e=>e.replace(/\.+$/,``),_=e=>{let t=(performance.now()-e)/1e3,n=Math.floor(t/60),r=Math.floor(t%60);return n>0?`[${n}m ${r}s]`:`[${r}s]`},v=(u=``)=>{o=!0,i=UXe(),s=g(u),l=performance.now(),process.stdout.write(`${S9.default.gray(R9)}
75534
75534
  `);let d=0,f=0;p(),a=setInterval(()=>{if(r&&s===c)return;h(),c=s;let n=S9.default.magenta(t[d]);if(r)process.stdout.write(`${n} ${s}...`);else if(e===`timer`)process.stdout.write(`${n} ${s} ${_(l)}`);else{let e=`.`.repeat(Math.floor(f)).slice(0,3);process.stdout.write(`${n} ${s}${e}`)}d=d+1<t.length?d+1:0,f=f<t.length?f+.125:0},n)},y=(t=``,n=0)=>{o=!1,clearInterval(a),h();let r=n===0?S9.default.green(L9):n===1?S9.default.red(iZe):S9.default.red(aZe);s=g(t??s),e===`timer`?process.stdout.write(`${r} ${s} ${_(l)}
75535
75535
  `):process.stdout.write(`${r} ${s}
75536
- `),m(),i()};return{start:v,stop:y,message:(e=``)=>{s=g(e??s)}}};async function X9(e){let{authManager:t,apiClient:n,reason:r,version:i}=e;if(t.isEnvAuth()||r===`welcome`&&t.isAuthenticated())return{success:!0};for(bZe(r===`welcome`?`Welcome to Abacus.AI CLI v${i}`:r===`expired`?`Session expired — please log in again`:`Invalid credentials — please log in again`);;){let e=await yZe({message:`How would you like to log in?`,options:[{value:`email`,label:`Log in with email`},{value:`apikey`,label:`Log in with API key`}]});if(j9(e))return G9(`Login cancelled`),{success:!1};if(e===`email`){let e=await SZe(t,n);if(e===`cancel`)return G9(`Login cancelled`),{success:!1};if(e===`success`)return K9(`You're all set!`),{success:!0}}else{let e=await CZe(t,n);if(e===`cancel`)return G9(`Login cancelled`),{success:!1};if(e===`success`)return K9(`You're all set!`),{success:!0}}}}async function SZe(e,t){let n=await _Ze({message:`Enter your email address`,placeholder:`you@example.com`,validate:e=>{if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e))return`Please enter a valid email address`}});if(j9(n))return`cancel`;let r=Y9();r.start(`Initiating device code login...`);let i,a,o;try{let e=await CY(),s=await t.authenticateDeviceForCodeLlm(n,e);if(!s?.success||!s?.result)return r.stop(`Failed to initiate login`),q9.error(s?.error??`Failed to start device code login`),`retry`;i=s.result.verificationUri,a=s.result.userCode,o=s.result.pollingInterval??5,r.stop(`Device code ready`)}catch(e){return r.stop(`Connection failed`),q9.error(e instanceof Error?e.message:`Failed to connect`),`retry`}W9(`URL: ${i}\nCode: ${a}`,`Open the URL and enter the code to log in`);let[s,c]=await Promise.all([J3(i),Y3(a)]);s&&c?q9.info(`Opening browser... (code copied to clipboard)`):s?q9.info(`Opening browser...`):c?q9.info(`Code copied to clipboard. Please open the URL manually.`):q9.info(`Please open the URL above and enter the code to log in.`);let l=Y9();l.start(`Waiting for authentication...`);let u=Date.now()+600*1e3,d=o*1e3;for(;Date.now()<u;){await new Promise(e=>setTimeout(e,d));try{let n=await t.pollDeviceCode(a);if(n?.success&&n.result?.deviceCode){if(await e.loginWithDeviceCode(n.result.deviceCode),n.result.chatWebUrl){let e=n.result.chatWebUrl.replace(/^https?:\/\//,``);t.setChatWebDomain(e)}return l.stop(`Authenticated!`),q9.success(`Logged in successfully`),`success`}}catch{}}return l.stop(`Timed out`),q9.error(`Authentication timed out. Please try again.`),`retry`}async function CZe(e,t){let n=await vZe({message:`Enter your API key · no key? https://abacus.ai/app/abacusai-cli`});if(j9(n))return`cancel`;let r=Y9();r.start(`Validating API key...`);try{await e.loginWithApiKey(n);let i=await t.getUserInfo();return i?.result?.email?(r.stop(`Authenticated!`),q9.success(`Logged in as ${i.result.email}`),`success`):(await e.logout(),r.stop(`Invalid API key`),q9.error(`Invalid API key — authentication failed`),`retry`)}catch(t){return await e.logout(),r.stop(`Login failed`),q9.error(t instanceof Error?t.message:`API key login failed`),`retry`}}function wZe(e){return e.type===`code_llm_tool_call`||e.type===`code_llm_agent_tool_request`}function TZe(e){let t=e.toolUseResult;return!!(t?.rejected||t?.content?.startsWith(`Error:`))}function EZe(e){if(e.type!==`code_llm_notification`)return!1;let t=(e.message??``).toLowerCase();return t.includes(`compacting conversation`)||t.includes(`compacted conversation`)}function DZe(e){let t={toolUses:0,responses:0};for(let n of e)switch(n.type){case`code_llm_tool_call`:case`code_llm_agent_tool_request`:t.toolUses+=Array.isArray(n.toolUseRequest)?n.toolUseRequest.length:1;break;case`text`:n.source===`bot`&&t.responses++;break}return t}function OZe(e,t){return{toolUses:e.toolUses+t.toolUses,responses:e.responses+t.responses}}function kZe(e){let t={toolUses:0,responses:0},n=[],r=[],i=0,a=[];for(let a=0;a<e.length;a++){let o=e[a];if(EZe(o)){let e=DZe(n);t=OZe(t,e),r.push(...n),n=[],i++;continue}n.push(o)}i>0&&a.push({kind:`compacted`,id:`compacted-${i}`,counts:t,segments:r});let o=AZe(n);return a.push(...o),a}function AZe(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.type===`thinking`){t.push({kind:`segment`,segment:r}),n++;continue}if(wZe(r)&&RYe.has(jZe(r))){let i=[r],a=n+1;for(;a<e.length;){let t=e[a];if(t.type===`thinking`){a++;continue}if(TZe(i[i.length-1]))break;if(wZe(t)&&RYe.has(jZe(t)))i.push(t),a++;else break}i.length===1?t.push({kind:`segment`,segment:i[0]}):t.push({kind:`tool-group`,id:i[0].id,segments:i}),n=a;continue}t.push({kind:`segment`,segment:r}),n++}return t}function jZe(e){let t=e.toolUseRequest;return t?Array.isArray(t)?t[0]?.name??``:t.name??``:``}function MZe(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n.type===`thinking`)return{thinkingStartTime:n.thinkingStartTime??null,thinkingEndTime:n.thinkingEndTime??null}}return{thinkingStartTime:null,thinkingEndTime:null}}function NZe(e){let t=(0,cQ.c)(77),{timing:n}=e,{setTitle:r}=cXe(),{segments:i,agentStatus:a,pendingToolPermission:o,conversationTitle:s,conversationId:c,addNotification:l,stop:u,rejectPendingPermission:d,clearQueue:f,totalCredits:p}=n6(),m=(0,X.useRef)(null),{authExpired:h,clearAuthExpired:g}=Z3(),_,v;t[0]!==l||t[1]!==h||t[2]!==g?(_=()=>{h&&(l(`Session expired — use /login to authenticate again.`,`error`),g())},v=[h,l,g],t[0]=l,t[1]=h,t[2]=g,t[3]=_,t[4]=v):(_=t[3],v=t[4]),(0,X.useEffect)(_,v);let[y,b]=(0,X.useState)(!1),x;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(x=(e,t)=>{(t.ctrl||t.super)&&e===`o`&&b(WZe)},t[5]=x):x=t[5],uQ(x);let S=_Xe(i),C,w;if(t[6]!==i){let e=kZe(i.filter(UZe));C=e.at(-1)??null,w=e.slice(0,-1),t[6]=i,t[7]=C,t[8]=w}else C=t[7],w=t[8];let T;t[9]!==C||t[10]!==w?(T={lastItem:C,prevItems:w},t[9]=C,t[10]=w,t[11]=T):T=t[11];let{lastItem:E,prevItems:D}=T,O;t[12]===i?O=t[13]:(O=MZe(i),t[12]=i,t[13]=O);let{thinkingStartTime:k,thinkingEndTime:A}=O,j=(0,X.useRef)(zd.Idle),[M,N]=(0,X.useState)(null),P,ee;t[14]===a?(P=t[15],ee=t[16]):(P=()=>{let e=j.current===zd.Idle,t=a!==zd.Idle&&a!==zd.WaitingForToolPermission;e&&t?N(Date.now()):a===zd.Idle&&N(null),j.current=a},ee=[a],t[14]=a,t[15]=P,t[16]=ee),(0,X.useEffect)(P,ee);let te=a===zd.WaitingForToolPermission&&o!==null,[F,I]=(0,X.useState)(!1),[L,ne]=(0,X.useState)(`0`),[R,z]=(0,X.useState)(0),re,ie;t[17]!==s||t[18]!==r?(re=()=>{r(s?`${s} • Abacus.AI CLI`:`Abacus.AI CLI`)},ie=[s,r],t[17]=s,t[18]=r,t[19]=re,t[20]=ie):(re=t[19],ie=t[20]),(0,X.useEffect)(re,ie);let ae,oe;t[21]!==n||t[22]!==p?(ae=()=>VQ(async()=>{let e=n.getFormattedDuration();z(p),ne(e),I(!0),await new Promise(HZe)},{wait:2e3,streams:[process.stdout,process.stderr]}),oe=[n,p],t[21]=n,t[22]=p,t[23]=ae,t[24]=oe):(ae=t[23],oe=t[24]),(0,X.useEffect)(ae,oe);let se=o!==null,ce,le;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(ce=()=>m.current?.hasText()??!1,le=()=>m.current?.hasQueue()??!1,t[25]=ce,t[26]=le):(ce=t[25],le=t[26]);let ue,de,fe;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(ue=()=>m.current?.saveAndClear(),de=()=>m.current?.clear(),fe=()=>m.current?.dequeueAllToComposer(),t[27]=ue,t[28]=de,t[29]=fe):(ue=t[27],de=t[28],fe=t[29]);let B;t[30]!==a||t[31]!==f||t[32]!==y||t[33]!==d||t[34]!==u||t[35]!==se?(B={agentStatus:a,hasPendingPermission:se,isExpandedView:y,composerHasText:ce,hasQueuedMessages:le,stopAgent:u,rejectPermission:d,saveAndClearComposer:ue,clearComposer:de,dequeueAllToComposer:fe,clearQueue:f,exitApp:VZe},t[30]=a,t[31]=f,t[32]=y,t[33]=d,t[34]=u,t[35]=se,t[36]=B):B=t[36];let pe=mXe(B),me=a!==zd.Idle&&a!==zd.WaitingForToolPermission,he=o?.request.tool.id??null,ge;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(ge=(0,Z.jsx)(F5,{}),t[37]=ge):ge=t[37];let _e;if(t[38]!==y||t[39]!==D){let e;t[41]===y?e=t[42]:(e=e=>e.kind===`compacted`?y?e.segments.map(BZe):(0,Z.jsx)(c6,{counts:e.counts,segments:e.segments},e.id):e.kind===`segment`?(0,Z.jsx)(g9,{segment:e.segment},e.segment.id):y?e.segments.map(zZe):(0,Z.jsx)(_9,{segments:e.segments},e.id),t[41]=y,t[42]=e),_e=D.map(e),t[38]=y,t[39]=D,t[40]=_e}else _e=t[40];let ve;t[43]!==y||t[44]!==E?(ve=E&&(E.kind===`compacted`?y?E.segments.map(RZe):(0,Z.jsx)(c6,{counts:E.counts,segments:E.segments},E.id):E.kind===`segment`?(0,Z.jsx)(g9,{segment:E.segment},E.segment.id):y?E.segments.map(LZe):(0,Z.jsx)(_9,{segments:E.segments},E.id)),t[43]=y,t[44]=E,t[45]=ve):ve=t[45];let ye;t[46]!==he||t[47]!==_e||t[48]!==ve?(ye=(0,Z.jsxs)(p2.Provider,{value:he,children:[_e,ve]}),t[46]=he,t[47]=_e,t[48]=ve,t[49]=ye):ye=t[49];let be;t[50]!==y||t[51]!==S?(be=!y&&(0,Z.jsx)(IYe,{state:S}),t[50]=y,t[51]=S,t[52]=be):be=t[52];let V;t[53]!==a||t[54]!==M||t[55]!==me||t[56]!==A||t[57]!==k?(V=me&&(0,Z.jsx)(G8,{onError:IZe,children:(0,Z.jsx)(jYe,{status:a,thinkingStartTime:k,thinkingEndTime:A,runStartTime:M})}),t[53]=a,t[54]=M,t[55]=me,t[56]=A,t[57]=k,t[58]=V):V=t[58];let xe;t[59]!==ye||t[60]!==be||t[61]!==V?(xe=(0,Z.jsxs)(Q,{flexDirection:`column`,gap:1,paddingBottom:1,width:`95%`,children:[ge,ye,be,V]}),t[59]=ye,t[60]=be,t[61]=V,t[62]=xe):xe=t[62];let Se;t[63]!==c||t[64]!==R||t[65]!==L||t[66]!==F||t[67]!==pe||t[68]!==te||t[69]!==o?(Se=F?(0,Z.jsx)(K8,{duration:L,credits:R,conversationId:c}):(0,Z.jsxs)(Z.Fragment,{children:[te&&(0,Z.jsx)(G8,{onError:FZe,children:(0,Z.jsx)(rXe,{pendingTool:o})}),(0,Z.jsx)(X.Activity,{mode:te?`hidden`:`visible`,children:(0,Z.jsx)(G8,{fallback:e=>(0,Z.jsxs)(Q,{flexDirection:`column`,paddingX:1,children:[(0,Z.jsx)($,{color:`red`,bold:!0,children:`Something went wrong in the input area.`}),(0,Z.jsx)($,{color:`yellow`,children:e.message}),(0,Z.jsxs)($,{dimColor:!0,children:[`Press Escape to restart the CLI, or resume with: `,hn.binName,` -c`,` `,c]})]}),onError:PZe,children:(0,Z.jsx)(W8,{hints:pe,composerRef:m})})})]}),t[63]=c,t[64]=R,t[65]=L,t[66]=F,t[67]=pe,t[68]=te,t[69]=o,t[70]=Se):Se=t[70];let Ce;t[71]!==xe||t[72]!==Se?(Ce=(0,Z.jsxs)(Z.Fragment,{children:[xe,Se]}),t[71]=xe,t[72]=Se,t[73]=Ce):Ce=t[73];let we;return t[74]!==y||t[75]!==Ce?(we=(0,Z.jsx)(P2.Provider,{value:y,children:Ce}),t[74]=y,t[75]=Ce,t[76]=we):we=t[76],we}function PZe(e){process.stderr.write(`[composer error] ${e.stack??e.message}\n`)}function FZe(e){process.stderr.write(`[tool-permission error] ${e.stack??e.message}\n`)}function IZe(e){process.stderr.write(`[status-indicator error] ${e.stack??e.message}\n`)}function LZe(e){return(0,Z.jsx)(g9,{segment:e},e.id)}function RZe(e){return(0,Z.jsx)(g9,{segment:e},e.id)}function zZe(e){return(0,Z.jsx)(g9,{segment:e},e.id)}function BZe(e){return(0,Z.jsx)(g9,{segment:e},e.id)}function VZe(){return HQ(0)}function HZe(e){return setTimeout(e,100)}function UZe(e){return!e.temp&&!e.isSpinny}function WZe(e){return!e}async function GZe({apiClient:e,authManager:t,configService:n,agentArgs:r}){let i,a=r?.[`permission-mode`];if(a)switch(a){case`yolo`:i=Rd.Yolo;break;case`accept-edits`:i=Rd.AcceptEdits;break;case`plan`:i=Rd.PlanMode;break;default:i=Rd.Normal;break}else r?.[`dangerously-skip-permissions`]?i=Rd.Yolo:r?.[`auto-accept-edits`]?i=Rd.AcceptEdits:r?.[`plan-mode`]&&(i=Rd.PlanMode);await WNe();let o=process.stdout,s=e=>{o&&o.writable&&o.write(e)},c=()=>s(nQ),l=()=>s(tQ),u=!1,d=n.get(`notifications`)??`full`;for(;;){u=!1;let a=new dFe,o=new HWe,s=null,f=()=>{u=!0,s?.unmount()};c();let p=bPe((0,Z.jsx)(Q3,{client:e,authManager:t,onAuthExpired:f,children:(0,Z.jsx)(fFe,{client:a,children:(0,Z.jsx)(f6,{children:(0,Z.jsx)(lXe,{children:(0,Z.jsx)(TWe,{mode:d,children:(0,Z.jsx)(nGe,{configService:n,children:(0,Z.jsx)(bWe,{children:(0,Z.jsx)(N2,{initialMode:i,children:(0,Z.jsx)(xWe,{children:(0,Z.jsx)(t6,{apiClient:e,configService:n,agentArgs:r,children:(0,Z.jsx)(NZe,{timing:o})})})})})})})})})})}),{exitOnCtrlC:!1,suspendable:!0,onSuspended:()=>{process.stderr.write(`
75536
+ `),m(),i()};return{start:v,stop:y,message:(e=``)=>{s=g(e??s)}}};async function X9(e){let{authManager:t,apiClient:n,reason:r,version:i}=e;if(t.isEnvAuth()||r===`welcome`&&t.isAuthenticated())return{success:!0};for(bZe(r===`welcome`?`Welcome to Abacus.AI CLI v${i}`:r===`expired`?`Session expired — please log in again`:`Invalid credentials — please log in again`);;){let e=await yZe({message:`How would you like to log in?`,options:[{value:`email`,label:`Log in with email`},{value:`apikey`,label:`Log in with API key`}]});if(j9(e))return G9(`Login cancelled`),{success:!1};if(e===`email`){let e=await SZe(t,n);if(e===`cancel`)return G9(`Login cancelled`),{success:!1};if(e===`success`)return K9(`You're all set!`),{success:!0}}else{let e=await CZe(t,n);if(e===`cancel`)return G9(`Login cancelled`),{success:!1};if(e===`success`)return K9(`You're all set!`),{success:!0}}}}async function SZe(e,t){let n=await _Ze({message:`Enter your email address`,placeholder:`you@example.com`,validate:e=>{if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e))return`Please enter a valid email address`}});if(j9(n))return`cancel`;let r=Y9();r.start(`Initiating device code login...`);let i,a,o;try{let e=await CY(),s=await t.authenticateDeviceForCodeLlm(n,e);if(!s?.success||!s?.result)return r.stop(`Failed to initiate login`),q9.error(s?.error??`Failed to start device code login`),`retry`;i=s.result.verificationUri,a=s.result.userCode,o=s.result.pollingInterval??5,r.stop(`Device code ready`)}catch(e){return r.stop(`Connection failed`),q9.error(e instanceof Error?e.message:`Failed to connect`),`retry`}W9(`URL: ${i}\nCode: ${a}`,`Open the URL and enter the code to log in`);let[s,c]=await Promise.all([J3(i),Y3(a)]);s&&c?q9.info(`Opening browser... (code copied to clipboard)`):s?q9.info(`Opening browser...`):c?q9.info(`Code copied to clipboard. Please open the URL manually.`):q9.info(`Please open the URL above and enter the code to log in.`);let l=Y9();l.start(`Waiting for authentication...`);let u=Date.now()+600*1e3,d=o*1e3;for(;Date.now()<u;){await new Promise(e=>setTimeout(e,d));try{let n=await t.pollDeviceCode(a);if(n?.success&&n.result?.deviceCode){if(await e.loginWithDeviceCode(n.result.deviceCode),n.result.chatWebUrl){let e=n.result.chatWebUrl.replace(/^https?:\/\//,``);t.setChatWebDomain(e)}return l.stop(`Authenticated!`),q9.success(`Logged in successfully`),`success`}}catch{}}return l.stop(`Timed out`),q9.error(`Authentication timed out. Please try again.`),`retry`}async function CZe(e,t){let n=await vZe({message:`Enter your API key · no key? https://abacus.ai/app/abacusai-cli`});if(j9(n))return`cancel`;let r=Y9();r.start(`Validating API key...`);try{await e.loginWithApiKey(n);let i=await t.getUserInfo();return i?.result?.email?(r.stop(`Authenticated!`),q9.success(`Logged in as ${i.result.email}`),`success`):(await e.logout(),r.stop(`Invalid API key`),q9.error(`Invalid API key — authentication failed`),`retry`)}catch(t){return await e.logout(),r.stop(`Login failed`),q9.error(t instanceof Error?t.message:`API key login failed`),`retry`}}function wZe(e){return e.type===`code_llm_tool_call`||e.type===`code_llm_agent_tool_request`}function TZe(e){let t=e.toolUseResult;return!!(t?.rejected||t?.content?.startsWith(`Error:`))}function EZe(e){if(e.type!==`code_llm_notification`)return!1;let t=(e.message??``).toLowerCase();return t.includes(`compacting conversation`)||t.includes(`compacted conversation`)}function DZe(e){let t={toolUses:0,responses:0};for(let n of e)switch(n.type){case`code_llm_tool_call`:case`code_llm_agent_tool_request`:t.toolUses+=Array.isArray(n.toolUseRequest)?n.toolUseRequest.length:1;break;case`text`:n.source===`bot`&&t.responses++;break}return t}function OZe(e,t){return{toolUses:e.toolUses+t.toolUses,responses:e.responses+t.responses}}function kZe(e){let t={toolUses:0,responses:0},n=[],r=[],i=0,a=[];for(let a=0;a<e.length;a++){let o=e[a];if(EZe(o)){let e=DZe(n);t=OZe(t,e),r.push(...n),n=[],i++;continue}n.push(o)}i>0&&a.push({kind:`compacted`,id:`compacted-${i}`,counts:t,segments:r});let o=AZe(n);return a.push(...o),a}function AZe(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.type===`thinking`){t.push({kind:`segment`,segment:r}),n++;continue}if(wZe(r)&&RYe.has(jZe(r))){let i=[r],a=n+1;for(;a<e.length;){let t=e[a];if(t.type===`thinking`){a++;continue}if(TZe(i[i.length-1]))break;if(wZe(t)&&RYe.has(jZe(t)))i.push(t),a++;else break}i.length===1?t.push({kind:`segment`,segment:i[0]}):t.push({kind:`tool-group`,id:i[0].id,segments:i}),n=a;continue}t.push({kind:`segment`,segment:r}),n++}return t}function jZe(e){let t=e.toolUseRequest;return t?Array.isArray(t)?t[0]?.name??``:t.name??``:``}function MZe(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n.type===`thinking`)return{thinkingStartTime:n.thinkingStartTime??null,thinkingEndTime:n.thinkingEndTime??null}}return{thinkingStartTime:null,thinkingEndTime:null}}function NZe(e){let t=(0,cQ.c)(77),{timing:n}=e,{setTitle:r}=cXe(),{segments:i,agentStatus:a,pendingToolPermission:o,conversationTitle:s,conversationId:c,addNotification:l,stop:u,rejectPendingPermission:d,clearQueue:f,totalCredits:p}=n6(),m=(0,X.useRef)(null),{authExpired:h,clearAuthExpired:g}=Z3(),_,v;t[0]!==l||t[1]!==h||t[2]!==g?(_=()=>{h&&(l(`Session expired — use /login to authenticate again.`,`error`),g())},v=[h,l,g],t[0]=l,t[1]=h,t[2]=g,t[3]=_,t[4]=v):(_=t[3],v=t[4]),(0,X.useEffect)(_,v);let[y,b]=(0,X.useState)(!1),x;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(x=(e,t)=>{(t.ctrl||t.super)&&e===`o`&&b(WZe)},t[5]=x):x=t[5],uQ(x);let S=_Xe(i),C,w;if(t[6]!==i){let e=kZe(i.filter(UZe));C=e.at(-1)??null,w=e.slice(0,-1),t[6]=i,t[7]=C,t[8]=w}else C=t[7],w=t[8];let T;t[9]!==C||t[10]!==w?(T={lastItem:C,prevItems:w},t[9]=C,t[10]=w,t[11]=T):T=t[11];let{lastItem:E,prevItems:D}=T,O;t[12]===i?O=t[13]:(O=MZe(i),t[12]=i,t[13]=O);let{thinkingStartTime:k,thinkingEndTime:A}=O,j=(0,X.useRef)(zd.Idle),[M,N]=(0,X.useState)(null),P,ee;t[14]===a?(P=t[15],ee=t[16]):(P=()=>{let e=j.current===zd.Idle,t=a!==zd.Idle&&a!==zd.WaitingForToolPermission;e&&t?N(Date.now()):a===zd.Idle&&N(null),j.current=a},ee=[a],t[14]=a,t[15]=P,t[16]=ee),(0,X.useEffect)(P,ee);let te=a===zd.WaitingForToolPermission&&o!==null,[F,I]=(0,X.useState)(!1),[L,ne]=(0,X.useState)(`0`),[R,z]=(0,X.useState)(0),re,ie;t[17]!==s||t[18]!==r?(re=()=>{r(s?`${s} • Abacus.AI CLI`:`Abacus.AI CLI`)},ie=[s,r],t[17]=s,t[18]=r,t[19]=re,t[20]=ie):(re=t[19],ie=t[20]),(0,X.useEffect)(re,ie);let ae,oe;t[21]!==n||t[22]!==p?(ae=()=>VQ(async()=>{let e=n.getFormattedDuration();z(p),ne(e),I(!0),await new Promise(HZe)},{wait:2e3,streams:[process.stdout,process.stderr]}),oe=[n,p],t[21]=n,t[22]=p,t[23]=ae,t[24]=oe):(ae=t[23],oe=t[24]),(0,X.useEffect)(ae,oe);let se=o!==null,ce,le;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(ce=()=>m.current?.hasText()??!1,le=()=>m.current?.hasQueue()??!1,t[25]=ce,t[26]=le):(ce=t[25],le=t[26]);let ue,de,fe;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(ue=()=>m.current?.saveAndClear(),de=()=>m.current?.clear(),fe=()=>m.current?.dequeueAllToComposer(),t[27]=ue,t[28]=de,t[29]=fe):(ue=t[27],de=t[28],fe=t[29]);let B;t[30]!==a||t[31]!==f||t[32]!==y||t[33]!==d||t[34]!==u||t[35]!==se?(B={agentStatus:a,hasPendingPermission:se,isExpandedView:y,composerHasText:ce,hasQueuedMessages:le,stopAgent:u,rejectPermission:d,saveAndClearComposer:ue,clearComposer:de,dequeueAllToComposer:fe,clearQueue:f,exitApp:VZe},t[30]=a,t[31]=f,t[32]=y,t[33]=d,t[34]=u,t[35]=se,t[36]=B):B=t[36];let pe=mXe(B),me=a!==zd.Idle&&a!==zd.WaitingForToolPermission,he=o?.request.tool.id??null,ge;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(ge=(0,Z.jsx)(F5,{}),t[37]=ge):ge=t[37];let _e;if(t[38]!==y||t[39]!==D){let e;t[41]===y?e=t[42]:(e=e=>e.kind===`compacted`?y?e.segments.map(BZe):(0,Z.jsx)(c6,{counts:e.counts,segments:e.segments},e.id):e.kind===`segment`?(0,Z.jsx)(g9,{segment:e.segment},e.segment.id):y?e.segments.map(zZe):(0,Z.jsx)(_9,{segments:e.segments},e.id),t[41]=y,t[42]=e),_e=D.map(e),t[38]=y,t[39]=D,t[40]=_e}else _e=t[40];let ve;t[43]!==y||t[44]!==E?(ve=E&&(E.kind===`compacted`?y?E.segments.map(RZe):(0,Z.jsx)(c6,{counts:E.counts,segments:E.segments},E.id):E.kind===`segment`?(0,Z.jsx)(g9,{segment:E.segment},E.segment.id):y?E.segments.map(LZe):(0,Z.jsx)(_9,{segments:E.segments},E.id)),t[43]=y,t[44]=E,t[45]=ve):ve=t[45];let ye;t[46]!==he||t[47]!==_e||t[48]!==ve?(ye=(0,Z.jsxs)(p2.Provider,{value:he,children:[_e,ve]}),t[46]=he,t[47]=_e,t[48]=ve,t[49]=ye):ye=t[49];let be;t[50]!==y||t[51]!==S?(be=!y&&(0,Z.jsx)(IYe,{state:S}),t[50]=y,t[51]=S,t[52]=be):be=t[52];let V;t[53]!==a||t[54]!==M||t[55]!==me||t[56]!==A||t[57]!==k?(V=me&&(0,Z.jsx)(G8,{onError:IZe,children:(0,Z.jsx)(jYe,{status:a,thinkingStartTime:k,thinkingEndTime:A,runStartTime:M})}),t[53]=a,t[54]=M,t[55]=me,t[56]=A,t[57]=k,t[58]=V):V=t[58];let xe;t[59]!==ye||t[60]!==be||t[61]!==V?(xe=(0,Z.jsxs)(Q,{flexDirection:`column`,gap:1,paddingBottom:1,width:`95%`,children:[ge,ye,be,V]}),t[59]=ye,t[60]=be,t[61]=V,t[62]=xe):xe=t[62];let Se;t[63]!==c||t[64]!==R||t[65]!==L||t[66]!==F||t[67]!==pe||t[68]!==te||t[69]!==o?(Se=F?(0,Z.jsx)(K8,{duration:L,credits:R,conversationId:c}):(0,Z.jsxs)(Z.Fragment,{children:[te&&(0,Z.jsx)(G8,{onError:FZe,children:(0,Z.jsx)(rXe,{pendingTool:o})}),(0,Z.jsx)(X.Activity,{mode:te?`hidden`:`visible`,children:(0,Z.jsx)(G8,{fallback:e=>(0,Z.jsxs)(Q,{flexDirection:`column`,paddingX:1,children:[(0,Z.jsx)($,{color:`red`,bold:!0,children:`Something went wrong in the input area.`}),(0,Z.jsx)($,{color:`yellow`,children:e.message}),(0,Z.jsxs)($,{dimColor:!0,children:[`Press Escape to restart the CLI, or resume with: `,hn.binName,` -c`,` `,c]})]}),onError:PZe,children:(0,Z.jsx)(W8,{hints:pe,composerRef:m})})})]}),t[63]=c,t[64]=R,t[65]=L,t[66]=F,t[67]=pe,t[68]=te,t[69]=o,t[70]=Se):Se=t[70];let Ce;t[71]!==xe||t[72]!==Se?(Ce=(0,Z.jsxs)(Z.Fragment,{children:[xe,Se]}),t[71]=xe,t[72]=Se,t[73]=Ce):Ce=t[73];let we;return t[74]!==y||t[75]!==Ce?(we=(0,Z.jsx)(P2.Provider,{value:y,children:Ce}),t[74]=y,t[75]=Ce,t[76]=we):we=t[76],we}function PZe(e){process.stderr.write(`[composer error] ${e.stack??e.message}\n`)}function FZe(e){process.stderr.write(`[tool-permission error] ${e.stack??e.message}\n`)}function IZe(e){process.stderr.write(`[status-indicator error] ${e.stack??e.message}\n`)}function LZe(e){return(0,Z.jsx)(g9,{segment:e},e.id)}function RZe(e){return(0,Z.jsx)(g9,{segment:e},e.id)}function zZe(e){return(0,Z.jsx)(g9,{segment:e},e.id)}function BZe(e){return(0,Z.jsx)(g9,{segment:e},e.id)}function VZe(){return HQ(0)}function HZe(e){return setTimeout(e,100)}function UZe(e){return!e.temp&&!e.isSpinny}function WZe(e){return!e}async function GZe({apiClient:e,authManager:t,configService:n,agentArgs:r}){let i,a=r?.[`permission-mode`];if(a)switch(a){case`yolo`:i=Rd.Yolo;break;case`accept-edits`:i=Rd.AcceptEdits;break;case`plan`:i=Rd.PlanMode;break;default:i=Rd.Normal;break}else r?.[`dangerously-skip-permissions`]?i=Rd.Yolo:r?.[`auto-accept-edits`]?i=Rd.AcceptEdits:r?.[`plan-mode`]&&(i=Rd.PlanMode);r?.model&&(r.model=await jQ(e,r.model,n.get(`client`))),await WNe();let o=process.stdout,s=e=>{o&&o.writable&&o.write(e)},c=()=>s(nQ),l=()=>s(tQ),u=!1,d=n.get(`notifications`)??`full`;for(;;){u=!1;let a=new dFe,o=new HWe,s=null,f=()=>{u=!0,s?.unmount()};c();let p=bPe((0,Z.jsx)(Q3,{client:e,authManager:t,onAuthExpired:f,children:(0,Z.jsx)(fFe,{client:a,children:(0,Z.jsx)(f6,{children:(0,Z.jsx)(lXe,{children:(0,Z.jsx)(TWe,{mode:d,children:(0,Z.jsx)(nGe,{configService:n,children:(0,Z.jsx)(bWe,{children:(0,Z.jsx)(N2,{initialMode:i,children:(0,Z.jsx)(xWe,{children:(0,Z.jsx)(t6,{apiClient:e,configService:n,agentArgs:r,children:(0,Z.jsx)(NZe,{timing:o})})})})})})})})})})}),{exitOnCtrlC:!1,suspendable:!0,onSuspended:()=>{process.stderr.write(`
75537
75537
  Abacus.AI has been suspended. Run \`fg\` to bring Abacus back.
75538
75538
  `)}});s=p;let m=!1,h=()=>{m||(m=!0,l())},g=()=>{m||(m=!0,p.cleanupTerminal())};if(process.once(`exit`,g),await p.waitUntilExit(),process.off(`exit`,g),h(),!u||!(await X9({authManager:t,apiClient:e,reason:`expired`,version:(await Promise.resolve().then(()=>$e(gQ()))).default.version})).success)break}}const KZe=dt([`codellm`,`cli`,`auth`]);async function qZe(e){let t=await SY.create(),n=new Ou(t,Sn(),gn.userAgentNames.cli,_Q.default.version),r=new rJ({cwd:process.cwd(),extraSources:[{read:async()=>({client:nt.CLI})}]});await r.load();let i=r.get(`baseUrl`);if(typeof i==`string`&&i)try{new URL(i),n.setUrl(i),n.resetEndpoints(),await n.getApiEndpoint()}catch{KZe.error`Invalid base URL: ${i}`,process.exit(1)}let a=!0;switch(e){case`login`:await JZe(t,n);break;case`logout`:a=await YZe(t);break;case`status`:await XZe(t,n);break;case`switch`:a=await ZZe(t,n);break}process.exit(+!a)}async function JZe(e,t){if(e.isEnvAuth()){q9.warn(`Currently authenticated via environment variable. Login is not needed.`);return}if(e.isAuthenticated()){let n=(await t.getUserInfo().catch(()=>null))?.result?.email;n&&q9.info(`Already logged in as ${XZ().bold().render(n)}`);let r=await U9({message:`Do you want to log in with a different account?`});if(j9(r)||!r)return;await e.logout()}await X9({authManager:e,apiClient:t,reason:`welcome`,version:_Q.default.version})}async function YZe(e){return e.isEnvAuth()?(q9.warn(`Currently authenticated via environment variable. Unset the environment variable to log out.`),!0):e.isAuthenticated()?await e.logout()?(q9.success(`Logged out successfully.`),!0):(q9.error(`Failed to log out.`),!1):(q9.info(`Not currently logged in.`),!0)}async function XZe(e,t){let n=e.getAuthKind();if(n.type===`logged_out`){console.log(ZZ(`yellow`)(`Not logged in`));return}let r=n.type===`env_api_key`||n.type===`env_device_code`?`environment variable`:n.type===`api_key`?`API key`:n.type===`device_code`?`device code`:`OAuth token`;console.log(XZ().bold().render(`Authentication Status`)),console.log(` Method: ${r}`);try{let e=await t.getUserInfo();if(e?.result){let{email:t,name:n,organization:r}=e.result;n&&console.log(` Name: ${n}`),t&&console.log(` Email: ${t}`),r?.name&&console.log(` Org: ${r.name}`)}}catch{console.log(XZ().dim().render(` (Could not fetch user details)`))}}async function ZZe(e,t){if(!e.isAuthenticated())return q9.error("Not logged in. Run `auth login` first."),!1;let n=Y9();n.start(`Fetching organizations...`);let r;try{let e=await t.listOrganizations();if(!e?.success||!e.result)return n.stop(`Failed to fetch organizations`),q9.error(`Could not retrieve organizations.`),!1;r=e.result,n.stop(`Organizations loaded`)}catch{return n.stop(`Failed`),q9.error(`Could not fetch organizations.`),!1}if(r.length===0)return q9.info(`No organizations available.`),!0;let i;try{i=(await t.getUserInfo())?.result?.organization?.organizationId}catch{}let a=await yZe({message:`Select an organization to switch to`,options:r.map(e=>({value:e.organizationId,label:e.name,hint:e.organizationId===i?`current`:e.workspace}))});if(j9(a))return G9(`Cancelled`),!0;if(a===i)return q9.info(`Already on this organization.`),!0;let o=Y9();o.start(`Switching organization...`);try{if(await t.switchOrganization(a)){let e=r.find(e=>e.organizationId===a)?.name??a;return o.stop(`Done`),q9.success(`Switched to ${XZ().bold().render(e)}`),!0}else return o.stop(`Failed`),q9.error(`Failed to switch organization.`),!1}catch{return o.stop(`Failed`),q9.error(`Failed to switch organization.`),!1}}async function QZe(e){let{currentVersion:t,explicit:n=!1,autoUpdate:r=!0,updateChannel:i,baseUrl:a}=e;if(!n&&EQ()||!n&&!r)return{action:`skipped`};let o;try{o=await DQ(t,i,a,{includeDev:n})}catch{return n?(q9.error(`Failed to check for updates. Please check your network connection.`),{action:`exit`}):{action:`skipped`}}if(!o)return n&&q9.success(`Already up to date (${t})`),{action:`skipped`};if(!n&&o.isEphemeral)return{action:`skipped`};let s=o.installationType===`native`,c=s?`Download v${o.latestVersion}`:OQ(o);bZe(`Update available: ${o.currentVersion} → ${o.latestVersion}`),s||W9(c,`Install command`);let l=await U9({message:`Would you like to update now?`,initialValue:!0});if(j9(l))return G9(`Update cancelled`),{action:`exit`};if(l){let e=Y9();e.start(`Updating...`);let{ok:t,output:n}=s?await AQ(o):kQ(o);if(t)return e.stop(`Updated to ${o.latestVersion}`),n&&W9(n,`Install output`),K9(`Restarting...`),{action:`updated`,version:o.latestVersion};{e.stop(`Update failed`),n&&W9(n,`Error output`),q9.error(`Update failed. You can try manually running the command above.`);let t=await U9({message:`Continue using v${o.currentVersion}?`,initialValue:!0});return j9(t)||!t?(G9(`Exiting`),{action:`exit`}):(K9(`Continuing with v${o.currentVersion}`),{action:`continue`})}}let u=await U9({message:`Continue using v${o.currentVersion}?`,initialValue:!0});return j9(u)||!u?(G9(`Exiting`),{action:`exit`}):(K9(`Continuing with v${o.currentVersion}`),{action:`continue`})}function $Ze(e,t){switch(e){case`bash`:return nQe(t);case`zsh`:return rQe(t);case`fish`:return iQe(t);case`pwsh`:return aQe(t)}}function eQe(){if(process.env.PSModulePath!==void 0)return`pwsh`;let e=process.env.SHELL??``;return e.endsWith(`zsh`)?`zsh`:e.endsWith(`bash`)?`bash`:e.endsWith(`fish`)?`fish`:process.platform===`win32`?`pwsh`:null}function tQe(e,t,n){switch(e){case`bash`:return n===`darwin`?[`${t}/.bash_profile`,`${t}/.bashrc`]:[`${t}/.bashrc`,`${t}/.bash_profile`];case`zsh`:return[`${t}/.zshrc`];case`fish`:return[`${t}/.config/fish/config.fish`];case`pwsh`:{let e=n===`win32`?i():t;return n===`win32`?[`${e}\\Documents\\PowerShell\\Microsoft.PowerShell_profile.ps1`,`${e}\\Documents\\WindowsPowerShell\\Microsoft.PowerShell_profile.ps1`]:[`${t}/.config/powershell/Microsoft.PowerShell_profile.ps1`,`${t}/.config/powershell/profile.ps1`]}}}const Z9=`# Abacus AI shell integration`;function nQe(e){return`\
75539
75539
  ${Z9}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abacus-ai/cli",
3
- "version": "2.5.1-canary.4",
3
+ "version": "2.5.1-canary.5",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "abacusai": "dist/index.mjs"