"use strict";(()=>{var e={};e.id=6366,e.ids=[6366],e.modules={85890:e=>{e.exports=require("better-sqlite3")},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")},78893:e=>{e.exports=require("buffer")},61282:e=>{e.exports=require("child_process")},84770:e=>{e.exports=require("crypto")},17702:e=>{e.exports=require("events")},92048:e=>{e.exports=require("fs")},20629:e=>{e.exports=require("fs/promises")},32615:e=>{e.exports=require("http")},35240:e=>{e.exports=require("https")},98216:e=>{e.exports=require("net")},19801:e=>{e.exports=require("os")},55315:e=>{e.exports=require("path")},76162:e=>{e.exports=require("stream")},82452:e=>{e.exports=require("tls")},17360:e=>{e.exports=require("url")},21764:e=>{e.exports=require("util")},71568:e=>{e.exports=require("zlib")},45762:(e,r,t)=>{t.r(r),t.d(r,{originalPathname:()=>v,patchFetch:()=>j,requestAsyncStorage:()=>w,routeModule:()=>f,serverHooks:()=>g,staticGenerationAsyncStorage:()=>q});var s={};t.r(s),t.d(s,{POST:()=>h});var o=t(49303),n=t(88716),i=t(60670),p=t(87070),a=t(97425),u=t(75748),l=t(10927),d=t(43839),c=t(89194),m=t(63661),x=t(19377);async function h(e,{params:r}){try{let{answer:t,cliTool:s}=await e.json();if(!t)return p.NextResponse.json({error:"answer is required"},{status:400});let o=(0,a.n)(),n=(0,u.gU)(o,r.id);if(!n)return p.NextResponse.json({error:`Worktree '${r.id}' not found`},{status:404});let i=s||n.cliToolId||"claude",h=d.g.getInstance().getTool(i);if(!await h.isRunning(r.id))return p.NextResponse.json({error:`${h.name} session is not running`},{status:400});let f=h.getSessionName(r.id),w=null;try{let e=await (0,c.NA)(r.id,i,5e3),s=(0,x.vp)(e),o=(0,x.Sg)(i);if(!(w=(0,m.F)(s,o)).isPrompt)return p.NextResponse.json({success:!1,reason:"prompt_no_longer_active",answer:t})}catch{console.warn("[prompt-response] Failed to verify prompt state, proceeding with send")}try{if("claude"===i&&w?.promptData?.type==="multiple_choice"&&/^\d+$/.test(t)&&w?.promptData?.type==="multiple_choice"){let e=parseInt(t,10),r=w.promptData.options,s=r.find(e=>e.isDefault),o=s?.number??1,n=e-o;if(r.some(e=>/^\[[ x]\] /.test(e.label))){let t=r.filter(e=>/^\[[ x]\] /.test(e.label)).length,s=[];if(n>0)for(let e=0;e<n;e++)s.push("Down");else if(n<0)for(let e=0;e<Math.abs(n);e++)s.push("Up");s.push("Space");let o=t-e+1;for(let e=0;e<o;e++)s.push("Down");s.push("Enter"),await (0,l.hL)(f,s)}else{let e=[];if(n>0)for(let r=0;r<n;r++)e.push("Down");else if(n<0)for(let r=0;r<Math.abs(n);r++)e.push("Up");e.push("Enter"),await (0,l.hL)(f,e)}}else await (0,l.Is)(f,t,!1),await new Promise(e=>setTimeout(e,100)),await (0,l.Is)(f,"",!0)}catch(r){let e=r instanceof Error?r.message:"Unknown error";return p.NextResponse.json({error:`Failed to send answer to tmux: ${e}`},{status:500})}return p.NextResponse.json({success:!0,answer:t})}catch(r){console.error("Failed to respond to prompt:",r);let e=r instanceof Error?r.message:"Internal server error";return p.NextResponse.json({error:e},{status:500})}}let f=new o.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/worktrees/[id]/prompt-response/route",pathname:"/api/worktrees/[id]/prompt-response",filename:"route",bundlePath:"app/api/worktrees/[id]/prompt-response/route"},resolvedPagePath:"/home/runner/work/CommandMate/CommandMate/src/app/api/worktrees/[id]/prompt-response/route.ts",nextConfigOutput:"",userland:s}),{requestAsyncStorage:w,staticGenerationAsyncStorage:q,serverHooks:g}=f,v="/api/worktrees/[id]/prompt-response/route";function j(){return(0,i.patchFetch)({serverHooks:g,staticGenerationAsyncStorage:q})}}};var r=require("../../../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[8948,5972,3853,4893,7425,9367,7536],()=>t(45762));module.exports=s})();