"use strict";(()=>{var e={};e.id=4931,e.ids=[4931],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")},61282:e=>{e.exports=require("child_process")},84770:e=>{e.exports=require("crypto")},92048:e=>{e.exports=require("fs")},19801:e=>{e.exports=require("os")},55315:e=>{e.exports=require("path")},21764:e=>{e.exports=require("util")},46769:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>y,patchFetch:()=>R,requestAsyncStorage:()=>x,routeModule:()=>h,serverHooks:()=>v,staticGenerationAsyncStorage:()=>k});var o={};r.r(o),r.d(o,{GET:()=>f,PATCH:()=>w});var i=r(49303),n=r(88716),s=r(60670),a=r(87070),u=r(97425),d=r(75748),l=r(97213),c=r(89194),p=r(19377),g=r(63661),m=r(3979);async function f(e,{params:t}){try{let e;let r=(0,u.n)(),o=(0,d.gU)(r,t.id);if(!o)return a.NextResponse.json({error:`Worktree '${t.id}' not found`},{status:404});let i=l.g.getInstance(),n={},s=!1,f=!1,w=!1;for(let e of["claude","codex","gemini"]){let o=i.getTool(e),a=await o.isRunning(t.id),u=!1,l=!1;if(a)try{let o=await (0,c.NA)(t.id,e,100),i=(0,p.vp)(o),n=(0,g.F)(i);if(n.isPrompt)u=!0;else{let t=i.split("\n").filter(e=>""!==e.trim()).slice(-15).join("\n");(0,p.Wg)(e,t)?l=!0:/^[>❯](\s*$|\s+\S)/m.test(t)||(l=!0)}!n.isPrompt&&(0,d._U)(r,t.id,void 0,10,e).some(e=>"prompt"===e.messageType&&e.promptData?.status!=="answered")&&(0,d.GP)(r,t.id,e)}catch{l=!0}n[e]={isRunning:a,isWaitingForResponse:u,isProcessing:l},a&&(s=!0),u&&(f=!0),l&&(w=!0)}try{let i=(0,d.Q7)(r,t.id);e=await (0,m.v)(o.path,i)}catch(e){console.error("[GET /api/worktrees/:id] Failed to get git status:",e)}return a.NextResponse.json({...o,gitStatus:e,isSessionRunning:s,isWaitingForResponse:f,isProcessing:w,sessionStatusByCli:n},{status:200})}catch(e){return console.error("Error fetching worktree:",e),a.NextResponse.json({error:"Failed to fetch worktree"},{status:500})}}async function w(e,{params:t}){try{let r=(0,u.n)();if(!(0,d.gU)(r,t.id))return a.NextResponse.json({error:`Worktree '${t.id}' not found`},{status:404});let o=await e.json();"description"in o&&(0,d.xr)(r,t.id,o.description),"link"in o&&(0,d.y)(r,t.id,o.link),"favorite"in o&&"boolean"==typeof o.favorite&&(0,d.R3)(r,t.id,o.favorite),"status"in o&&["todo","doing","done",null].includes(o.status)&&(0,d.Nf)(r,t.id,o.status),"cliToolId"in o&&["claude","codex","gemini"].includes(o.cliToolId)&&(0,d.VW)(r,t.id,o.cliToolId);let i=(0,d.gU)(r,t.id),n=l.g.getInstance(),s=i?.cliToolId||"claude",c=n.getTool(s),p=await c.isRunning(t.id);return a.NextResponse.json({...i,isSessionRunning:p},{status:200})}catch(e){return console.error("Error updating worktree:",e),a.NextResponse.json({error:"Failed to update worktree"},{status:500})}}let h=new i.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/worktrees/[id]/route",pathname:"/api/worktrees/[id]",filename:"route",bundlePath:"app/api/worktrees/[id]/route"},resolvedPagePath:"/home/runner/work/CommandMate/CommandMate/src/app/api/worktrees/[id]/route.ts",nextConfigOutput:"",userland:o}),{requestAsyncStorage:x,staticGenerationAsyncStorage:k,serverHooks:v}=h,y="/api/worktrees/[id]/route";function R(){return(0,s.patchFetch)({serverHooks:v,staticGenerationAsyncStorage:k})}},3979:(e,t,r)=>{r.d(t,{v:()=>s});var o=r(61282);let i=(0,r(21764).promisify)(o.execFile);async function n(e,t){try{let{stdout:r}=await i("git",e,{cwd:t,timeout:1e3});return r.trim()}catch(t){return console.error("[git-utils] Git command failed:",{args:e,error:t instanceof Error?t.message:"Unknown error"}),null}}async function s(e,t){let r;let o=await n(["rev-parse","--abbrev-ref","HEAD"],e);r=null===o?"(unknown)":"HEAD"===o?"(detached HEAD)":o;let i=await n(["rev-parse","--short","HEAD"],e),s=await n(["status","--porcelain"],e);return{currentBranch:r,initialBranch:t,isBranchMismatch:null!==t&&"(unknown)"!==r&&"(detached HEAD)"!==r&&r!==t,commitHash:i??"(unknown)",isDirty:null!==s&&s.length>0}}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),o=t.X(0,[8948,5972,7425,7213,1528],()=>r(46769));module.exports=o})();