(()=>{var a={};a.id=506,a.ids=[506],a.modules={261:a=>{"use strict";a.exports=require("next/dist/shared/lib/router/utils/app-paths")},3295:a=>{"use strict";a.exports=require("next/dist/server/app-render/after-task-async-storage.external.js")},10846:a=>{"use strict";a.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},29294:a=>{"use strict";a.exports=require("next/dist/server/app-render/work-async-storage.external.js")},31421:a=>{"use strict";a.exports=require("node:child_process")},44870:a=>{"use strict";a.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},48161:a=>{"use strict";a.exports=require("node:os")},51455:a=>{"use strict";a.exports=require("node:fs/promises")},63033:a=>{"use strict";a.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},73024:a=>{"use strict";a.exports=require("node:fs")},74423:(a,b,c)=>{"use strict";let d;c.d(b,{BE:()=>r,Xo:()=>p,dk:()=>u,fQ:()=>q,jw:()=>t});var e=c(77598),f=c.n(e),g=c(73024),h=c(51455),i=c(48161),j=c(76760),k=c.n(j);let l=k().join((0,i.homedir)(),".cockpit"),m=k().join(l,"password.json");function n(a,b){return new Promise((c,d)=>{f().scrypt(a,b,64,(a,b)=>{a?d(a):c(b)})})}function o(){return null==d&&(d=function(){if(!(0,g.existsSync)(m))return null;try{let a=c(73024).readFileSync(m,"utf-8"),b=JSON.parse(a);if(b.hash&&b.salt)return b;return null}catch{return null}}()),d}function p(){return null===o()}async function q(a){await (0,h.mkdir)(l,{recursive:!0});let b=f().randomBytes(32),c={hash:(await n(a,b)).toString("hex"),salt:b.toString("hex")};await (0,h.writeFile)(m,JSON.stringify(c),"utf-8"),d=c}async function r(a){let b=o();if(!b)return!1;let c=Buffer.from(b.salt,"hex"),d=await n(a,c),e=Buffer.from(b.hash,"hex");return d.length===e.length&&f().timingSafeEqual(d,e)}function s(){let a=o();return a?.hash??null}function t(){let a=s();if(!a)return"";let b=Date.now().toString(16),c=f().createHmac("sha256",a).update(b).digest("hex");return`${b}.${c}`}function u(a){let b=s();if(!b)return!1;let c=a.indexOf(".");if(-1===c)return!1;let d=a.slice(0,c),e=a.slice(c+1),g=f().createHmac("sha256",b).update(d).digest("hex");return e.length===g.length&&f().timingSafeEqual(Buffer.from(e,"hex"),Buffer.from(g,"hex"))}},75145:(a,b,c)=>{"use strict";c.r(b),c.d(b,{handler:()=>I,patchFetch:()=>H,routeModule:()=>D,serverHooks:()=>G,workAsyncStorage:()=>E,workUnitAsyncStorage:()=>F});var d={};c.r(d),c.d(d,{POST:()=>C});var e=c(19225),f=c(84006),g=c(8317),h=c(99373),i=c(34775),j=c(24235),k=c(261),l=c(54365),m=c(90771),n=c(73461),o=c(67798),p=c(92280),q=c(62018),r=c(45696),s=c(47929),t=c(86439),u=c(37527),v=c(31421),w=c(48161),x=c.n(w),y=c(23211),z=c(74423);function A(a,b,c){return new Promise((d,e)=>{(0,v.execFile)(a,b,{cwd:c,maxBuffer:5242880},(a,b)=>{a?e(a):d(b)})})}let B=`Generate a git commit message for the changes below.

Rules:
- First line: short summary under 72 characters, imperative mood (e.g. "Add", "Fix", "Update")
- If needed, add a blank line then a brief body with bullet points
- Focus on the "why" not the "what" when possible

Changes:
`;async function C(a){let b;if(!((b=a.cookies.get("cockpit_session")?.value||a.headers.get("authorization")?.replace("Bearer ",""))&&(0,z.dk)(b)))return y.NextResponse.json({error:"Unauthorized"},{status:401});let{cwd:c,files:d}=await a.json();if(!c||!d?.length)return y.NextResponse.json({error:"cwd and files are required"},{status:400});try{let a,b="";try{b=await A("git",["diff","--numstat","HEAD","--",...d],c)}catch{try{b=await A("git",["diff","--numstat","--cached","--",...d],c)}catch{}}let e="";try{e=await A("git",["diff","--stat","-p","-U1","HEAD","--",...d],c)}catch{try{e=await A("git",["diff","--stat","-p","-U1","--cached","--",...d],c)}catch{}}e.length>4e3&&(e=e.slice(0,4e3)+"\n[truncated]");let f=B+(b?`Summary:
${b}
`:"")+e,g=await function(a,b,c,d,e=!1){return new Promise((f,g)=>{let h="win32"===process.platform,i=e?{PATH:process.env.PATH||"",HOME:process.env.HOME||x().homedir(),USER:process.env.USER||x().userInfo().username,...h?{USERPROFILE:process.env.USERPROFILE||x().homedir(),HOMEDRIVE:process.env.HOMEDRIVE||"",HOMEPATH:process.env.HOMEPATH||"",SYSTEMROOT:process.env.SYSTEMROOT||""}:{TERM:"xterm-256color"}}:Object.fromEntries(Object.entries(process.env).filter(a=>null!=a[1]));delete i.CLAUDECODE,delete i.CLAUDE_CODE_ENTRYPOINT;let j=(0,v.spawn)(a,b,{cwd:c,env:i,...h?{shell:!0}:{detached:!0}}),k="",l="";j.stdout.on("data",a=>{k+=a.toString()}),j.stderr.on("data",a=>{l+=a.toString()}),j.on("error",g),j.on("close",a=>{0!==a?(console.error("[generate-message] CLI exit code:",a,"stderr:",l,"stdout:",k.slice(0,500)),g(Error(l||k||`Process exited with code ${a}`))):f(k)}),j.stdin.write(d),j.stdin.end()})}("claude",["-p","--model","sonnet","--effort","low","--output-format","json","--system-prompt","Output ONLY the commit message. No explanations, no markdown, no quotes, no preamble.","--no-session-persistence","--tools","","--disable-slash-commands","--setting-sources","","--permission-mode","bypassPermissions"],c,f,!0);try{a=JSON.parse(g).result||""}catch{a=g}if(!(a=a.replace(/^(?:here(?:'s| is)(?: your| the| a)? commit message:?\s*)/i,"").replace(/^```\n?/,"").replace(/\n?```$/,"").trim()))return console.error("[generate-message] empty result, raw output:",g.slice(0,500)),y.NextResponse.json({error:"Empty response from model"},{status:500});return y.NextResponse.json({message:a})}catch(b){let a=b instanceof Error?b.message:"Failed to generate message";return console.error("[generate-message] error:",a),y.NextResponse.json({error:a},{status:500})}}let D=new e.AppRouteRouteModule({definition:{kind:f.RouteKind.APP_ROUTE,page:"/api/git/generate-message/route",pathname:"/api/git/generate-message",filename:"route",bundlePath:"app/api/git/generate-message/route"},distDir:".next",relativeProjectDir:"",resolvedPagePath:"/home/dev/repos/cockpit/src/app/api/git/generate-message/route.ts",nextConfigOutput:"",userland:d,...{}}),{workAsyncStorage:E,workUnitAsyncStorage:F,serverHooks:G}=D;function H(){return(0,g.patchFetch)({workAsyncStorage:E,workUnitAsyncStorage:F})}async function I(a,b,c){c.requestMeta&&(0,h.setRequestMeta)(a,c.requestMeta),D.isDev&&(0,h.addRequestMeta)(a,"devRequestTimingInternalsEnd",process.hrtime.bigint());let d="/api/git/generate-message/route";"/index"===d&&(d="/");let e=await D.prepare(a,b,{srcPage:d,multiZoneDraftMode:!1});if(!e)return b.statusCode=400,b.end("Bad Request"),null==c.waitUntil||c.waitUntil.call(c,Promise.resolve()),null;let{buildId:g,params:v,nextConfig:w,parsedUrl:x,isDraftMode:y,prerenderManifest:z,routerServerContext:A,isOnDemandRevalidate:B,revalidateOnlyGenerated:C,resolvedPathname:E,clientReferenceManifest:F,serverActionsManifest:G}=e,H=(0,k.normalizeAppPath)(d),I=!!(z.dynamicRoutes[H]||z.routes[E]),J=async()=>((null==A?void 0:A.render404)?await A.render404(a,b,x,!1):b.end("This page could not be found"),null);if(I&&!y){let a=!!z.routes[E],b=z.dynamicRoutes[H];if(b&&!1===b.fallback&&!a){if(w.adapterPath)return await J();throw new t.NoFallbackError}}let K=null;!I||D.isDev||y||(K="/index"===(K=E)?"/":K);let L=!0===D.isDev||!I,M=I&&!L;G&&F&&(0,j.setManifestsSingleton)({page:d,clientReferenceManifest:F,serverActionsManifest:G});let N=a.method||"GET",O=(0,i.getTracer)(),P=O.getActiveScopeSpan(),Q=!!(null==A?void 0:A.isWrappedByNextServer),R=!!(0,h.getRequestMeta)(a,"minimalMode"),S=(0,h.getRequestMeta)(a,"incrementalCache")||await D.getIncrementalCache(a,w,z,R);null==S||S.resetRequestCache(),globalThis.__incrementalCache=S;let T={params:v,previewProps:z.preview,renderOpts:{experimental:{authInterrupts:!!w.experimental.authInterrupts},cacheComponents:!!w.cacheComponents,supportsDynamicResponse:L,incrementalCache:S,cacheLifeProfiles:w.cacheLife,waitUntil:c.waitUntil,onClose:a=>{b.on("close",a)},onAfterTaskError:void 0,onInstrumentationRequestError:(b,c,d,e)=>D.onRequestError(a,b,d,e,A)},sharedContext:{buildId:g}},U=new l.NodeNextRequest(a),V=new l.NodeNextResponse(b),W=m.NextRequestAdapter.fromNodeNextRequest(U,(0,m.signalFromNodeResponse)(b));try{let e,g=async a=>D.handle(W,T).finally(()=>{if(!a)return;a.setAttributes({"http.status_code":b.statusCode,"next.rsc":!1});let c=O.getRootSpanAttributes();if(!c)return;if(c.get("next.span_type")!==n.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${c.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let f=c.get("next.route");if(f){let b=`${N} ${f}`;a.setAttributes({"next.route":f,"http.route":f,"next.span_name":b}),a.updateName(b),e&&e!==a&&(e.setAttribute("http.route",f),e.updateName(b))}else a.updateName(`${N} ${d}`)}),h=async e=>{var h,i;let j=async({previousCacheEntry:f})=>{try{if(!R&&B&&C&&!f)return b.statusCode=404,b.setHeader("x-nextjs-cache","REVALIDATED"),b.end("This page could not be found"),null;let d=await g(e);a.fetchMetrics=T.renderOpts.fetchMetrics;let h=T.renderOpts.pendingWaitUntil;h&&c.waitUntil&&(c.waitUntil(h),h=void 0);let i=T.renderOpts.collectedTags;if(!I)return await (0,p.I)(U,V,d,T.renderOpts.pendingWaitUntil),null;{let a=await d.blob(),b=(0,q.toNodeOutgoingHttpHeaders)(d.headers);i&&(b[s.NEXT_CACHE_TAGS_HEADER]=i),!b["content-type"]&&a.type&&(b["content-type"]=a.type);let c=void 0!==T.renderOpts.collectedRevalidate&&!(T.renderOpts.collectedRevalidate>=s.INFINITE_CACHE)&&T.renderOpts.collectedRevalidate,e=void 0===T.renderOpts.collectedExpire||T.renderOpts.collectedExpire>=s.INFINITE_CACHE?void 0:T.renderOpts.collectedExpire;return{value:{kind:u.CachedRouteKind.APP_ROUTE,status:d.status,body:Buffer.from(await a.arrayBuffer()),headers:b},cacheControl:{revalidate:c,expire:e}}}}catch(b){throw(null==f?void 0:f.isStale)&&await D.onRequestError(a,b,{routerKind:"App Router",routePath:d,routeType:"route",revalidateReason:(0,o.c)({isStaticGeneration:M,isOnDemandRevalidate:B})},!1,A),b}},k=await D.handleResponse({req:a,nextConfig:w,cacheKey:K,routeKind:f.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:z,isRoutePPREnabled:!1,isOnDemandRevalidate:B,revalidateOnlyGenerated:C,responseGenerator:j,waitUntil:c.waitUntil,isMinimalMode:R});if(!I)return null;if((null==k||null==(h=k.value)?void 0:h.kind)!==u.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==k||null==(i=k.value)?void 0:i.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});R||b.setHeader("x-nextjs-cache",B?"REVALIDATED":k.isMiss?"MISS":k.isStale?"STALE":"HIT"),y&&b.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let l=(0,q.fromNodeOutgoingHttpHeaders)(k.value.headers);return R&&I||l.delete(s.NEXT_CACHE_TAGS_HEADER),!k.cacheControl||b.getHeader("Cache-Control")||l.get("Cache-Control")||l.set("Cache-Control",(0,r.getCacheControlHeader)(k.cacheControl)),await (0,p.I)(U,V,new Response(k.value.body,{headers:l,status:k.value.status||200})),null};Q&&P?await h(P):(e=O.getActiveScopeSpan(),await O.withPropagatedContext(a.headers,()=>O.trace(n.BaseServerSpan.handleRequest,{spanName:`${N} ${d}`,kind:i.SpanKind.SERVER,attributes:{"http.method":N,"http.target":a.url}},h),void 0,!Q))}catch(b){if(b instanceof t.NoFallbackError||await D.onRequestError(a,b,{routerKind:"App Router",routePath:H,routeType:"route",revalidateReason:(0,o.c)({isStaticGeneration:M,isOnDemandRevalidate:B})},!1,A),I)throw b;return await (0,p.I)(U,V,new Response(null,{status:500})),null}}},76760:a=>{"use strict";a.exports=require("node:path")},77598:a=>{"use strict";a.exports=require("node:crypto")},78335:()=>{},86439:a=>{"use strict";a.exports=require("next/dist/shared/lib/no-fallback-error.external")},96487:()=>{}};var b=require("../../../../webpack-runtime.js");b.C(a);var c=b.X(0,[3445,1813],()=>b(b.s=75145));module.exports=c})();