UNPKG

aicommit2

Version:

A Reactive CLI that generates commit messages for Git and Jujutsu with various AI

16 lines 173 kB
import{command as F,cli as hs}from"cleye";import{createRequire as gs}from"module";import mo from"crypto";import O from"fs";import ue from"os";import P from"path";import{Buffer as fo}from"node:buffer";import ae from"node:path";import yt,{ChildProcess as po,exec as ys}from"node:child_process";import U from"node:process";import ws,{execSync as Pe,exec as Cs}from"child_process";import{fileURLToPath as ho}from"node:url";import bs,{constants as go}from"node:os";import Es from"assert";import vs from"events";import{createWriteStream as Ps,createReadStream as As,readFileSync as xs}from"node:fs";import Ss from"buffer";import wt from"stream";import $s,{promisify as Rs}from"util";import{debuglog as Is,promisify as ks}from"node:util";import T from"inquirer";import{from as Be,switchMap as yo,of as Ls,tap as Ms,mergeMap as wo,catchError as Os,BehaviorSubject as Co,ReplaySubject as Ts,Subscription as Ct,lastValueFrom as bt,toArray as Et,filter as bo,map as Eo,Subject as Ds}from"rxjs";import I from"fs/promises";import h from"chalk";import He from"readline";import vo from"figlet";import Ns from"gradient-string";import Po from"ora";import _s from"inquirer-reactive-list-prompt";import K from"winston";import"winston-daily-rotate-file";import js from"axios";import{fileURLToPath as Fs,pathToFileURL as Gs}from"url";import{readdir as Ao,stat as Bs,rm as Hs}from"node:fs/promises";import Us from"chokidar";import{takeUntil as xo,finalize as So}from"rxjs/operators";var Ks="aicommit2",$o="2.5.21",Ws="A Reactive CLI that generates commit messages for Git and Jujutsu with various AI",qs=["cli","ai","git","jujutsu","jj","vcs","version-control","commit","git-commit","jujutsu-commit","command-line","commandline","aipick","aicommit","aicommits","aicommit2","openai","huggingface","anthropic","claude","claude3","gemini","gemini-pro","generative-ai","mistral","ollama","llama3","llama3.2","llama3.3","gemma","llm","chatgpt","cohere","groq","codestral","perplexity","deepseek","deepseek-r1","pre-commit"],zs="MIT",Ys="tak-bro/aicommit2",Vs="Hyungtak Jin(@tak-bro)",Js="module",Xs=["dist"],Qs={aicommit2:"./dist/cli.mjs",aic2:"./dist/cli.mjs"},Zs={prepare:"simple-git-hooks",build:"pkgroll --minify",lint:"eslint --cache .","type-check":"tsc",test:"tsx tests",prepack:"pnpm build && clean-pkg-json",prettier:"prettier"},er={"@anthropic-ai/sdk":"^0.39.0","@aws-sdk/client-bedrock-runtime":"^3.678.0","@aws-sdk/credential-providers":"^3.678.0","@dqbd/tiktoken":"^1.0.21","@google/generative-ai":"^0.24.1","@inquirer/prompts":"^3.3.2","@pacote/xxhash":"^0.3.2","@types/winston":"^2.4.4",axios:"^1.9.0",chalk:"^5.4.1",chokidar:"^4.0.3",cleye:"^1.3.4","cohere-ai":"^7.19.0","copy-paste":"^1.5.3",figlet:"^1.8.1","formdata-node":"^6.0.3","gradient-string":"^3.0.0","groq-sdk":"^0.7.0",inquirer:"9.2.8","inquirer-reactive-list-prompt":"1.1.0",ollama:"^0.5.15",openai:"^6.3.0",ora:"^8.2.0",readline:"^1.3.0",rxjs:"^7.8.2",undici:"^7.10.0",uuid:"^9.0.1",winston:"^3.17.0","winston-daily-rotate-file":"^5.0.0"},tr={"@github/copilot-sdk":"0.2.0"},or={"@pvtnbr/eslint-config":"^0.33.0","@semantic-release/changelog":"^6.0.3","@semantic-release/commit-analyzer":"^12.0.0","@semantic-release/git":"^10.0.1","@semantic-release/github":"^10.3.5","@semantic-release/npm":"^12.0.1","@semantic-release/release-notes-generator":"^13.0.0","@types/figlet":"^1.7.0","@types/ini":"^1.3.34","@types/inquirer":"^9.0.8","@types/node":"^18.19.103","@types/uuid":"^9.0.8","@typescript-eslint/eslint-plugin":"^6.21.0","@typescript-eslint/parser":"^6.21.0","clean-pkg-json":"^1.3.0","conventional-changelog-conventionalcommits":"^7.0.2","conventional-commits-parser":"^5.0.0",eslint:"^8.57.1","eslint-config-prettier":"^8.10.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.31.0","eslint-plugin-jsonc":"^2.20.1","eslint-plugin-no-use-extend-native":"^0.5.0","eslint-plugin-promise":"^6.6.0","eslint-plugin-unicorn":"^49.0.0","eslint-plugin-unused-imports":"^3.2.0",execa:"^7.2.0","fs-fixture":"^1.2.0","https-proxy-agent":"^5.0.1",ini:"^3.0.1","lint-staged":"^13.3.0",manten:"^0.7.0",pkgroll:"^1.11.1",prettier:"^3.5.3","semantic-release":"^23.1.1","simple-git-hooks":"^2.13.0",tsx:"^3.14.0",typescript:"^4.9.5","undici-types":"^7.10.0"},nr={extends:["@pvtnbr","prettier"],rules:{"unicorn/no-process-exit":"off"},overrides:[{files:"./src/commands/prepare-commit-msg-hook.ts",rules:{"unicorn/prevent-abbreviations":"off"}}]},sr={branches:["main"],plugins:[["@semantic-release/commit-analyzer",{preset:"conventionalcommits",releaseRules:[{type:"docs",release:!1},{type:"style",release:!1},{type:"test",release:!1},{type:"ci",release:!1},{type:"refactor",release:"patch"},{type:"chore",release:"patch"},{type:"feat",release:"patch"},{scope:"major",release:"major"},{scope:"minor",release:"minor"},{scope:"patch",release:"patch"}]}],"@semantic-release/release-notes-generator",["@semantic-release/changelog",{changelogFile:"CHANGELOG.md"}],"@semantic-release/github",["@semantic-release/git",{assets:["CHANGELOG.md"],message:"chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"}],"@semantic-release/npm"]},rr={name:Ks,version:$o,description:Ws,keywords:qs,license:zs,repository:Ys,author:Vs,type:Js,files:Xs,bin:Qs,scripts:Zs,"simple-git-hooks":{"pre-commit":"pnpm lint-staged"},"lint-staged":{"*.ts":["prettier --config ./.prettierrc --write","eslint --fix"]},dependencies:er,optionalDependencies:tr,devDependencies:or,eslintConfig:nr,release:sr},vt=gs(import.meta.url),ne=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function de(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var me={exports:{}},Pt,Ro;function ir(){if(Ro)return Pt;Ro=1,Pt=n,n.sync=s;var e=O;function t(r,a){var c=a.pathExt!==void 0?a.pathExt:process.env.PATHEXT;if(!c||(c=c.split(";"),c.indexOf("")!==-1))return!0;for(var l=0;l<c.length;l++){var u=c[l].toLowerCase();if(u&&r.substr(-u.length).toLowerCase()===u)return!0}return!1}function o(r,a,c){return!r.isSymbolicLink()&&!r.isFile()?!1:t(a,c)}function n(r,a,c){e.stat(r,function(l,u){c(l,l?!1:o(u,r,a))})}function s(r,a){return o(e.statSync(r),r,a)}return Pt}var At,Io;function ar(){if(Io)return At;Io=1,At=t,t.sync=o;var e=O;function t(r,a,c){e.stat(r,function(l,u){c(l,l?!1:n(u,a))})}function o(r,a){return n(e.statSync(r),a)}function n(r,a){return r.isFile()&&s(r,a)}function s(r,a){var c=r.mode,l=r.uid,u=r.gid,d=a.uid!==void 0?a.uid:process.getuid&&process.getuid(),p=a.gid!==void 0?a.gid:process.getgid&&process.getgid(),g=parseInt("100",8),y=parseInt("010",8),f=parseInt("001",8),S=g|y,$=c&f||c&y&&u===p||c&g&&l===d||c&S&&d===0;return $}return At}var Ue;process.platform==="win32"||ne.TESTING_WINDOWS?Ue=ir():Ue=ar();var cr=xt;xt.sync=lr;function xt(e,t,o){if(typeof t=="function"&&(o=t,t={}),!o){if(typeof Promise!="function")throw new TypeError("callback not provided");return new Promise(function(n,s){xt(e,t||{},function(r,a){r?s(r):n(a)})})}Ue(e,t||{},function(n,s){n&&(n.code==="EACCES"||t&&t.ignoreErrors)&&(n=null,s=!1),o(n,s)})}function lr(e,t){try{return Ue.sync(e,t||{})}catch(o){if(t&&t.ignoreErrors||o.code==="EACCES")return!1;throw o}}const fe=process.platform==="win32"||process.env.OSTYPE==="cygwin"||process.env.OSTYPE==="msys",ko=P,ur=fe?";":":",Lo=cr,Mo=e=>Object.assign(new Error(`not found: ${e}`),{code:"ENOENT"}),Oo=(e,t)=>{const o=t.colon||ur,n=e.match(/\//)||fe&&e.match(/\\/)?[""]:[...fe?[process.cwd()]:[],...(t.path||process.env.PATH||"").split(o)],s=fe?t.pathExt||process.env.PATHEXT||".EXE;.CMD;.BAT;.COM":"",r=fe?s.split(o):[""];return fe&&e.indexOf(".")!==-1&&r[0]!==""&&r.unshift(""),{pathEnv:n,pathExt:r,pathExtExe:s}},To=(e,t,o)=>{typeof t=="function"&&(o=t,t={}),t||(t={});const{pathEnv:n,pathExt:s,pathExtExe:r}=Oo(e,t),a=[],c=u=>new Promise((d,p)=>{if(u===n.length)return t.all&&a.length?d(a):p(Mo(e));const g=n[u],y=/^".*"$/.test(g)?g.slice(1,-1):g,f=ko.join(y,e),S=!y&&/^\.[\\\/]/.test(e)?e.slice(0,2)+f:f;d(l(S,u,0))}),l=(u,d,p)=>new Promise((g,y)=>{if(p===s.length)return g(c(d+1));const f=s[p];Lo(u+f,{pathExt:r},(S,$)=>{if(!S&&$)if(t.all)a.push(u+f);else return g(u+f);return g(l(u,d,p+1))})});return o?c(0).then(u=>o(null,u),o):c(0)},dr=(e,t)=>{t=t||{};const{pathEnv:o,pathExt:n,pathExtExe:s}=Oo(e,t),r=[];for(let a=0;a<o.length;a++){const c=o[a],l=/^".*"$/.test(c)?c.slice(1,-1):c,u=ko.join(l,e),d=!l&&/^\.[\\\/]/.test(e)?e.slice(0,2)+u:u;for(let p=0;p<n.length;p++){const g=d+n[p];try{if(Lo.sync(g,{pathExt:s}))if(t.all)r.push(g);else return g}catch{}}}if(t.all&&r.length)return r;if(t.nothrow)return null;throw Mo(e)};var mr=To;To.sync=dr;var St={exports:{}};const Do=(e={})=>{const t=e.env||process.env;return(e.platform||process.platform)!=="win32"?"PATH":Object.keys(t).reverse().find(n=>n.toUpperCase()==="PATH")||"Path"};St.exports=Do,St.exports.default=Do;var fr=St.exports;const No=P,pr=mr,hr=fr;function _o(e,t){const o=e.options.env||process.env,n=process.cwd(),s=e.options.cwd!=null,r=s&&process.chdir!==void 0&&!process.chdir.disabled;if(r)try{process.chdir(e.options.cwd)}catch{}let a;try{a=pr.sync(e.command,{path:o[hr({env:o})],pathExt:t?No.delimiter:void 0})}catch{}finally{r&&process.chdir(n)}return a&&(a=No.resolve(s?e.options.cwd:"",a)),a}function gr(e){return _o(e)||_o(e,!0)}var yr=gr,$t={};const Rt=/([()\][%!^"`<>&|;, *?])/g;function wr(e){return e=e.replace(Rt,"^$1"),e}function Cr(e,t){return e=`${e}`,e=e.replace(/(?=(\\+?)?)\1"/g,'$1$1\\"'),e=e.replace(/(?=(\\+?)?)\1$/,"$1$1"),e=`"${e}"`,e=e.replace(Rt,"^$1"),t&&(e=e.replace(Rt,"^$1")),e}$t.command=wr,$t.argument=Cr;var br=/^#!(.*)/;const Er=br;var vr=(e="")=>{const t=e.match(Er);if(!t)return null;const[o,n]=t[0].replace(/#! ?/,"").split(" "),s=o.split("/").pop();return s==="env"?n:n?`${s} ${n}`:s};const It=O,Pr=vr;function Ar(e){const o=Buffer.alloc(150);let n;try{n=It.openSync(e,"r"),It.readSync(n,o,0,150,0),It.closeSync(n)}catch{}return Pr(o.toString())}var xr=Ar;const Sr=P,jo=yr,Fo=$t,$r=xr,Rr=process.platform==="win32",Ir=/\.(?:com|exe)$/i,kr=/node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;function Lr(e){e.file=jo(e);const t=e.file&&$r(e.file);return t?(e.args.unshift(e.file),e.command=t,jo(e)):e.file}function Mr(e){if(!Rr)return e;const t=Lr(e),o=!Ir.test(t);if(e.options.forceShell||o){const n=kr.test(t);e.command=Sr.normalize(e.command),e.command=Fo.command(e.command),e.args=e.args.map(r=>Fo.argument(r,n));const s=[e.command].concat(e.args).join(" ");e.args=["/d","/s","/c",`"${s}"`],e.command=process.env.comspec||"cmd.exe",e.options.windowsVerbatimArguments=!0}return e}function Or(e,t,o){t&&!Array.isArray(t)&&(o=t,t=null),t=t?t.slice(0):[],o=Object.assign({},o);const n={command:e,args:t,options:o,file:void 0,original:{command:e,args:t}};return o.shell?n:Mr(n)}var Tr=Or;const kt=process.platform==="win32";function Lt(e,t){return Object.assign(new Error(`${t} ${e.command} ENOENT`),{code:"ENOENT",errno:"ENOENT",syscall:`${t} ${e.command}`,path:e.command,spawnargs:e.args})}function Dr(e,t){if(!kt)return;const o=e.emit;e.emit=function(n,s){if(n==="exit"){const r=Go(s,t);if(r)return o.call(e,"error",r)}return o.apply(e,arguments)}}function Go(e,t){return kt&&e===1&&!t.file?Lt(t.original,"spawn"):null}function Nr(e,t){return kt&&e===1&&!t.file?Lt(t.original,"spawnSync"):null}var _r={hookChildProcess:Dr,verifyENOENT:Go,verifyENOENTSync:Nr,notFoundError:Lt};const Bo=ws,Mt=Tr,Ot=_r;function Ho(e,t,o){const n=Mt(e,t,o),s=Bo.spawn(n.command,n.args,n.options);return Ot.hookChildProcess(s,n),s}function jr(e,t,o){const n=Mt(e,t,o),s=Bo.spawnSync(n.command,n.args,n.options);return s.error=s.error||Ot.verifyENOENTSync(s.status,n),s}me.exports=Ho,me.exports.spawn=Ho,me.exports.sync=jr,me.exports._parse=Mt,me.exports._enoent=Ot;var Fr=me.exports,Gr=de(Fr);function Br(e){const t=typeof e=="string"?` `:` `.charCodeAt(),o=typeof e=="string"?"\r":"\r".charCodeAt();return e[e.length-1]===t&&(e=e.slice(0,-1)),e[e.length-1]===o&&(e=e.slice(0,-1)),e}function Uo(e={}){const{env:t=process.env,platform:o=process.platform}=e;return o!=="win32"?"PATH":Object.keys(t).reverse().find(n=>n.toUpperCase()==="PATH")||"Path"}const Hr=({cwd:e=U.cwd(),path:t=U.env[Uo()],preferLocal:o=!0,execPath:n=U.execPath,addExecPath:s=!0}={})=>{const r=e instanceof URL?ho(e):e,a=ae.resolve(r),c=[];return o&&Ur(c,a),s&&Kr(c,n,a),[...c,t].join(ae.delimiter)},Ur=(e,t)=>{let o;for(;o!==t;)e.push(ae.join(t,"node_modules/.bin")),o=t,t=ae.resolve(t,"..")},Kr=(e,t,o)=>{const n=t instanceof URL?ho(t):t;e.push(ae.resolve(o,n,".."))},Wr=({env:e=U.env,...t}={})=>{e={...e};const o=Uo({env:e});return t.path=e[o],e[o]=Hr(t),e},qr=(e,t,o,n)=>{if(o==="length"||o==="prototype"||o==="arguments"||o==="caller")return;const s=Object.getOwnPropertyDescriptor(e,o),r=Object.getOwnPropertyDescriptor(t,o);!zr(s,r)&&n||Object.defineProperty(e,o,r)},zr=function(e,t){return e===void 0||e.configurable||e.writable===t.writable&&e.enumerable===t.enumerable&&e.configurable===t.configurable&&(e.writable||e.value===t.value)},Yr=(e,t)=>{const o=Object.getPrototypeOf(t);o!==Object.getPrototypeOf(e)&&Object.setPrototypeOf(e,o)},Vr=(e,t)=>`/* Wrapped ${e}*/ ${t}`,Jr=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),Xr=Object.getOwnPropertyDescriptor(Function.prototype.toString,"name"),Qr=(e,t,o)=>{const n=o===""?"":`with ${o.trim()}() `,s=Vr.bind(null,n,t.toString());Object.defineProperty(s,"name",Xr),Object.defineProperty(e,"toString",{...Jr,value:s})};function Zr(e,t,{ignoreNonConfigurable:o=!1}={}){const{name:n}=e;for(const s of Reflect.ownKeys(t))qr(e,t,s,o);return Yr(e,t),Qr(e,t,n),e}const Ke=new WeakMap,Ko=(e,t={})=>{if(typeof e!="function")throw new TypeError("Expected a function");let o,n=0;const s=e.displayName||e.name||"<anonymous>",r=function(...a){if(Ke.set(r,++n),n===1)o=e.apply(this,a),e=null;else if(t.throw===!0)throw new Error(`Function \`${s}\` can only be called once`);return o};return Zr(r,e),Ke.set(r,n),r};Ko.callCount=e=>{if(!Ke.has(e))throw new Error(`The given function \`${e.name}\` is not wrapped by the \`onetime\` package`);return Ke.get(e)};const ei=()=>{const e=qo-Wo+1;return Array.from({length:e},ti)},ti=(e,t)=>({name:`SIGRT${t+1}`,number:Wo+t,action:"terminate",description:"Application-specific signal (realtime)",standard:"posix"}),Wo=34,qo=64,oi=[{name:"SIGHUP",number:1,action:"terminate",description:"Terminal closed",standard:"posix"},{name:"SIGINT",number:2,action:"terminate",description:"User interruption with CTRL-C",standard:"ansi"},{name:"SIGQUIT",number:3,action:"core",description:"User interruption with CTRL-\\",standard:"posix"},{name:"SIGILL",number:4,action:"core",description:"Invalid machine instruction",standard:"ansi"},{name:"SIGTRAP",number:5,action:"core",description:"Debugger breakpoint",standard:"posix"},{name:"SIGABRT",number:6,action:"core",description:"Aborted",standard:"ansi"},{name:"SIGIOT",number:6,action:"core",description:"Aborted",standard:"bsd"},{name:"SIGBUS",number:7,action:"core",description:"Bus error due to misaligned, non-existing address or paging error",standard:"bsd"},{name:"SIGEMT",number:7,action:"terminate",description:"Command should be emulated but is not implemented",standard:"other"},{name:"SIGFPE",number:8,action:"core",description:"Floating point arithmetic error",standard:"ansi"},{name:"SIGKILL",number:9,action:"terminate",description:"Forced termination",standard:"posix",forced:!0},{name:"SIGUSR1",number:10,action:"terminate",description:"Application-specific signal",standard:"posix"},{name:"SIGSEGV",number:11,action:"core",description:"Segmentation fault",standard:"ansi"},{name:"SIGUSR2",number:12,action:"terminate",description:"Application-specific signal",standard:"posix"},{name:"SIGPIPE",number:13,action:"terminate",description:"Broken pipe or socket",standard:"posix"},{name:"SIGALRM",number:14,action:"terminate",description:"Timeout or timer",standard:"posix"},{name:"SIGTERM",number:15,action:"terminate",description:"Termination",standard:"ansi"},{name:"SIGSTKFLT",number:16,action:"terminate",description:"Stack is empty or overflowed",standard:"other"},{name:"SIGCHLD",number:17,action:"ignore",description:"Child process terminated, paused or unpaused",standard:"posix"},{name:"SIGCLD",number:17,action:"ignore",description:"Child process terminated, paused or unpaused",standard:"other"},{name:"SIGCONT",number:18,action:"unpause",description:"Unpaused",standard:"posix",forced:!0},{name:"SIGSTOP",number:19,action:"pause",description:"Paused",standard:"posix",forced:!0},{name:"SIGTSTP",number:20,action:"pause",description:'Paused using CTRL-Z or "suspend"',standard:"posix"},{name:"SIGTTIN",number:21,action:"pause",description:"Background process cannot read terminal input",standard:"posix"},{name:"SIGBREAK",number:21,action:"terminate",description:"User interruption with CTRL-BREAK",standard:"other"},{name:"SIGTTOU",number:22,action:"pause",description:"Background process cannot write to terminal output",standard:"posix"},{name:"SIGURG",number:23,action:"ignore",description:"Socket received out-of-band data",standard:"bsd"},{name:"SIGXCPU",number:24,action:"core",description:"Process timed out",standard:"bsd"},{name:"SIGXFSZ",number:25,action:"core",description:"File too big",standard:"bsd"},{name:"SIGVTALRM",number:26,action:"terminate",description:"Timeout or timer",standard:"bsd"},{name:"SIGPROF",number:27,action:"terminate",description:"Timeout or timer",standard:"bsd"},{name:"SIGWINCH",number:28,action:"ignore",description:"Terminal window size changed",standard:"bsd"},{name:"SIGIO",number:29,action:"terminate",description:"I/O is available",standard:"other"},{name:"SIGPOLL",number:29,action:"terminate",description:"Watched event",standard:"other"},{name:"SIGINFO",number:29,action:"ignore",description:"Request for process information",standard:"other"},{name:"SIGPWR",number:30,action:"terminate",description:"Device running out of power",standard:"systemv"},{name:"SIGSYS",number:31,action:"core",description:"Invalid system call",standard:"other"},{name:"SIGUNUSED",number:31,action:"terminate",description:"Invalid system call",standard:"other"}],zo=()=>{const e=ei();return[...oi,...e].map(ni)},ni=({name:e,number:t,description:o,action:n,forced:s=!1,standard:r})=>{const{signals:{[e]:a}}=go,c=a!==void 0;return{name:e,number:c?a:t,description:o,supported:c,action:n,forced:s,standard:r}},si=()=>{const e=zo();return Object.fromEntries(e.map(ri))},ri=({name:e,number:t,description:o,supported:n,action:s,forced:r,standard:a})=>[e,{name:e,number:t,description:o,supported:n,action:s,forced:r,standard:a}],ii=si(),ai=()=>{const e=zo(),t=qo+1,o=Array.from({length:t},(n,s)=>ci(s,e));return Object.assign({},...o)},ci=(e,t)=>{const o=li(e,t);if(o===void 0)return{};const{name:n,description:s,supported:r,action:a,forced:c,standard:l}=o;return{[e]:{name:n,number:e,description:s,supported:r,action:a,forced:c,standard:l}}},li=(e,t)=>{const o=t.find(({name:n})=>go.signals[n]===e);return o!==void 0?o:t.find(n=>n.number===e)};ai();const ui=({timedOut:e,timeout:t,errorCode:o,signal:n,signalDescription:s,exitCode:r,isCanceled:a})=>e?`timed out after ${t} milliseconds`:a?"was canceled":o!==void 0?`failed with ${o}`:n!==void 0?`was killed with ${n} (${s})`:r!==void 0?`failed with exit code ${r}`:"failed",We=({stdout:e,stderr:t,all:o,error:n,signal:s,exitCode:r,command:a,escapedCommand:c,timedOut:l,isCanceled:u,killed:d,parsed:{options:{timeout:p,cwd:g=U.cwd()}}})=>{r=r===null?void 0:r,s=s===null?void 0:s;const y=s===void 0?void 0:ii[s].description,f=n&&n.code,$=`Command ${ui({timedOut:l,timeout:p,errorCode:f,signal:s,signalDescription:y,exitCode:r,isCanceled:u})}: ${a}`,x=Object.prototype.toString.call(n)==="[object Error]",A=x?`${$} ${n.message}`:$,v=[A,t,e].filter(Boolean).join(` `);return x?(n.originalMessage=n.message,n.message=v):n=new Error(v),n.shortMessage=A,n.command=a,n.escapedCommand=c,n.exitCode=r,n.signal=s,n.signalDescription=y,n.stdout=e,n.stderr=t,n.cwd=g,o!==void 0&&(n.all=o),"bufferedData"in n&&delete n.bufferedData,n.failed=!0,n.timedOut=!!l,n.isCanceled=u,n.killed=d&&!l,n},qe=["stdin","stdout","stderr"],di=e=>qe.some(t=>e[t]!==void 0),Yo=e=>{if(!e)return;const{stdio:t}=e;if(t===void 0)return qe.map(n=>e[n]);if(di(e))throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${qe.map(n=>`\`${n}\``).join(", ")}`);if(typeof t=="string")return t;if(!Array.isArray(t))throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof t}\``);const o=Math.max(t.length,qe.length);return Array.from({length:o},(n,s)=>t[s])},mi=e=>{const t=Yo(e);return t==="ipc"?"ipc":t===void 0||typeof t=="string"?[t,t,t,"ipc"]:t.includes("ipc")?t:[...t,"ipc"]};var pe={exports:{}},ze={exports:{}};ze.exports;var Vo;function fi(){return Vo||(Vo=1,function(e){e.exports=["SIGABRT","SIGALRM","SIGHUP","SIGINT","SIGTERM"],process.platform!=="win32"&&e.exports.push("SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT"),process.platform==="linux"&&e.exports.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT","SIGUNUSED")}(ze)),ze.exports}var M=ne.process;const ce=function(e){return e&&typeof e=="object"&&typeof e.removeListener=="function"&&typeof e.emit=="function"&&typeof e.reallyExit=="function"&&typeof e.listeners=="function"&&typeof e.kill=="function"&&typeof e.pid=="number"&&typeof e.on=="function"};if(!ce(M))pe.exports=function(){return function(){}};else{var pi=Es,Ae=fi(),hi=/^win/i.test(M.platform),Ye=vs;typeof Ye!="function"&&(Ye=Ye.EventEmitter);var N;M.__signal_exit_emitter__?N=M.__signal_exit_emitter__:(N=M.__signal_exit_emitter__=new Ye,N.count=0,N.emitted={}),N.infinite||(N.setMaxListeners(1/0),N.infinite=!0),pe.exports=function(e,t){if(!ce(ne.process))return function(){};pi.equal(typeof e,"function","a callback must be provided for exit handler"),xe===!1&&Jo();var o="exit";t&&t.alwaysLast&&(o="afterexit");var n=function(){N.removeListener(o,e),N.listeners("exit").length===0&&N.listeners("afterexit").length===0&&Tt()};return N.on(o,e),n};var Tt=function(){!xe||!ce(ne.process)||(xe=!1,Ae.forEach(function(t){try{M.removeListener(t,Dt[t])}catch{}}),M.emit=Nt,M.reallyExit=Xo,N.count-=1)};pe.exports.unload=Tt;var he=function(t,o,n){N.emitted[t]||(N.emitted[t]=!0,N.emit(t,o,n))},Dt={};Ae.forEach(function(e){Dt[e]=function(){if(ce(ne.process)){var o=M.listeners(e);o.length===N.count&&(Tt(),he("exit",null,e),he("afterexit",null,e),hi&&e==="SIGHUP"&&(e="SIGINT"),M.kill(M.pid,e))}}}),pe.exports.signals=function(){return Ae};var xe=!1,Jo=function(){xe||!ce(ne.process)||(xe=!0,N.count+=1,Ae=Ae.filter(function(t){try{return M.on(t,Dt[t]),!0}catch{return!1}}),M.emit=yi,M.reallyExit=gi)};pe.exports.load=Jo;var Xo=M.reallyExit,gi=function(t){ce(ne.process)&&(M.exitCode=t||0,he("exit",M.exitCode,null),he("afterexit",M.exitCode,null),Xo.call(M,M.exitCode))},Nt=M.emit,yi=function(t,o){if(t==="exit"&&ce(ne.process)){o!==void 0&&(M.exitCode=o);var n=Nt.apply(this,arguments);return he("exit",M.exitCode,null),he("afterexit",M.exitCode,null),n}else return Nt.apply(this,arguments)}}var wi=pe.exports,Ci=de(wi);const bi=1e3*5,Ei=(e,t="SIGTERM",o={})=>{const n=e(t);return vi(e,t,o,n),n},vi=(e,t,o,n)=>{if(!Pi(t,o,n))return;const s=xi(o),r=setTimeout(()=>{e("SIGKILL")},s);r.unref&&r.unref()},Pi=(e,{forceKillAfterTimeout:t},o)=>Ai(e)&&t!==!1&&o,Ai=e=>e===bs.constants.signals.SIGTERM||typeof e=="string"&&e.toUpperCase()==="SIGTERM",xi=({forceKillAfterTimeout:e=!0})=>{if(e===!0)return bi;if(!Number.isFinite(e)||e<0)throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${e}\` (${typeof e})`);return e},Si=(e,t)=>{e.kill()&&(t.isCanceled=!0)},$i=(e,t,o)=>{e.kill(t),o(Object.assign(new Error("Timed out"),{timedOut:!0,signal:t}))},Ri=(e,{timeout:t,killSignal:o="SIGTERM"},n)=>{if(t===0||t===void 0)return n;let s;const r=new Promise((c,l)=>{s=setTimeout(()=>{$i(e,o,l)},t)}),a=n.finally(()=>{clearTimeout(s)});return Promise.race([r,a])},Ii=({timeout:e})=>{if(e!==void 0&&(!Number.isFinite(e)||e<0))throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${e}\` (${typeof e})`)},ki=async(e,{cleanup:t,detached:o},n)=>{if(!t||o)return n;const s=Ci(()=>{e.kill()});return n.finally(()=>{s()})};function _t(e){return e!==null&&typeof e=="object"&&typeof e.pipe=="function"}function Qo(e){return _t(e)&&e.writable!==!1&&typeof e._write=="function"&&typeof e._writableState=="object"}const Li=e=>e instanceof po&&typeof e.then=="function",jt=(e,t,o)=>{if(typeof o=="string")return e[t].pipe(Ps(o)),e;if(Qo(o))return e[t].pipe(o),e;if(!Li(o))throw new TypeError("The second argument must be a string, a stream or an Execa child process.");if(!Qo(o.stdin))throw new TypeError("The target child process's stdin must be available.");return e[t].pipe(o.stdin),o},Mi=e=>{e.stdout!==null&&(e.pipeStdout=jt.bind(void 0,e,"stdout")),e.stderr!==null&&(e.pipeStderr=jt.bind(void 0,e,"stderr")),e.all!==void 0&&(e.pipeAll=jt.bind(void 0,e,"all"))};var Se={exports:{}};const{PassThrough:Oi}=wt;var Ti=e=>{e={...e};const{array:t}=e;let{encoding:o}=e;const n=o==="buffer";let s=!1;t?s=!(o||n):o=o||"utf8",n&&(o=null);const r=new Oi({objectMode:s});o&&r.setEncoding(o);let a=0;const c=[];return r.on("data",l=>{c.push(l),s?a=c.length:a+=l.length}),r.getBufferedValue=()=>t?c:n?Buffer.concat(c,a):c.join(""),r.getBufferedLength=()=>a,r};const{constants:Di}=Ss,Ni=wt,{promisify:_i}=$s,ji=Ti,Fi=_i(Ni.pipeline);class Zo extends Error{constructor(){super("maxBuffer exceeded"),this.name="MaxBufferError"}}async function Ft(e,t){if(!e)throw new Error("Expected a stream");t={maxBuffer:1/0,...t};const{maxBuffer:o}=t,n=ji(t);return await new Promise((s,r)=>{const a=c=>{c&&n.getBufferedLength()<=Di.MAX_LENGTH&&(c.bufferedData=n.getBufferedValue()),r(c)};(async()=>{try{await Fi(e,n),s()}catch(c){a(c)}})(),n.on("data",()=>{n.getBufferedLength()>o&&a(new Zo)})}),n.getBufferedValue()}Se.exports=Ft,Se.exports.buffer=(e,t)=>Ft(e,{...t,encoding:"buffer"}),Se.exports.array=(e,t)=>Ft(e,{...t,array:!0}),Se.exports.MaxBufferError=Zo;var Gi=Se.exports,en=de(Gi);const{PassThrough:Bi}=wt;var Hi=function(){var e=[],t=new Bi({objectMode:!0});return t.setMaxListeners(0),t.add=o,t.isEmpty=n,t.on("unpipe",s),Array.prototype.slice.call(arguments).forEach(o),t;function o(r){return Array.isArray(r)?(r.forEach(o),this):(e.push(r),r.once("end",s.bind(null,r)),r.once("error",t.emit.bind(t,"error")),r.pipe(t,{end:!1}),this)}function n(){return e.length==0}function s(r){e=e.filter(function(a){return a!==r}),!e.length&&t.readable&&t.end()}},Ui=de(Hi);const tn=e=>{if(e!==void 0)throw new TypeError("The `input` and `inputFile` options cannot be both set.")},Ki=({input:e,inputFile:t})=>typeof t!="string"?e:(tn(e),xs(t)),Wi=e=>{const t=Ki(e);if(_t(t))throw new TypeError("The `input` option cannot be a stream in sync mode");return t},qi=({input:e,inputFile:t})=>typeof t!="string"?e:(tn(e),As(t)),zi=(e,t)=>{const o=qi(t);o!==void 0&&(_t(o)?o.pipe(e.stdin):e.stdin.end(o))},Yi=(e,{all:t})=>{if(!t||!e.stdout&&!e.stderr)return;const o=Ui();return e.stdout&&o.add(e.stdout),e.stderr&&o.add(e.stderr),o},Gt=async(e,t)=>{if(!(!e||t===void 0)){e.destroy();try{return await t}catch(o){return o.bufferedData}}},Bt=(e,{encoding:t,buffer:o,maxBuffer:n})=>{if(!(!e||!o))return t?en(e,{encoding:t,maxBuffer:n}):en.buffer(e,{maxBuffer:n})},Vi=async({stdout:e,stderr:t,all:o},{encoding:n,buffer:s,maxBuffer:r},a)=>{const c=Bt(e,{encoding:n,buffer:s,maxBuffer:r}),l=Bt(t,{encoding:n,buffer:s,maxBuffer:r}),u=Bt(o,{encoding:n,buffer:s,maxBuffer:r*2});try{return await Promise.all([a,c,l,u])}catch(d){return Promise.all([{error:d,signal:d.signal,timedOut:d.timedOut},Gt(e,c),Gt(t,l),Gt(o,u)])}},Ji=(async()=>{})().constructor.prototype,Xi=["then","catch","finally"].map(e=>[e,Reflect.getOwnPropertyDescriptor(Ji,e)]),on=(e,t)=>{for(const[o,n]of Xi){const s=typeof t=="function"?(...r)=>Reflect.apply(n.value,t(),r):n.value.bind(t);Reflect.defineProperty(e,o,{...n,value:s})}},Qi=e=>new Promise((t,o)=>{e.on("exit",(n,s)=>{t({exitCode:n,signal:s})}),e.on("error",n=>{o(n)}),e.stdin&&e.stdin.on("error",n=>{o(n)})}),nn=(e,t=[])=>Array.isArray(t)?[e,...t]:[e],Zi=/^[\w.-]+$/,ea=/"/g,ta=e=>typeof e!="string"||Zi.test(e)?e:`"${e.replace(ea,'\\"')}"`,sn=(e,t)=>nn(e,t).join(" "),rn=(e,t)=>nn(e,t).map(o=>ta(o)).join(" "),an=/ +/g,cn=e=>{const t=[];for(const o of e.trim().split(an)){const n=t[t.length-1];n&&n.endsWith("\\")?t[t.length-1]=`${n.slice(0,-1)} ${o}`:t.push(o)}return t},ln=e=>{const t=typeof e;if(t==="string")return e;if(t==="number")return String(e);if(t==="object"&&e!==null&&!(e instanceof po)&&"stdout"in e){const o=typeof e.stdout;if(o==="string")return e.stdout;if(fo.isBuffer(e.stdout))return e.stdout.toString();throw new TypeError(`Unexpected "${o}" stdout in template expression`)}throw new TypeError(`Unexpected "${t}" in template expression`)},un=(e,t,o)=>o||e.length===0||t.length===0?[...e,...t]:[...e.slice(0,-1),`${e[e.length-1]}${t[0]}`,...t.slice(1)],oa=({templates:e,expressions:t,tokens:o,index:n,template:s})=>{const r=s??e.raw[n],a=r.split(an).filter(Boolean),c=un(o,a,r.startsWith(" "));if(n===t.length)return c;const l=t[n],u=Array.isArray(l)?l.map(d=>ln(d)):[ln(l)];return un(c,u,r.endsWith(" "))},dn=(e,t)=>{let o=[];for(const[n,s]of e.entries())o=oa({templates:e,expressions:t,tokens:o,index:n,template:s});return o},na=Is("execa").enabled,Ve=(e,t)=>String(e).padStart(t,"0"),sa=()=>{const e=new Date;return`${Ve(e.getHours(),2)}:${Ve(e.getMinutes(),2)}:${Ve(e.getSeconds(),2)}.${Ve(e.getMilliseconds(),3)}`},mn=(e,{verbose:t})=>{t&&U.stderr.write(`[${sa()}] ${e} `)},ra=1e3*1e3*100,ia=({env:e,extendEnv:t,preferLocal:o,localDir:n,execPath:s})=>{const r=t?{...U.env,...e}:e;return o?Wr({env:r,cwd:n,execPath:s}):r},fn=(e,t,o={})=>{const n=Gr._parse(e,t,o);return e=n.command,t=n.args,o=n.options,o={maxBuffer:ra,buffer:!0,stripFinalNewline:!0,extendEnv:!0,preferLocal:!1,localDir:o.cwd||U.cwd(),execPath:U.execPath,encoding:"utf8",reject:!0,cleanup:!0,all:!1,windowsHide:!0,verbose:na,...o},o.env=ia(o),o.stdio=Yo(o),U.platform==="win32"&&ae.basename(e,".exe")==="cmd"&&t.unshift("/q"),{file:e,args:t,options:o,parsed:n}},$e=(e,t,o)=>typeof t!="string"&&!fo.isBuffer(t)?o===void 0?void 0:"":e.stripFinalNewline?Br(t):t;function b(e,t,o){const n=fn(e,t,o),s=sn(e,t),r=rn(e,t);mn(r,n.options),Ii(n.options);let a;try{a=yt.spawn(n.file,n.args,n.options)}catch(y){const f=new yt.ChildProcess,S=Promise.reject(We({error:y,stdout:"",stderr:"",all:"",command:s,escapedCommand:r,parsed:n,timedOut:!1,isCanceled:!1,killed:!1}));return on(f,S),f}const c=Qi(a),l=Ri(a,n.options,c),u=ki(a,n.options,l),d={isCanceled:!1};a.kill=Ei.bind(null,a.kill.bind(a)),a.cancel=Si.bind(null,a,d);const g=Ko(async()=>{const[{error:y,exitCode:f,signal:S,timedOut:$},x,A,v]=await Vi(a,n.options,u),w=$e(n.options,x),k=$e(n.options,A),L=$e(n.options,v);if(y||f!==0||S!==null){const D=We({error:y,exitCode:f,signal:S,stdout:w,stderr:k,all:L,command:s,escapedCommand:r,parsed:n,timedOut:$,isCanceled:d.isCanceled||(n.options.signal?n.options.signal.aborted:!1),killed:a.killed});if(!n.options.reject)return D;throw D}return{command:s,escapedCommand:r,exitCode:0,stdout:w,stderr:k,all:L,failed:!1,timedOut:!1,isCanceled:!1,killed:!1}});return zi(a,n.options),a.all=Yi(a,n.options),Mi(a),on(a,g),a}function Ht(e,t,o){const n=fn(e,t,o),s=sn(e,t),r=rn(e,t);mn(r,n.options);const a=Wi(n.options);let c;try{c=yt.spawnSync(n.file,n.args,{...n.options,input:a})}catch(d){throw We({error:d,stdout:"",stderr:"",all:"",command:s,escapedCommand:r,parsed:n,timedOut:!1,isCanceled:!1,killed:!1})}const l=$e(n.options,c.stdout,c.error),u=$e(n.options,c.stderr,c.error);if(c.error||c.status!==0||c.signal!==null){const d=We({stdout:l,stderr:u,error:c.error,signal:c.signal,exitCode:c.status,command:s,escapedCommand:r,parsed:n,timedOut:c.error&&c.error.code==="ETIMEDOUT",isCanceled:!1,killed:c.signal!==null});if(!n.options.reject)return d;throw d}return{command:s,escapedCommand:r,exitCode:0,stdout:l,stderr:u,failed:!1,timedOut:!1,isCanceled:!1,killed:!1}}const aa=({input:e,inputFile:t,stdio:o})=>e===void 0&&t===void 0&&o===void 0?{stdin:"inherit"}:{},pn=(e={})=>({preferLocal:!0,...aa(e),...e});function hn(e){function t(o,...n){if(!Array.isArray(o))return hn({...e,...o});const[s,...r]=dn(o,n);return b(s,r,pn(e))}return t.sync=(o,...n)=>{if(!Array.isArray(o))throw new TypeError("Please use $(options).sync`command` instead of $.sync(options)`command`.");const[s,...r]=dn(o,n);return Ht(s,r,pn(e))},t}const ca=hn();function la(e,t){const[o,...n]=cn(e);return b(o,n,t)}function ua(e,t){const[o,...n]=cn(e);return Ht(o,n,t)}function da(e,t,o={}){t&&!Array.isArray(t)&&typeof t=="object"&&(o=t,t=[]);const n=mi(o),s=U.execArgv.filter(c=>!c.startsWith("--inspect")),{nodePath:r=U.execPath,nodeOptions:a=s}=o;return b(r,[...a,e,...Array.isArray(t)?t:[]],{...o,stdin:void 0,stdout:void 0,stderr:void 0,stdio:n,shell:!1})}var ma=Object.freeze({__proto__:null,execa:b,execaSync:Ht,$:ca,execaCommand:la,execaCommandSync:ua,execaNode:da});const{hasOwnProperty:Ut}=Object.prototype,Je=typeof process<"u"&&process.platform==="win32"?`\r `:` `,Kt=(e,t)=>{const o=[];let n="";typeof t=="string"?t={section:t,whitespace:!1}:(t=t||Object.create(null),t.whitespace=t.whitespace===!0);const s=t.whitespace?" = ":"=";for(const r of Object.keys(e)){const a=e[r];if(a&&Array.isArray(a))for(const c of a)n+=ge(r+"[]")+s+ge(c)+Je;else a&&typeof a=="object"?o.push(r):n+=ge(r)+s+ge(a)+Je}t.section&&n.length&&(n="["+ge(t.section)+"]"+Je+n);for(const r of o){const a=gn(r).join("\\."),c=(t.section?t.section+".":"")+a,{whitespace:l}=t,u=Kt(e[r],{section:c,whitespace:l});n.length&&u.length&&(n+=Je),n+=u}return n},gn=e=>e.replace(/\1/g,"LITERAL\\1LITERAL").replace(/\\\./g,"").split(/\./).map(t=>t.replace(/\1/g,"\\.").replace(/\2LITERAL\\1LITERAL\2/g,"")),yn=e=>{const t=Object.create(null);let o=t,n=null;const s=/^\[([^\]]*)\]$|^([^=]+)(=(.*))?$/i,r=e.split(/[\r\n]+/g);for(const c of r){if(!c||c.match(/^\s*[;#]/))continue;const l=c.match(s);if(!l)continue;if(l[1]!==void 0){if(n=Xe(l[1]),n==="__proto__"){o=Object.create(null);continue}o=t[n]=t[n]||Object.create(null);continue}const u=Xe(l[2]),d=u.length>2&&u.slice(-2)==="[]",p=d?u.slice(0,-2):u;if(p==="__proto__")continue;const g=l[3]?Xe(l[4]):!0,y=g==="true"||g==="false"||g==="null"?JSON.parse(g):g;d&&(Ut.call(o,p)?Array.isArray(o[p])||(o[p]=[o[p]]):o[p]=[]),Array.isArray(o[p])?o[p].push(y):o[p]=y}const a=[];for(const c of Object.keys(t)){if(!Ut.call(t,c)||typeof t[c]!="object"||Array.isArray(t[c]))continue;const l=gn(c);o=t;const u=l.pop(),d=u.replace(/\\\./g,".");for(const p of l)p!=="__proto__"&&((!Ut.call(o,p)||typeof o[p]!="object")&&(o[p]=Object.create(null)),o=o[p]);o===t&&d===u||(o[d]=t[c],a.push(c))}for(const c of a)delete t[c];return t},wn=e=>e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"),ge=e=>typeof e!="string"||e.match(/[=\r\n]/)||e.match(/^\[/)||e.length>1&&wn(e)||e!==e.trim()?JSON.stringify(e):e.split(";").join("\\;").split("#").join("\\#"),Xe=(e,t)=>{if(e=(e||"").trim(),wn(e)){e.charAt(0)==="'"&&(e=e.slice(1,-1));try{e=JSON.parse(e)}catch{}}else{let o=!1,n="";for(let s=0,r=e.length;s<r;s++){const a=e.charAt(s);if(o)"\\;#".indexOf(a)!==-1?n+=a:n+="\\"+a,o=!1;else{if(";#".indexOf(a)!==-1)break;a==="\\"?o=!0:n+=a}}return o&&(n+="\\"),n.trim()}return e};var fa={parse:yn,decode:yn,stringify:Kt,encode:Kt,safe:ge,unsafe:Xe},ye=de(fa);const we=3,pa=3,Cn={mode:"none",maxHunkLines:0,maxDiffLines:0},ha=(e,t={})=>{const o={...Cn,...t},n=e.split(` `).length;return o.mode==="none"||!e.trim()?{diff:e,stats:{originalLines:n,compressedLines:n,originalChars:e.length,compressedChars:e.length,truncatedHunks:0,truncatedFiles:0}}:ga(e,o,n)},ga=(e,t,o)=>{const n=ya(e),s=[];let r=0,a=0;const c=t.maxDiffLines>0?t.maxDiffLines:1/0,l=t.maxHunkLines>0?t.maxHunkLines:1/0;for(let p=0;p<n.length;p++){if(s.length>=c){a+=n.length-p;break}const{lines:g,hunksTruncated:y}=wa(n[p],l);r+=y;const f=c-s.length;if(g.length>f){s.push(...g.slice(0,f)),a+=n.length-p-1;break}s.push(...g)}if(r>0||a>0){const p=[];r>0&&p.push(`${r} hunk${r>1?"s":""} truncated`),a>0&&p.push(`${a} file${a>1?"s":""} omitted`),s.push("",`[diff compressed \u2014 ${p.join(", ")}]`)}const d=s.join(` `);return{diff:d,stats:{originalLines:o,compressedLines:s.length,originalChars:e.length,compressedChars:d.length,truncatedHunks:r,truncatedFiles:a}}},ya=e=>{const t=e.split(` `),o=[];let n=[];for(const s of t)s.startsWith("diff --git ")?(n.length>0&&o.push(n),n=[s]):n.push(s);return n.length>0&&o.push(n),o},wa=(e,t)=>{const n=[`=== ${ba(e)} ===`];let s=0;const r=[];let a=null;for(const c of e)if(!Ea(c)){if(c.startsWith("@@")){a&&r.push(a),a={header:c,lines:[]};continue}a&&a.lines.push(c)}a&&r.push(a);for(const c of r){n.push(c.header);const l=Ca(c.lines);if(t>0&&l.length>t){const u=l.length-t;n.push(...l.slice(0,t)),n.push(`[... ${u} lines truncated]`),s++}else n.push(...l)}return{lines:n,hunksTruncated:s}},Ca=e=>{if(e.length===0)return[];const t=e.map(r=>r.startsWith("+")||r.startsWith("-")),o=new Array(e.length).fill(!1);for(let r=0;r<e.length;r++)if(t[r]){o[r]=!0;for(let a=1;a<=pa;a++)r-a>=0&&(o[r-a]=!0),r+a<e.length&&(o[r+a]=!0);continue}const n=[];let s=!1;for(let r=0;r<e.length;r++)o[r]?(s&&(n.push(" ..."),s=!1),n.push(e[r])):s=!0;return n},ba=e=>{const o=(e[0]||"").match(/^diff --git a\/(.+?) b\/(.+)$/);if(!o)return"unknown";const[,n,s]=o;return n!==s?`${n} \u2192 ${s}`:s},Ea=e=>e.startsWith("diff --git ")||e.startsWith("index ")||e.startsWith("--- a/")||e.startsWith("--- /dev/null")||e.startsWith("+++ b/")||e.startsWith("+++ /dev/null")||e.startsWith("old mode ")||e.startsWith("new mode ")||e.startsWith("new file mode ")||e.startsWith("deleted file mode ")||e.startsWith("similarity index ")||e.startsWith("rename from ")||e.startsWith("rename to ")||e.startsWith("Binary files ");class m extends Error{constructor(t,o={}){super(t,{cause:o.cause}),this.name="KnownError",this.code=o.code,this.suggestions=o.suggestions||[]}}const Re=" ",W=e=>{if(e instanceof Error){if(e instanceof m){e.suggestions.length>0&&(console.error(""),console.error(`${Re}${h.yellow("Suggestions:")}`),e.suggestions.forEach(t=>{console.error(`${Re} ${h.dim("\u2022")} ${t}`)}));return}e.stack&&console.error(h.dim(e.stack.split(` `).slice(1).join(` `))),console.error(` ${Re}${h.dim(`aicommit2 v${$o}`)}`),console.error(` ${Re}Please open a Bug report with the information above:`),console.error(`${Re}https://github.com/tak-bro/aicommit2/issues/new/choose`)}},Qe=e=>I.lstat(e).then(()=>!0,()=>!1),bn=async e=>{try{await I.mkdir(e,{recursive:!0})}catch(t){if(t.code!=="EEXIST")throw t}},va=e=>e&&`${e[0].toUpperCase()}${e.slice(1)}`,Pa=(e,t)=>{const o=Math.ceil(e),n=Math.floor(t);return Math.floor(Math.random()*(n-o+1))+o},En=(e,t)=>e.disabled&&!t.disabled?1:!e.disabled&&t.disabled?-1:0,Wt=e=>e.reduce((t,o)=>Array.isArray(o)?t.concat(Wt(o)):t.concat(o),[]),Aa=(e,t=5)=>e.replace(/[\n\r]/g,"").split(" ").slice(0,t).join(" "),xa=e=>{let t=0;for(let o=0;o<e.length;o++){const n=e.charCodeAt(o);t=(t<<5)-t+n,t=t&t}return Math.abs(t)},Sa=e=>{const t=e%360,o=65+e%15,n=45+e%10;return`hsl(${t}, ${o}%, ${n}%)`},$a=e=>{const[t,o,n]=e.match(/\d+/g).map((p,g)=>g===0?Number(p):Number(p)/100),s=(1-Math.abs(2*n-1))*o,r=s*(1-Math.abs(t/60%2-1)),a=n-s/2;let c,l,u;t<60?[c,l,u]=[s,r,0]:t<120?[c,l,u]=[r,s,0]:t<180?[c,l,u]=[0,s,r]:t<240?[c,l,u]=[0,r,s]:t<300?[c,l,u]=[r,0,s]:[c,l,u]=[s,0,r];const d=p=>{const g=Math.round((p+a)*255).toString(16);return g.length===1?"0"+g:g};return`#${d(c)}${d(l)}${d(u)}`},Ra=e=>{const t=xa(e),o=Sa(t);return{primary:$a(o),secondary:"#FFFFFF"}},Ia=e=>{try{return{ok:!0,data:JSON.parse(e)}}catch(t){return{ok:!1,error:t}}},Ze=e=>{if(!e||typeof e!="string")return"";if(P.isAbsolute(e))return P.resolve(e);if(Le){const t=P.dirname(Le),o=P.join(t,e);return P.resolve(o)}else return""},ka=["","conventional","gitmoji"],Ie="http://localhost:11434",{hasOwnProperty:La}=Object.prototype,qt=(e,t)=>La.call(e,t),Ce=["OPENAI","COPILOT_SDK","OPENROUTER","OLLAMA","HUGGINGFACE","GEMINI","ANTHROPIC","MISTRAL","CODESTRAL","COHERE","GROQ","PERPLEXITY","DEEPSEEK","GITHUB_MODELS","BEDROCK"],vn=e=>{const t=ue.platform(),o=ue.homedir();let n,s;switch(e){case"config":n=process.env.XDG_CONFIG_HOME;break;case"data":n=process.env.XDG_DATA_HOME;break;case"cache":n=process.env.XDG_CACHE_HOME;break;case"state":n=process.env.XDG_STATE_HOME;break;default:n=void 0}if(t==="darwin")e==="cache"?s=P.join(o,"Library","Caches"):s=P.join(o,"Library","Application Support");else if(t==="win32")s=process.env.LOCALAPPDATA||o;else switch(e){case"config":s=P.join(o,".config");break;case"data":s=P.join(o,".local","share");break;case"cache":s=P.join(o,".cache");break;case"state":s=P.join(o,".local","state");break;default:s=o}return n||s},Pn=P.join(vn("config"),"aicommit2"),q=P.join(vn("state"),"aicommit2","logs"),An=P.join(Pn,"config.ini"),xn=P.join(q,"aicommit2-%DATE%.log"),Sn=P.join(q,"exceptions-%DATE%.log"),Ma=e=>{const t=Object.keys(e),o=new Set([...Ce,...t.filter(n=>/^[A-Z][A-Z0-9_]*$/.test(n))]);return Array.from(o)},E=(e,t,o)=>{if(!t)throw new m(`Invalid config property ${e}: ${o}`)},G=(e,t=!1)=>o=>typeof o=="boolean"?o:o==null?t:(E(e,/^(?:true|false)$/.test(o),"Must be a boolean(true or false)"),o==="true"),et=e=>t=>{if(!t)return{};if(typeof t=="object")return E(e,!Array.isArray(t),"Must be a JSON object"),t;try{const o=JSON.parse(t);return E(e,typeof o=="object"&&o!==null&&!Array.isArray(o),"Must be a valid JSON object"),o}catch(o){throw new m(`Invalid ${e}: Must be valid JSON. Error: ${o.message}`)}},i={systemPrompt(e){return e||""},systemPromptPath(e){return e||""},codeReviewPromptPath(e){return e||""},timeout(e){if(!e)return 6e4;E("timeout",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return E("timeout",t>=500,"Must be greater than 500ms"),t},temperature(e){if(!e)return .7;E("temperature",/^(2|\d)(\.\d{1,2})?$/.test(e),"Must be decimal between 0 and 2");const t=Number(e);return E("temperature",t>0,"Must be greater than 0"),E("temperature",t<=2,"Must be less than or equal to 2"),t},maxTokens(e){return e?(E("maxTokens",/^\d+$/.test(e),"Must be an integer"),Number(e)):8192},logLevel(e){return e?(E("logLevel",/^(?:error|warn|info|http|verbose|debug|silly)$/.test(e),"Must be a valid log level (error, warn, info, http, verbose, debug, silly)"),e):"info"},logFilePath(e){return e||xn},exceptionLogFilePath(e){return e||Sn},locale(e){return e?(E("locale",e,"Cannot be empty"),E("locale",/^[a-z-]+$/i.test(e),"Must be a valid locale (letters and dashes/underscores). You can consult the list of codes in: https://wikipedia.org/wiki/List_of_ISO_639-1_codes"),e):"en"},generate(e){if(!e)return 1;E("generate",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return E("generate",t>0,"Must be greater than 0"),E("generate",t<=5,"Must be less or equal to 5"),t},type(e){return e?(E("type",ka.includes(e),"Invalid commit type"),e):"conventional"},maxLength(e){if(!e)return 50;E("maxLength",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return E("maxLength",t>=20,"Must be greater than 20 characters"),t},exclude:e=>e?(typeof e=="string"?e?.split(","):e).map(o=>o.trim()).filter(o=>!!o&&o.length>0):[],topP:e=>{if(!e)return .9;E("topP",/^(1|\d)(\.\d{1,2})?$/.test(e),"Must be decimal between 0 and 1");const t=Number(e);return E("topP",t>0,"Must be greater than 0"),E("topP",t<=1,"Must be less than or equal to 1"),t},logging:G("logging",!0),includeBody:G("includeBody"),codeReview:G("codeReview"),disabled:G("disabled"),watchMode:G("watchMode"),forceGit:G("forceGit"),stream:G("stream"),disableLowerCase:G("disableLowerCase"),jjAutoNew:G("jjAutoNew"),autoCopy:G("autoCopy"),modelNameDisplay:e=>e?(E("modelNameDisplay",/^(?:none|short|full)$/.test(e),"Must be none, short, or full"),e):"short",diffCompression:e=>e?(E("diffCompression",/^(?:none|compact)$/.test(e),"Must be none or compact"),e):Cn.mode,maxHunkLines:e=>e?(E("maxHunkLines",/^\d+$/.test(e),"Must be an integer"),Number(e)):0,maxDiffLines:e=>e?(E("maxDiffLines",/^\d+$/.test(e),"Must be an integer"),Number(e)):0,diffContext:e=>{if(!e)return we;E("diffContext",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return E("diffContext",t>=0&&t<=10,"Must be between 0 and 10"),t},useStats:G("useStats",!0),statsDays:e=>{if(!e)return 30;E("statsDays",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return E("statsDays",t>0,"Must be greater than 0"),t}},ke={OPENAI:{key:e=>e||"",envKey:e=>e||"",model:e=>e?(typeof e=="string"?e?.split(","):e).map(o=>o.trim()).filter(o=>!!o&&o.length>0):["gpt-4o-mini"],url:e=>e?(E("OPENAI.url",/^https?:\/\//.test(e),"Must be a valid URL"),e):"https://api.openai.com",path:e=>e||"/v1/chat/completions",proxy:e=>e||"",topP:i.topP,systemPrompt:i.systemPrompt,systemPromptPath:i.systemPromptPath,codeReviewPromptPath:i.codeReviewPromptPath,timeout:i.timeout,temperature:i.temperature,maxTokens:i.maxTokens,logging:i.logging,locale:i.locale,generate:i.generate,type:i.type,maxLength:i.maxLength,includeBody:i.includeBody,codeReview:i.codeReview,disabled:i.disabled,stream:i.stream,watchMode:i.watchMode,disableLowerCase:i.disableLowerCase,diffCompression:i.diffCompression,maxHunkLines:i.maxHunkLines,maxDiffLines:i.maxDiffLines,diffContext:i.diffContext},OPENROUTER:{key:e=>e||"",envKey:e=>e||"",model:e=>e?(typeof e=="string"?e?.split(","):e).map(o=>o.trim()).filter(o=>!!o&&o.length>0):["openrouter/auto"],url:e=>e?(E("OPENROUTER.url",/^https?:\/\//.test(e),"Must be a valid URL"),e):"https://openrouter.ai",path:e=>e||"/api/v1/chat/completions",responseFormat:et("OPENROUTER.responseFormat"),provider:et("OPENROUTER.provider"),reasoning:et("OPENROUTER.reasoning"),topP:i.topP,systemPrompt:i.systemPrompt,systemPromptPath:i.systemPromptPath,codeReviewPromptPath:i.codeReviewPromptPath,timeout:i.timeout,temperature:i.temperature,maxTokens:i.maxTokens,logging:i.logging,locale:i.locale,generate:i.generate,type:i.type,maxLength:i.maxLength,includeBody:i.includeBody,codeReview:i.codeReview,disabled:i.disabled,stream:i.stream,watchMode:i.watchMode,disableLowerCase:i.disableLowerCase,diffCompression:i.diffCompression,maxHunkLines:i.maxHunkLines,maxDiffLines:i.maxDiffLines,diffContext:i.diffContext},HUGGINGFACE:{cookie:e=>e||"",model:e=>e?(typeof e=="string"?e?.split(","):e).map(o=>o.trim()).filter(o=>!!o&&o.length>0):["CohereForAI/c4ai-command-r-plus"],systemPrompt:i.systemPrompt,systemPromptPath:i.systemPromptPath,codeReviewPromptPath:i.codeReviewPromptPath,timeout:i.timeout,temperature:i.temperature,maxTokens:i.maxTokens,topP:i.topP,logging:i.logging,locale:i.locale,generate:i.generate,type:i.type,maxLength:i.maxLength,includeBody:i.includeBody,codeReview:i.codeReview,disabled:i.disabled,stream:i.stream,watchMode:i.watchMode,disableLowerCase:i.disableLowerCase,diffCompression:i.diffCompression,maxHunkLines:i.maxHunkLines,maxDiffLines:i.maxDiffLines,diffContext:i.diffContext},GEMINI:{key:e=>e||"",envKey:e=>e||"",model:e=>e?(typeof e=="string"?e?.split(","):e).map(o=>o.trim()).filter(o=>!!o&&o.length>0):["gemini-3-flash-preview"],systemPrompt:i.systemPrompt,systemPromptPath:i.systemPromptPath,codeReviewPromptPath:i.codeReviewPromptPath,timeout:i.timeout,temperature:i.temperature,maxTokens:i.maxTokens,logging:i.logging,locale:i.locale,generate:i.generate,type:i.type,maxLength:i.maxLength,includeBody:i.includeBody,topP:i.topP,codeReview:i.codeReview,disabled:i.disabled,stream:i.stream,watchMode:i.watchMode,disableLowerCase:i.disableLowerCase,diffCompression:i.diffCompression,maxHunkLines:i.maxHunkLines,maxDiffLines:i.maxDiffLines,diffContext:i.diffContext},ANTHROPIC:{key:e=>e||"",envKey:e=>e||"",model:e=>e?(typeof e=="string"?e?.split(","):e).map(o=>o.trim()).filter(o=>!!o&&o.length>0):["claude-sonnet-4-20250514"],systemPrompt:i.systemPrompt,systemPromptPath:i.systemPromptPath,codeReviewPromptPath:i.codeReviewPromptPath,timeout:i.timeout,temperature:i.temperature,maxTokens:i.maxTokens,logging:i.logging,locale:i.locale,generate:i.generate,type:i.type,maxLength:i.maxLength,includeBody:i.includeBody,topP:i.topP,codeReview:i.codeReview,disabled:i.disabled,stream:i.stream,watchMode:i.watchMode,disableLowerCase:i.disableLowerCase,diffCompression:i.diffCompression,maxHunkLines:i.maxHunkLines,maxDiffLines:i.maxDiffLines,diffContext:i.diffContext},MISTRAL:{key:e=>e||"",envKey:e=>e||"",model:e=>e?(typeof e=="string"?e?.split(","):e).map(o=>o.trim()).filter(o=>!!o&&o.length>0):["mistral-small-latest"],systemPrompt:i.systemPrompt,systemPromptPath:i.systemPromptPath,codeReviewPromptPath:i.codeReviewPromptPath,timeout:i.timeout,temperature:i.temperature,maxTokens:i.maxTokens,logging:i.logging,locale:i.locale,generate:i.generate,type:i.type,maxLength:i.maxLength,includeBody:i.includeBody,topP:i.topP,codeReview:i.codeReview,disabled:i.disabled,stream:i.stream,watchMode:i.watchMode,disableLowerCase:i.disableLowerCase,diffCompression:i.diffCompression,maxHunkLines:i.maxHunkLines,maxDiffLines:i.maxDiffLines,diffContext:i.diffContext},CODESTRAL:{key:e=>e||"",envKey:e=>e||"",model:e=>e?(typeof e=="string"?e?.split(","):e).map(o=>o.trim()).filter(o=>!!o&&o.length>0):["codestral-latest"],topP:i.topP,systemPrompt:i.systemPrompt,systemPromptPath:i.systemPromptPath,codeReviewPromptPath:i.codeReviewPromptPath,timeout:i.timeout,temperature:i.temperature,maxTokens:i.maxTokens,logging:i.logging,locale:i.locale,generate:i.generate,type:i.type,maxLength:i.maxLength,includeBody:i.includeBody,codeReview:i.codeReview,disabled:i.disabled,stream:i.stream,watchMode:i.watchMode,disableLowerCase:i.disableLowerCase,diffCompression:i.diffCompression,maxHunkLines:i.maxHunkLines,maxDiffLines:i.maxDiffLines,diffContext:i.diffContext},OLLAMA:{model:e=>e?(typeof e=="string"?e?.split(","):e).map(o=>o.trim()).filter(o=>!!o&&o.length>0):[],host:e=>e?(E("OLLAMA.host",/^https?:\/\//.test(e),"Must be a valid URL"),e):Ie,timeout:e=>{if(!e)return 1e5;E("OLLAMA.timeout",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return E("OLLAMA.timeout",t>=500,"Must be greater than 500ms"),t},auth:e=>e|