"use strict";(()=>{var e={};e.id=6521,e.ids=[6521],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")},30781:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>x,patchFetch:()=>y,requestAsyncStorage:()=>d,routeModule:()=>p,serverHooks:()=>l,staticGenerationAsyncStorage:()=>m});var s={};r.r(s),r.d(s,{POST:()=>c});var n=r(49303),o=r(88716),i=r(60670),a=r(87070),u=r(10927);async function c(e,{params:t}){try{var r;let{cliToolId:s,lines:n=1e3}=await e.json();if(!s)return a.NextResponse.json({error:"Missing cliToolId"},{status:400});let o=(r=t.id,`mcbd-${s}-${r}`);if(!await u.Hk(o))return a.NextResponse.json({output:`Session not running. Starting ${s} session...
`});let i=await u.xq(o,n);return a.NextResponse.json({output:i})}catch(e){return console.error("Capture API error:",e),a.NextResponse.json({error:e.message},{status:500})}}let p=new n.AppRouteRouteModule({definition:{kind:o.x.APP_ROUTE,page:"/api/worktrees/[id]/capture/route",pathname:"/api/worktrees/[id]/capture",filename:"route",bundlePath:"app/api/worktrees/[id]/capture/route"},resolvedPagePath:"/home/runner/work/CommandMate/CommandMate/src/app/api/worktrees/[id]/capture/route.ts",nextConfigOutput:"",userland:s}),{requestAsyncStorage:d,staticGenerationAsyncStorage:m,serverHooks:l}=p,x="/api/worktrees/[id]/capture/route";function y(){return(0,i.patchFetch)({serverHooks:l,staticGenerationAsyncStorage:m})}},10927:(e,t,r)=>{r.d(t,{AJ:()=>c,Hk:()=>o,Is:()=>a,ZV:()=>p,ed:()=>i,xq:()=>u});var s=r(61282);let n=(0,r(21764).promisify)(s.exec);async function o(e){try{return await n(`tmux has-session -t "${e}"`,{timeout:5e3}),!0}catch{return!1}}async function i(e,t){let r,s,o;"string"==typeof e?(r=e,s=t,o=5e4):(r=e.sessionName,s=e.workingDirectory,o=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 ${o}`,{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,"'\\''"),o=r?`tmux send-keys -t "${e}" '${s}' C-m`:`tmux send-keys -t "${e}" '${s}'`;try{await n(o,{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 p(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(30781));module.exports=s})();