import{hz as B,sz as R}from"./cli-0.5.4-k5fz4zd3.mjs";import"./cli-0.5.4-wbqf44ym.mjs";import"./cli-0.5.4-9ewg9gfs.mjs";import"./cli-0.5.4-we3mspgg.mjs";import"./cli-0.5.4-jzhazry0.mjs";import"./cli-0.5.4-82sw3hrw.mjs";import"./cli-0.5.4-31v143kt.mjs";import"./cli-0.5.4-1cy7wd6s.mjs";import"./cli-0.5.4-5e0pk96f.mjs";import"./cli-0.5.4-z154a7bp.mjs";import"./cli-0.5.4-ng5p0zjs.mjs";import"./cli-0.5.4-5hp7ks3t.mjs";import"./cli-0.5.4-8hdwp78f.mjs";import"./cli-0.5.4-mr9aznxx.mjs";import"./cli-0.5.4-jevfk5q7.mjs";import"./cli-0.5.4-27dzbzdy.mjs";import"./cli-0.5.4-a5bkdqqb.mjs";import"./cli-0.5.4-j2hnw539.mjs";import"./cli-0.5.4-9w59nnw4.mjs";import"./cli-0.5.4-z5d3q8kh.mjs";import"./cli-0.5.4-c0r12dqp.mjs";import"./cli-0.5.4-kqh172jk.mjs";import"./cli-0.5.4-vv4jbgkc.mjs";import"./cli-0.5.4-s7k1f0wc.mjs";import"./cli-0.5.4-0h0yz2k5.mjs";import"./cli-0.5.4-942dm5q1.mjs";import"./cli-0.5.4-rcmp5h4y.mjs";import"./cli-0.5.4-xdcww3x8.mjs";import"./cli-0.5.4-fq32ny1h.mjs";import{AY as q,BY as O,CY as j,EY as h}from"./cli-0.5.4-h1m67ngp.mjs";import"./cli-0.5.4-49erze3e.mjs";import"./cli-0.5.4-jytjks37.mjs";import"./cli-0.5.4-mn22gk7g.mjs";import"./cli-0.5.4-5t3jj85n.mjs";import"./cli-0.5.4-5shjmmkz.mjs";import"./cli-0.5.4-zb412kkm.mjs";import"./cli-0.5.4-prfn3sxd.mjs";import"./cli-0.5.4-6xmgebmk.mjs";import"./cli-0.5.4-vjgejcrz.mjs";import"./cli-0.5.4-jqt00ywx.mjs";import"./cli-0.5.4-9e7rkd8e.mjs";import"./cli-0.5.4-jp4wtw87.mjs";import"./cli-0.5.4-hambpq58.mjs";import"./cli-0.5.4-syvgmg9g.mjs";import"./cli-0.5.4-w8ttefr5.mjs";import"./cli-0.5.4-j7kkqxv6.mjs";import"./cli-0.5.4-qrwczx7j.mjs";import"./cli-0.5.4-v2z6p9td.mjs";import{R6 as M,T6 as U}from"./cli-0.5.4-cbq01zg3.mjs";import"./cli-0.5.4-37v5fhf1.mjs";import"./cli-0.5.4-7grzwf6q.mjs";import"./cli-0.5.4-9qmek5dq.mjs";import"./cli-0.5.4-9c6r1fjg.mjs";import"./cli-0.5.4-2dw33ms6.mjs";import"./cli-0.5.4-x1fzfxmm.mjs";import"./cli-0.5.4-e822fzaq.mjs";import"./cli-0.5.4-09dvrzcr.mjs";import{Pfa as G,Sfa as f}from"./cli-0.5.4-end8wj9r.mjs";import"./cli-0.5.4-4x206j04.mjs";import"./cli-0.5.4-yd3rd9qt.mjs";import"./cli-0.5.4-sgcaw17t.mjs";import"./cli-0.5.4-jmc3bzbn.mjs";import"./cli-0.5.4-959vxhhb.mjs";import{Zma as N}from"./cli-0.5.4-aacw1src.mjs";function C(){let z,E=new Promise((H)=>{z=H}),K=_;return _=E,K.then(()=>z)}function $(z){return M(O,z)}function P(z){let E=z.match(/Created new pane:\s*(.+)/);if(E&&E[1])return E[1].trim();return""}function v(){let z=process.env.ITERM_SESSION_ID;if(!z)return null;let E=z.indexOf(":");if(E===-1)return null;return z.slice(E+1)}class w{type="iterm2";displayName="iTerm2";supportsHideShow=!1;async isAvailable(){let z=q();if(G(`[ITermBackend] isAvailable check: inITerm2=${z}`),!z)return G("[ITermBackend] isAvailable: false (not in iTerm2)"),!1;let E=await j();return G(`[ITermBackend] isAvailable: ${E} (it2 CLI ${E?"found":"not found"})`),E}async isRunningInside(){let z=q();return G(`[ITermBackend] isRunningInside: ${z}`),z}async createTeammatePaneInSwarmView(z,E){G(`[ITermBackend] createTeammatePaneInSwarmView called for ${z} with color ${E}`);let K=await C();try{while(!0){let H=!Z;G(`[ITermBackend] Creating pane: isFirstTeammate=${H}, existingPanes=${J.length}`);let Q,V;if(H){let W=v();if(W)Q=["session","split","-v","-s",W],G(`[ITermBackend] First split from leader session: ${W}`);else Q=["session","split","-v"],G("[ITermBackend] First split from active session (no leader ID)")}else if(V=J[J.length-1],V)Q=["session","split","-s",V],G(`[ITermBackend] Subsequent split from teammate session: ${V}`);else Q=["session","split"],G("[ITermBackend] Subsequent split from active session (no teammate ID)");let X=await $(Q);if(X.code!==0){if(V){let W=await $(["session","list"]);if(W.code===0&&!W.stdout.includes(V)){G(`[ITermBackend] Split failed targeting dead session ${V}, pruning and retrying: ${X.stderr}`);let y=J.indexOf(V);if(y!==-1)J.splice(y,1);if(J.length===0)Z=!1;continue}}throw Error(`Failed to create iTerm2 split pane: ${X.stderr}`)}if(H)Z=!0;let Y=P(X.stdout);if(!Y)throw Error(`Failed to parse session ID from split output: ${X.stdout}`);return G(`[ITermBackend] Created teammate pane for ${z}: ${Y}`),J.push(Y),{paneId:Y,isFirstTeammate:H}}}finally{K()}}async sendCommandToPane(z,E,K){let Q=await $(z?["session","run","-s",z,E]:["session","run",E]);if(Q.code!==0)throw Error(`Failed to send command to iTerm2 pane ${z}: ${Q.stderr}`)}async setPaneBorderColor(z,E,K){}async setPaneTitle(z,E,K,H){}async enablePaneBorderStatus(z,E){}async rebalancePanes(z,E){G("[ITermBackend] Pane rebalancing not implemented for iTerm2")}async killPane(z,E){let K=await $(["session","close","-f","-s",z]),H=J.indexOf(z);if(H!==-1)J.splice(H,1);if(J.length===0)Z=!1;return K.code===0}async hidePane(z,E){return G("[ITermBackend] hidePane not supported in iTerm2"),!1}async showPane(z,E,K){return G("[ITermBackend] showPane not supported in iTerm2"),!1}}var J,Z=!1,_;var L=N(()=>{f();U();h();R();J=[],_=Promise.resolve();B(w)});L();export{w as ITermBackend};
