"use strict";(()=>{var e={};e.id=6865,e.ids=[6865],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")},75144:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>w,patchFetch:()=>x,requestAsyncStorage:()=>g,routeModule:()=>m,serverHooks:()=>v,staticGenerationAsyncStorage:()=>y});var o={};r.r(o),r.d(o,{POST:()=>f});var s=r(49303),n=r(88716),i=r(60670),a=r(87070),p=r(55315),l=r.n(p),u=r(97425),c=r(67722),d=r(57440),h=r(93346);async function f(e){try{let{repositoryPath:t}=await e.json();if(!t||"string"!=typeof t)return a.NextResponse.json({error:"Repository path is required"},{status:400});let{CM_ROOT_DIR:r}=(0,h.dU)();if(!(0,d.j)(t,r))return a.NextResponse.json({error:"Invalid or unsafe repository path"},{status:400});let o=l().resolve(r,t),s=await (0,c.e9)(o);if(0===s.length)return a.NextResponse.json({error:"No worktrees found in the specified path. Make sure it is a valid git repository."},{status:404});let n=(0,u.n)();return(0,c.h2)(n,s),a.NextResponse.json({success:!0,message:`Successfully scanned and added ${s.length} worktree(s)`,worktreeCount:s.length,repositoryPath:s[0].repositoryPath,repositoryName:s[0].repositoryName},{status:200})}catch(t){console.error("Error scanning repository:",t);let e=t instanceof Error?t.message:"Failed to scan repository";return a.NextResponse.json({error:e},{status:500})}}let m=new s.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/repositories/scan/route",pathname:"/api/repositories/scan",filename:"route",bundlePath:"app/api/repositories/scan/route"},resolvedPagePath:"/home/runner/work/CommandMate/CommandMate/src/app/api/repositories/scan/route.ts",nextConfigOutput:"",userland:o}),{requestAsyncStorage:g,staticGenerationAsyncStorage:y,serverHooks:v}=m,w="/api/repositories/scan/route";function x(){return(0,i.patchFetch)({serverHooks:v,staticGenerationAsyncStorage:y})}},57440:(e,t,r)=>{r.d(t,{j:()=>n});var o=r(55315),s=r.n(o);function n(e,t){if(!e||""===e.trim()||e.includes("\0"))return!1;let r=e;try{r=decodeURIComponent(e)}catch{r=e}if(r.includes("\0"))return!1;let o=s().resolve(t),n=s().resolve(t,r),i=s().relative(o,n);return!(i.startsWith("..")||s().isAbsolute(i))}},67722:(e,t,r)=>{r.d(t,{Lj:()=>c,a$:()=>l,e9:()=>u,h2:()=>d});var o=r(61282),s=r(21764),n=r(55315),i=r.n(n),a=r(75748),p=r(93346);function l(){let e=process.env.WORKTREE_REPOS;if(e&&e.trim())return e.split(",").map(e=>e.trim()).filter(e=>e.length>0);let t=(0,p.Hb)("CM_ROOT_DIR");return t&&t.trim()?[t.trim()]:[]}async function u(e){let t=(0,s.promisify)(o.exec);try{let{stdout:r}=await t("git worktree list",{cwd:e}),o=function(e){if(!e||""===e.trim())return[];let t=e.trim().split("\n"),r=[];for(let e of t){let t=e.trim();if(!t)continue;let o=t.match(/^(.+?)\s+([a-z0-9]+)\s+(?:\[(.+?)\]|\(detached HEAD\))/);if(o){let[,e,t,s]=o;r.push({path:e.trim(),branch:s||`detached-${t}`,commit:t})}}return r}(r),s=i().resolve(e),n=i().basename(s);return o.map(e=>({id:function(e,t){if(!e)return"";let r=e=>e.toLowerCase().replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,""),o=r(e);if(t){let e=r(t);return`${e}-${o}`}return o}(e.branch,n),name:e.branch,path:i().resolve(e.path),repositoryPath:s,repositoryName:n})).filter(e=>["/etc","/root","/sys","/proc","/dev","/boot","/bin","/sbin","/usr/bin","/usr/sbin"].some(t=>e.path.startsWith(t))?(console.warn(`Skipping potentially unsafe worktree path: ${e.path}`),!1):!(e.path.includes("\0")||e.path.includes(".."))||(console.warn(`Skipping path with potentially malicious characters: ${e.path}`),!1))}catch(r){let e=r instanceof Error?r.message:String(r),t=r.code;if(e?.includes("not a git repository")||128===t)return[];throw r}}async function c(e){let t=[];for(let r of e)try{console.log(`Scanning repository: ${r}`);let e=await u(r);t.push(...e),console.log(`  Found ${e.length} worktree(s)`)}catch(e){console.error(`Error scanning repository ${r}:`,e)}return t}function d(e,t){if(0===t.length)return;let r=new Map;for(let e of t){let t=e.repositoryPath||"";r.has(t)||r.set(t,[]),r.get(t).push(e)}for(let[t,o]of r){if(!t)continue;let r=(0,a.Pv)(e,t),s=new Set(o.map(e=>e.id)),n=r.filter(e=>!s.has(e));if(n.length>0){let r=(0,a.pM)(e,n);console.log(`Removed ${r.deletedCount} deleted worktree(s) from ${t}`)}for(let t of o)(0,a.ly)(e,t)}}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),o=t.X(0,[8948,5972,7425],()=>r(75144));module.exports=o})();