"use strict";(()=>{var e={};e.id=7586,e.ids=[7586],e.modules={20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},61282:e=>{e.exports=require("child_process")},21764:e=>{e.exports=require("util")},35135:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>x,patchFetch:()=>y,requestAsyncStorage:()=>l,routeModule:()=>d,serverHooks:()=>w,staticGenerationAsyncStorage:()=>p});var s={};r.r(s),r.d(s,{POST:()=>c});var n=r(49303),i=r(88716),o=r(60670),a=r(87070),u=r(10927);async function c(e,{params:t}){try{var r;let{cliToolId:s,command:n}=await e.json();if(!s||!n)return a.NextResponse.json({error:"Missing cliToolId or command"},{status:400});let i=(r=t.id,`mcbd-${s}-${r}`);return await u.Hk(i)||await u.ed(i,process.cwd()),await m(i,n),a.NextResponse.json({success:!0})}catch(e){return console.error("Terminal API error:",e),a.NextResponse.json({error:e.message},{status:500})}}async function m(e,t){await u.Is(e,t)}let d=new n.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/worktrees/[id]/terminal/route",pathname:"/api/worktrees/[id]/terminal",filename:"route",bundlePath:"app/api/worktrees/[id]/terminal/route"},resolvedPagePath:"/home/runner/work/CommandMate/CommandMate/src/app/api/worktrees/[id]/terminal/route.ts",nextConfigOutput:"",userland:s}),{requestAsyncStorage:l,staticGenerationAsyncStorage:p,serverHooks:w}=d,x="/api/worktrees/[id]/terminal/route";function y(){return(0,o.patchFetch)({serverHooks:w,staticGenerationAsyncStorage:p})}},10927:(e,t,r)=>{r.d(t,{AJ:()=>c,Hk:()=>i,Is:()=>a,ZV:()=>m,ed:()=>o,xq:()=>u});var s=r(61282);let n=(0,r(21764).promisify)(s.exec);async function i(e){try{return await n(`tmux has-session -t "${e}"`,{timeout:5e3}),!0}catch{return!1}}async function o(e,t){let r,s,i;"string"==typeof e?(r=e,s=t,i=5e4):(r=e.sessionName,s=e.workingDirectory,i=e.historyLimit||5e4);try{await n(`tmux new-session -d -s "${r}" -c "${s}"`,{timeout:5e3}),await n(`tmux set-option -t "${r}" history-limit ${i}`,{timeout:5e3})}catch(t){let e=t instanceof Error?t.message:String(t);throw Error(`Failed to create tmux session: ${e}`)}}async function a(e,t,r=!0){let s=t.replace(/'/g,"'\\''"),i=r?`tmux send-keys -t "${e}" '${s}' C-m`:`tmux send-keys -t "${e}" '${s}'`;try{await n(i,{timeout:5e3})}catch(t){let e=t instanceof Error?t.message:String(t);throw Error(`Failed to send keys to tmux session: ${e}`)}}async function u(e,t){let r,s;"number"==typeof t?(r=-t,s="-"):t?(r=t.startLine??-1e4,s=t.endLine??"-"):(r=-1e3,s="-");try{let{stdout:t}=await n(`tmux capture-pane -t "${e}" -p -e -S ${r} -E ${s}`,{timeout:5e3,maxBuffer:10485760});return t}catch(t){let e=t instanceof Error?t.message:String(t);throw Error(`Failed to capture pane: ${e}`)}}async function c(e){try{return await n(`tmux kill-session -t "${e}"`,{timeout:5e3}),!0}catch(t){let e=t instanceof Error?t.message:String(t);if(e?.includes("no server running")||e?.includes("can't find session"))return!1;throw Error(`Failed to kill tmux session: ${e}`)}}async function m(e,t){try{await n(`tmux send-keys -t "${e}" ${t}`,{timeout:5e3})}catch(t){let e=t instanceof Error?t.message:String(t);throw Error(`Failed to send special key: ${e}`)}}}};var t=require("../../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),s=t.X(0,[8948,5972],()=>r(35135));module.exports=s})();