aicommit2 2.4.31 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +146 -57
- package/dist/cli.mjs +184 -173
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,26 +1,54 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{command as de,cli as Mn}from"cleye";import{createRequire as Rn}from"module";import Dn from"crypto";import X from"fs";import Fe from"os";import x from"path";import{Buffer as Tr}from"node:buffer";import ge from"node:path";import Rt,{ChildProcess as jr,exec as On}from"node:child_process";import ae from"node:process";import Nn,{execSync as Ze,exec as Fn}from"child_process";import{fileURLToPath as Br}from"node:url";import _n,{constants as Gr}from"node:os";import Hr from"assert";import Ur from"events";import{createWriteStream as Ln,createReadStream as Tn,readFileSync as jn}from"node:fs";import Bn from"buffer";import Dt from"stream";import zr,{promisify as Gn}from"util";import{debuglog as Hn,promisify as Un}from"node:util";import et from"inquirer";import{of as Ot,concatMap as F,from as D,map as O,catchError as N,mergeMap as Kr,BehaviorSubject as Wr,ReplaySubject as zn,Subscription as Nt,lastValueFrom as Ft,toArray as _t,filter as Yr,Subject as Lt}from"rxjs";import _ from"fs/promises";import C from"chalk";import Kn from"@anthropic-ai/sdk";import{fromPromise as L}from"rxjs/internal/observable/innerFrom";import{xxh64 as Jr}from"@pacote/xxhash";import U from"winston";import"winston-daily-rotate-file";import Vr from"https";import Wn from"axios";import{CohereClientV2 as Yn}from"cohere-ai";import qr from"openai";import{GoogleGenerativeAI as Jn,HarmCategory as tt,HarmBlockThreshold as rt}from"@google/generative-ai";import Vn from"http";import qn from"net";import Xn from"tls";import Qn,{fileURLToPath as Zn,pathToFileURL as es}from"url";import Xr from"tty";import ts from"groq-sdk";import{Ollama as rs}from"ollama";import{fetch as os,Agent as ns}from"undici";import ot from"readline";import Qr from"figlet";import ss from"gradient-string";import Zr from"ora";import is from"inquirer-reactive-list-prompt";import{readdir as eo,stat as as,rm as cs}from"node:fs/promises";import ls from"chokidar";import{takeUntil as to,finalize as ro}from"rxjs/operators";var us="aicommit2",oo="2.4.31",ds="A Reactive CLI that generates commit messages for Git and Jujutsu with various AI",ms=["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"],fs="MIT",ps="tak-bro/aicommit2",hs="Hyungtak Jin(@tak-bro)",gs="module",ys=["dist"],ws={aicommit2:"./dist/cli.mjs",aic2:"./dist/cli.mjs"},vs={prepare:"simple-git-hooks",build:"pkgroll --minify",lint:"eslint --cache .","type-check":"tsc",test:"tsx tests",prepack:"pnpm build && clean-pkg-json",prettier:"prettier"},Cs={"@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.0.16",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"},bs={"@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"},Es={extends:["@pvtnbr","prettier"],rules:{"unicorn/no-process-exit":"off"},overrides:[{files:"./src/commands/prepare-commit-msg-hook.ts",rules:{"unicorn/prevent-abbreviations":"off"}}]},Ps={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"]},$s={name:us,version:oo,description:ds,keywords:ms,license:fs,repository:ps,author:hs,type:gs,files:ys,bin:ws,scripts:vs,"simple-git-hooks":{"pre-commit":"pnpm lint-staged"},"lint-staged":{"*.ts":["prettier --config ./.prettierrc --write","eslint --fix"]},dependencies:Cs,devDependencies:bs,eslintConfig:Es,release:Ps},As=Rn(import.meta.url),H=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ee(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Pe={exports:{}},Tt,no;function ks(){if(no)return Tt;no=1,Tt=o,o.sync=n;var t=X;function e(s,i){var l=i.pathExt!==void 0?i.pathExt:process.env.PATHEXT;if(!l||(l=l.split(";"),l.indexOf("")!==-1))return!0;for(var a=0;a<l.length;a++){var d=l[a].toLowerCase();if(d&&s.substr(-d.length).toLowerCase()===d)return!0}return!1}function r(s,i,l){return!s.isSymbolicLink()&&!s.isFile()?!1:e(i,l)}function o(s,i,l){t.stat(s,function(a,d){l(a,a?!1:r(d,s,i))})}function n(s,i){return r(t.statSync(s),s,i)}return Tt}var jt,so;function Ss(){if(so)return jt;so=1,jt=e,e.sync=r;var t=X;function e(s,i,l){t.stat(s,function(a,d){l(a,a?!1:o(d,i))})}function r(s,i){return o(t.statSync(s),i)}function o(s,i){return s.isFile()&&n(s,i)}function n(s,i){var l=s.mode,a=s.uid,d=s.gid,c=i.uid!==void 0?i.uid:process.getuid&&process.getuid(),u=i.gid!==void 0?i.gid:process.getgid&&process.getgid(),f=parseInt("100",8),p=parseInt("010",8),h=parseInt("001",8),g=f|p,y=l&h||l&p&&d===u||l&f&&a===c||l&g&&c===0;return y}return jt}var nt;process.platform==="win32"||H.TESTING_WINDOWS?nt=ks():nt=Ss();var xs=Bt;Bt.sync=Is;function Bt(t,e,r){if(typeof e=="function"&&(r=e,e={}),!r){if(typeof Promise!="function")throw new TypeError("callback not provided");return new Promise(function(o,n){Bt(t,e||{},function(s,i){s?n(s):o(i)})})}nt(t,e||{},function(o,n){o&&(o.code==="EACCES"||e&&e.ignoreErrors)&&(o=null,n=!1),r(o,n)})}function Is(t,e){try{return nt.sync(t,e||{})}catch(r){if(e&&e.ignoreErrors||r.code==="EACCES")return!1;throw r}}const $e=process.platform==="win32"||process.env.OSTYPE==="cygwin"||process.env.OSTYPE==="msys",io=x,Ms=$e?";":":",ao=xs,co=t=>Object.assign(new Error(`not found: ${t}`),{code:"ENOENT"}),lo=(t,e)=>{const r=e.colon||Ms,o=t.match(/\//)||$e&&t.match(/\\/)?[""]:[...$e?[process.cwd()]:[],...(e.path||process.env.PATH||"").split(r)],n=$e?e.pathExt||process.env.PATHEXT||".EXE;.CMD;.BAT;.COM":"",s=$e?n.split(r):[""];return $e&&t.indexOf(".")!==-1&&s[0]!==""&&s.unshift(""),{pathEnv:o,pathExt:s,pathExtExe:n}},uo=(t,e,r)=>{typeof e=="function"&&(r=e,e={}),e||(e={});const{pathEnv:o,pathExt:n,pathExtExe:s}=lo(t,e),i=[],l=d=>new Promise((c,u)=>{if(d===o.length)return e.all&&i.length?c(i):u(co(t));const f=o[d],p=/^".*"$/.test(f)?f.slice(1,-1):f,h=io.join(p,t),g=!p&&/^\.[\\\/]/.test(t)?t.slice(0,2)+h:h;c(a(g,d,0))}),a=(d,c,u)=>new Promise((f,p)=>{if(u===n.length)return f(l(c+1));const h=n[u];ao(d+h,{pathExt:s},(g,y)=>{if(!g&&y)if(e.all)i.push(d+h);else return f(d+h);return f(a(d,c,u+1))})});return r?l(0).then(d=>r(null,d),r):l(0)},Rs=(t,e)=>{e=e||{};const{pathEnv:r,pathExt:o,pathExtExe:n}=lo(t,e),s=[];for(let i=0;i<r.length;i++){const l=r[i],a=/^".*"$/.test(l)?l.slice(1,-1):l,d=io.join(a,t),c=!a&&/^\.[\\\/]/.test(t)?t.slice(0,2)+d:d;for(let u=0;u<o.length;u++){const f=c+o[u];try{if(ao.sync(f,{pathExt:n}))if(e.all)s.push(f);else return f}catch{}}}if(e.all&&s.length)return s;if(e.nothrow)return null;throw co(t)};var Ds=uo;uo.sync=Rs;var Gt={exports:{}};const mo=(t={})=>{const e=t.env||process.env;return(t.platform||process.platform)!=="win32"?"PATH":Object.keys(e).reverse().find(o=>o.toUpperCase()==="PATH")||"Path"};Gt.exports=mo,Gt.exports.default=mo;var Os=Gt.exports;const fo=x,Ns=Ds,Fs=Os;function po(t,e){const r=t.options.env||process.env,o=process.cwd(),n=t.options.cwd!=null,s=n&&process.chdir!==void 0&&!process.chdir.disabled;if(s)try{process.chdir(t.options.cwd)}catch{}let i;try{i=Ns.sync(t.command,{path:r[Fs({env:r})],pathExt:e?fo.delimiter:void 0})}catch{}finally{s&&process.chdir(o)}return i&&(i=fo.resolve(n?t.options.cwd:"",i)),i}function _s(t){return po(t)||po(t,!0)}var Ls=_s,Ht={};const Ut=/([()\][%!^"`<>&|;, *?])/g;function Ts(t){return t=t.replace(Ut,"^$1"),t}function js(t,e){return t=`${t}`,t=t.replace(/(?=(\\+?)?)\1"/g,'$1$1\\"'),t=t.replace(/(?=(\\+?)?)\1$/,"$1$1"),t=`"${t}"`,t=t.replace(Ut,"^$1"),e&&(t=t.replace(Ut,"^$1")),t}Ht.command=Ts,Ht.argument=js;var Bs=/^#!(.*)/;const Gs=Bs;var Hs=(t="")=>{const e=t.match(Gs);if(!e)return null;const[r,o]=e[0].replace(/#! ?/,"").split(" "),n=r.split("/").pop();return n==="env"?o:o?`${n} ${o}`:n};const zt=X,Us=Hs;function zs(t){const r=Buffer.alloc(150);let o;try{o=zt.openSync(t,"r"),zt.readSync(o,r,0,150,0),zt.closeSync(o)}catch{}return Us(r.toString())}var Ks=zs;const Ws=x,ho=Ls,go=Ht,Ys=Ks,Js=process.platform==="win32",Vs=/\.(?:com|exe)$/i,qs=/node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;function Xs(t){t.file=ho(t);const e=t.file&&Ys(t.file);return e?(t.args.unshift(t.file),t.command=e,ho(t)):t.file}function Qs(t){if(!Js)return t;const e=Xs(t),r=!Vs.test(e);if(t.options.forceShell||r){const o=qs.test(e);t.command=Ws.normalize(t.command),t.command=go.command(t.command),t.args=t.args.map(s=>go.argument(s,o));const n=[t.command].concat(t.args).join(" ");t.args=["/d","/s","/c",`"${n}"`],t.command=process.env.comspec||"cmd.exe",t.options.windowsVerbatimArguments=!0}return t}function Zs(t,e,r){e&&!Array.isArray(e)&&(r=e,e=null),e=e?e.slice(0):[],r=Object.assign({},r);const o={command:t,args:e,options:r,file:void 0,original:{command:t,args:e}};return r.shell?o:Qs(o)}var ei=Zs;const Kt=process.platform==="win32";function Wt(t,e){return Object.assign(new Error(`${e} ${t.command} ENOENT`),{code:"ENOENT",errno:"ENOENT",syscall:`${e} ${t.command}`,path:t.command,spawnargs:t.args})}function ti(t,e){if(!Kt)return;const r=t.emit;t.emit=function(o,n){if(o==="exit"){const s=yo(n,e);if(s)return r.call(t,"error",s)}return r.apply(t,arguments)}}function yo(t,e){return Kt&&t===1&&!e.file?Wt(e.original,"spawn"):null}function ri(t,e){return Kt&&t===1&&!e.file?Wt(e.original,"spawnSync"):null}var oi={hookChildProcess:ti,verifyENOENT:yo,verifyENOENTSync:ri,notFoundError:Wt};const wo=Nn,Yt=ei,Jt=oi;function vo(t,e,r){const o=Yt(t,e,r),n=wo.spawn(o.command,o.args,o.options);return Jt.hookChildProcess(n,o),n}function ni(t,e,r){const o=Yt(t,e,r),n=wo.spawnSync(o.command,o.args,o.options);return n.error=n.error||Jt.verifyENOENTSync(n.status,o),n}Pe.exports=vo,Pe.exports.spawn=vo,Pe.exports.sync=ni,Pe.exports._parse=Yt,Pe.exports._enoent=Jt;var si=Pe.exports,ii=Ee(si);function ai(t){const e=typeof t=="string"?`
|
|
2
|
+
import{command as ce,cli as Ks}from"cleye";import{createRequire as zs}from"module";import Ws from"crypto";import Z from"fs";import Le from"os";import M from"path";import{Buffer as Kr}from"node:buffer";import we from"node:path";import jt,{ChildProcess as zr,exec as Ys}from"node:child_process";import le from"node:process";import Vs,{execSync as rt,exec as qs}from"child_process";import{fileURLToPath as Wr}from"node:url";import Js,{constants as Yr}from"node:os";import Vr from"assert";import qr from"events";import{createWriteStream as Xs,createReadStream as Qs,readFileSync as Zs}from"node:fs";import en from"buffer";import Bt from"stream";import Jr,{promisify as tn}from"util";import{debuglog as rn,promisify as on}from"node:util";import ot from"inquirer";import{of as Xr,concatMap as F,from as N,map as T,catchError as L,tap as Qr,mergeMap as Zr,BehaviorSubject as eo,ReplaySubject as sn,Subscription as Gt,lastValueFrom as Ut,toArray as Ht,filter as to,Subject as Kt}from"rxjs";import D from"fs/promises";import g from"chalk";import ro from"openai";import{fromPromise as j}from"rxjs/internal/observable/innerFrom";import{xxh64 as oo}from"@pacote/xxhash";import K from"winston";import"winston-daily-rotate-file";import nn from"http";import so from"https";import an from"net";import cn from"tls";import ln,{fileURLToPath as un,pathToFileURL as dn}from"url";import no from"tty";import mn from"@anthropic-ai/sdk";import pn from"axios";import{CohereClientV2 as fn}from"cohere-ai";import{GoogleGenerativeAI as hn,HarmCategory as st,HarmBlockThreshold as nt}from"@google/generative-ai";import gn from"groq-sdk";import{Ollama as yn}from"ollama";import{fetch as wn,Agent as vn}from"undici";import it from"readline";import io from"figlet";import Cn from"gradient-string";import ao from"ora";import bn from"inquirer-reactive-list-prompt";import{readdir as co,stat as En,rm as $n}from"node:fs/promises";import Pn from"chokidar";import{takeUntil as lo,finalize as uo}from"rxjs/operators";var An="aicommit2",mo="2.5.1",Sn="A Reactive CLI that generates commit messages for Git and Jujutsu with various AI",kn=["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"],In="MIT",Mn="tak-bro/aicommit2",xn="Hyungtak Jin(@tak-bro)",Rn="module",On=["dist"],Dn={aicommit2:"./dist/cli.mjs",aic2:"./dist/cli.mjs"},_n={prepare:"simple-git-hooks",build:"pkgroll --minify",lint:"eslint --cache .","type-check":"tsc",test:"tsx tests",prepack:"pnpm build && clean-pkg-json",prettier:"prettier"},Nn={"@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.0.16",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"},Tn={"@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"},Ln={extends:["@pvtnbr","prettier"],rules:{"unicorn/no-process-exit":"off"},overrides:[{files:"./src/commands/prepare-commit-msg-hook.ts",rules:{"unicorn/prevent-abbreviations":"off"}}]},Fn={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"]},jn={name:An,version:mo,description:Sn,keywords:kn,license:In,repository:Mn,author:xn,type:Rn,files:On,bin:Dn,scripts:_n,"simple-git-hooks":{"pre-commit":"pnpm lint-staged"},"lint-staged":{"*.ts":["prettier --config ./.prettierrc --write","eslint --fix"]},dependencies:Nn,devDependencies:Tn,eslintConfig:Ln,release:Fn},Bn=zs(import.meta.url),H=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Pe(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Ae={exports:{}},zt,po;function Gn(){if(po)return zt;po=1,zt=o,o.sync=s;var t=Z;function e(n,i){var a=i.pathExt!==void 0?i.pathExt:process.env.PATHEXT;if(!a||(a=a.split(";"),a.indexOf("")!==-1))return!0;for(var c=0;c<a.length;c++){var d=a[c].toLowerCase();if(d&&n.substr(-d.length).toLowerCase()===d)return!0}return!1}function r(n,i,a){return!n.isSymbolicLink()&&!n.isFile()?!1:e(i,a)}function o(n,i,a){t.stat(n,function(c,d){a(c,c?!1:r(d,n,i))})}function s(n,i){return r(t.statSync(n),n,i)}return zt}var Wt,fo;function Un(){if(fo)return Wt;fo=1,Wt=e,e.sync=r;var t=Z;function e(n,i,a){t.stat(n,function(c,d){a(c,c?!1:o(d,i))})}function r(n,i){return o(t.statSync(n),i)}function o(n,i){return n.isFile()&&s(n,i)}function s(n,i){var a=n.mode,c=n.uid,d=n.gid,l=i.uid!==void 0?i.uid:process.getuid&&process.getuid(),u=i.gid!==void 0?i.gid:process.getgid&&process.getgid(),p=parseInt("100",8),f=parseInt("010",8),h=parseInt("001",8),y=p|f,w=a&h||a&f&&d===u||a&p&&c===l||a&y&&l===0;return w}return Wt}var at;process.platform==="win32"||H.TESTING_WINDOWS?at=Gn():at=Un();var Hn=Yt;Yt.sync=Kn;function Yt(t,e,r){if(typeof e=="function"&&(r=e,e={}),!r){if(typeof Promise!="function")throw new TypeError("callback not provided");return new Promise(function(o,s){Yt(t,e||{},function(n,i){n?s(n):o(i)})})}at(t,e||{},function(o,s){o&&(o.code==="EACCES"||e&&e.ignoreErrors)&&(o=null,s=!1),r(o,s)})}function Kn(t,e){try{return at.sync(t,e||{})}catch(r){if(e&&e.ignoreErrors||r.code==="EACCES")return!1;throw r}}const Se=process.platform==="win32"||process.env.OSTYPE==="cygwin"||process.env.OSTYPE==="msys",ho=M,zn=Se?";":":",go=Hn,yo=t=>Object.assign(new Error(`not found: ${t}`),{code:"ENOENT"}),wo=(t,e)=>{const r=e.colon||zn,o=t.match(/\//)||Se&&t.match(/\\/)?[""]:[...Se?[process.cwd()]:[],...(e.path||process.env.PATH||"").split(r)],s=Se?e.pathExt||process.env.PATHEXT||".EXE;.CMD;.BAT;.COM":"",n=Se?s.split(r):[""];return Se&&t.indexOf(".")!==-1&&n[0]!==""&&n.unshift(""),{pathEnv:o,pathExt:n,pathExtExe:s}},vo=(t,e,r)=>{typeof e=="function"&&(r=e,e={}),e||(e={});const{pathEnv:o,pathExt:s,pathExtExe:n}=wo(t,e),i=[],a=d=>new Promise((l,u)=>{if(d===o.length)return e.all&&i.length?l(i):u(yo(t));const p=o[d],f=/^".*"$/.test(p)?p.slice(1,-1):p,h=ho.join(f,t),y=!f&&/^\.[\\\/]/.test(t)?t.slice(0,2)+h:h;l(c(y,d,0))}),c=(d,l,u)=>new Promise((p,f)=>{if(u===s.length)return p(a(l+1));const h=s[u];go(d+h,{pathExt:n},(y,w)=>{if(!y&&w)if(e.all)i.push(d+h);else return p(d+h);return p(c(d,l,u+1))})});return r?a(0).then(d=>r(null,d),r):a(0)},Wn=(t,e)=>{e=e||{};const{pathEnv:r,pathExt:o,pathExtExe:s}=wo(t,e),n=[];for(let i=0;i<r.length;i++){const a=r[i],c=/^".*"$/.test(a)?a.slice(1,-1):a,d=ho.join(c,t),l=!c&&/^\.[\\\/]/.test(t)?t.slice(0,2)+d:d;for(let u=0;u<o.length;u++){const p=l+o[u];try{if(go.sync(p,{pathExt:s}))if(e.all)n.push(p);else return p}catch{}}}if(e.all&&n.length)return n;if(e.nothrow)return null;throw yo(t)};var Yn=vo;vo.sync=Wn;var Vt={exports:{}};const Co=(t={})=>{const e=t.env||process.env;return(t.platform||process.platform)!=="win32"?"PATH":Object.keys(e).reverse().find(o=>o.toUpperCase()==="PATH")||"Path"};Vt.exports=Co,Vt.exports.default=Co;var Vn=Vt.exports;const bo=M,qn=Yn,Jn=Vn;function Eo(t,e){const r=t.options.env||process.env,o=process.cwd(),s=t.options.cwd!=null,n=s&&process.chdir!==void 0&&!process.chdir.disabled;if(n)try{process.chdir(t.options.cwd)}catch{}let i;try{i=qn.sync(t.command,{path:r[Jn({env:r})],pathExt:e?bo.delimiter:void 0})}catch{}finally{n&&process.chdir(o)}return i&&(i=bo.resolve(s?t.options.cwd:"",i)),i}function Xn(t){return Eo(t)||Eo(t,!0)}var Qn=Xn,qt={};const Jt=/([()\][%!^"`<>&|;, *?])/g;function Zn(t){return t=t.replace(Jt,"^$1"),t}function ei(t,e){return t=`${t}`,t=t.replace(/(?=(\\+?)?)\1"/g,'$1$1\\"'),t=t.replace(/(?=(\\+?)?)\1$/,"$1$1"),t=`"${t}"`,t=t.replace(Jt,"^$1"),e&&(t=t.replace(Jt,"^$1")),t}qt.command=Zn,qt.argument=ei;var ti=/^#!(.*)/;const ri=ti;var oi=(t="")=>{const e=t.match(ri);if(!e)return null;const[r,o]=e[0].replace(/#! ?/,"").split(" "),s=r.split("/").pop();return s==="env"?o:o?`${s} ${o}`:s};const Xt=Z,si=oi;function ni(t){const r=Buffer.alloc(150);let o;try{o=Xt.openSync(t,"r"),Xt.readSync(o,r,0,150,0),Xt.closeSync(o)}catch{}return si(r.toString())}var ii=ni;const ai=M,$o=Qn,Po=qt,ci=ii,li=process.platform==="win32",ui=/\.(?:com|exe)$/i,di=/node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;function mi(t){t.file=$o(t);const e=t.file&&ci(t.file);return e?(t.args.unshift(t.file),t.command=e,$o(t)):t.file}function pi(t){if(!li)return t;const e=mi(t),r=!ui.test(e);if(t.options.forceShell||r){const o=di.test(e);t.command=ai.normalize(t.command),t.command=Po.command(t.command),t.args=t.args.map(n=>Po.argument(n,o));const s=[t.command].concat(t.args).join(" ");t.args=["/d","/s","/c",`"${s}"`],t.command=process.env.comspec||"cmd.exe",t.options.windowsVerbatimArguments=!0}return t}function fi(t,e,r){e&&!Array.isArray(e)&&(r=e,e=null),e=e?e.slice(0):[],r=Object.assign({},r);const o={command:t,args:e,options:r,file:void 0,original:{command:t,args:e}};return r.shell?o:pi(o)}var hi=fi;const Qt=process.platform==="win32";function Zt(t,e){return Object.assign(new Error(`${e} ${t.command} ENOENT`),{code:"ENOENT",errno:"ENOENT",syscall:`${e} ${t.command}`,path:t.command,spawnargs:t.args})}function gi(t,e){if(!Qt)return;const r=t.emit;t.emit=function(o,s){if(o==="exit"){const n=Ao(s,e);if(n)return r.call(t,"error",n)}return r.apply(t,arguments)}}function Ao(t,e){return Qt&&t===1&&!e.file?Zt(e.original,"spawn"):null}function yi(t,e){return Qt&&t===1&&!e.file?Zt(e.original,"spawnSync"):null}var wi={hookChildProcess:gi,verifyENOENT:Ao,verifyENOENTSync:yi,notFoundError:Zt};const So=Vs,er=hi,tr=wi;function ko(t,e,r){const o=er(t,e,r),s=So.spawn(o.command,o.args,o.options);return tr.hookChildProcess(s,o),s}function vi(t,e,r){const o=er(t,e,r),s=So.spawnSync(o.command,o.args,o.options);return s.error=s.error||tr.verifyENOENTSync(s.status,o),s}Ae.exports=ko,Ae.exports.spawn=ko,Ae.exports.sync=vi,Ae.exports._parse=er,Ae.exports._enoent=tr;var Ci=Ae.exports,bi=Pe(Ci);function Ei(t){const e=typeof t=="string"?`
|
|
3
3
|
`:`
|
|
4
|
-
`.charCodeAt(),r=typeof t=="string"?"\r":"\r".charCodeAt();return t[t.length-1]===e&&(t=t.slice(0,-1)),t[t.length-1]===r&&(t=t.slice(0,-1)),t}function
|
|
5
|
-
${e}`,
|
|
6
|
-
${o.message}`:
|
|
7
|
-
`);return
|
|
8
|
-
`)},
|
|
4
|
+
`.charCodeAt(),r=typeof t=="string"?"\r":"\r".charCodeAt();return t[t.length-1]===e&&(t=t.slice(0,-1)),t[t.length-1]===r&&(t=t.slice(0,-1)),t}function Io(t={}){const{env:e=process.env,platform:r=process.platform}=t;return r!=="win32"?"PATH":Object.keys(e).reverse().find(o=>o.toUpperCase()==="PATH")||"Path"}const $i=({cwd:t=le.cwd(),path:e=le.env[Io()],preferLocal:r=!0,execPath:o=le.execPath,addExecPath:s=!0}={})=>{const n=t instanceof URL?Wr(t):t,i=we.resolve(n),a=[];return r&&Pi(a,i),s&&Ai(a,o,i),[...a,e].join(we.delimiter)},Pi=(t,e)=>{let r;for(;r!==e;)t.push(we.join(e,"node_modules/.bin")),r=e,e=we.resolve(e,"..")},Ai=(t,e,r)=>{const o=e instanceof URL?Wr(e):e;t.push(we.resolve(r,o,".."))},Si=({env:t=le.env,...e}={})=>{t={...t};const r=Io({env:t});return e.path=t[r],t[r]=$i(e),t},ki=(t,e,r,o)=>{if(r==="length"||r==="prototype"||r==="arguments"||r==="caller")return;const s=Object.getOwnPropertyDescriptor(t,r),n=Object.getOwnPropertyDescriptor(e,r);!Ii(s,n)&&o||Object.defineProperty(t,r,n)},Ii=function(t,e){return t===void 0||t.configurable||t.writable===e.writable&&t.enumerable===e.enumerable&&t.configurable===e.configurable&&(t.writable||t.value===e.value)},Mi=(t,e)=>{const r=Object.getPrototypeOf(e);r!==Object.getPrototypeOf(t)&&Object.setPrototypeOf(t,r)},xi=(t,e)=>`/* Wrapped ${t}*/
|
|
5
|
+
${e}`,Ri=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),Oi=Object.getOwnPropertyDescriptor(Function.prototype.toString,"name"),Di=(t,e,r)=>{const o=r===""?"":`with ${r.trim()}() `,s=xi.bind(null,o,e.toString());Object.defineProperty(s,"name",Oi),Object.defineProperty(t,"toString",{...Ri,value:s})};function _i(t,e,{ignoreNonConfigurable:r=!1}={}){const{name:o}=t;for(const s of Reflect.ownKeys(e))ki(t,e,s,r);return Mi(t,e),Di(t,e,o),t}const ct=new WeakMap,Mo=(t,e={})=>{if(typeof t!="function")throw new TypeError("Expected a function");let r,o=0;const s=t.displayName||t.name||"<anonymous>",n=function(...i){if(ct.set(n,++o),o===1)r=t.apply(this,i),t=null;else if(e.throw===!0)throw new Error(`Function \`${s}\` can only be called once`);return r};return _i(n,t),ct.set(n,o),n};Mo.callCount=t=>{if(!ct.has(t))throw new Error(`The given function \`${t.name}\` is not wrapped by the \`onetime\` package`);return ct.get(t)};const Ni=()=>{const t=Ro-xo+1;return Array.from({length:t},Ti)},Ti=(t,e)=>({name:`SIGRT${e+1}`,number:xo+e,action:"terminate",description:"Application-specific signal (realtime)",standard:"posix"}),xo=34,Ro=64,Li=[{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"}],Oo=()=>{const t=Ni();return[...Li,...t].map(Fi)},Fi=({name:t,number:e,description:r,action:o,forced:s=!1,standard:n})=>{const{signals:{[t]:i}}=Yr,a=i!==void 0;return{name:t,number:a?i:e,description:r,supported:a,action:o,forced:s,standard:n}},ji=()=>{const t=Oo();return Object.fromEntries(t.map(Bi))},Bi=({name:t,number:e,description:r,supported:o,action:s,forced:n,standard:i})=>[t,{name:t,number:e,description:r,supported:o,action:s,forced:n,standard:i}],Gi=ji(),Ui=()=>{const t=Oo(),e=Ro+1,r=Array.from({length:e},(o,s)=>Hi(s,t));return Object.assign({},...r)},Hi=(t,e)=>{const r=Ki(t,e);if(r===void 0)return{};const{name:o,description:s,supported:n,action:i,forced:a,standard:c}=r;return{[t]:{name:o,number:t,description:s,supported:n,action:i,forced:a,standard:c}}},Ki=(t,e)=>{const r=e.find(({name:o})=>Yr.signals[o]===t);return r!==void 0?r:e.find(o=>o.number===t)};Ui();const zi=({timedOut:t,timeout:e,errorCode:r,signal:o,signalDescription:s,exitCode:n,isCanceled:i})=>t?`timed out after ${e} milliseconds`:i?"was canceled":r!==void 0?`failed with ${r}`:o!==void 0?`was killed with ${o} (${s})`:n!==void 0?`failed with exit code ${n}`:"failed",lt=({stdout:t,stderr:e,all:r,error:o,signal:s,exitCode:n,command:i,escapedCommand:a,timedOut:c,isCanceled:d,killed:l,parsed:{options:{timeout:u,cwd:p=le.cwd()}}})=>{n=n===null?void 0:n,s=s===null?void 0:s;const f=s===void 0?void 0:Gi[s].description,h=o&&o.code,w=`Command ${zi({timedOut:c,timeout:u,errorCode:h,signal:s,signalDescription:f,exitCode:n,isCanceled:d})}: ${i}`,C=Object.prototype.toString.call(o)==="[object Error]",b=C?`${w}
|
|
6
|
+
${o.message}`:w,E=[b,e,t].filter(Boolean).join(`
|
|
7
|
+
`);return C?(o.originalMessage=o.message,o.message=E):o=new Error(E),o.shortMessage=b,o.command=i,o.escapedCommand=a,o.exitCode=n,o.signal=s,o.signalDescription=f,o.stdout=t,o.stderr=e,o.cwd=p,r!==void 0&&(o.all=r),"bufferedData"in o&&delete o.bufferedData,o.failed=!0,o.timedOut=!!c,o.isCanceled=d,o.killed=l&&!c,o},ut=["stdin","stdout","stderr"],Wi=t=>ut.some(e=>t[e]!==void 0),Do=t=>{if(!t)return;const{stdio:e}=t;if(e===void 0)return ut.map(o=>t[o]);if(Wi(t))throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${ut.map(o=>`\`${o}\``).join(", ")}`);if(typeof e=="string")return e;if(!Array.isArray(e))throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof e}\``);const r=Math.max(e.length,ut.length);return Array.from({length:r},(o,s)=>e[s])},Yi=t=>{const e=Do(t);return e==="ipc"?"ipc":e===void 0||typeof e=="string"?[e,e,e,"ipc"]:e.includes("ipc")?e:[...e,"ipc"]};var ke={exports:{}},dt={exports:{}};dt.exports;var _o;function Vi(){return _o||(_o=1,function(t){t.exports=["SIGABRT","SIGALRM","SIGHUP","SIGINT","SIGTERM"],process.platform!=="win32"&&t.exports.push("SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT"),process.platform==="linux"&&t.exports.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT","SIGUNUSED")}(dt)),dt.exports}var B=H.process;const ve=function(t){return t&&typeof t=="object"&&typeof t.removeListener=="function"&&typeof t.emit=="function"&&typeof t.reallyExit=="function"&&typeof t.listeners=="function"&&typeof t.kill=="function"&&typeof t.pid=="number"&&typeof t.on=="function"};if(!ve(B))ke.exports=function(){return function(){}};else{var qi=Vr,Fe=Vi(),Ji=/^win/i.test(B.platform),mt=qr;typeof mt!="function"&&(mt=mt.EventEmitter);var z;B.__signal_exit_emitter__?z=B.__signal_exit_emitter__:(z=B.__signal_exit_emitter__=new mt,z.count=0,z.emitted={}),z.infinite||(z.setMaxListeners(1/0),z.infinite=!0),ke.exports=function(t,e){if(!ve(H.process))return function(){};qi.equal(typeof t,"function","a callback must be provided for exit handler"),je===!1&&No();var r="exit";e&&e.alwaysLast&&(r="afterexit");var o=function(){z.removeListener(r,t),z.listeners("exit").length===0&&z.listeners("afterexit").length===0&&rr()};return z.on(r,t),o};var rr=function(){!je||!ve(H.process)||(je=!1,Fe.forEach(function(e){try{B.removeListener(e,or[e])}catch{}}),B.emit=sr,B.reallyExit=To,z.count-=1)};ke.exports.unload=rr;var Ie=function(e,r,o){z.emitted[e]||(z.emitted[e]=!0,z.emit(e,r,o))},or={};Fe.forEach(function(t){or[t]=function(){if(ve(H.process)){var r=B.listeners(t);r.length===z.count&&(rr(),Ie("exit",null,t),Ie("afterexit",null,t),Ji&&t==="SIGHUP"&&(t="SIGINT"),B.kill(B.pid,t))}}}),ke.exports.signals=function(){return Fe};var je=!1,No=function(){je||!ve(H.process)||(je=!0,z.count+=1,Fe=Fe.filter(function(e){try{return B.on(e,or[e]),!0}catch{return!1}}),B.emit=Qi,B.reallyExit=Xi)};ke.exports.load=No;var To=B.reallyExit,Xi=function(e){ve(H.process)&&(B.exitCode=e||0,Ie("exit",B.exitCode,null),Ie("afterexit",B.exitCode,null),To.call(B,B.exitCode))},sr=B.emit,Qi=function(e,r){if(e==="exit"&&ve(H.process)){r!==void 0&&(B.exitCode=r);var o=sr.apply(this,arguments);return Ie("exit",B.exitCode,null),Ie("afterexit",B.exitCode,null),o}else return sr.apply(this,arguments)}}var Zi=ke.exports,ea=Pe(Zi);const ta=1e3*5,ra=(t,e="SIGTERM",r={})=>{const o=t(e);return oa(t,e,r,o),o},oa=(t,e,r,o)=>{if(!sa(e,r,o))return;const s=ia(r),n=setTimeout(()=>{t("SIGKILL")},s);n.unref&&n.unref()},sa=(t,{forceKillAfterTimeout:e},r)=>na(t)&&e!==!1&&r,na=t=>t===Js.constants.signals.SIGTERM||typeof t=="string"&&t.toUpperCase()==="SIGTERM",ia=({forceKillAfterTimeout:t=!0})=>{if(t===!0)return ta;if(!Number.isFinite(t)||t<0)throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${t}\` (${typeof t})`);return t},aa=(t,e)=>{t.kill()&&(e.isCanceled=!0)},ca=(t,e,r)=>{t.kill(e),r(Object.assign(new Error("Timed out"),{timedOut:!0,signal:e}))},la=(t,{timeout:e,killSignal:r="SIGTERM"},o)=>{if(e===0||e===void 0)return o;let s;const n=new Promise((a,c)=>{s=setTimeout(()=>{ca(t,r,c)},e)}),i=o.finally(()=>{clearTimeout(s)});return Promise.race([n,i])},ua=({timeout:t})=>{if(t!==void 0&&(!Number.isFinite(t)||t<0))throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${t}\` (${typeof t})`)},da=async(t,{cleanup:e,detached:r},o)=>{if(!e||r)return o;const s=ea(()=>{t.kill()});return o.finally(()=>{s()})};function nr(t){return t!==null&&typeof t=="object"&&typeof t.pipe=="function"}function Lo(t){return nr(t)&&t.writable!==!1&&typeof t._write=="function"&&typeof t._writableState=="object"}const ma=t=>t instanceof zr&&typeof t.then=="function",ir=(t,e,r)=>{if(typeof r=="string")return t[e].pipe(Xs(r)),t;if(Lo(r))return t[e].pipe(r),t;if(!ma(r))throw new TypeError("The second argument must be a string, a stream or an Execa child process.");if(!Lo(r.stdin))throw new TypeError("The target child process's stdin must be available.");return t[e].pipe(r.stdin),r},pa=t=>{t.stdout!==null&&(t.pipeStdout=ir.bind(void 0,t,"stdout")),t.stderr!==null&&(t.pipeStderr=ir.bind(void 0,t,"stderr")),t.all!==void 0&&(t.pipeAll=ir.bind(void 0,t,"all"))};var Be={exports:{}};const{PassThrough:fa}=Bt;var ha=t=>{t={...t};const{array:e}=t;let{encoding:r}=t;const o=r==="buffer";let s=!1;e?s=!(r||o):r=r||"utf8",o&&(r=null);const n=new fa({objectMode:s});r&&n.setEncoding(r);let i=0;const a=[];return n.on("data",c=>{a.push(c),s?i=a.length:i+=c.length}),n.getBufferedValue=()=>e?a:o?Buffer.concat(a,i):a.join(""),n.getBufferedLength=()=>i,n};const{constants:ga}=en,ya=Bt,{promisify:wa}=Jr,va=ha,Ca=wa(ya.pipeline);class Fo extends Error{constructor(){super("maxBuffer exceeded"),this.name="MaxBufferError"}}async function ar(t,e){if(!t)throw new Error("Expected a stream");e={maxBuffer:1/0,...e};const{maxBuffer:r}=e,o=va(e);return await new Promise((s,n)=>{const i=a=>{a&&o.getBufferedLength()<=ga.MAX_LENGTH&&(a.bufferedData=o.getBufferedValue()),n(a)};(async()=>{try{await Ca(t,o),s()}catch(a){i(a)}})(),o.on("data",()=>{o.getBufferedLength()>r&&i(new Fo)})}),o.getBufferedValue()}Be.exports=ar,Be.exports.buffer=(t,e)=>ar(t,{...e,encoding:"buffer"}),Be.exports.array=(t,e)=>ar(t,{...e,array:!0}),Be.exports.MaxBufferError=Fo;var ba=Be.exports,jo=Pe(ba);const{PassThrough:Ea}=Bt;var $a=function(){var t=[],e=new Ea({objectMode:!0});return e.setMaxListeners(0),e.add=r,e.isEmpty=o,e.on("unpipe",s),Array.prototype.slice.call(arguments).forEach(r),e;function r(n){return Array.isArray(n)?(n.forEach(r),this):(t.push(n),n.once("end",s.bind(null,n)),n.once("error",e.emit.bind(e,"error")),n.pipe(e,{end:!1}),this)}function o(){return t.length==0}function s(n){t=t.filter(function(i){return i!==n}),!t.length&&e.readable&&e.end()}},Pa=Pe($a);const Bo=t=>{if(t!==void 0)throw new TypeError("The `input` and `inputFile` options cannot be both set.")},Aa=({input:t,inputFile:e})=>typeof e!="string"?t:(Bo(t),Zs(e)),Sa=t=>{const e=Aa(t);if(nr(e))throw new TypeError("The `input` option cannot be a stream in sync mode");return e},ka=({input:t,inputFile:e})=>typeof e!="string"?t:(Bo(t),Qs(e)),Ia=(t,e)=>{const r=ka(e);r!==void 0&&(nr(r)?r.pipe(t.stdin):t.stdin.end(r))},Ma=(t,{all:e})=>{if(!e||!t.stdout&&!t.stderr)return;const r=Pa();return t.stdout&&r.add(t.stdout),t.stderr&&r.add(t.stderr),r},cr=async(t,e)=>{if(!(!t||e===void 0)){t.destroy();try{return await e}catch(r){return r.bufferedData}}},lr=(t,{encoding:e,buffer:r,maxBuffer:o})=>{if(!(!t||!r))return e?jo(t,{encoding:e,maxBuffer:o}):jo.buffer(t,{maxBuffer:o})},xa=async({stdout:t,stderr:e,all:r},{encoding:o,buffer:s,maxBuffer:n},i)=>{const a=lr(t,{encoding:o,buffer:s,maxBuffer:n}),c=lr(e,{encoding:o,buffer:s,maxBuffer:n}),d=lr(r,{encoding:o,buffer:s,maxBuffer:n*2});try{return await Promise.all([i,a,c,d])}catch(l){return Promise.all([{error:l,signal:l.signal,timedOut:l.timedOut},cr(t,a),cr(e,c),cr(r,d)])}},Ra=(async()=>{})().constructor.prototype,Oa=["then","catch","finally"].map(t=>[t,Reflect.getOwnPropertyDescriptor(Ra,t)]),Go=(t,e)=>{for(const[r,o]of Oa){const s=typeof e=="function"?(...n)=>Reflect.apply(o.value,e(),n):o.value.bind(e);Reflect.defineProperty(t,r,{...o,value:s})}},Da=t=>new Promise((e,r)=>{t.on("exit",(o,s)=>{e({exitCode:o,signal:s})}),t.on("error",o=>{r(o)}),t.stdin&&t.stdin.on("error",o=>{r(o)})}),Uo=(t,e=[])=>Array.isArray(e)?[t,...e]:[t],_a=/^[\w.-]+$/,Na=/"/g,Ta=t=>typeof t!="string"||_a.test(t)?t:`"${t.replace(Na,'\\"')}"`,Ho=(t,e)=>Uo(t,e).join(" "),Ko=(t,e)=>Uo(t,e).map(r=>Ta(r)).join(" "),zo=/ +/g,Wo=t=>{const e=[];for(const r of t.trim().split(zo)){const o=e[e.length-1];o&&o.endsWith("\\")?e[e.length-1]=`${o.slice(0,-1)} ${r}`:e.push(r)}return e},Yo=t=>{const e=typeof t;if(e==="string")return t;if(e==="number")return String(t);if(e==="object"&&t!==null&&!(t instanceof zr)&&"stdout"in t){const r=typeof t.stdout;if(r==="string")return t.stdout;if(Kr.isBuffer(t.stdout))return t.stdout.toString();throw new TypeError(`Unexpected "${r}" stdout in template expression`)}throw new TypeError(`Unexpected "${e}" in template expression`)},Vo=(t,e,r)=>r||t.length===0||e.length===0?[...t,...e]:[...t.slice(0,-1),`${t[t.length-1]}${e[0]}`,...e.slice(1)],La=({templates:t,expressions:e,tokens:r,index:o,template:s})=>{const n=s??t.raw[o],i=n.split(zo).filter(Boolean),a=Vo(r,i,n.startsWith(" "));if(o===e.length)return a;const c=e[o],d=Array.isArray(c)?c.map(l=>Yo(l)):[Yo(c)];return Vo(a,d,n.endsWith(" "))},qo=(t,e)=>{let r=[];for(const[o,s]of t.entries())r=La({templates:t,expressions:e,tokens:r,index:o,template:s});return r},Fa=rn("execa").enabled,pt=(t,e)=>String(t).padStart(e,"0"),ja=()=>{const t=new Date;return`${pt(t.getHours(),2)}:${pt(t.getMinutes(),2)}:${pt(t.getSeconds(),2)}.${pt(t.getMilliseconds(),3)}`},Jo=(t,{verbose:e})=>{e&&le.stderr.write(`[${ja()}] ${t}
|
|
8
|
+
`)},Ba=1e3*1e3*100,Ga=({env:t,extendEnv:e,preferLocal:r,localDir:o,execPath:s})=>{const n=e?{...le.env,...t}:t;return r?Si({env:n,cwd:o,execPath:s}):n},Xo=(t,e,r={})=>{const o=bi._parse(t,e,r);return t=o.command,e=o.args,r=o.options,r={maxBuffer:Ba,buffer:!0,stripFinalNewline:!0,extendEnv:!0,preferLocal:!1,localDir:r.cwd||le.cwd(),execPath:le.execPath,encoding:"utf8",reject:!0,cleanup:!0,all:!1,windowsHide:!0,verbose:Fa,...r},r.env=Ga(r),r.stdio=Do(r),le.platform==="win32"&&we.basename(t,".exe")==="cmd"&&e.unshift("/q"),{file:t,args:e,options:r,parsed:o}},Ge=(t,e,r)=>typeof e!="string"&&!Kr.isBuffer(e)?r===void 0?void 0:"":t.stripFinalNewline?Ei(e):e;function I(t,e,r){const o=Xo(t,e,r),s=Ho(t,e),n=Ko(t,e);Jo(n,o.options),ua(o.options);let i;try{i=jt.spawn(o.file,o.args,o.options)}catch(f){const h=new jt.ChildProcess,y=Promise.reject(lt({error:f,stdout:"",stderr:"",all:"",command:s,escapedCommand:n,parsed:o,timedOut:!1,isCanceled:!1,killed:!1}));return Go(h,y),h}const a=Da(i),c=la(i,o.options,a),d=da(i,o.options,c),l={isCanceled:!1};i.kill=ra.bind(null,i.kill.bind(i)),i.cancel=aa.bind(null,i,l);const p=Mo(async()=>{const[{error:f,exitCode:h,signal:y,timedOut:w},C,b,E]=await xa(i,o.options,d),k=Ge(o.options,C),$=Ge(o.options,b),P=Ge(o.options,E);if(f||h!==0||y!==null){const O=lt({error:f,exitCode:h,signal:y,stdout:k,stderr:$,all:P,command:s,escapedCommand:n,parsed:o,timedOut:w,isCanceled:l.isCanceled||(o.options.signal?o.options.signal.aborted:!1),killed:i.killed});if(!o.options.reject)return O;throw O}return{command:s,escapedCommand:n,exitCode:0,stdout:k,stderr:$,all:P,failed:!1,timedOut:!1,isCanceled:!1,killed:!1}});return Ia(i,o.options),i.all=Ma(i,o.options),pa(i),Go(i,p),i}function ur(t,e,r){const o=Xo(t,e,r),s=Ho(t,e),n=Ko(t,e);Jo(n,o.options);const i=Sa(o.options);let a;try{a=jt.spawnSync(o.file,o.args,{...o.options,input:i})}catch(l){throw lt({error:l,stdout:"",stderr:"",all:"",command:s,escapedCommand:n,parsed:o,timedOut:!1,isCanceled:!1,killed:!1})}const c=Ge(o.options,a.stdout,a.error),d=Ge(o.options,a.stderr,a.error);if(a.error||a.status!==0||a.signal!==null){const l=lt({stdout:c,stderr:d,error:a.error,signal:a.signal,exitCode:a.status,command:s,escapedCommand:n,parsed:o,timedOut:a.error&&a.error.code==="ETIMEDOUT",isCanceled:!1,killed:a.signal!==null});if(!o.options.reject)return l;throw l}return{command:s,escapedCommand:n,exitCode:0,stdout:c,stderr:d,failed:!1,timedOut:!1,isCanceled:!1,killed:!1}}const Ua=({input:t,inputFile:e,stdio:r})=>t===void 0&&e===void 0&&r===void 0?{stdin:"inherit"}:{},Qo=(t={})=>({preferLocal:!0,...Ua(t),...t});function Zo(t){function e(r,...o){if(!Array.isArray(r))return Zo({...t,...r});const[s,...n]=qo(r,o);return I(s,n,Qo(t))}return e.sync=(r,...o)=>{if(!Array.isArray(r))throw new TypeError("Please use $(options).sync`command` instead of $.sync(options)`command`.");const[s,...n]=qo(r,o);return ur(s,n,Qo(t))},e}const Ha=Zo();function Ka(t,e){const[r,...o]=Wo(t);return I(r,o,e)}function za(t,e){const[r,...o]=Wo(t);return ur(r,o,e)}function Wa(t,e,r={}){e&&!Array.isArray(e)&&typeof e=="object"&&(r=e,e=[]);const o=Yi(r),s=le.execArgv.filter(a=>!a.startsWith("--inspect")),{nodePath:n=le.execPath,nodeOptions:i=s}=r;return I(n,[...i,t,...Array.isArray(e)?e:[]],{...r,stdin:void 0,stdout:void 0,stderr:void 0,stdio:o,shell:!1})}var Ya=Object.freeze({__proto__:null,execa:I,execaSync:ur,$:Ha,execaCommand:Ka,execaCommandSync:za,execaNode:Wa});const{hasOwnProperty:dr}=Object.prototype,ft=typeof process<"u"&&process.platform==="win32"?`\r
|
|
9
9
|
`:`
|
|
10
|
-
`,
|
|
10
|
+
`,mr=(t,e)=>{const r=[];let o="";typeof e=="string"?e={section:e,whitespace:!1}:(e=e||Object.create(null),e.whitespace=e.whitespace===!0);const s=e.whitespace?" = ":"=";for(const n of Object.keys(t)){const i=t[n];if(i&&Array.isArray(i))for(const a of i)o+=Me(n+"[]")+s+Me(a)+ft;else i&&typeof i=="object"?r.push(n):o+=Me(n)+s+Me(i)+ft}e.section&&o.length&&(o="["+Me(e.section)+"]"+ft+o);for(const n of r){const i=es(n).join("\\."),a=(e.section?e.section+".":"")+i,{whitespace:c}=e,d=mr(t[n],{section:a,whitespace:c});o.length&&d.length&&(o+=ft),o+=d}return o},es=t=>t.replace(/\1/g,"LITERAL\\1LITERAL").replace(/\\\./g,"").split(/\./).map(e=>e.replace(/\1/g,"\\.").replace(/\2LITERAL\\1LITERAL\2/g,"")),ts=t=>{const e=Object.create(null);let r=e,o=null;const s=/^\[([^\]]*)\]$|^([^=]+)(=(.*))?$/i,n=t.split(/[\r\n]+/g);for(const a of n){if(!a||a.match(/^\s*[;#]/))continue;const c=a.match(s);if(!c)continue;if(c[1]!==void 0){if(o=ht(c[1]),o==="__proto__"){r=Object.create(null);continue}r=e[o]=e[o]||Object.create(null);continue}const d=ht(c[2]),l=d.length>2&&d.slice(-2)==="[]",u=l?d.slice(0,-2):d;if(u==="__proto__")continue;const p=c[3]?ht(c[4]):!0,f=p==="true"||p==="false"||p==="null"?JSON.parse(p):p;l&&(dr.call(r,u)?Array.isArray(r[u])||(r[u]=[r[u]]):r[u]=[]),Array.isArray(r[u])?r[u].push(f):r[u]=f}const i=[];for(const a of Object.keys(e)){if(!dr.call(e,a)||typeof e[a]!="object"||Array.isArray(e[a]))continue;const c=es(a);r=e;const d=c.pop(),l=d.replace(/\\\./g,".");for(const u of c)u!=="__proto__"&&((!dr.call(r,u)||typeof r[u]!="object")&&(r[u]=Object.create(null)),r=r[u]);r===e&&l===d||(r[l]=e[a],i.push(a))}for(const a of i)delete e[a];return e},rs=t=>t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"),Me=t=>typeof t!="string"||t.match(/[=\r\n]/)||t.match(/^\[/)||t.length>1&&rs(t)||t!==t.trim()?JSON.stringify(t):t.split(";").join("\\;").split("#").join("\\#"),ht=(t,e)=>{if(t=(t||"").trim(),rs(t)){t.charAt(0)==="'"&&(t=t.slice(1,-1));try{t=JSON.parse(t)}catch{}}else{let r=!1,o="";for(let s=0,n=t.length;s<n;s++){const i=t.charAt(s);if(r)"\\;#".indexOf(i)!==-1?o+=i:o+="\\"+i,r=!1;else{if(";#".indexOf(i)!==-1)break;i==="\\"?r=!0:o+=i}}return r&&(o+="\\"),o.trim()}return t};var Va={parse:ts,decode:ts,stringify:mr,encode:mr,safe:Me,unsafe:ht},xe=Pe(Va);class v extends Error{constructor(e,r={}){super(e,{cause:r.cause}),this.name="KnownError",this.code=r.code,this.suggestions=r.suggestions||[]}}const Ue=" ",me=t=>{if(t instanceof Error){if(t instanceof v){t.suggestions.length>0&&(console.error(""),console.error(`${Ue}${g.yellow("Suggestions:")}`),t.suggestions.forEach(e=>{console.error(`${Ue} ${g.dim("\u2022")} ${e}`)}));return}t.stack&&console.error(g.dim(t.stack.split(`
|
|
11
11
|
`).slice(1).join(`
|
|
12
12
|
`))),console.error(`
|
|
13
|
-
${
|
|
14
|
-
${ir}Please open a Bug report with the information above:`),console.error(`${ir}https://github.com/tak-bro/aicommit2/issues/new/choose`)))},Vo=t=>_.lstat(t).then(()=>!0,()=>!1),qo=async t=>{try{await _.mkdir(t,{recursive:!0})}catch(e){if(e.code!=="EEXIST")throw e}},ft=t=>t&&`${t[0].toUpperCase()}${t.slice(1)}`,pt=(t,e)=>{const r=Math.ceil(t),o=Math.floor(e);return Math.floor(Math.random()*(o-r+1))+r},Na=(t,e)=>t.disabled&&!e.disabled?1:!t.disabled&&e.disabled?-1:0,ht=t=>t.reduce((e,r)=>Array.isArray(r)?e.concat(ht(r)):e.concat(r),[]),Xo=(t,e=5)=>t.replace(/[\n\r]/g,"").split(" ").slice(0,e).join(" "),Fa=t=>{let e=0;for(let r=0;r<t.length;r++){const o=t.charCodeAt(r);e=(e<<5)-e+o,e=e&e}return Math.abs(e)},_a=t=>{const e=t%360,r=65+t%15,o=45+t%10;return`hsl(${e}, ${r}%, ${o}%)`},La=t=>{const[e,r,o]=t.match(/\d+/g).map((u,f)=>f===0?Number(u):Number(u)/100),n=(1-Math.abs(2*o-1))*r,s=n*(1-Math.abs(e/60%2-1)),i=o-n/2;let l,a,d;e<60?[l,a,d]=[n,s,0]:e<120?[l,a,d]=[s,n,0]:e<180?[l,a,d]=[0,n,s]:e<240?[l,a,d]=[0,s,n]:e<300?[l,a,d]=[s,0,n]:[l,a,d]=[n,0,s];const c=u=>{const f=Math.round((u+i)*255).toString(16);return f.length===1?"0"+f:f};return`#${c(l)}${c(a)}${c(d)}`},Ta=t=>{const e=Fa(t),r=_a(e);return{primary:La(r),secondary:"#FFFFFF"}},Qo=t=>{try{return{ok:!0,data:JSON.parse(t)}}catch(e){return{ok:!1,error:e}}},gt=t=>{if(!t||typeof t!="string")return"";if(x.isAbsolute(t))return x.resolve(t);if(Ge){const e=x.dirname(Ge),r=x.join(e,t);return x.resolve(r)}else return""},ja=["","conventional","gitmoji"],ar="http://localhost:11434",{hasOwnProperty:Ba}=Object.prototype,cr=(t,e)=>Ba.call(t,e),lr=["OPENAI","OLLAMA","HUGGINGFACE","GEMINI","ANTHROPIC","MISTRAL","CODESTRAL","COHERE","GROQ","PERPLEXITY","DEEPSEEK","GITHUB_MODELS","BEDROCK"],Zo=t=>{const e=Fe.platform(),r=Fe.homedir();let o,n;switch(t){case"config":o=process.env.XDG_CONFIG_HOME;break;case"data":o=process.env.XDG_DATA_HOME;break;case"cache":o=process.env.XDG_CACHE_HOME;break;case"state":o=process.env.XDG_STATE_HOME;break;default:o=void 0}if(e==="darwin")t==="cache"?n=x.join(r,"Library","Caches"):n=x.join(r,"Library","Application Support");else if(e==="win32")n=process.env.LOCALAPPDATA||r;else switch(t){case"config":n=x.join(r,".config");break;case"data":n=x.join(r,".local","share");break;case"cache":n=x.join(r,".cache");break;case"state":n=x.join(r,".local","state");break;default:n=r}return o||n},Ga=x.join(Zo("config"),"aicommit2"),ce=x.join(Zo("state"),"aicommit2","logs"),en=x.join(Ga,"config.ini"),tn=x.join(ce,"aicommit2-%DATE%.log"),rn=x.join(ce,"exceptions-%DATE%.log"),Ha=t=>{const e=Object.keys(t),r=new Set([...lr,...e.filter(o=>/^[A-Z][A-Z0-9_]*$/.test(o))]);return Array.from(r)},I=(t,e,r)=>{if(!e)throw new w(`Invalid config property ${t}: ${r}`)},me=(t,e=!1)=>r=>typeof r=="boolean"?r:r==null?e:(I(t,/^(?:true|false)$/.test(r),"Must be a boolean(true or false)"),r==="true"),m={systemPrompt(t){return t||""},systemPromptPath(t){return t||""},codeReviewPromptPath(t){return t||""},timeout(t){if(!t)return 6e4;I("timeout",/^\d+$/.test(t),"Must be an integer");const e=Number(t);return I("timeout",e>=500,"Must be greater than 500ms"),e},temperature(t){if(!t)return .7;I("temperature",/^(2|\d)(\.\d{1,2})?$/.test(t),"Must be decimal between 0 and 2");const e=Number(t);return I("temperature",e>0,"Must be greater than 0"),I("temperature",e<=2,"Must be less than or equal to 2"),e},maxTokens(t){return t?(I("maxTokens",/^\d+$/.test(t),"Must be an integer"),Number(t)):8192},logLevel(t){return t?(I("logLevel",/^(?:error|warn|info|http|verbose|debug|silly)$/.test(t),"Must be a valid log level (error, warn, info, http, verbose, debug, silly)"),t):"info"},logFilePath(t){return t||tn},exceptionLogFilePath(t){return t||rn},locale(t){return t?(I("locale",t,"Cannot be empty"),I("locale",/^[a-z-]+$/i.test(t),"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"),t):"en"},generate(t){if(!t)return 1;I("generate",/^\d+$/.test(t),"Must be an integer");const e=Number(t);return I("generate",e>0,"Must be greater than 0"),I("generate",e<=5,"Must be less or equal to 5"),e},type(t){return t?(I("type",ja.includes(t),"Invalid commit type"),t):"conventional"},maxLength(t){if(!t)return 50;I("maxLength",/^\d+$/.test(t),"Must be an integer");const e=Number(t);return I("maxLength",e>=20,"Must be greater than 20 characters"),e},exclude:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):[],topP:t=>{if(!t)return .9;I("topP",/^(1|\d)(\.\d{1,2})?$/.test(t),"Must be decimal between 0 and 1");const e=Number(t);return I("topP",e>0,"Must be greater than 0"),I("topP",e<=1,"Must be less than or equal to 1"),e},logging:me("logging",!0),includeBody:me("includeBody"),codeReview:me("codeReview"),disabled:me("disabled"),watchMode:me("watchMode"),forceGit:me("forceGit"),disableLowerCase:me("disableLowerCase"),jjAutoNew:me("jjAutoNew")},Be={OPENAI:{key:t=>t||"",envKey:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["gpt-4o-mini"],url:t=>t?(I("OPENAI.url",/^https?:\/\//.test(t),"Must be a valid URL"),t):"https://api.openai.com",path:t=>t||"/v1/chat/completions",proxy:t=>t||"",topP:m.topP,systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},HUGGINGFACE:{cookie:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["CohereForAI/c4ai-command-r-plus"],systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,topP:m.topP,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},GEMINI:{key:t=>t||"",envKey:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["gemini-3-flash-preview"],systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,topP:m.topP,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},ANTHROPIC:{key:t=>t||"",envKey:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["claude-3-5-haiku-20241022"],systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,topP:m.topP,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},MISTRAL:{key:t=>t||"",envKey:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["mistral-small-latest"],systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,topP:m.topP,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},CODESTRAL:{key:t=>t||"",envKey:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["codestral-latest"],topP:m.topP,systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},OLLAMA:{model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):[],host:t=>t?(I("OLLAMA.host",/^https?:\/\//.test(t),"Must be a valid URL"),t):ar,timeout:t=>{if(!t)return 1e5;I("OLLAMA.timeout",/^\d+$/.test(t),"Must be an integer");const e=Number(t);return I("OLLAMA.timeout",e>=500,"Must be greater than 500ms"),e},auth:t=>t||"",key:t=>t||"",envKey:t=>t||"",numCtx:t=>{if(!t)return 2048;I("OLLAMA.numCtx",/^\d+$/.test(t),"Must be an integer");const e=Number(t);return I("OLLAMA.numCtx",e>=2048,"Must be greater than 2048"),e},systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,topP:m.topP,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},COHERE:{key:t=>t||"",envKey:t=>t||"",url:t=>t?(I("COHERE.url",/^https?:\/\//.test(t),"Must be a valid URL"),t):"https://api.cohere.ai",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["command-a-03-2025"],systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,timeout:m.timeout,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,topP:m.topP,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},GROQ:{key:t=>t||"",envKey:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["llama-3.3-70b-versatile"],systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,topP:m.topP,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},PERPLEXITY:{key:t=>t||"",envKey:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["sonar"],topP:m.topP,systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},DEEPSEEK:{key:t=>t||"",envKey:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["deepseek-coder"],topP:m.topP,systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},GITHUB_MODELS:{key:t=>t||"",envKey:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["gpt-4o-mini"],systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,topP:m.topP,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},BEDROCK:{key:t=>t||"",envKey:t=>t&&t.length>0?t:"BEDROCK_API_KEY",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>{const o=r.trim();return o&&!o.includes(".")&&!o.includes(":")&&console.warn(`[Bedrock] Model ID "${o}" may be invalid.
|
|
13
|
+
${Ue}${g.dim(`aicommit2 v${mo}`)}`),console.error(`
|
|
14
|
+
${Ue}Please open a Bug report with the information above:`),console.error(`${Ue}https://github.com/tak-bro/aicommit2/issues/new/choose`)}},gt=t=>D.lstat(t).then(()=>!0,()=>!1),os=async t=>{try{await D.mkdir(t,{recursive:!0})}catch(e){if(e.code!=="EEXIST")throw e}},yt=t=>t&&`${t[0].toUpperCase()}${t.slice(1)}`,wt=(t,e)=>{const r=Math.ceil(t),o=Math.floor(e);return Math.floor(Math.random()*(o-r+1))+r},qa=(t,e)=>t.disabled&&!e.disabled?1:!t.disabled&&e.disabled?-1:0,vt=t=>t.reduce((e,r)=>Array.isArray(r)?e.concat(vt(r)):e.concat(r),[]),ss=(t,e=5)=>t.replace(/[\n\r]/g,"").split(" ").slice(0,e).join(" "),Ja=t=>{let e=0;for(let r=0;r<t.length;r++){const o=t.charCodeAt(r);e=(e<<5)-e+o,e=e&e}return Math.abs(e)},Xa=t=>{const e=t%360,r=65+t%15,o=45+t%10;return`hsl(${e}, ${r}%, ${o}%)`},Qa=t=>{const[e,r,o]=t.match(/\d+/g).map((u,p)=>p===0?Number(u):Number(u)/100),s=(1-Math.abs(2*o-1))*r,n=s*(1-Math.abs(e/60%2-1)),i=o-s/2;let a,c,d;e<60?[a,c,d]=[s,n,0]:e<120?[a,c,d]=[n,s,0]:e<180?[a,c,d]=[0,s,n]:e<240?[a,c,d]=[0,n,s]:e<300?[a,c,d]=[n,0,s]:[a,c,d]=[s,0,n];const l=u=>{const p=Math.round((u+i)*255).toString(16);return p.length===1?"0"+p:p};return`#${l(a)}${l(c)}${l(d)}`},Za=t=>{const e=Ja(t),r=Xa(e);return{primary:Qa(r),secondary:"#FFFFFF"}},ns=t=>{try{return{ok:!0,data:JSON.parse(t)}}catch(e){return{ok:!1,error:e}}},Ct=t=>{if(!t||typeof t!="string")return"";if(M.isAbsolute(t))return M.resolve(t);if(ze){const e=M.dirname(ze),r=M.join(e,t);return M.resolve(r)}else return""},ec=["","conventional","gitmoji"],bt="http://localhost:11434",{hasOwnProperty:tc}=Object.prototype,pr=(t,e)=>tc.call(t,e),He=["OPENAI","OLLAMA","HUGGINGFACE","GEMINI","ANTHROPIC","MISTRAL","CODESTRAL","COHERE","GROQ","PERPLEXITY","DEEPSEEK","GITHUB_MODELS","BEDROCK"],is=t=>{const e=Le.platform(),r=Le.homedir();let o,s;switch(t){case"config":o=process.env.XDG_CONFIG_HOME;break;case"data":o=process.env.XDG_DATA_HOME;break;case"cache":o=process.env.XDG_CACHE_HOME;break;case"state":o=process.env.XDG_STATE_HOME;break;default:o=void 0}if(e==="darwin")t==="cache"?s=M.join(r,"Library","Caches"):s=M.join(r,"Library","Application Support");else if(e==="win32")s=process.env.LOCALAPPDATA||r;else switch(t){case"config":s=M.join(r,".config");break;case"data":s=M.join(r,".local","share");break;case"cache":s=M.join(r,".cache");break;case"state":s=M.join(r,".local","state");break;default:s=r}return o||s},as=M.join(is("config"),"aicommit2"),ue=M.join(is("state"),"aicommit2","logs"),cs=M.join(as,"config.ini"),ls=M.join(ue,"aicommit2-%DATE%.log"),us=M.join(ue,"exceptions-%DATE%.log"),rc=t=>{const e=Object.keys(t),r=new Set([...He,...e.filter(o=>/^[A-Z][A-Z0-9_]*$/.test(o))]);return Array.from(r)},R=(t,e,r)=>{if(!e)throw new v(`Invalid config property ${t}: ${r}`)},pe=(t,e=!1)=>r=>typeof r=="boolean"?r:r==null?e:(R(t,/^(?:true|false)$/.test(r),"Must be a boolean(true or false)"),r==="true"),m={systemPrompt(t){return t||""},systemPromptPath(t){return t||""},codeReviewPromptPath(t){return t||""},timeout(t){if(!t)return 6e4;R("timeout",/^\d+$/.test(t),"Must be an integer");const e=Number(t);return R("timeout",e>=500,"Must be greater than 500ms"),e},temperature(t){if(!t)return .7;R("temperature",/^(2|\d)(\.\d{1,2})?$/.test(t),"Must be decimal between 0 and 2");const e=Number(t);return R("temperature",e>0,"Must be greater than 0"),R("temperature",e<=2,"Must be less than or equal to 2"),e},maxTokens(t){return t?(R("maxTokens",/^\d+$/.test(t),"Must be an integer"),Number(t)):8192},logLevel(t){return t?(R("logLevel",/^(?:error|warn|info|http|verbose|debug|silly)$/.test(t),"Must be a valid log level (error, warn, info, http, verbose, debug, silly)"),t):"info"},logFilePath(t){return t||ls},exceptionLogFilePath(t){return t||us},locale(t){return t?(R("locale",t,"Cannot be empty"),R("locale",/^[a-z-]+$/i.test(t),"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"),t):"en"},generate(t){if(!t)return 1;R("generate",/^\d+$/.test(t),"Must be an integer");const e=Number(t);return R("generate",e>0,"Must be greater than 0"),R("generate",e<=5,"Must be less or equal to 5"),e},type(t){return t?(R("type",ec.includes(t),"Invalid commit type"),t):"conventional"},maxLength(t){if(!t)return 50;R("maxLength",/^\d+$/.test(t),"Must be an integer");const e=Number(t);return R("maxLength",e>=20,"Must be greater than 20 characters"),e},exclude:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):[],topP:t=>{if(!t)return .9;R("topP",/^(1|\d)(\.\d{1,2})?$/.test(t),"Must be decimal between 0 and 1");const e=Number(t);return R("topP",e>0,"Must be greater than 0"),R("topP",e<=1,"Must be less than or equal to 1"),e},logging:pe("logging",!0),includeBody:pe("includeBody"),codeReview:pe("codeReview"),disabled:pe("disabled"),watchMode:pe("watchMode"),forceGit:pe("forceGit"),disableLowerCase:pe("disableLowerCase"),jjAutoNew:pe("jjAutoNew")},Ke={OPENAI:{key:t=>t||"",envKey:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["gpt-4o-mini"],url:t=>t?(R("OPENAI.url",/^https?:\/\//.test(t),"Must be a valid URL"),t):"https://api.openai.com",path:t=>t||"/v1/chat/completions",proxy:t=>t||"",topP:m.topP,systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},HUGGINGFACE:{cookie:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["CohereForAI/c4ai-command-r-plus"],systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,topP:m.topP,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},GEMINI:{key:t=>t||"",envKey:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["gemini-3-flash-preview"],systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,topP:m.topP,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},ANTHROPIC:{key:t=>t||"",envKey:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["claude-sonnet-4-20250514"],systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,topP:m.topP,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},MISTRAL:{key:t=>t||"",envKey:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["mistral-small-latest"],systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,topP:m.topP,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},CODESTRAL:{key:t=>t||"",envKey:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["codestral-latest"],topP:m.topP,systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},OLLAMA:{model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):[],host:t=>t?(R("OLLAMA.host",/^https?:\/\//.test(t),"Must be a valid URL"),t):bt,timeout:t=>{if(!t)return 1e5;R("OLLAMA.timeout",/^\d+$/.test(t),"Must be an integer");const e=Number(t);return R("OLLAMA.timeout",e>=500,"Must be greater than 500ms"),e},auth:t=>t||"",key:t=>t||"",envKey:t=>t||"",numCtx:t=>{if(!t)return 2048;R("OLLAMA.numCtx",/^\d+$/.test(t),"Must be an integer");const e=Number(t);return R("OLLAMA.numCtx",e>=2048,"Must be greater than 2048"),e},systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,topP:m.topP,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},COHERE:{key:t=>t||"",envKey:t=>t||"",url:t=>t?(R("COHERE.url",/^https?:\/\//.test(t),"Must be a valid URL"),t):"https://api.cohere.ai",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["command-a-03-2025"],systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,timeout:m.timeout,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,topP:m.topP,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},GROQ:{key:t=>t||"",envKey:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["llama-3.3-70b-versatile"],systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,topP:m.topP,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},PERPLEXITY:{key:t=>t||"",envKey:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["sonar"],topP:m.topP,systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},DEEPSEEK:{key:t=>t||"",envKey:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["deepseek-chat"],topP:m.topP,systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},GITHUB_MODELS:{key:t=>t||"",envKey:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>r.trim()).filter(r=>!!r&&r.length>0):["gpt-4o-mini"],systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,topP:m.topP,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase},BEDROCK:{key:t=>t||"",envKey:t=>t&&t.length>0?t:"BEDROCK_API_KEY",model:t=>t?(typeof t=="string"?t?.split(","):t).map(r=>{const o=r.trim();return o&&!o.includes(".")&&!o.includes(":")&&console.warn(`[Bedrock] Model ID "${o}" may be invalid.
|
|
15
15
|
Expected formats:
|
|
16
16
|
- Foundation model: "provider.model-name-version" (e.g., "anthropic.claude-haiku-4-5-20251001-v1:0")
|
|
17
17
|
- Inference profile: "prefix.provider.model-name-version" (e.g., "us.anthropic.claude-haiku-4-5-20251001-v1:0")
|
|
18
18
|
- ARN: Full Amazon Resource Name
|
|
19
|
-
See https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles.html`),o}).filter(r=>!!r&&r.length>0):["anthropic.claude-haiku-4-5-20251001-v1:0"],runtimeMode:t=>{t&&console.warn("[Bedrock] DEPRECATION: runtimeMode is no longer used. Authentication method is now auto-detected from configured credentials.")},region:t=>t||process.env.AWS_REGION||process.env.AWS_DEFAULT_REGION||"",profile:t=>t||process.env.AWS_PROFILE||"",accessKeyId:t=>t||process.env.AWS_ACCESS_KEY_ID||"",secretAccessKey:t=>t||process.env.AWS_SECRET_ACCESS_KEY||"",sessionToken:t=>t||process.env.AWS_SESSION_TOKEN||"",applicationEndpointId:t=>t||process.env.BEDROCK_APPLICATION_ENDPOINT_ID||"",applicationInferenceProfileArn:t=>t||process.env.BEDROCK_APPLICATION_INFERENCE_PROFILE_ARN||process.env.BEDROCK_INFERENCE_PROFILE_ARN||"",applicationBaseUrl:t=>t||process.env.BEDROCK_APPLICATION_BASE_URL||"",systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:t=>{if(!t)return;I("temperature",/^(2|\d)(\.\d{1,2})?$/.test(t),"Must be decimal between 0 and 2");const e=Number(t);return I("temperature",e>0,"Must be greater than 0"),I("temperature",e<=2,"Must be less than or equal to 2"),e},maxTokens:t=>{if(t)return I("maxTokens",/^\d+$/.test(t),"Must be an integer"),Number(t)},logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,topP:t=>{if(!t)return;I("topP",/^(1|\d)(\.\d{1,2})?$/.test(t),"Must be decimal between 0 and 1");const e=Number(t);return I("topP",e>0,"Must be greater than 0"),I("topP",e<=1,"Must be less than or equal to 1"),e},codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase,inferenceParameters:t=>{if(!t)return{};if(typeof t=="object")return t;try{const e=JSON.parse(t);return I("BEDROCK.inferenceParameters",typeof e=="object"&&e!==null&&!Array.isArray(e),"Must be a valid JSON object"),e}catch(e){throw new w(`Invalid BEDROCK.inferenceParameters: Must be valid JSON. Error: ${e.message}`)}}}};let Ge;const Ua=(t=[])=>{const e={};for(const r of t)if(r.startsWith("--")){const[o,n]=r.slice(2).split("="),[s,i]=o.split(".");s&&i&&s in Be?(e[s]||(e[s]={}),e[s][i]=n):e[o]=n}return e},za=()=>{const t=Fe.homedir(),e=process.env.AICOMMIT_CONFIG_PATH,r=en,o=x.join(t,".aicommit2");return[e,r,o].filter(n=>!!n)},Ie=async()=>{const t=za();for(const e of t)if(await Vo(e))return e;return en},Ka=t=>t.replace(/\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(e,r,o)=>{const n=r||o;return process.env[n]??""}),He=async()=>{const t=await Ie();Ge=t;try{const e=await _.readFile(t,"utf8"),r=Ka(e);return xe.parse(r)}catch(e){return e.code==="ENOENT"?(Ge=void 0,{}):(console.error(`Error reading config file ${t}:`,e),Ge=void 0,{})}},we=async(t,e=[])=>{const r=await He(),o=Ua(e),n={...t,...o},s={},i=Ha(r),l={};for(const d of i){const c=r[d]?.envKey;let u;c?(u=[c],d==="BEDROCK"&&c!=="BEDROCK_APPLICATION_API_KEY"&&u.push("BEDROCK_APPLICATION_API_KEY")):d==="BEDROCK"?u=["BEDROCK_API_KEY","BEDROCK_APPLICATION_API_KEY"]:u=[`${d}_API_KEY`];const f=u.map(p=>p?process.env[p]:void 0).find(p=>typeof p=="string"&&p.length>0);f&&(l[d]={key:f})}const a=(d,c)=>{const u=n[`${d}.${c}`]??n[d]?.[c],f=l[d]?.[c],p=r[d]?.[c],h=n[c]??r[c];return u!==void 0?u:f!==void 0?f:p!==void 0?p:h};for(const[d,c]of Object.entries(m)){const u=n[d]??r[d];s[d]=c(u)}for(const d of i){s[d]={};const c=Be[d]||yt(d);for(const[u,f]of Object.entries(c)){const p=a(d,u);s[d][u]=f(p)}}return s},ur=async t=>{const e=await He();for(const[n,s]of t){const[i,l]=n.split(".");if(!l){const c=m[n];if(!c)throw new w(`Invalid config property: ${n}`);e[n]=c(s);continue}if(e[i]||(e[i]={}),lr.includes(i)){const c=Be[i][l];if(!c)throw new w(`Invalid config property: ${n}`);e[i][l]=c(s);continue}if(!/^[A-Z][A-Z0-9_]*$/.test(i))throw new w(`Invalid service name: ${i}. Service names must be uppercase letters, numbers, and underscores.`);const d=yt(i);if(!d[l])throw new w(`Invalid config property for custom service: ${n}`);try{e[i][l]=d[l](s)}catch(c){throw c instanceof w?c:new w(`Invalid value for ${n}: ${c.message}`)}}const r=await Ie(),o=x.dirname(r);await _.mkdir(o,{recursive:!0}),await _.writeFile(r,xe.stringify(e),"utf8")},Wa=async t=>{const e=await He();for(const[n,s]of t){const[i,l]=n.split("."),a=e[i];if(l==="model"){a||(e[i]={});const c=e[i][l]||[],u=typeof s=="string"?s.split(",").map(f=>f.trim()).filter(f=>!!f):s;e[i][l]=ht([...c,...u]);continue}if(a&&a.compatible===!0){a||(e[i]={});const c=yt(i);if(!c[l])throw new w(`Invalid config property: ${n}`);try{e[i][l]=c[l](s)}catch(u){throw u instanceof w?u:new w(`Invalid value for ${n}: ${u.message}`)}continue}if(i in Be){a||(e[i]={});const c=Be[i][l];if(!c)throw new w(`Invalid config property: ${n}`);e[i][l]=c(s)}else{const c=yt(i);if(!c[l])throw new w(`Invalid config property: ${n}`);e[i]||(e[i]={}),e[i][l]=c[l](s)}}const r=await Ie(),o=x.dirname(r);await _.mkdir(o,{recursive:!0}),await _.writeFile(r,xe.stringify(e),"utf8")},Ya=async()=>{const t=await He();console.log(xe.stringify(t))},Ja=async()=>{console.log(await Ie())},yt=t=>({compatible:me("compatible"),stream:me("stream"),url:e=>e?(I(`${t}.url`,/^https?:\/\//.test(e),"Must be a valid URL"),e):"",path:e=>e||"",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):[],systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,topP:m.topP,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase}),le=t=>typeof t=="string"&&t.trim().length>0,Me=t=>(Array.isArray(t.model)?t.model:le(t.model)?[t.model.trim()]:[]).length>0,dr=t=>{const e=le(t.key),r=le(t.region)||le(process.env.AWS_REGION)||le(process.env.AWS_DEFAULT_REGION),o=le(t.profile)||le(process.env.AWS_PROFILE),n=le(t.accessKeyId)&&le(t.secretAccessKey)||le(process.env.AWS_ACCESS_KEY_ID)&&le(process.env.AWS_SECRET_ACCESS_KEY);return r&&(e||o||n)},Re=(t,e)=>Object.entries(t).map(([r,o])=>[r,o]).filter(([r,o])=>!o.disabled).filter(([r,o])=>lr.includes(r)||o.compatible===!0).filter(([r,o])=>{switch(e){case"commit":return r==="OLLAMA"?!!o&&Me(o):r==="HUGGINGFACE"?!!o&&!!o.cookie:r==="BEDROCK"?Me(o)&&dr(o):!!o.key&&o.key.length>0;case"review":const n=t.codeReview||o.codeReview;return r==="OLLAMA"?!!o&&Me(o)&&n:r==="HUGGINGFACE"?!!o&&!!o.cookie&&n:r==="BEDROCK"?Me(o)&&dr(o)&&n:!!o.key&&o.key.length>0&&n;case"watch":const s=t.watchMode||o.watchMode;return r==="OLLAMA"?!!o&&Me(o)&&s:r==="HUGGINGFACE"?!!o&&!!o.cookie&&s:r==="BEDROCK"?Me(o)&&dr(o)&&s:o.compatible?!!o.url&&!!o.key&&s:!!o.key&&o.key.length>0&&s}}).map(([r])=>r);class Q{static create(e,r){return new e(r)}}const Ue=new Map,ve=(t,e,r)=>{const o=Jr(0).update(e).digest("hex").substring(0,8),n=`${t}_${o}_${r}`;if(Ue.has(n))return Ue.get(n);const s=new Date,i=Xa(s,t,e,r),l=`${ce}/${i}`,a=U.createLogger({level:"info",format:U.format.combine(U.format.timestamp({format:"YYYY-MM-DDTHH:mm:ss.SSSZ"}),U.format.printf(({timestamp:d,level:c,message:u,...f})=>f&&Object.keys(f).length>0?`[${d}] ${c}: ${u} ${JSON.stringify(f,null,2)}`:`[${d}] ${c}: ${u}`)),transports:[new U.transports.File({filename:l})]});return a.info(`=== ${t.toUpperCase()} AI SERVICE LOG ===`),a.info(`Diff Hash: ${o}`),a.info(`Request Type: ${r.toUpperCase()}`),a.info(`Start Time: ${s.toISOString()}`),a.info("=".repeat(50)),a.info(""),Ue.set(n,a),a},Va=t=>{const e={...t},r=["authorization","x-api-key","x-goog-api-key","api-key","x-amzn-bedrock-application-key"];for(const o of r){const n=o.toLowerCase(),s=Object.keys(e).find(i=>i.toLowerCase()===n);s&&e[s]&&typeof e[s]=="string"&&(e[s].startsWith("Bearer ")?e[s]="Bearer [MASKED]":e[s]="[MASKED]")}return e},Z=(t,e,r,o,n,s,i=!0)=>{if(!i)return;const l=ve(r,t,e);l.info(`Making request to ${r} API with model: ${o}`),l.info(`Request URL: ${n}`),l.info("Request headers:",Va(s))},se=(t,e,r,o,n=!0)=>{if(!n)return;ve(r,t,e).info("Request payload:",o)},ee=(t,e,r,o,n,s=!0)=>{if(!s)return;const i=ve(r,t,e);i.info("System prompt:",{prompt:o}),i.info("User prompt:",{prompt:n})},W=(t,e,r,o,n=!0)=>{if(!n)return;ve(r,t,e).info("Response received:",o)},j=(t,e,r,o,n=!0)=>{if(!n)return;ve(r,t,e).error("API request failed:",o)},Y=(t,e,r,o,n,s=!0)=>{if(!s)return;const i=ve(r,t,e);o?i.info(`Request completed successfully in ${o}ms`):i.info("Request completed successfully"),n&&i.info("Final processed response:",{response:n}),i.info(""),i.info("=".repeat(50)),i.info(`End Time: ${new Date().toISOString()}`),i.info("=== REQUEST COMPLETED ===")},qa=(t,e,r,o,n,s,i,l=!0)=>{if(!l)return;const a=ve(r,t,e);i?a.error(`Request failed after ${s}ms:`,{error:i}):(a.info(`Request completed in ${s}ms`),a.info("Response:",{response:n})),Y(t,e,r,s,n,l)},Xa=(t,e,r,o)=>{const{year:n,month:s,day:i,hours:l,minutes:a,seconds:d}=Qa(t),u=Jr(0).update(r).digest("hex").substring(0,8),f=e.toLowerCase().replace(/[^a-z0-9]/g,"").substring(0,20);return o==="review"?`${n}-${s}-${i}_${l}-${a}-${d}_${u}_${f}_review.log`:`${n}-${s}-${i}_${l}-${a}-${d}_${u}_${f}_commit.log`},Qa=t=>{const e=t.getFullYear().toString(),r=(t.getMonth()+1).toString().padStart(2,"0"),o=t.getDate().toString().padStart(2,"0"),n=t.getHours().toString().padStart(2,"0"),s=t.getMinutes().toString().padStart(2,"0"),i=t.getSeconds().toString().padStart(2,"0");return{year:e,month:r,day:o,hours:n,minutes:s,seconds:i}},mr=()=>{for(const[t,e]of Ue.entries())try{e.close()}catch(r){console.error(`Failed to close logger ${t}:`,r)}Ue.clear()};process.on("exit",mr),process.on("SIGINT",()=>{mr(),process.exit(0)}),process.on("SIGTERM",()=>{mr(),process.exit(0)});let wt,on="info";async function Za(t){if(wt){console.warn("Logger already initialized. Skipping re-initialization.");return}const e=t?.logLevel||"info";on=e;const r=t?.logFilePath||tn,o=t?.exceptionLogFilePath||rn,n=t?.logging??!0;await qo(x.dirname(r)),await qo(x.dirname(o));const s=[];n?s.push(new U.transports.DailyRotateFile({filename:r,datePattern:"YYYY-MM-DD",zippedArchive:!0,maxSize:"20m",maxFiles:"14d",level:e,format:U.format.combine(U.format.timestamp(),U.format.printf(({level:i,message:l,timestamp:a})=>`[${a}] ${i}: ${l}`))})):s.push(new U.transports.Console({silent:!0})),wt=U.createLogger({level:e,format:U.format.json(),transports:s,exceptionHandlers:n?[new U.transports.DailyRotateFile({filename:o,datePattern:"YYYY-MM-DD",zippedArchive:!0,maxSize:"20m",maxFiles:"14d",format:U.format.combine(U.format.timestamp(),U.format.json())})]:[],exitOnError:!1,silent:!n})}const De=new Proxy({},{get:(t,e,r)=>{if(!wt)throw new Error("Logger not initialized. Call initializeLogger() first.");return Reflect.get(wt,e,r)}});function vt(){const t=U.config.npm.levels;return(t[on]??t.info)>=t.verbose}class te{constructor(e){this.handleError$=r=>{const o=this.getDetailedErrorMessage(r),n=r.status?`HTTP ${r.status}: ${o}`:o;if(this.params.config.logging){const s=this.params.stagedDiff.diff,i=this.serviceName.replace(/\[|\]/g,"").trim();qa(s,"commit",i,"Error occurred","",void 0,n)}return De.error(`${this.errorPrefix} ${n}`),r.stack&&De.error(` ${r.stack}`),r.content&&De.error(` Problematic content: ${r.content}`),r.originalError&&De.error(` Original error: ${r.originalError}`),Ot({name:`${this.errorPrefix} ${n}`,value:n,isError:!0,disabled:!0})},this.serviceName="AI",this.errorPrefix="ERROR",this.colors={primary:""},this.params=e,this.logSessionId=e.logSessionId}getDetailedErrorMessage(e){const r=e.message||"";return r.includes("API key")||r.includes("api_key")?"Invalid API key. Check your API key configuration":r.includes("rate_limit")||r.includes("Rate limit")||r.includes("429")||r.includes("Too Many Requests")?"Rate limit exceeded. Wait a moment and try again, or upgrade your plan":r.includes("model")||r.includes("Model")?"Model not found or not accessible. Check if the model name is correct":r.includes("timeout")||r.includes("Timeout")?"Request timed out. Try again or increase the timeout setting":r.includes("network")||r.includes("connection")||r.includes("ECONNREFUSED")?"Network error. Check your internet connection and try again":r.includes("quota")||r.includes("usage")||r.includes("QUOTA_EXCEEDED")?"API quota exceeded. Check your usage limits":r.includes("401")||r.includes("Unauthorized")?"Authentication failed. Your API key may be invalid or expired":r.includes("403")||r.includes("Forbidden")?"Access denied. Your API key may not have permission for this model":r.includes("404")||r.includes("Not Found")?"Model or endpoint not found. Check your model configuration":r.includes("500")||r.includes("Internal Server Error")?"Server error. Try again later":r.includes("overloaded")||r.includes("capacity")||r.includes("SERVICE_UNAVAILABLE")||r.includes("unavailable")?"Service is temporarily unavailable. Try again in a few minutes":this.getServiceSpecificErrorMessage(e)||r||"Unknown error occurred"}getServiceSpecificErrorMessage(e){return null}cleanJsonCodeBlock(e){const r=/```(?:json|JSON)?\s*([\s\S]*?)\s*```/,o=e.match(r);return o?o[1].trim():e}extractJsonFromResponse(e){let r=e.indexOf("[");if(r!==-1){const o=this.extractBalancedJson(e,r,"[","]");if(o)return o}if(r=e.indexOf("{"),r!==-1){const o=this.extractBalancedJson(e,r,"{","}");if(o)return o}return null}extractBalancedJson(e,r,o,n){let s=0,i=!1,l=!1;for(let a=r;a<e.length;a++){const d=e[a];if(l){l=!1;continue}if(d==="\\"&&i){l=!0;continue}if(d==='"'){i=!i;continue}if(!i&&(d===o&&s++,d===n&&s--,s===0))return e.slice(r,a+1)}return null}parseMessage(e,r,o){const n=this.cleanJsonCodeBlock(e),s=this.extractJsonFromResponse(n);if(!s){const u=new Error("AI response did not contain a valid JSON object or array.");throw u.name="InvalidJsonResponse",u.content=e,u}const i=Qo(s);if(!i.ok){const u=new Error("Failed to parse AI response as JSON");throw u.name="JsonParseError",u.content=s,u.originalError=i.error,u}const l=i.data,a=Array.isArray(l)?l:[l];if(!a.length||!a.every(u=>typeof u.subject=="string")){const u=new Error("AI response contained malformed commit message data.");throw u.name="MalformedCommitMessage",u.content=e,u}const c=a.map(u=>this.extractMessageAsType(u,r)).map(u=>({title:`${u.subject}`,value:`${u.subject}${u.body?`
|
|
19
|
+
See https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles.html`),o}).filter(r=>!!r&&r.length>0):["anthropic.claude-haiku-4-5-20251001-v1:0"],runtimeMode:t=>{t&&console.warn("[Bedrock] DEPRECATION: runtimeMode is no longer used. Authentication method is now auto-detected from configured credentials.")},region:t=>t||process.env.AWS_REGION||process.env.AWS_DEFAULT_REGION||"",profile:t=>t||process.env.AWS_PROFILE||"",accessKeyId:t=>t||process.env.AWS_ACCESS_KEY_ID||"",secretAccessKey:t=>t||process.env.AWS_SECRET_ACCESS_KEY||"",sessionToken:t=>t||process.env.AWS_SESSION_TOKEN||"",applicationEndpointId:t=>t||process.env.BEDROCK_APPLICATION_ENDPOINT_ID||"",applicationInferenceProfileArn:t=>t||process.env.BEDROCK_APPLICATION_INFERENCE_PROFILE_ARN||process.env.BEDROCK_INFERENCE_PROFILE_ARN||"",applicationBaseUrl:t=>t||process.env.BEDROCK_APPLICATION_BASE_URL||"",systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:t=>{if(!t)return;R("temperature",/^(2|\d)(\.\d{1,2})?$/.test(t),"Must be decimal between 0 and 2");const e=Number(t);return R("temperature",e>0,"Must be greater than 0"),R("temperature",e<=2,"Must be less than or equal to 2"),e},maxTokens:t=>{if(t)return R("maxTokens",/^\d+$/.test(t),"Must be an integer"),Number(t)},logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,topP:t=>{if(!t)return;R("topP",/^(1|\d)(\.\d{1,2})?$/.test(t),"Must be decimal between 0 and 1");const e=Number(t);return R("topP",e>0,"Must be greater than 0"),R("topP",e<=1,"Must be less than or equal to 1"),e},codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase,inferenceParameters:t=>{if(!t)return{};if(typeof t=="object")return t;try{const e=JSON.parse(t);return R("BEDROCK.inferenceParameters",typeof e=="object"&&e!==null&&!Array.isArray(e),"Must be a valid JSON object"),e}catch(e){throw new v(`Invalid BEDROCK.inferenceParameters: Must be valid JSON. Error: ${e.message}`)}}}},oc=t=>typeof t=="object"&&t!==null,ds=(t,e)=>{Object.keys(t).forEach(r=>{const o=t[r];oc(o)&&e in o&&(o[e]=!0)})},sc=t=>{ds(t,"includeBody")},nc=t=>{ds(t,"disableLowerCase")};let ze;const ic=(t=[])=>{const e={};for(const r of t)if(r.startsWith("--")){const[o,s]=r.slice(2).split("="),[n,i]=o.split(".");n&&i&&n in Ke?(e[n]||(e[n]={}),e[n][i]=s):e[o]=s}return e},ac=()=>{const t=Le.homedir(),e=process.env.AICOMMIT_CONFIG_PATH,r=cs,o=M.join(t,".aicommit2");return[e,r,o].filter(s=>!!s)},Re=async()=>{const t=ac();for(const e of t)if(await gt(e))return e;return cs},cc=t=>t.replace(/\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(e,r,o)=>{const s=r||o;return process.env[s]??""}),We=async()=>{const t=await Re();ze=t;try{const e=await D.readFile(t,"utf8"),r=cc(e);return xe.parse(r)}catch(e){return e.code==="ENOENT"?(ze=void 0,{}):(console.error(`Error reading config file ${t}:`,e),ze=void 0,{})}},ge=async(t,e=[])=>{const r=await We(),o=ic(e),s={...t,...o},n={},i=rc(r),a={};for(const d of i){const l=r[d]?.envKey;let u;l?(u=[l],d==="BEDROCK"&&l!=="BEDROCK_APPLICATION_API_KEY"&&u.push("BEDROCK_APPLICATION_API_KEY")):d==="BEDROCK"?u=["BEDROCK_API_KEY","BEDROCK_APPLICATION_API_KEY"]:u=[`${d}_API_KEY`];const p=u.map(f=>f?process.env[f]:void 0).find(f=>typeof f=="string"&&f.length>0);p&&(a[d]={key:p})}const c=(d,l)=>{const u=s[`${d}.${l}`]??s[d]?.[l],p=a[d]?.[l],f=r[d]?.[l],h=s[l]??r[l];return u!==void 0?u:p!==void 0?p:f!==void 0?f:h};for(const[d,l]of Object.entries(m)){const u=s[d]??r[d];n[d]=l(u)}for(const d of i){n[d]={};const l=Ke[d]||Et(d);for(const[u,p]of Object.entries(l)){const f=c(d,u);n[d][u]=p(f)}}return n},fr=async t=>{const e=await We();for(const[s,n]of t){const[i,a]=s.split(".");if(!a){const l=m[s];if(!l)throw new v(`Invalid config property: ${s}`);e[s]=l(n);continue}if(e[i]||(e[i]={}),He.includes(i)){const l=Ke[i][a];if(!l)throw new v(`Invalid config property: ${s}`);e[i][a]=l(n);continue}if(!/^[A-Z][A-Z0-9_]*$/.test(i))throw new v(`Invalid service name: ${i}. Service names must be uppercase letters, numbers, and underscores.`);const d=Et(i);if(!d[a])throw new v(`Invalid config property for custom service: ${s}`);try{e[i][a]=d[a](n)}catch(l){throw l instanceof v?l:new v(`Invalid value for ${s}: ${l.message}`)}}const r=await Re(),o=M.dirname(r);await D.mkdir(o,{recursive:!0}),await D.writeFile(r,xe.stringify(e),"utf8")},lc=async t=>{const e=await We();for(const[s,n]of t){const[i,a]=s.split("."),c=e[i];if(a==="model"){c||(e[i]={});const l=e[i][a]||[],u=typeof n=="string"?n.split(",").map(p=>p.trim()).filter(p=>!!p):n;e[i][a]=vt([...l,...u]);continue}if(c&&c.compatible===!0){c||(e[i]={});const l=Et(i);if(!l[a])throw new v(`Invalid config property: ${s}`);try{e[i][a]=l[a](n)}catch(u){throw u instanceof v?u:new v(`Invalid value for ${s}: ${u.message}`)}continue}if(i in Ke){c||(e[i]={});const l=Ke[i][a];if(!l)throw new v(`Invalid config property: ${s}`);e[i][a]=l(n)}else{const l=Et(i);if(!l[a])throw new v(`Invalid config property: ${s}`);e[i]||(e[i]={}),e[i][a]=l[a](n)}}const r=await Re(),o=M.dirname(r);await D.mkdir(o,{recursive:!0}),await D.writeFile(r,xe.stringify(e),"utf8")},uc=async()=>{const t=await We();console.log(xe.stringify(t))},dc=async()=>{console.log(await Re())},Et=t=>({compatible:pe("compatible"),stream:pe("stream"),url:e=>e?(R(`${t}.url`,/^https?:\/\//.test(e),"Must be a valid URL"),e):"",path:e=>e||"",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):[],systemPrompt:m.systemPrompt,systemPromptPath:m.systemPromptPath,codeReviewPromptPath:m.codeReviewPromptPath,timeout:m.timeout,temperature:m.temperature,maxTokens:m.maxTokens,logging:m.logging,locale:m.locale,generate:m.generate,type:m.type,maxLength:m.maxLength,includeBody:m.includeBody,topP:m.topP,codeReview:m.codeReview,disabled:m.disabled,watchMode:m.watchMode,disableLowerCase:m.disableLowerCase}),Y=t=>typeof t=="string"&&t.trim().length>0,Ce=t=>(Array.isArray(t.model)?t.model:Y(t.model)?[t.model.trim()]:[]).length>0,$t=t=>{const e=Y(t.key),r=Y(t.region)||Y(process.env.AWS_REGION)||Y(process.env.AWS_DEFAULT_REGION),o=Y(t.profile)||Y(process.env.AWS_PROFILE),s=Y(t.accessKeyId)&&Y(t.secretAccessKey)||Y(process.env.AWS_ACCESS_KEY_ID)&&Y(process.env.AWS_SECRET_ACCESS_KEY),n=Y(t.applicationBaseUrl)||Y(process.env.BEDROCK_APPLICATION_BASE_URL),i=Y(t.applicationEndpointId)||Y(process.env.BEDROCK_APPLICATION_ENDPOINT_ID),a=Y(process.env.BEDROCK_APPLICATION_API_KEY);return r&&(e||o||s)||(n&&e||i&&a)},Oe=(t,e)=>Object.entries(t).map(([r,o])=>[r,o]).filter(([r,o])=>!o.disabled).filter(([r,o])=>He.includes(r)||o.compatible===!0).filter(([r,o])=>{switch(e){case"commit":return r==="OLLAMA"?!!o&&Ce(o):r==="HUGGINGFACE"?!!o&&!!o.cookie:r==="BEDROCK"?Ce(o)&&$t(o):!!o.key&&o.key.length>0;case"review":const s=t.codeReview||o.codeReview;return r==="OLLAMA"?!!o&&Ce(o)&&s:r==="HUGGINGFACE"?!!o&&!!o.cookie&&s:r==="BEDROCK"?Ce(o)&&$t(o)&&s:!!o.key&&o.key.length>0&&s;case"watch":const n=t.watchMode||o.watchMode;return r==="OLLAMA"?!!o&&Ce(o)&&n:r==="HUGGINGFACE"?!!o&&!!o.cookie&&n:r==="BEDROCK"?Ce(o)&&$t(o)&&n:o.compatible?!!o.url&&!!o.key&&n:!!o.key&&o.key.length>0&&n}}).map(([r])=>r);class mc{static create(e,r){return new e(r)}}const Ye=new Map,be=(t,e,r)=>{const o=oo(0).update(e).digest("hex").substring(0,8),s=`${t}_${o}_${r}`;if(Ye.has(s))return Ye.get(s);const n=new Date,i=hc(n,t,e,r),a=`${ue}/${i}`,c=K.createLogger({level:"info",format:K.format.combine(K.format.timestamp({format:"YYYY-MM-DDTHH:mm:ss.SSSZ"}),K.format.printf(({timestamp:d,level:l,message:u,...p})=>p&&Object.keys(p).length>0?`[${d}] ${l}: ${u} ${JSON.stringify(p,null,2)}`:`[${d}] ${l}: ${u}`)),transports:[new K.transports.File({filename:a})]});return c.info(`=== ${t.toUpperCase()} AI SERVICE LOG ===`),c.info(`Diff Hash: ${o}`),c.info(`Request Type: ${r.toUpperCase()}`),c.info(`Start Time: ${n.toISOString()}`),c.info("=".repeat(50)),c.info(""),Ye.set(s,c),c},pc=t=>{const e={...t},r=["authorization","x-api-key","x-goog-api-key","api-key","x-amzn-bedrock-application-key"];for(const o of r){const s=o.toLowerCase(),n=Object.keys(e).find(i=>i.toLowerCase()===s);n&&e[n]&&typeof e[n]=="string"&&(e[n].startsWith("Bearer ")?e[n]="Bearer [MASKED]":e[n]="[MASKED]")}return e},ee=(t,e,r,o,s,n,i=!0)=>{if(!i)return;const a=be(r,t,e);a.info(`Making request to ${r} API with model: ${o}`),a.info(`Request URL: ${s}`),a.info("Request headers:",pc(n))},ne=(t,e,r,o,s=!0)=>{if(!s)return;be(r,t,e).info("Request payload:",o)},te=(t,e,r,o,s,n=!0)=>{if(!n)return;const i=be(r,t,e);i.info("System prompt:",{prompt:o}),i.info("User prompt:",{prompt:s})},V=(t,e,r,o,s=!0)=>{if(!s)return;be(r,t,e).info("Response received:",o)},G=(t,e,r,o,s=!0)=>{if(!s)return;be(r,t,e).error("API request failed:",o)},q=(t,e,r,o,s,n=!0)=>{if(!n)return;const i=be(r,t,e);o?i.info(`Request completed successfully in ${o}ms`):i.info("Request completed successfully"),s&&i.info("Final processed response:",{response:s}),i.info(""),i.info("=".repeat(50)),i.info(`End Time: ${new Date().toISOString()}`),i.info("=== REQUEST COMPLETED ===")},fc=(t,e,r,o,s,n,i,a=!0)=>{if(!a)return;const c=be(r,t,e);i?c.error(`Request failed after ${n}ms:`,{error:i}):(c.info(`Request completed in ${n}ms`),c.info("Response:",{response:s})),q(t,e,r,n,s,a)},hc=(t,e,r,o)=>{const{year:s,month:n,day:i,hours:a,minutes:c,seconds:d}=gc(t),u=oo(0).update(r).digest("hex").substring(0,8),p=e.toLowerCase().replace(/[^a-z0-9]/g,"").substring(0,20);return o==="review"?`${s}-${n}-${i}_${a}-${c}-${d}_${u}_${p}_review.log`:`${s}-${n}-${i}_${a}-${c}-${d}_${u}_${p}_commit.log`},gc=t=>{const e=t.getFullYear().toString(),r=(t.getMonth()+1).toString().padStart(2,"0"),o=t.getDate().toString().padStart(2,"0"),s=t.getHours().toString().padStart(2,"0"),n=t.getMinutes().toString().padStart(2,"0"),i=t.getSeconds().toString().padStart(2,"0");return{year:e,month:r,day:o,hours:s,minutes:n,seconds:i}},hr=()=>{for(const[t,e]of Ye.entries())try{e.close()}catch(r){console.error(`Failed to close logger ${t}:`,r)}Ye.clear()};process.on("exit",hr),process.on("SIGINT",()=>{hr(),process.exit(0)}),process.on("SIGTERM",()=>{hr(),process.exit(0)});const A={label:g.bold.green,command:g.bold.white,hint:g.gray,highlight:g.bold.magenta,dim:g.dim},x={MISSING_API_KEY:"MISSING_API_KEY",INVALID_API_KEY:"INVALID_API_KEY",AUTH_FAILED:"AUTH_FAILED",RATE_LIMITED:"RATE_LIMITED",QUOTA_EXCEEDED:"QUOTA_EXCEEDED",MODEL_NOT_FOUND:"MODEL_NOT_FOUND",MODEL_ACCESS_DENIED:"MODEL_ACCESS_DENIED",NETWORK_ERROR:"NETWORK_ERROR",TIMEOUT:"TIMEOUT",SERVICE_UNAVAILABLE:"SERVICE_UNAVAILABLE",NO_STAGED_CHANGES:"NO_STAGED_CHANGES",EMPTY_COMMIT_MESSAGE:"EMPTY_COMMIT_MESSAGE",VCS_NOT_FOUND:"VCS_NOT_FOUND",INVALID_CONFIG:"INVALID_CONFIG",CONFIG_NOT_FOUND:"CONFIG_NOT_FOUND",SERVER_ERROR:"SERVER_ERROR",UNKNOWN:"UNKNOWN"},gr={missingApiKey:t=>{const e=t.toUpperCase();return[`Missing API key for ${A.highlight(e)}.`,"",`${A.label("\u2192")} Run: ${A.command(`aicommit2 config set ${e}.key=YOUR_API_KEY`)}`].join(`
|
|
20
|
+
`)},invalidApiKey:t=>{const e=t.toUpperCase();return[`Invalid or expired API key for ${A.highlight(e)}.`,"",`${A.label("\u2192")} Update: ${A.command(`aicommit2 config set ${e}.key=YOUR_NEW_KEY`)}`].join(`
|
|
21
|
+
`)},noApiKeysConfigured:()=>["No AI provider API keys configured.","",`${A.label("\u2192")} Please set at least one API key:`,` ${A.command("aicommit2 config set OPENAI.key=sk-...")}`,` ${A.command("aicommit2 config set ANTHROPIC.key=sk-ant-...")}`,` ${A.command("aicommit2 config set OLLAMA.model=llama3.2")} ${A.dim("(no key needed)")}`,"",`${A.hint("Tip:")} ${A.command("aicommit2 config get")} ${A.hint("to see current config")}`].join(`
|
|
22
|
+
`),rateLimited:t=>[`Rate limit exceeded${t?` for ${A.highlight(t)}`:""}.`,"",`${A.label("\u2192")} Wait a moment and try again`,`${A.label("\u2192")} Or use a different AI provider`].join(`
|
|
23
|
+
`),quotaExceeded:t=>[`API quota exceeded${t?` for ${A.highlight(t)}`:""}.`,"",`${A.label("\u2192")} Upgrade your API plan or wait for reset`].join(`
|
|
24
|
+
`),modelNotFound:(t,e)=>{const r=e.toUpperCase();return[`Model ${A.highlight(`"${t}"`)} not found for ${A.highlight(r)}.`,"",`${A.label("\u2192")} Update: ${A.command(`aicommit2 config set ${r}.model=VALID_MODEL`)}`].join(`
|
|
25
|
+
`)},modelAccessDenied:(t,e)=>[`Access denied to model ${A.highlight(`"${t}"`)} on ${A.highlight(e)}.`,"",`${A.label("\u2192")} Check API access or upgrade your plan`].join(`
|
|
26
|
+
`),networkError:t=>[`Network connection failed${t?` to ${A.highlight(t)}`:""}.`,"",`${A.label("\u2192")} Check internet connectivity and try again`].join(`
|
|
27
|
+
`),timeout:(t,e)=>{const r=e?` from ${A.highlight(e)}`:"",o=Math.round(t*1.5);return[`Request timed out${r} after ${t}ms.`,"",`${A.label("\u2192")} Increase: ${A.command(`aicommit2 config set timeout=${o}`)}`].join(`
|
|
28
|
+
`)},serviceUnavailable:t=>[`${A.highlight(t)} service is temporarily unavailable.`,"",`${A.label("\u2192")} Try again in a few minutes`].join(`
|
|
29
|
+
`),noStagedChanges:t=>{const e=t.toLowerCase()==="jujutsu"?"jj":t.toLowerCase()==="yadm"?"yadm add":"git add";return[`No staged changes found in ${A.highlight(t)} repository.`,"",`${A.label("\u2192")} Stage: ${A.command(`${e} <files>`)}`,`${A.label("\u2192")} Or use: ${A.command("aicommit2 --all")}`].join(`
|
|
30
|
+
`)},emptyCommitMessage:()=>"Commit message cannot be empty.",vcsNotFound:t=>{const r={git:"https://git-scm.com/downloads",yadm:"https://yadm.io/docs/install",jujutsu:"https://github.com/jj-vcs/jj#installation"}[t.toLowerCase()]||"";return[`${A.highlight(t)} is not installed or not found in PATH.`,"",r?`${A.label("\u2192")} Install: ${A.command(r)}`:""].filter(Boolean).join(`
|
|
31
|
+
`)},notInRepository:t=>[`Not in a ${A.highlight(t)} repository.`,"",`${A.label("\u2192")} Init: ${A.command(`${t.toLowerCase()} init`)}`].join(`
|
|
32
|
+
`),invalidConfigFormat:t=>[`Invalid configuration format for ${A.highlight(`"${t}"`)}`,"",`${A.label("\u2192")} Use: ${A.command("aicommit2 config set PROVIDER.key=value")}`].join(`
|
|
33
|
+
`),invalidConfigValue:(t,e)=>[`Invalid value for ${A.highlight(`"${t}"`)}`,"",`${A.label("\u2192")} Expected: ${A.dim(e)}`].join(`
|
|
34
|
+
`),serverError:(t,e)=>{const r=e?` ${A.dim(`(HTTP ${e})`)}`:"";return`${A.highlight(t)} server error${r}. Try again later.`},ollamaNotRunning:()=>[`${A.highlight("Ollama")} is not running or not accessible.`,"",`${A.label("\u2192")} Start: ${A.command("ollama serve")}`].join(`
|
|
35
|
+
`),ollamaModelNotPulled:t=>[`Ollama model ${A.highlight(`"${t}"`)} is not available locally.`,"",`${A.label("\u2192")} Pull: ${A.command(`ollama pull ${t}`)}`].join(`
|
|
36
|
+
`)},yc=t=>({401:x.INVALID_API_KEY,403:x.MODEL_ACCESS_DENIED,404:x.MODEL_NOT_FOUND,429:x.RATE_LIMITED,500:x.SERVER_ERROR,502:x.SERVICE_UNAVAILABLE,503:x.SERVICE_UNAVAILABLE,504:x.TIMEOUT})[t]||x.UNKNOWN,wc=t=>{const e=t.toLowerCase();return e.includes("api key")||e.includes("api_key")||e.includes("apikey")?e.includes("missing")?x.MISSING_API_KEY:x.INVALID_API_KEY:e.includes("401")||e.includes("unauthorized")||e.includes("authentication")?x.AUTH_FAILED:e.includes("rate")||e.includes("429")||e.includes("too many")?x.RATE_LIMITED:e.includes("quota")||e.includes("usage")||e.includes("limit exceeded")?x.QUOTA_EXCEEDED:e.includes("model")&&(e.includes("not found")||e.includes("404"))?x.MODEL_NOT_FOUND:e.includes("403")||e.includes("forbidden")||e.includes("access denied")?x.MODEL_ACCESS_DENIED:e.includes("econnrefused")||e.includes("network")||e.includes("connection")?x.NETWORK_ERROR:e.includes("timeout")||e.includes("timed out")||e.includes("504")?x.TIMEOUT:e.includes("unavailable")||e.includes("overloaded")||e.includes("503")||e.includes("502")?x.SERVICE_UNAVAILABLE:e.includes("500")||e.includes("internal server error")?x.SERVER_ERROR:x.UNKNOWN},ie={missingApiKey:t=>`Missing API key for ${t.toUpperCase()}`,invalidApiKey:t=>`Invalid API key for ${t.toUpperCase()}`,rateLimited:t=>`Rate limit exceeded${t?` for ${t}`:""}`,quotaExceeded:t=>`API quota exceeded${t?` for ${t}`:""}`,modelNotFound:(t,e)=>`Model "${t}" not found for ${e.toUpperCase()}`,modelAccessDenied:(t,e)=>`Access denied to model "${t}" on ${e}`,networkError:t=>`Network connection failed${t?` to ${t}`:""}`,timeout:(t,e)=>`Request timed out${e?` from ${e}`:""} after ${t}ms`,serviceUnavailable:t=>`${t} service is temporarily unavailable`,serverError:(t,e)=>`${t} server error${e?` (HTTP ${e})`:""}`,unknown:t=>`An error occurred with ${t}. Please try again.`,ollamaNotRunning:()=>"Ollama is not running. Start with: ollama serve",ollamaModelNotPulled:t=>`Ollama model "${t}" not found. Pull with: ollama pull ${t}`},vc=(t,e={})=>{const{provider:r="AI",model:o,timeout:s}=e;switch(t){case x.MISSING_API_KEY:return ie.missingApiKey(r);case x.INVALID_API_KEY:case x.AUTH_FAILED:return ie.invalidApiKey(r);case x.RATE_LIMITED:return ie.rateLimited(r);case x.QUOTA_EXCEEDED:return ie.quotaExceeded(r);case x.MODEL_NOT_FOUND:return ie.modelNotFound(o||"unknown",r);case x.MODEL_ACCESS_DENIED:return ie.modelAccessDenied(o||"unknown",r);case x.NETWORK_ERROR:return ie.networkError(r);case x.TIMEOUT:return ie.timeout(s||1e4,r);case x.SERVICE_UNAVAILABLE:return ie.serviceUnavailable(r);case x.SERVER_ERROR:return ie.serverError(r);default:return ie.unknown(r)}};let Pt,ms="info";async function Cc(t){if(Pt){console.warn("Logger already initialized. Skipping re-initialization.");return}const e=t?.logLevel||"info";ms=e;const r=t?.logFilePath||ls,o=t?.exceptionLogFilePath||us,s=t?.logging??!0;await os(M.dirname(r)),await os(M.dirname(o));const n=[];s?n.push(new K.transports.DailyRotateFile({filename:r,datePattern:"YYYY-MM-DD",zippedArchive:!0,maxSize:"20m",maxFiles:"14d",level:e,format:K.format.combine(K.format.timestamp(),K.format.printf(({level:i,message:a,timestamp:c})=>`[${c}] ${i}: ${a}`))})):n.push(new K.transports.Console({silent:!0})),Pt=K.createLogger({level:e,format:K.format.json(),transports:n,exceptionHandlers:s?[new K.transports.DailyRotateFile({filename:o,datePattern:"YYYY-MM-DD",zippedArchive:!0,maxSize:"20m",maxFiles:"14d",format:K.format.combine(K.format.timestamp(),K.format.json())})]:[],exitOnError:!1,silent:!s})}const De=new Proxy({},{get:(t,e,r)=>{if(!Pt)throw new Error("Logger not initialized. Call initializeLogger() first.");return Reflect.get(Pt,e,r)}});function At(){const t=K.config.npm.levels;return(t[ms]??t.info)>=t.verbose}class re{constructor(e){this.handleError$=r=>{const o=this.getDetailedErrorMessage(r),s=r.status?`HTTP ${r.status}: ${o}`:o;if(this.params.config.logging){const n=this.params.stagedDiff.diff,i=this.serviceName.replace(/\[|\]/g,"").trim();fc(n,"commit",i,"Error occurred","",void 0,s)}return De.error(`${this.errorPrefix} ${s}`),r.stack&&De.error(` ${r.stack}`),r.content&&De.error(` Problematic content: ${r.content}`),r.originalError&&De.error(` Original error: ${r.originalError}`),Xr({name:`${this.errorPrefix} ${s}`,value:s,isError:!0,disabled:!0})},this.serviceName="AI",this.errorPrefix="ERROR",this.colors={primary:""},this.params=e,this.logSessionId=e.logSessionId}getProviderName(){const e=String.fromCharCode(27),r=new RegExp(`${e}\\[[0-9;]*m`,"g");return this.serviceName.replace(r,"").replace(/\[|\]/g,"").trim()}getDetailedErrorMessage(e){const r=e.message||"",o=this.getProviderName(),s=this.params.config.model?.[0],n=this.params.config.timeout,i=this.getServiceSpecificErrorMessage(e);if(i)return i;const a=e.code||(e.status?yc(e.status):wc(r));return a!==x.UNKNOWN?vc(a,{provider:o,model:s,timeout:n}):r||"Unknown error occurred"}getServiceSpecificErrorMessage(e){return null}cleanJsonCodeBlock(e){const r=/```(?:json|JSON)?\s*([\s\S]*?)\s*```/,o=e.match(r);return o?o[1].trim():e}extractJsonFromResponse(e){let r=e.indexOf("[");if(r!==-1){const o=this.extractBalancedJson(e,r,"[","]");if(o)return o}if(r=e.indexOf("{"),r!==-1){const o=this.extractBalancedJson(e,r,"{","}");if(o)return o}return null}extractBalancedJson(e,r,o,s){let n=0,i=!1,a=!1;for(let c=r;c<e.length;c++){const d=e[c];if(a){a=!1;continue}if(d==="\\"&&i){a=!0;continue}if(d==='"'){i=!i;continue}if(!i&&(d===o&&n++,d===s&&n--,n===0))return e.slice(r,c+1)}return null}parseMessage(e,r,o){const s=this.cleanJsonCodeBlock(e),n=this.extractJsonFromResponse(s);if(!n){const u=new Error("AI response did not contain a valid JSON object or array.");throw u.name="InvalidJsonResponse",u.content=e,u}const i=ns(n);if(!i.ok){const u=new Error("Failed to parse AI response as JSON");throw u.name="JsonParseError",u.content=n,u.originalError=i.error,u}const a=i.data,c=Array.isArray(a)?a:[a];if(!c.length||!c.every(u=>typeof u.subject=="string")){const u=new Error("AI response contained malformed commit message data.");throw u.name="MalformedCommitMessage",u.content=e,u}const l=c.map(u=>this.extractMessageAsType(u,r)).map(u=>({title:`${u.subject}`,value:`${u.subject}${u.body?`
|
|
20
37
|
|
|
21
38
|
${u.body}`:""}${u.footer?`
|
|
22
39
|
|
|
23
|
-
${u.footer}`:""}`})).slice(0,o);if(this.isLoggingEnabled()){const u=c.map(f=>f.title).join(", ");De.info(`${this.serviceName} Parsed ${c.length} commit messages: ${u}`)}return c}extractMessageAsType(e,r){switch(r){case"conventional":const o=/(\w+)(?:\(.*?\))?:\s*(.*)/,n=e.subject.match(o),s=n?n[0]:e.subject;return{...e,subject:this.normalizeCommitMessage(s)};case"gitmoji":const i=/:\w*:\s*(.*)/,l=e.subject.match(i),a=this.params.config.disableLowerCase??!1;return{...e,subject:l&&!a?l[0].toLowerCase():e.subject};default:return e}}normalizeCommitMessage(e){const r=/^(\w+)(\(.*?\))?:\s(.*)$/,o=e.match(r);if(o){const[,n,s,i]=o,l=this.params.config.disableLowerCase??!1,a=n.toLowerCase(),d=l?i:i.charAt(0).toLowerCase()+i.slice(1);e=`${a}${s||""}: ${d}`}return e}sanitizeResponse(e){if(typeof e=="string")try{return[{title:`${Xo(e)}...`,value:e}]}catch{return[]}return e.map(r=>{try{return{title:`${Xo(r)}...`,value:r}}catch{return{title:"",value:""}}})}isLoggingEnabled(){return this.params.config.logging&&!!this.logSessionId}}const ec=["claude-4","claude-haiku-4","claude-sonnet-4","claude-opus-4"],tc=t=>{const e=t.toLowerCase();return ec.some(r=>e===r||e.startsWith(`${r}-`)||e.startsWith(`${r}.`))},J={locale:"en",maxLength:50,type:"conventional",generate:1,systemPrompt:"",systemPromptPath:"",codeReviewPromptPath:"",vcs_branch:""},rc={"":"<commit message>",conventional:`<type>(<optional scope>): <description>
|
|
40
|
+
${u.footer}`:""}`})).slice(0,o);if(this.isLoggingEnabled()){const u=l.map(p=>p.title).join(", ");De.info(`${this.serviceName} Parsed ${l.length} commit messages: ${u}`)}return l}extractMessageAsType(e,r){switch(r){case"conventional":const o=/(\w+)(?:\(.*?\))?:\s*(.*)/,s=e.subject.match(o),n=s?s[0]:e.subject;return{...e,subject:this.normalizeCommitMessage(n)};case"gitmoji":const i=/:\w*:\s*(.*)/,a=e.subject.match(i),c=this.params.config.disableLowerCase??!1;return{...e,subject:a&&!c?a[0].toLowerCase():e.subject};default:return e}}normalizeCommitMessage(e){const r=/^(\w+)(\(.*?\))?:\s(.*)$/,o=e.match(r);if(o){const[,s,n,i]=o,a=this.params.config.disableLowerCase??!1,c=s.toLowerCase(),d=a?i:i.charAt(0).toLowerCase()+i.slice(1);e=`${c}${n||""}: ${d}`}return e}sanitizeResponse(e){if(typeof e=="string")try{return[{title:`${ss(e)}...`,value:e}]}catch{return[]}return e.map(r=>{try{return{title:`${ss(r)}...`,value:r}}catch{return{title:"",value:""}}})}isLoggingEnabled(){return this.params.config.logging&&!!this.logSessionId}}var yr={},wr={exports:{}},Ve={exports:{}},vr,ps;function bc(){if(ps)return vr;ps=1;var t=1e3,e=t*60,r=e*60,o=r*24,s=o*7,n=o*365.25;vr=function(l,u){u=u||{};var p=typeof l;if(p==="string"&&l.length>0)return i(l);if(p==="number"&&isFinite(l))return u.long?c(l):a(l);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(l))};function i(l){if(l=String(l),!(l.length>100)){var u=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(l);if(u){var p=parseFloat(u[1]),f=(u[2]||"ms").toLowerCase();switch(f){case"years":case"year":case"yrs":case"yr":case"y":return p*n;case"weeks":case"week":case"w":return p*s;case"days":case"day":case"d":return p*o;case"hours":case"hour":case"hrs":case"hr":case"h":return p*r;case"minutes":case"minute":case"mins":case"min":case"m":return p*e;case"seconds":case"second":case"secs":case"sec":case"s":return p*t;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return p;default:return}}}}function a(l){var u=Math.abs(l);return u>=o?Math.round(l/o)+"d":u>=r?Math.round(l/r)+"h":u>=e?Math.round(l/e)+"m":u>=t?Math.round(l/t)+"s":l+"ms"}function c(l){var u=Math.abs(l);return u>=o?d(l,u,o,"day"):u>=r?d(l,u,r,"hour"):u>=e?d(l,u,e,"minute"):u>=t?d(l,u,t,"second"):l+" ms"}function d(l,u,p,f){var h=u>=p*1.5;return Math.round(l/p)+" "+f+(h?"s":"")}return vr}var Cr,fs;function hs(){if(fs)return Cr;fs=1;function t(e){o.debug=o,o.default=o,o.coerce=d,o.disable=a,o.enable=n,o.enabled=c,o.humanize=bc(),o.destroy=l,Object.keys(e).forEach(u=>{o[u]=e[u]}),o.names=[],o.skips=[],o.formatters={};function r(u){let p=0;for(let f=0;f<u.length;f++)p=(p<<5)-p+u.charCodeAt(f),p|=0;return o.colors[Math.abs(p)%o.colors.length]}o.selectColor=r;function o(u){let p,f=null,h,y;function w(...C){if(!w.enabled)return;const b=w,E=Number(new Date),k=E-(p||E);b.diff=k,b.prev=p,b.curr=E,p=E,C[0]=o.coerce(C[0]),typeof C[0]!="string"&&C.unshift("%O");let $=0;C[0]=C[0].replace(/%([a-zA-Z%])/g,(O,S)=>{if(O==="%%")return"%";$++;const U=o.formatters[S];if(typeof U=="function"){const _=C[$];O=U.call(b,_),C.splice($,1),$--}return O}),o.formatArgs.call(b,C),(b.log||o.log).apply(b,C)}return w.namespace=u,w.useColors=o.useColors(),w.color=o.selectColor(u),w.extend=s,w.destroy=o.destroy,Object.defineProperty(w,"enabled",{enumerable:!0,configurable:!1,get:()=>f!==null?f:(h!==o.namespaces&&(h=o.namespaces,y=o.enabled(u)),y),set:C=>{f=C}}),typeof o.init=="function"&&o.init(w),w}function s(u,p){const f=o(this.namespace+(typeof p>"u"?":":p)+u);return f.log=this.log,f}function n(u){o.save(u),o.namespaces=u,o.names=[],o.skips=[];const p=(typeof u=="string"?u:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const f of p)f[0]==="-"?o.skips.push(f.slice(1)):o.names.push(f)}function i(u,p){let f=0,h=0,y=-1,w=0;for(;f<u.length;)if(h<p.length&&(p[h]===u[f]||p[h]==="*"))p[h]==="*"?(y=h,w=f,h++):(f++,h++);else if(y!==-1)h=y+1,w++,f=w;else return!1;for(;h<p.length&&p[h]==="*";)h++;return h===p.length}function a(){const u=[...o.names,...o.skips.map(p=>"-"+p)].join(",");return o.enable(""),u}function c(u){for(const p of o.skips)if(i(u,p))return!1;for(const p of o.names)if(i(u,p))return!0;return!1}function d(u){return u instanceof Error?u.stack||u.message:u}function l(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return o.enable(o.load()),o}return Cr=t,Cr}Ve.exports;var gs;function Ec(){return gs||(gs=1,function(t,e){e.formatArgs=o,e.save=s,e.load=n,e.useColors=r,e.storage=i(),e.destroy=(()=>{let c=!1;return()=>{c||(c=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),e.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function r(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let c;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(c=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(c[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function o(c){if(c[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+c[0]+(this.useColors?"%c ":" ")+"+"+t.exports.humanize(this.diff),!this.useColors)return;const d="color: "+this.color;c.splice(1,0,d,"color: inherit");let l=0,u=0;c[0].replace(/%[a-zA-Z%]/g,p=>{p!=="%%"&&(l++,p==="%c"&&(u=l))}),c.splice(u,0,d)}e.log=console.debug||console.log||(()=>{});function s(c){try{c?e.storage.setItem("debug",c):e.storage.removeItem("debug")}catch{}}function n(){let c;try{c=e.storage.getItem("debug")||e.storage.getItem("DEBUG")}catch{}return!c&&typeof process<"u"&&"env"in process&&(c=process.env.DEBUG),c}function i(){try{return localStorage}catch{}}t.exports=hs()(e);const{formatters:a}=t.exports;a.j=function(c){try{return JSON.stringify(c)}catch(d){return"[UnexpectedJSONParseError]: "+d.message}}}(Ve,Ve.exports)),Ve.exports}var qe={exports:{}},br,ys;function $c(){return ys||(ys=1,br=(t,e=process.argv)=>{const r=t.startsWith("-")?"":t.length===1?"-":"--",o=e.indexOf(r+t),s=e.indexOf("--");return o!==-1&&(s===-1||o<s)}),br}var Er,ws;function Pc(){if(ws)return Er;ws=1;const t=Le,e=no,r=$c(),{env:o}=process;let s;r("no-color")||r("no-colors")||r("color=false")||r("color=never")?s=0:(r("color")||r("colors")||r("color=true")||r("color=always"))&&(s=1),"FORCE_COLOR"in o&&(o.FORCE_COLOR==="true"?s=1:o.FORCE_COLOR==="false"?s=0:s=o.FORCE_COLOR.length===0?1:Math.min(parseInt(o.FORCE_COLOR,10),3));function n(c){return c===0?!1:{level:c,hasBasic:!0,has256:c>=2,has16m:c>=3}}function i(c,d){if(s===0)return 0;if(r("color=16m")||r("color=full")||r("color=truecolor"))return 3;if(r("color=256"))return 2;if(c&&!d&&s===void 0)return 0;const l=s||0;if(o.TERM==="dumb")return l;if(process.platform==="win32"){const u=t.release().split(".");return Number(u[0])>=10&&Number(u[2])>=10586?Number(u[2])>=14931?3:2:1}if("CI"in o)return["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","GITHUB_ACTIONS","BUILDKITE"].some(u=>u in o)||o.CI_NAME==="codeship"?1:l;if("TEAMCITY_VERSION"in o)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(o.TEAMCITY_VERSION)?1:0;if(o.COLORTERM==="truecolor")return 3;if("TERM_PROGRAM"in o){const u=parseInt((o.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(o.TERM_PROGRAM){case"iTerm.app":return u>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(o.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(o.TERM)||"COLORTERM"in o?1:l}function a(c){const d=i(c,c&&c.isTTY);return n(d)}return Er={supportsColor:a,stdout:n(i(!0,e.isatty(1))),stderr:n(i(!0,e.isatty(2)))},Er}qe.exports;var vs;function Ac(){return vs||(vs=1,function(t,e){const r=no,o=Jr;e.init=l,e.log=a,e.formatArgs=n,e.save=c,e.load=d,e.useColors=s,e.destroy=o.deprecate(()=>{},"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."),e.colors=[6,2,3,4,5,1];try{const p=Pc();p&&(p.stderr||p).level>=2&&(e.colors=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221])}catch{}e.inspectOpts=Object.keys(process.env).filter(p=>/^debug_/i.test(p)).reduce((p,f)=>{const h=f.substring(6).toLowerCase().replace(/_([a-z])/g,(w,C)=>C.toUpperCase());let y=process.env[f];return/^(yes|on|true|enabled)$/i.test(y)?y=!0:/^(no|off|false|disabled)$/i.test(y)?y=!1:y==="null"?y=null:y=Number(y),p[h]=y,p},{});function s(){return"colors"in e.inspectOpts?!!e.inspectOpts.colors:r.isatty(process.stderr.fd)}function n(p){const{namespace:f,useColors:h}=this;if(h){const y=this.color,w="\x1B[3"+(y<8?y:"8;5;"+y),C=` ${w};1m${f} \x1B[0m`;p[0]=C+p[0].split(`
|
|
41
|
+
`).join(`
|
|
42
|
+
`+C),p.push(w+"m+"+t.exports.humanize(this.diff)+"\x1B[0m")}else p[0]=i()+f+" "+p[0]}function i(){return e.inspectOpts.hideDate?"":new Date().toISOString()+" "}function a(...p){return process.stderr.write(o.formatWithOptions(e.inspectOpts,...p)+`
|
|
43
|
+
`)}function c(p){p?process.env.DEBUG=p:delete process.env.DEBUG}function d(){return process.env.DEBUG}function l(p){p.inspectOpts={};const f=Object.keys(e.inspectOpts);for(let h=0;h<f.length;h++)p.inspectOpts[f[h]]=e.inspectOpts[f[h]]}t.exports=hs()(e);const{formatters:u}=t.exports;u.o=function(p){return this.inspectOpts.colors=this.useColors,o.inspect(p,this.inspectOpts).split(`
|
|
44
|
+
`).map(f=>f.trim()).join(" ")},u.O=function(p){return this.inspectOpts.colors=this.useColors,o.inspect(p,this.inspectOpts)}}(qe,qe.exports)),qe.exports}typeof process>"u"||process.type==="renderer"||process.browser===!0||process.__nwjs?wr.exports=Ec():wr.exports=Ac();var $r=wr.exports,Pr={};Object.defineProperty(Pr,"__esModule",{value:!0});function Sc(t){return function(e,r){return new Promise((o,s)=>{t.call(this,e,r,(n,i)=>{n?s(n):o(i)})})}}Pr.default=Sc;var Cs=H&&H.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};const kc=qr,Ic=Cs($r),Mc=Cs(Pr),Je=Ic.default("agent-base");function xc(t){return!!t&&typeof t.addRequest=="function"}function Ar(){const{stack:t}=new Error;return typeof t!="string"?!1:t.split(`
|
|
45
|
+
`).some(e=>e.indexOf("(https.js:")!==-1||e.indexOf("node:https:")!==-1)}function St(t,e){return new St.Agent(t,e)}(function(t){class e extends kc.EventEmitter{constructor(o,s){super();let n=s;typeof o=="function"?this.callback=o:o&&(n=o),this.timeout=null,n&&typeof n.timeout=="number"&&(this.timeout=n.timeout),this.maxFreeSockets=1,this.maxSockets=1,this.maxTotalSockets=1/0,this.sockets={},this.freeSockets={},this.requests={},this.options={}}get defaultPort(){return typeof this.explicitDefaultPort=="number"?this.explicitDefaultPort:Ar()?443:80}set defaultPort(o){this.explicitDefaultPort=o}get protocol(){return typeof this.explicitProtocol=="string"?this.explicitProtocol:Ar()?"https:":"http:"}set protocol(o){this.explicitProtocol=o}callback(o,s,n){throw new Error('"agent-base" has no default implementation, you must subclass and override `callback()`')}addRequest(o,s){const n=Object.assign({},s);typeof n.secureEndpoint!="boolean"&&(n.secureEndpoint=Ar()),n.host==null&&(n.host="localhost"),n.port==null&&(n.port=n.secureEndpoint?443:80),n.protocol==null&&(n.protocol=n.secureEndpoint?"https:":"http:"),n.host&&n.path&&delete n.path,delete n.agent,delete n.hostname,delete n._defaultAgent,delete n.defaultPort,delete n.createConnection,o._last=!0,o.shouldKeepAlive=!1;let i=!1,a=null;const c=n.timeout||this.timeout,d=f=>{o._hadError||(o.emit("error",f),o._hadError=!0)},l=()=>{a=null,i=!0;const f=new Error(`A "socket" was not created for HTTP request before ${c}ms`);f.code="ETIMEOUT",d(f)},u=f=>{i||(a!==null&&(clearTimeout(a),a=null),d(f))},p=f=>{if(i)return;if(a!=null&&(clearTimeout(a),a=null),xc(f)){Je("Callback returned another Agent instance %o",f.constructor.name),f.addRequest(o,n);return}if(f){f.once("free",()=>{this.freeSocket(f,n)}),o.onSocket(f);return}const h=new Error(`no Duplex stream was returned to agent-base for \`${o.method} ${o.path}\``);d(h)};if(typeof this.callback!="function"){d(new Error("`callback` is not defined"));return}this.promisifiedCallback||(this.callback.length>=3?(Je("Converting legacy callback function to promise"),this.promisifiedCallback=Mc.default(this.callback)):this.promisifiedCallback=this.callback),typeof c=="number"&&c>0&&(a=setTimeout(l,c)),"port"in n&&typeof n.port!="number"&&(n.port=Number(n.port));try{Je("Resolving socket for %o request: %o",n.protocol,`${o.method} ${o.path}`),Promise.resolve(this.promisifiedCallback(o,n)).then(p,u)}catch(f){Promise.reject(f).catch(u)}}freeSocket(o,s){Je("Freeing socket %o %o",o.constructor.name,s),o.destroy()}destroy(){Je("Destroying agent %o",this.constructor.name)}}t.Agent=e,t.prototype=t.Agent.prototype})(St||(St={}));var Rc=St,Sr={},Oc=H&&H.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(Sr,"__esModule",{value:!0});const Dc=Oc($r),Xe=Dc.default("https-proxy-agent:parse-proxy-response");function _c(t){return new Promise((e,r)=>{let o=0;const s=[];function n(){const u=t.read();u?l(u):t.once("readable",n)}function i(){t.removeListener("end",c),t.removeListener("error",d),t.removeListener("close",a),t.removeListener("readable",n)}function a(u){Xe("onclose had error %o",u)}function c(){Xe("onend")}function d(u){i(),Xe("onerror %o",u),r(u)}function l(u){s.push(u),o+=u.length;const p=Buffer.concat(s,o);if(p.indexOf(`\r
|
|
46
|
+
\r
|
|
47
|
+
`)===-1){Xe("have not received end of HTTP headers yet..."),n();return}const h=p.toString("ascii",0,p.indexOf(`\r
|
|
48
|
+
`)),y=+h.split(" ")[1];Xe("got proxy server response: %o",h),e({statusCode:y,buffered:p})}t.on("error",d),t.on("close",a),t.on("end",c),n()})}Sr.default=_c;var Nc=H&&H.__awaiter||function(t,e,r,o){function s(n){return n instanceof r?n:new r(function(i){i(n)})}return new(r||(r=Promise))(function(n,i){function a(l){try{d(o.next(l))}catch(u){i(u)}}function c(l){try{d(o.throw(l))}catch(u){i(u)}}function d(l){l.done?n(l.value):s(l.value).then(a,c)}d((o=o.apply(t,e||[])).next())})},_e=H&&H.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(yr,"__esModule",{value:!0});const bs=_e(an),Es=_e(cn),Tc=_e(ln),Lc=_e(Vr),Fc=_e($r),jc=Rc,Bc=_e(Sr),Qe=Fc.default("https-proxy-agent:agent");class Gc extends jc.Agent{constructor(e){let r;if(typeof e=="string"?r=Tc.default.parse(e):r=e,!r)throw new Error("an HTTP(S) proxy server `host` and `port` must be specified!");Qe("creating new HttpsProxyAgent instance: %o",r),super(r);const o=Object.assign({},r);this.secureProxy=r.secureProxy||Kc(o.protocol),o.host=o.hostname||o.host,typeof o.port=="string"&&(o.port=parseInt(o.port,10)),!o.port&&o.host&&(o.port=this.secureProxy?443:80),this.secureProxy&&!("ALPNProtocols"in o)&&(o.ALPNProtocols=["http 1.1"]),o.host&&o.path&&(delete o.path,delete o.pathname),this.proxy=o}callback(e,r){return Nc(this,void 0,void 0,function*(){const{proxy:o,secureProxy:s}=this;let n;s?(Qe("Creating `tls.Socket`: %o",o),n=Es.default.connect(o)):(Qe("Creating `net.Socket`: %o",o),n=bs.default.connect(o));const i=Object.assign({},o.headers);let c=`CONNECT ${`${r.host}:${r.port}`} HTTP/1.1\r
|
|
49
|
+
`;o.auth&&(i["Proxy-Authorization"]=`Basic ${Buffer.from(o.auth).toString("base64")}`);let{host:d,port:l,secureEndpoint:u}=r;Hc(l,u)||(d+=`:${l}`),i.Host=d,i.Connection="close";for(const w of Object.keys(i))c+=`${w}: ${i[w]}\r
|
|
50
|
+
`;const p=Bc.default(n);n.write(`${c}\r
|
|
51
|
+
`);const{statusCode:f,buffered:h}=yield p;if(f===200){if(e.once("socket",Uc),r.secureEndpoint){Qe("Upgrading socket connection to TLS");const w=r.servername||r.host;return Es.default.connect(Object.assign(Object.assign({},zc(r,"host","hostname","path","port")),{socket:n,servername:w}))}return n}n.destroy();const y=new bs.default.Socket({writable:!1});return y.readable=!0,e.once("socket",w=>{Qe("replaying proxy buffer for failed request"),Lc.default(w.listenerCount("data")>0),w.push(h),w.push(null)}),y})}}yr.default=Gc;function Uc(t){t.resume()}function Hc(t,e){return!!(!e&&t===80||e&&t===443)}function Kc(t){return typeof t=="string"?/^https:?$/i.test(t):!1}function zc(t,...e){const r={};let o;for(o in t)e.includes(o)||(r[o]=t[o]);return r}var Wc=H&&H.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};const kr=Wc(yr);function Ir(t){return new kr.default(t)}(function(t){t.HttpsProxyAgent=kr.default,t.prototype=kr.default.prototype})(Ir||(Ir={}));var Yc=Ir,Vc=Pe(Yc);const J={locale:"en",maxLength:50,type:"conventional",generate:1,systemPrompt:"",systemPromptPath:"",codeReviewPromptPath:"",vcs_branch:""},qc={"":"<commit message>",conventional:`<type>(<optional scope>): <description>
|
|
24
52
|
|
|
25
53
|
[optional body]
|
|
26
54
|
|
|
@@ -28,26 +56,26 @@ ${u.footer}`:""}`})).slice(0,o);if(this.isLoggingEnabled()){const u=c.map(f=>f.t
|
|
|
28
56
|
|
|
29
57
|
[optional body]
|
|
30
58
|
|
|
31
|
-
[optional footer(s)]`},
|
|
59
|
+
[optional footer(s)]`},Jc={"":"",gitmoji:`
|
|
32
60
|
${Object.entries({":sparkles:":"Introduce new features.",":bug:":"Fix a bug.",":memo:":"Add or update documentation.",":art:":"Improve structure / format of the code.",":zap:":"Improve performance.",":fire:":"Remove code or files.",":ambulance:":"Critical hotfix.",":white_check_mark:":"Add, update, or pass tests.",":lock:":"Fix security or privacy issues.",":rocket:":"Deploy stuff.",":lipstick:":"Add or update the UI and style files.",":tada:":"Begin a project.",":recycle:":"Refactor code.",":wrench:":"Add or update configuration files.",":bulb:":"Add or update comments in source code.",":twisted_rightwards_arrows:":"Merge branches."}).map(([t,e])=>` - ${t}: ${e}`).join(`
|
|
33
61
|
`)}`,conventional:`
|
|
34
62
|
${Object.entries({docs:"Documentation only changes",style:"Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)",refactor:"A code change that neither fixes a bug nor adds a feature",perf:"A code change that improves performance",test:"Adding missing tests or correcting existing tests",build:"Changes that affect the build system or external dependencies",ci:"Changes to CI configuration files, scripts",chore:"Other changes that don't modify src or test files",revert:"Reverts a previous commit",feat:"A new feature",fix:"A bug fix"}).map(([t,e])=>` - ${t}: ${e}`).join(`
|
|
35
|
-
`)}`},
|
|
63
|
+
`)}`},Mr=(t,e)=>t.replace(/{(\w+)}/g,(r,o)=>e[o]?.toString()||J[o]?.toString()),Xc=(t,e)=>{const r=e.split("-")[0].toLowerCase(),o={conventional:{en:{subject:"fix(auth): fix bug in user authentication process",body:"- Update login function to handle edge cases\\n- Add additional error logging for debugging"},zh:{subject:"fix(auth): \u4FEE\u590D\u7528\u6237\u8BA4\u8BC1\u8FC7\u7A0B\u4E2D\u7684\u9519\u8BEF",body:"- \u66F4\u65B0\u767B\u5F55\u51FD\u6570\u4EE5\u5904\u7406\u8FB9\u7F18\u60C5\u51B5\\n- \u6DFB\u52A0\u989D\u5916\u7684\u9519\u8BEF\u65E5\u5FD7\u7528\u4E8E\u8C03\u8BD5"},ja:{subject:"fix(auth): \u30E6\u30FC\u30B6\u30FC\u8A8D\u8A3C\u30D7\u30ED\u30BB\u30B9\u306E\u30D0\u30B0\u3092\u4FEE\u6B63",body:"- \u30A8\u30C3\u30B8\u30B1\u30FC\u30B9\u3092\u51E6\u7406\u3059\u308B\u305F\u3081\u306B\u30ED\u30B0\u30A4\u30F3\u6A5F\u80FD\u3092\u66F4\u65B0\\n- \u30C7\u30D0\u30C3\u30B0\u7528\u306E\u8FFD\u52A0\u30A8\u30E9\u30FC\u30ED\u30B0\u3092\u8FFD\u52A0"},ko:{subject:"fix(auth): \uC0AC\uC6A9\uC790 \uC778\uC99D \uD504\uB85C\uC138\uC2A4\uC758 \uBC84\uADF8 \uC218\uC815",body:"- \uC5E3\uC9C0 \uCF00\uC774\uC2A4\uB97C \uCC98\uB9AC\uD558\uB3C4\uB85D \uB85C\uADF8\uC778 \uD568\uC218 \uC5C5\uB370\uC774\uD2B8\\n- \uB514\uBC84\uAE45\uC744 \uC704\uD55C \uCD94\uAC00 \uC624\uB958 \uB85C\uAE45 \uCD94\uAC00"},es:{subject:"fix(auth): corregir error en el proceso de autenticaci\xF3n",body:"- Actualizar funci\xF3n de inicio de sesi\xF3n para manejar casos extremos\\n- Agregar registro de errores adicional para depuraci\xF3n"},fr:{subject:"fix(auth): corriger un bug dans le processus d'authentification",body:"- Mettre \xE0 jour la fonction de connexion pour g\xE9rer les cas limites\\n- Ajouter une journalisation d'erreurs suppl\xE9mentaire pour le d\xE9bogage"},de:{subject:"fix(auth): Fehler im Benutzerauthentifizierungsprozess beheben",body:"- Login-Funktion aktualisiert, um Randf\xE4lle zu behandeln\\n- Zus\xE4tzliche Fehlerprotokollierung f\xFCr Debugging hinzugef\xFCgt"}},gitmoji:{en:{subject:":sparkles: Add real-time chat feature",body:"- Implement WebSocket connection\\n- Add message encryption\\n- Include typing indicators"},zh:{subject:":sparkles: \u6DFB\u52A0\u5B9E\u65F6\u804A\u5929\u529F\u80FD",body:"- \u5B9E\u73B0WebSocket\u8FDE\u63A5\\n- \u6DFB\u52A0\u6D88\u606F\u52A0\u5BC6\\n- \u5305\u542B\u8F93\u5165\u6307\u793A\u5668"},ja:{subject:":sparkles: \u30EA\u30A2\u30EB\u30BF\u30A4\u30E0\u30C1\u30E3\u30C3\u30C8\u6A5F\u80FD\u3092\u8FFD\u52A0",body:"- WebSocket\u63A5\u7D9A\u3092\u5B9F\u88C5\\n- \u30E1\u30C3\u30BB\u30FC\u30B8\u6697\u53F7\u5316\u3092\u8FFD\u52A0\\n- \u5165\u529B\u30A4\u30F3\u30B8\u30B1\u30FC\u30BF\u30FC\u3092\u542B\u3080"},ko:{subject:":sparkles: \uC2E4\uC2DC\uAC04 \uCC44\uD305 \uAE30\uB2A5 \uCD94\uAC00",body:"- WebSocket \uC5F0\uACB0 \uAD6C\uD604\\n- \uBA54\uC2DC\uC9C0 \uC554\uD638\uD654 \uCD94\uAC00\\n- \uC785\uB825 \uD45C\uC2DC\uAE30 \uD3EC\uD568"},es:{subject:":sparkles: Agregar funci\xF3n de chat en tiempo real",body:"- Implementar conexi\xF3n WebSocket\\n- Agregar cifrado de mensajes\\n- Incluir indicadores de escritura"},fr:{subject:":sparkles: Ajouter une fonctionnalit\xE9 de chat en temps r\xE9el",body:"- Impl\xE9menter une connexion WebSocket\\n- Ajouter le chiffrement des messages\\n- Inclure des indicateurs de saisie"},de:{subject:":sparkles: Echtzeit-Chat-Funktion hinzuf\xFCgen",body:"- WebSocket-Verbindung implementieren\\n- Nachrichtenverschl\xFCsselung hinzuf\xFCgen\\n- Tippindikatoren einschlie\xDFen"}},"":{en:{subject:"",body:""}}},s=o[t]||o[""];return s[r]||s.en},$s=t=>{const{type:e,maxLength:r,generate:o,locale:s}=t,n="You are an expert Git commit message writer specializing in analyzing code changes and creating precise, meaningful commit messages.",i=`Your task is to generate exactly ${o} ${e} style commit message${o!==1?"s":""} based on the provided git diff.`;return[n,i,"",["## Requirements:",`1. Language: Write all messages in ${s}`,`2. Format: Strictly follow the ${e} commit format:`,`${qc[e]}`,`3. Allowed Types:${Jc[e]}`,"","## Guidelines:",`- Subject line: Max ${r} characters, imperative mood, no period`,"- Analyze the diff to understand:"," * What files were changed"," * What functionality was added, modified, or removed"," * The scope and impact of changes","- For the commit type, choose based on:"," * feat: New functionality or feature"," * fix: Bug fixes or error corrections"," * refactor: Code restructuring without changing functionality"," * docs: Documentation changes only"," * style: Formatting, missing semi-colons, etc"," * test: Adding or modifying tests"," * chore: Maintenance tasks, dependency updates"," * perf: Performance improvements"," * build: Build system or external dependency changes"," * ci: CI configuration changes","- Scope: Extract from file paths or logical grouping (e.g., auth, api, ui)","- Body (when needed):"," * Explain the motivation for the change"," * Compare previous behavior with new behavior"," * Note any breaking changes or important details","- Footer: Include references to issues, breaking changes if applicable","","## Analysis Approach:","1. Identify the primary purpose of the changes","2. Group related changes together","3. Determine the most appropriate type and scope","4. Write a clear, concise subject line","5. Add body details for complex changes","","Remember: The commit message should help future developers understand WHY this change was made, not just WHAT was changed."].join(`
|
|
36
64
|
`)].filter(Boolean).join(`
|
|
37
|
-
`)},
|
|
65
|
+
`)},kt=(t,e,r)=>{const o=s=>{const n=Xc(s,r);return s==="conventional"||s==="gitmoji"?`${Array(e).fill(null).map((i,a)=>`
|
|
38
66
|
{
|
|
39
|
-
"subject": "${
|
|
40
|
-
"body": "${
|
|
67
|
+
"subject": "${n.subject}",
|
|
68
|
+
"body": "${n.body}",
|
|
41
69
|
"footer": ""
|
|
42
70
|
}`).join(",")}`:""};return[`
|
|
43
71
|
Lastly, Provide your response as a JSON array containing exactly ${e} object${e!==1?"s":""}, each with the following keys:`,`- "subject": The main commit message using the ${t} style. It should be a concise summary of the changes.`,'- "body": An optional detailed explanation of the changes. If not needed, use an empty string.','- "footer": An optional footer for metadata like BREAKING CHANGES. If not needed, use an empty string.',`The array must always contain ${e} element${e!==1?"s":""}, no more and no less.`,`Example response format:
|
|
44
72
|
[${o(t)}
|
|
45
73
|
]`,`Ensure you generate exactly ${e} commit message${e!==1?"s":""}, even if it requires creating slightly varied versions for similar changes.`,"The response should be valid JSON that can be parsed without errors."].filter(Boolean).join(`
|
|
46
|
-
`)},
|
|
47
|
-
${
|
|
48
|
-
${
|
|
49
|
-
${
|
|
50
|
-
${
|
|
74
|
+
`)},oe=t=>{const{systemPrompt:e,systemPromptPath:r,type:o,generate:s,locale:n}=t;if(e)return`${Mr(e,t)}
|
|
75
|
+
${kt(o,s,n)}`;if(!r)return`${$s(t)}
|
|
76
|
+
${kt(o,s,n)}`;try{const i=Z.readFileSync(Ct(r),"utf-8");return`${Mr(i,t)}
|
|
77
|
+
${kt(o,s,n)}`}catch{return`${$s(t)}
|
|
78
|
+
${kt(o,s,n)}`}},se=t=>{const{codeReviewPromptPath:e,locale:r}=t,o=`I'll give you the output of the "git diff" command as an input. Please review the following code and provide your feedback in Markdown format. Focus on:
|
|
51
79
|
|
|
52
80
|
1. Language: ${r}
|
|
53
81
|
2. Code quality and best practices
|
|
@@ -55,7 +83,7 @@ ${Ct(o,n,s)}`}},oe=t=>{const{codeReviewPromptPath:e,locale:r}=t,o=`I'll give you
|
|
|
55
83
|
4. Performance improvements
|
|
56
84
|
5. Readability and maintainability
|
|
57
85
|
|
|
58
|
-
Please structure your response with appropriate Markdown headings, code blocks, and bullet points.`;if(!e)return o;try{const
|
|
86
|
+
Please structure your response with appropriate Markdown headings, code blocks, and bullet points.`;if(!e)return o;try{const s=Z.readFileSync(Ct(e),"utf-8");return`${Mr(s,t)}`}catch{return o}},Ps=async t=>{if(t.systemPromptPath)try{Z.readFileSync(Ct(t.systemPromptPath),"utf-8")}catch(e){throw new v(`Error reading system prompt file: ${t.systemPromptPath}, ${e}`)}if(t.codeReview&&t.codeReviewPromptPath)try{Z.readFileSync(Ct(t.codeReviewPromptPath),"utf-8")}catch(e){throw new v(`Error reading code review prompt file: ${t.codeReviewPromptPath}, ${e}`)}},Ee=(t,e="commit")=>e==="review"?`Please analyze the following diff and provide a comprehensive code review:
|
|
59
87
|
|
|
60
88
|
\`\`\`diff
|
|
61
89
|
${t}
|
|
@@ -67,149 +95,138 @@ Focus on code quality, potential issues, and improvement suggestions.`:`Please a
|
|
|
67
95
|
${t}
|
|
68
96
|
\`\`\`
|
|
69
97
|
|
|
70
|
-
Focus on understanding the purpose and impact of these changes to create meaningful commit message(s).`,sc=10*60*1e3;class ic extends te{constructor(e){super(e),this.params=e,this.colors={primary:"#AE5630",secondary:"#fff"},this.serviceName=C.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[Anthropic]"),this.errorPrefix=C.red.bold("[Anthropic]"),this.anthropic=new Kn({apiKey:this.params.config.key,...this.params.config.timeout>sc&&{timeout:this.params.config.timeout}})}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("API key")||r.includes("api_key")?"Invalid API key. Check your Anthropic API key in configuration":r.includes("quota")||r.includes("usage")?"API quota exceeded. Check your Anthropic usage limits":r.includes("model_not_found")||r.includes("Model not found")||/model.*does not exist/i.test(r)?"Model not found or not accessible. Check if the Claude model name is correct":r.includes("403")||r.includes("Forbidden")?"Access denied. Your API key may not have permission for this Claude model":r.includes("404")||r.includes("Not Found")?"Model or endpoint not found. Check your Claude model configuration":r.includes("500")||r.includes("Internal Server Error")?"Anthropic server error. Try again later":null}generateCommitMessage$(){return L(this.generateMessage("commit")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),N(this.handleError$))}generateCodeReview$(){return L(this.generateMessage("review")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),N(this.handleError$))}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,logging:i,temperature:l,locale:a,generate:d,type:c,maxLength:u,maxTokens:f,topP:p,model:h}=this.params.config,g={...J,locale:a,maxLength:u,type:c,generate:d,systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,vcs_branch:this.params.branchName||""},y=e==="review"?oe(g):re(g),v=Ce(r,e),b=`${this.params.config.url||"https://api.anthropic.com"}/v1/messages`,k={"Content-Type":"application/json","x-api-key":this.params.config.key,"anthropic-version":"2023-06-01"};Z(r,e,"Anthropic",h,b,k,i),ee(r,e,"Anthropic",y,v,i);const P=tc(h),$={max_tokens:f,temperature:l,system:y,messages:[{role:"user",content:v}],model:h,...P?{}:{top_p:p}};se(r,e,"Anthropic",$,i);const M=Date.now();try{const A=await this.anthropic.messages.create($),G=Date.now()-M;W(r,e,"Anthropic",A,i);const R=A.content.map(({text:fe})=>fe).join("");return Y(r,e,"Anthropic",G,R,i),e==="review"?this.sanitizeResponse(R):this.parseMessage(R,c,d)}catch(A){throw j(r,e,"Anthropic",A,i),A}}}const ie="Bedrock",he={MISSING_DEPENDENCY:"MissingDependencyError",MISSING_REGION:"MissingRegionError",MISSING_MODEL_ID:"MissingModelIdError",MISSING_API_KEY:"MissingApiKeyError",MISSING_APPLICATION_KEY:"MissingApplicationKeyError",INVALID_RESPONSE:"InvalidResponseError",EMPTY_RESPONSE:"EmptyResponseError"},K=t=>typeof t=="string"&&t.length>0;let ze=null,Ke=null;const an=t=>{const e=new Error('Amazon Bedrock support requires "@aws-sdk/client-bedrock-runtime" and "@aws-sdk/credential-providers". Install them with `pnpm add @aws-sdk/client-bedrock-runtime @aws-sdk/credential-providers`.');return e.name=he.MISSING_DEPENDENCY,e.originalError=t,e},ac=async()=>{if(ze)return ze;try{return ze=await import("@aws-sdk/client-bedrock-runtime"),ze}catch(t){throw ze=null,an(t)}},cn=async()=>{if(Ke)return Ke;try{return Ke=await import("@aws-sdk/credential-providers"),Ke}catch(t){throw Ke=null,an(t)}};class cc extends te{constructor(e){super(e),this.params=e,this.credentialCache=void 0,this.credentialCacheTimestamp=0,this.CREDENTIAL_CACHE_TTL=5*60*1e3,this.bedrockConfig=this.params.config,this.colors={primary:"#232F3E",secondary:"#FF9900"},this.serviceName=C.bgHex(this.colors.primary).hex(this.colors.secondary).bold(`[${ie}]`),this.errorPrefix=C.red.bold(`[${ie}]`),this.validateConfiguration()}validateConfiguration(){const e=this.bedrockConfig;if(!K(e.model)){const n=new Error("Model ID or inference profile ARN is required.");throw n.name=he.MISSING_MODEL_ID,n}if(!this.getRegion()){const n=new Error("AWS region is required. Configure BEDROCK.region or set AWS_REGION/AWS_DEFAULT_REGION.");throw n.name=he.MISSING_REGION,n}const r=K(e.key),o=this.canUseAwsSdk();if(!r&&!o){const n=new Error("Authentication required: Configure AWS credentials (profile, access keys, IAM role) or API key (BEDROCK.key).");throw n.name=he.MISSING_API_KEY,n}if(r&&!o&&!this.getRegion()&&!K(e.applicationBaseUrl)){const n=new Error("Bearer token authentication requires region or applicationBaseUrl to construct endpoint.");throw n.name=he.MISSING_REGION,n}}canUseAwsSdk(){const e=this.bedrockConfig,r=K(e.profile)||K(process.env.AWS_PROFILE),o=K(e.accessKeyId)&&K(e.secretAccessKey)||K(process.env.AWS_ACCESS_KEY_ID)&&K(process.env.AWS_SECRET_ACCESS_KEY);return r||o}determineAuthMethod(){const e=K(this.bedrockConfig.key);if(this.canUseAwsSdk())return"aws-sdk";if(e)return"bearer-token";throw new Error("No authentication method configured")}getServiceSpecificErrorMessage(e){const r=e?.name||e.code,o=e.message||"";switch(r){case"UnrecognizedClientException":case"InvalidSignatureException":return"Authentication with AWS failed. Check your IAM credentials or Bedrock API key settings.";case"AccessDeniedException":return"Access denied. Ensure the IAM principal or application key has permission to invoke the Bedrock resource.";case"ValidationException":return"Invalid request for the selected Bedrock model. Verify the model ID and payload.";case"ResourceNotFoundException":return"The specified Bedrock model, endpoint, or inference profile could not be found.";case"ThrottlingException":return"Request throttled by Bedrock. Reduce request rate or check service quotas."}return o.includes("Region")?"AWS region is required for Bedrock. Configure BEDROCK.region or set AWS_REGION/AWS_DEFAULT_REGION.":null}generateCommitMessage$(){return L(this.generateMessage("commit")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),N(this.handleError$))}generateCodeReview$(){return L(this.generateMessage("review")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),N(this.handleError$))}async generateMessage(e){const r=this.params.stagedDiff.diff,o=this.bedrockConfig,n=o.model,{logging:s,inferenceParameters:i}=o,l={...J,locale:o.locale,maxLength:o.maxLength,type:o.type,generate:o.generate,systemPrompt:o.systemPrompt,systemPromptPath:o.systemPromptPath,codeReviewPromptPath:o.codeReviewPromptPath},a=e==="review"?oe(l):re(l),d=Ce(r,e),c={region:this.getRegion(),profile:o.profile,modelId:n},u=`https://bedrock-runtime.${this.getRegion()||"unknown"}.amazonaws.com/model/${encodeURIComponent(n)}/converse`;Z(r,e,ie,n,u,c,s),ee(r,e,ie,a,d,s);const f={modelId:n,systemPrompt:a,userPrompt:d,...i&&Object.keys(i).length>0&&{inferenceConfig:i}};se(r,e,ie,f,s);const p=Date.now();try{const h=this.determineAuthMethod();vt()&&(console.log(C.cyan(`[Bedrock] Authentication method: ${h}`)),console.log(C.cyan(`[Bedrock] Model ID: ${n}`)),console.log(C.cyan(`[Bedrock] Region: ${this.getRegion()}`)),console.log(C.cyan(`[Bedrock] Has AWS credentials: ${this.canUseAwsSdk()}`)),console.log(C.cyan(`[Bedrock] Has API key: ${K(o.key)}`)));const g=h==="bearer-token"?await this.invokeWithBearerToken({model:n,systemPrompt:a,userPrompt:d,logging:s,requestType:e,diff:r,inferenceConfig:i}):await this.invokeWithAwsSdk({model:n,systemPrompt:a,userPrompt:d,logging:s,requestType:e,diff:r,inferenceConfig:i}),y=Date.now()-p;return Y(r,e,ie,y,g,s),e==="review"?this.sanitizeResponse(g):this.parseMessage(g,o.type,o.generate)}catch(h){throw j(r,e,ie,h,s),h instanceof Error&&(h.status=h?.status||h?.$metadata?.httpStatusCode),h}}async invokeWithAwsSdk(e){const r=this.getRegion(),{model:o,systemPrompt:n,userPrompt:s,inferenceConfig:i,logging:l,requestType:a,diff:d}=e,{BedrockRuntimeClient:c,ConverseCommand:u}=await ac(),f=this.bedrockConfig,p={region:r,requestHandler:{requestTimeout:f.timeout||12e4}},h=await this.resolveCredentials();h&&(p.credentials=h);const g=new c(p),y=new u({modelId:o,messages:[{role:"user",content:[{text:s}]}],...n?{system:[{text:n}]}:{},...i&&Object.keys(i).length>0&&{inferenceConfig:i}});vt()&&console.log(C.cyan(`[Bedrock] Sending ConverseCommand with modelId: ${o}`));let v;try{v=await g.send(y),W(d,a,ie,v,l)}catch(b){throw vt()&&(console.error(C.red(`[Bedrock] AWS SDK Error: ${b.name}`)),console.error(C.red(`[Bedrock] Error message: ${b.message}`)),b.$metadata&&(console.error(C.red(`[Bedrock] Request ID: ${b.$metadata.requestId}`)),console.error(C.red(`[Bedrock] HTTP Status: ${b.$metadata.httpStatusCode}`))),b.$fault&&console.error(C.red(`[Bedrock] Fault: ${b.$fault}`))),b}const E=v.output?.message?.content?.[0]?.text||"";if(!E){const b=new Error("No text content found in Bedrock response.");throw b.name=he.EMPTY_RESPONSE,b.content=v,b}return E}invokeWithBearerToken(e){const{model:r,systemPrompt:o,userPrompt:n,inferenceConfig:s,logging:i,requestType:l,diff:a}=e,d=this.bedrockConfig,c=this.getRegion(),u=encodeURIComponent(r),f=d.applicationBaseUrl||`https://bedrock-runtime.${c}.amazonaws.com/model/${u}/converse`,p=new URL(f),h={modelId:r,messages:[{role:"user",content:[{text:n}]}],...s&&Object.keys(s).length>0&&{inferenceConfig:s}};o&&(h.system=[{text:o}]);const g=JSON.stringify(h),y={"Content-Type":"application/json","Content-Length":Buffer.byteLength(g).toString()};return K(d.key)&&(y.Authorization=`Bearer ${d.key}`),K(d.applicationInferenceProfileArn)&&(y["x-amzn-bedrock-inference-profile-arn"]=d.applicationInferenceProfileArn),K(d.applicationEndpointId)&&(y["x-amzn-bedrock-endpoint-id"]=d.applicationEndpointId),new Promise((v,E)=>{const b=Vr.request({method:"POST",protocol:p.protocol,hostname:p.hostname,port:p.port,path:p.pathname+p.search,headers:y,timeout:d.timeout},k=>{const P=[];k.on("data",$=>P.push($)),k.on("end",()=>{const $=Buffer.concat(P).toString("utf8");if(k.statusCode&&k.statusCode>=400){const R=new Error(`Bedrock application endpoint responded with status ${k.statusCode}.`);return R.status=k.statusCode,R.content=$,j(a,l,ie,R,i),E(R)}const M=Qo($);if(!M.ok){const R=new Error("Failed to parse Bedrock application response as JSON. The Bedrock Converse API should always return valid JSON.");return R.name=he.INVALID_RESPONSE,R.content=$,j(a,l,ie,R,i),E(R)}const A=M.data;W(a,l,ie,A,i);const G=A.output?.message?.content?.[0]?.text||"";if(!G){const R=new Error("No text content found in Bedrock response.");return R.name=he.EMPTY_RESPONSE,R.content=A,j(a,l,ie,R,i),E(R)}v(G)})});b.on("error",k=>{const P=k;j(a,l,ie,P,i),E(P)}),b.write(g),b.end()})}getRegion(){return this.bedrockConfig.region||process.env.AWS_REGION||process.env.AWS_DEFAULT_REGION||""}async resolveCredentials(){const e=Date.now();if(this.credentialCache&&e-this.credentialCacheTimestamp<this.CREDENTIAL_CACHE_TTL)return this.credentialCache;const r=this.bedrockConfig,o=r.profile,n=r.accessKeyId,s=r.secretAccessKey,i=r.sessionToken;let l;if(K(o)){const{fromIni:a}=await cn();l=a({profile:o})}else if(K(n)&&K(s))l=async()=>({accessKeyId:n,secretAccessKey:s,sessionToken:i||process.env.AWS_SESSION_TOKEN||void 0});else if(process.env.AWS_PROFILE){const{fromIni:a}=await cn();l=a({profile:process.env.AWS_PROFILE})}return l&&(this.credentialCache=l,this.credentialCacheTimestamp=e),l}}class We{constructor(e={}){if(!e.method)throw new Error("method should be defined!");if(!e.baseURL)throw new Error("baseURL should be defined!");this.config={...e},this.axiosInstance=Wn.create(this.config)}setHeaders(e){return this.config.headers=e,this}setParams(e){return this.config.params=e,this}setBody(e){return this.config.data=e,this}addBody(e){return this.config.data={...this.config.data,...e},this}setMethod(e){return this.config.method=e,this}async execute(){try{return await this.axiosInstance.request(this.config)}catch(e){throw e}}}class lc extends te{constructor(e){super(e),this.params=e,this.apiKey="",this.colors={primary:"#e28c58",secondary:"#fff"},this.serviceName=C.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[Codestral]"),this.errorPrefix=C.red.bold("[Codestral]"),this.apiKey=this.params.config.key}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("API key")||r.includes("api_key")?"Invalid API key. Check your Codestral API key in configuration":r.includes("rate_limit")||r.includes("Rate limit")?"Rate limit exceeded. Wait a moment and try again, or upgrade your Codestral plan":r.includes("model")||r.includes("Model")?"Model not found or not accessible. Check if the Codestral model name is correct":r.includes("Invalid model type")?"Invalid model type. Use supported models: codestral-latest, codestral-2501":r.includes("overloaded")||r.includes("capacity")?"Codestral service is overloaded. Try again in a few minutes":r.includes("403")||r.includes("Forbidden")?"Access denied. Your API key may not have permission for this Codestral model":r.includes("404")||r.includes("Not Found")?"Model or endpoint not found. Check your Codestral model configuration":r.includes("500")||r.includes("Internal Server Error")?"Codestral server error. Try again later":null}generateCommitMessage$(){return L(this.generateMessage("commit")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),N(this.handleError$))}generateCodeReview$(){return L(this.generateMessage("review")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),N(this.handleError$))}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,logging:i,locale:l,generate:a,type:d,maxLength:c}=this.params.config,u={...J,locale:l,maxLength:c,type:d,generate:a,systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,vcs_branch:this.params.branchName||""},f=e==="review"?oe(u):re(u);this.checkAvailableModels();const p=Ce(r,e),g=`${this.params.config.url||"https://codestral.mistral.ai"}/v1/chat/completions`,y={Authorization:`Bearer ${this.apiKey}`,"content-type":"application/json"};Z(r,e,"Codestral",this.params.config.model,g,y,i),ee(r,e,"Codestral",f,p,i);const v=await this.createChatCompletions(f,e);return e==="review"?this.sanitizeResponse(v):this.parseMessage(v,d,a)}checkAvailableModels(){if(["codestral-latest","codestral-2501"].includes(this.params.config.model))return!0;throw new Error("Invalid model type of Codestral AI")}async createChatCompletions(e,r){const o=this.params.stagedDiff.diff,{logging:n}=this.params.config,s=this.params.config.url||"https://codestral.mistral.ai",i={model:this.params.config.model,messages:[{role:"system",content:e},{role:"user",content:Ce(this.params.stagedDiff.diff,r)}],temperature:this.params.config.temperature,top_p:this.params.config.topP,max_tokens:this.params.config.maxTokens,stream:!1,safe_prompt:!1,random_seed:pt(10,1e3)};r==="commit"&&(i.response_format={type:"json_object"}),se(o,r,"Codestral",i,n);const l=Date.now();try{const d=await new We({method:"POST",baseURL:`${s}/v1/chat/completions`,timeout:this.params.config.timeout}).setHeaders({Authorization:`Bearer ${this.apiKey}`,"content-type":"application/json"}).setBody(i).execute(),c=Date.now()-l,u=d.data;if(W(o,r,"Codestral",u,n),!u.choices||u.choices.length===0||!u.choices[0].message?.content)throw j(o,r,"Codestral",{message:"No Content on response",result:u},n),new Error("No Content on response. Please open a Bug report");const p=u.choices[0].message.content;return Y(o,r,"Codestral",c,p,n),p}catch(a){throw j(o,r,"Codestral",a,n),a}}}class uc extends te{constructor(e){super(e),this.params=e,this.colors={primary:"#D18EE2",secondary:"#fff"},this.serviceName=C.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[Cohere]"),this.errorPrefix=C.red.bold("[Cohere]"),this.cohere=new Yn({token:this.params.config.key})}isValidCohereV2Response(e){const r=e;return r?.message?.content!==void 0&&Array.isArray(r.message.content)&&r.message.content.length>0&&typeof r.message.content[0]?.text=="string"}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("API key")||r.includes("api_key")?"Invalid API key. Check your Cohere API key in configuration":r.includes("rate_limit")||r.includes("Rate limit")?"Rate limit exceeded. Wait a moment and try again, or upgrade your Cohere plan":r.includes("model")||r.includes("Model")?"Model not found or not accessible. Check if the Cohere model name is correct":r.includes("overloaded")||r.includes("capacity")?"Cohere service is overloaded. Try again in a few minutes":r.includes("403")||r.includes("Forbidden")?"Access denied. Your API key may not have permission for this Cohere model":r.includes("404")||r.includes("Not Found")?"Model or endpoint not found. Check your Cohere model configuration":r.includes("500")||r.includes("Internal Server Error")?"Cohere server error. Try again later":null}generateCommitMessage$(){return L(this.generateMessage("commit")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),N(this.handleError$))}generateCodeReview$(){return L(this.generateMessage("review")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),N(this.handleError$))}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,logging:i,temperature:l,locale:a,generate:d,type:c,maxLength:u,maxTokens:f}=this.params.config,p={...J,locale:a,maxLength:u,type:c,generate:d,systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,vcs_branch:this.params.branchName||""},h=e==="review"?oe(p):re(p),g=`Here is the diff: ${r}`,y=[...h?[{role:"system",content:h}]:[],{role:"user",content:g}],E=`${this.params.config.url}/v2/chat`;Z(r,e,"Cohere",this.params.config.model,E,{},i),ee(r,e,"Cohere",h,g,i);const b={model:this.params.config.model,messages:y,max_tokens:f,temperature:l,seed:pt(10,1e3),p:this.params.config.topP};se(r,e,"Cohere",b,i);const k=Date.now();try{const P=await this.cohere.chat(b,{timeoutInSeconds:Math.floor(this.params.config.timeout/1e3)}),$=Date.now()-k;if(!this.isValidCohereV2Response(P))throw new Error("Invalid response structure from Cohere v2 API");const M=P.message.content[0].text;return W(r,e,"Cohere",P,i),Y(r,e,"Cohere",$,M,i),e==="review"?this.sanitizeResponse(M):this.parseMessage(M,c,d)}catch(P){throw j(r,e,"Cohere",P,i),P}}}class dc extends te{constructor(e){super(e),this.params=e,this.colors={primary:"#53a3f9",secondary:"#fff"},this.serviceName=C.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[DeepSeek]"),this.errorPrefix=C.red.bold("[DeepSeek]");const r=this.params.config.url||"https://api.deepseek.com";this.deepSeek=new qr({baseURL:r,apiKey:this.params.config.key})}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("API key")||r.includes("api_key")?"Invalid API key. Check your DeepSeek API key in configuration":r.includes("rate_limit")||r.includes("Rate limit")?"Rate limit exceeded. Wait a moment and try again, or upgrade your DeepSeek plan":r.includes("model")||r.includes("Model")?"Model not found or not accessible. Check if the DeepSeek model name is correct":r.includes("Invalid model type")?"Invalid model type. Use supported models: deepseek-reasoner, deepseek-chat":r.includes("overloaded")||r.includes("capacity")?"DeepSeek service is overloaded. Try again in a few minutes":r.includes("403")||r.includes("Forbidden")?"Access denied. Your API key may not have permission for this DeepSeek model":r.includes("404")||r.includes("Not Found")?"Model or endpoint not found. Check your DeepSeek model configuration":r.includes("500")||r.includes("Internal Server Error")?"DeepSeek server error. Try again later":null}generateCommitMessage$(){return L(this.generateMessage("commit")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),N(this.handleError$))}generateCodeReview$(){return L(this.generateMessage("review")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),N(this.handleError$))}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,logging:i,locale:l,generate:a,type:d,maxLength:c}=this.params.config,u={...J,locale:l,maxLength:c,type:d,generate:a,systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,vcs_branch:this.params.branchName||""},f=e==="review"?oe(u):re(u);this.checkAvailableModels();const p=Ce(r,e),g=`${this.params.config.url||"https://api.deepseek.com"}/chat/completions`,y={Authorization:`Bearer ${this.params.config.key}`,"Content-Type":"application/json"};Z(r,e,"DeepSeek",this.params.config.model,g,y,i),ee(r,e,"DeepSeek",f,p,i);const v=await this.createChatCompletions(f,p,e);return e==="review"?this.sanitizeResponse(v):this.parseMessage(v,d,a)}checkAvailableModels(){if(["deepseek-reasoner","deepseek-chat"].includes(this.params.config.model))return!0;throw new Error("Invalid model type of DeepSeek")}async createChatCompletions(e,r,o){const n=this.params.stagedDiff.diff,{logging:s}=this.params.config,i={messages:[{role:"system",content:e},{role:"user",content:r}],model:this.params.config.model,max_tokens:this.params.config.maxTokens,top_p:this.params.config.topP,temperature:this.params.config.temperature};se(n,o,"DeepSeek",i,s);const l=Date.now();try{const a=await this.deepSeek.chat.completions.create(i,{timeout:this.params.config.timeout}),d=Date.now()-l,c=a.choices?.[0];if(!c?.message)throw new Error("DeepSeek API returned invalid response structure");const u=c.message.content||c.message.reasoning_content||"";if(!u)throw new Error("DeepSeek API returned empty response");return W(n,o,"DeepSeek",a,s),Y(n,o,"DeepSeek",d,u,s),u}catch(a){throw j(n,o,"DeepSeek",a,s),a}}}class mc extends te{constructor(e){super(e),this.params=e,this.colors={primary:"#0077FF",secondary:"#fff"},this.serviceName=C.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[Gemini]"),this.errorPrefix=C.red.bold("[Gemini]"),this.genAI=new Jn(this.params.config.key)}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("API key")||r.includes("api_key")?"Invalid API key. Check your Google AI Studio API key in configuration":r.includes("quota")||r.includes("QUOTA_EXCEEDED")?"API quota exceeded. Check your Google AI Studio usage limits":r.includes("model")||r.includes("Model")?"Model not found or not accessible. Check if the Gemini model name is correct":r.includes("SAFETY")||r.includes("safety")?"Content blocked by safety filters. Try rephrasing your request":r.includes("RECITATION")||r.includes("recitation")?"Content blocked due to recitation concerns. Try a different approach":r.includes("403")||r.includes("Forbidden")?"Access denied. Your API key may not have permission for this Gemini model":r.includes("404")||r.includes("Not Found")?"Model or endpoint not found. Check your Gemini model configuration":r.includes("500")||r.includes("Internal Server Error")?"Google AI service error. Try again later":r.includes("MAX_TOKENS")||r.includes("truncated")||r.includes("maxOutputTokens")?"Response truncated due to token limit. Gemini 2.5+ models use thinking tokens. Try increasing maxTokens (recommended: 8192+)":null}generateCommitMessage$(){return L(this.generateMessage("commit")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),N(this.handleError$))}generateCodeReview$(){return L(this.generateMessage("review")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),N(this.handleError$))}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:n,logging:s,locale:i,codeReviewPromptPath:l,generate:a,type:d,maxLength:c}=this.params.config,u=this.params.config.maxTokens,f={...J,locale:i,maxLength:c,type:d,generate:a,systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:l,vcs_branch:this.params.branchName||""},p=e==="review"?oe(f):re(f),h={maxOutputTokens:u,temperature:this.params.config.temperature,topP:this.params.config.topP},g=this.genAI.getGenerativeModel({model:this.params.config.model,systemInstruction:p,generationConfig:h,safetySettings:[{category:tt.HARM_CATEGORY_HATE_SPEECH,threshold:rt.BLOCK_LOW_AND_ABOVE},{category:tt.HARM_CATEGORY_SEXUALLY_EXPLICIT,threshold:rt.BLOCK_LOW_AND_ABOVE},{category:tt.HARM_CATEGORY_HARASSMENT,threshold:rt.BLOCK_LOW_AND_ABOVE},{category:tt.HARM_CATEGORY_DANGEROUS_CONTENT,threshold:rt.BLOCK_LOW_AND_ABOVE}]}),y=Ce(r,e),E=`${this.params.config.url||"https://generativelanguage.googleapis.com"}/v1beta/models/${this.params.config.model}:generateContent`,b={"Content-Type":"application/json","x-goog-api-key":this.params.config.key};Z(r,e,"Gemini",this.params.config.model,E,b,s),ee(r,e,"Gemini",p,y,s),se(r,e,"Gemini",{systemInstruction:{parts:[{text:p}]},contents:[{parts:[{text:y}]}],generationConfig:h},s);const P=Date.now();try{const $=this.params.config.timeout>1e4?{request:{timeout:this.params.config.timeout}}:void 0,M=await g.generateContent(y,$),A=M.response;if(A.candidates?.[0]?.finishReason==="MAX_TOKENS"){const q=A.usageMetadata;throw new Error(`Response truncated: maxOutputTokens exceeded. Thinking tokens: ${q?.thoughtsTokenCount??"N/A"}, Output tokens: ${q?.candidatesTokenCount??"N/A"}. Increase maxTokens config for Gemini 2.5+ thinking models.`)}const R=A.text(),fe=Date.now()-P;return W(r,e,"Gemini",{response:R,candidates:M.response.candidates,usageMetadata:M.response.usageMetadata},s),Y(r,e,"Gemini",fe,R,s),e==="review"?this.sanitizeResponse(R):this.parseMessage(R,d,a)}catch($){throw j(r,e,"Gemini",$,s),$}}}var pr={},hr={exports:{}},Ye={exports:{}},gr,ln;function fc(){if(ln)return gr;ln=1;var t=1e3,e=t*60,r=e*60,o=r*24,n=o*7,s=o*365.25;gr=function(c,u){u=u||{};var f=typeof c;if(f==="string"&&c.length>0)return i(c);if(f==="number"&&isFinite(c))return u.long?a(c):l(c);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(c))};function i(c){if(c=String(c),!(c.length>100)){var u=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(c);if(u){var f=parseFloat(u[1]),p=(u[2]||"ms").toLowerCase();switch(p){case"years":case"year":case"yrs":case"yr":case"y":return f*s;case"weeks":case"week":case"w":return f*n;case"days":case"day":case"d":return f*o;case"hours":case"hour":case"hrs":case"hr":case"h":return f*r;case"minutes":case"minute":case"mins":case"min":case"m":return f*e;case"seconds":case"second":case"secs":case"sec":case"s":return f*t;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return f;default:return}}}}function l(c){var u=Math.abs(c);return u>=o?Math.round(c/o)+"d":u>=r?Math.round(c/r)+"h":u>=e?Math.round(c/e)+"m":u>=t?Math.round(c/t)+"s":c+"ms"}function a(c){var u=Math.abs(c);return u>=o?d(c,u,o,"day"):u>=r?d(c,u,r,"hour"):u>=e?d(c,u,e,"minute"):u>=t?d(c,u,t,"second"):c+" ms"}function d(c,u,f,p){var h=u>=f*1.5;return Math.round(c/f)+" "+p+(h?"s":"")}return gr}var yr,un;function dn(){if(un)return yr;un=1;function t(e){o.debug=o,o.default=o,o.coerce=d,o.disable=l,o.enable=s,o.enabled=a,o.humanize=fc(),o.destroy=c,Object.keys(e).forEach(u=>{o[u]=e[u]}),o.names=[],o.skips=[],o.formatters={};function r(u){let f=0;for(let p=0;p<u.length;p++)f=(f<<5)-f+u.charCodeAt(p),f|=0;return o.colors[Math.abs(f)%o.colors.length]}o.selectColor=r;function o(u){let f,p=null,h,g;function y(...v){if(!y.enabled)return;const E=y,b=Number(new Date),k=b-(f||b);E.diff=k,E.prev=f,E.curr=b,f=b,v[0]=o.coerce(v[0]),typeof v[0]!="string"&&v.unshift("%O");let P=0;v[0]=v[0].replace(/%([a-zA-Z%])/g,(M,A)=>{if(M==="%%")return"%";P++;const G=o.formatters[A];if(typeof G=="function"){const R=v[P];M=G.call(E,R),v.splice(P,1),P--}return M}),o.formatArgs.call(E,v),(E.log||o.log).apply(E,v)}return y.namespace=u,y.useColors=o.useColors(),y.color=o.selectColor(u),y.extend=n,y.destroy=o.destroy,Object.defineProperty(y,"enabled",{enumerable:!0,configurable:!1,get:()=>p!==null?p:(h!==o.namespaces&&(h=o.namespaces,g=o.enabled(u)),g),set:v=>{p=v}}),typeof o.init=="function"&&o.init(y),y}function n(u,f){const p=o(this.namespace+(typeof f>"u"?":":f)+u);return p.log=this.log,p}function s(u){o.save(u),o.namespaces=u,o.names=[],o.skips=[];const f=(typeof u=="string"?u:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const p of f)p[0]==="-"?o.skips.push(p.slice(1)):o.names.push(p)}function i(u,f){let p=0,h=0,g=-1,y=0;for(;p<u.length;)if(h<f.length&&(f[h]===u[p]||f[h]==="*"))f[h]==="*"?(g=h,y=p,h++):(p++,h++);else if(g!==-1)h=g+1,y++,p=y;else return!1;for(;h<f.length&&f[h]==="*";)h++;return h===f.length}function l(){const u=[...o.names,...o.skips.map(f=>"-"+f)].join(",");return o.enable(""),u}function a(u){for(const f of o.skips)if(i(u,f))return!1;for(const f of o.names)if(i(u,f))return!0;return!1}function d(u){return u instanceof Error?u.stack||u.message:u}function c(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return o.enable(o.load()),o}return yr=t,yr}Ye.exports;var mn;function pc(){return mn||(mn=1,function(t,e){e.formatArgs=o,e.save=n,e.load=s,e.useColors=r,e.storage=i(),e.destroy=(()=>{let a=!1;return()=>{a||(a=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),e.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function r(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let a;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(a=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(a[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function o(a){if(a[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+a[0]+(this.useColors?"%c ":" ")+"+"+t.exports.humanize(this.diff),!this.useColors)return;const d="color: "+this.color;a.splice(1,0,d,"color: inherit");let c=0,u=0;a[0].replace(/%[a-zA-Z%]/g,f=>{f!=="%%"&&(c++,f==="%c"&&(u=c))}),a.splice(u,0,d)}e.log=console.debug||console.log||(()=>{});function n(a){try{a?e.storage.setItem("debug",a):e.storage.removeItem("debug")}catch{}}function s(){let a;try{a=e.storage.getItem("debug")||e.storage.getItem("DEBUG")}catch{}return!a&&typeof process<"u"&&"env"in process&&(a=process.env.DEBUG),a}function i(){try{return localStorage}catch{}}t.exports=dn()(e);const{formatters:l}=t.exports;l.j=function(a){try{return JSON.stringify(a)}catch(d){return"[UnexpectedJSONParseError]: "+d.message}}}(Ye,Ye.exports)),Ye.exports}var Je={exports:{}},wr,fn;function hc(){return fn||(fn=1,wr=(t,e=process.argv)=>{const r=t.startsWith("-")?"":t.length===1?"-":"--",o=e.indexOf(r+t),n=e.indexOf("--");return o!==-1&&(n===-1||o<n)}),wr}var vr,pn;function gc(){if(pn)return vr;pn=1;const t=Fe,e=Xr,r=hc(),{env:o}=process;let n;r("no-color")||r("no-colors")||r("color=false")||r("color=never")?n=0:(r("color")||r("colors")||r("color=true")||r("color=always"))&&(n=1),"FORCE_COLOR"in o&&(o.FORCE_COLOR==="true"?n=1:o.FORCE_COLOR==="false"?n=0:n=o.FORCE_COLOR.length===0?1:Math.min(parseInt(o.FORCE_COLOR,10),3));function s(a){return a===0?!1:{level:a,hasBasic:!0,has256:a>=2,has16m:a>=3}}function i(a,d){if(n===0)return 0;if(r("color=16m")||r("color=full")||r("color=truecolor"))return 3;if(r("color=256"))return 2;if(a&&!d&&n===void 0)return 0;const c=n||0;if(o.TERM==="dumb")return c;if(process.platform==="win32"){const u=t.release().split(".");return Number(u[0])>=10&&Number(u[2])>=10586?Number(u[2])>=14931?3:2:1}if("CI"in o)return["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","GITHUB_ACTIONS","BUILDKITE"].some(u=>u in o)||o.CI_NAME==="codeship"?1:c;if("TEAMCITY_VERSION"in o)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(o.TEAMCITY_VERSION)?1:0;if(o.COLORTERM==="truecolor")return 3;if("TERM_PROGRAM"in o){const u=parseInt((o.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(o.TERM_PROGRAM){case"iTerm.app":return u>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(o.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(o.TERM)||"COLORTERM"in o?1:c}function l(a){const d=i(a,a&&a.isTTY);return s(d)}return vr={supportsColor:l,stdout:s(i(!0,e.isatty(1))),stderr:s(i(!0,e.isatty(2)))},vr}Je.exports;var hn;function yc(){return hn||(hn=1,function(t,e){const r=Xr,o=zr;e.init=c,e.log=l,e.formatArgs=s,e.save=a,e.load=d,e.useColors=n,e.destroy=o.deprecate(()=>{},"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."),e.colors=[6,2,3,4,5,1];try{const f=gc();f&&(f.stderr||f).level>=2&&(e.colors=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221])}catch{}e.inspectOpts=Object.keys(process.env).filter(f=>/^debug_/i.test(f)).reduce((f,p)=>{const h=p.substring(6).toLowerCase().replace(/_([a-z])/g,(y,v)=>v.toUpperCase());let g=process.env[p];return/^(yes|on|true|enabled)$/i.test(g)?g=!0:/^(no|off|false|disabled)$/i.test(g)?g=!1:g==="null"?g=null:g=Number(g),f[h]=g,f},{});function n(){return"colors"in e.inspectOpts?!!e.inspectOpts.colors:r.isatty(process.stderr.fd)}function s(f){const{namespace:p,useColors:h}=this;if(h){const g=this.color,y="\x1B[3"+(g<8?g:"8;5;"+g),v=` ${y};1m${p} \x1B[0m`;f[0]=v+f[0].split(`
|
|
71
|
-
`).join(`
|
|
72
|
-
`+v),f.push(y+"m+"+t.exports.humanize(this.diff)+"\x1B[0m")}else f[0]=i()+p+" "+f[0]}function i(){return e.inspectOpts.hideDate?"":new Date().toISOString()+" "}function l(...f){return process.stderr.write(o.formatWithOptions(e.inspectOpts,...f)+`
|
|
73
|
-
`)}function a(f){f?process.env.DEBUG=f:delete process.env.DEBUG}function d(){return process.env.DEBUG}function c(f){f.inspectOpts={};const p=Object.keys(e.inspectOpts);for(let h=0;h<p.length;h++)f.inspectOpts[p[h]]=e.inspectOpts[p[h]]}t.exports=dn()(e);const{formatters:u}=t.exports;u.o=function(f){return this.inspectOpts.colors=this.useColors,o.inspect(f,this.inspectOpts).split(`
|
|
74
|
-
`).map(p=>p.trim()).join(" ")},u.O=function(f){return this.inspectOpts.colors=this.useColors,o.inspect(f,this.inspectOpts)}}(Je,Je.exports)),Je.exports}typeof process>"u"||process.type==="renderer"||process.browser===!0||process.__nwjs?hr.exports=pc():hr.exports=yc();var Cr=hr.exports,br={};Object.defineProperty(br,"__esModule",{value:!0});function wc(t){return function(e,r){return new Promise((o,n)=>{t.call(this,e,r,(s,i)=>{s?n(s):o(i)})})}}br.default=wc;var gn=H&&H.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};const vc=Ur,Cc=gn(Cr),bc=gn(br),Ve=Cc.default("agent-base");function Ec(t){return!!t&&typeof t.addRequest=="function"}function Er(){const{stack:t}=new Error;return typeof t!="string"?!1:t.split(`
|
|
75
|
-
`).some(e=>e.indexOf("(https.js:")!==-1||e.indexOf("node:https:")!==-1)}function bt(t,e){return new bt.Agent(t,e)}(function(t){class e extends vc.EventEmitter{constructor(o,n){super();let s=n;typeof o=="function"?this.callback=o:o&&(s=o),this.timeout=null,s&&typeof s.timeout=="number"&&(this.timeout=s.timeout),this.maxFreeSockets=1,this.maxSockets=1,this.maxTotalSockets=1/0,this.sockets={},this.freeSockets={},this.requests={},this.options={}}get defaultPort(){return typeof this.explicitDefaultPort=="number"?this.explicitDefaultPort:Er()?443:80}set defaultPort(o){this.explicitDefaultPort=o}get protocol(){return typeof this.explicitProtocol=="string"?this.explicitProtocol:Er()?"https:":"http:"}set protocol(o){this.explicitProtocol=o}callback(o,n,s){throw new Error('"agent-base" has no default implementation, you must subclass and override `callback()`')}addRequest(o,n){const s=Object.assign({},n);typeof s.secureEndpoint!="boolean"&&(s.secureEndpoint=Er()),s.host==null&&(s.host="localhost"),s.port==null&&(s.port=s.secureEndpoint?443:80),s.protocol==null&&(s.protocol=s.secureEndpoint?"https:":"http:"),s.host&&s.path&&delete s.path,delete s.agent,delete s.hostname,delete s._defaultAgent,delete s.defaultPort,delete s.createConnection,o._last=!0,o.shouldKeepAlive=!1;let i=!1,l=null;const a=s.timeout||this.timeout,d=p=>{o._hadError||(o.emit("error",p),o._hadError=!0)},c=()=>{l=null,i=!0;const p=new Error(`A "socket" was not created for HTTP request before ${a}ms`);p.code="ETIMEOUT",d(p)},u=p=>{i||(l!==null&&(clearTimeout(l),l=null),d(p))},f=p=>{if(i)return;if(l!=null&&(clearTimeout(l),l=null),Ec(p)){Ve("Callback returned another Agent instance %o",p.constructor.name),p.addRequest(o,s);return}if(p){p.once("free",()=>{this.freeSocket(p,s)}),o.onSocket(p);return}const h=new Error(`no Duplex stream was returned to agent-base for \`${o.method} ${o.path}\``);d(h)};if(typeof this.callback!="function"){d(new Error("`callback` is not defined"));return}this.promisifiedCallback||(this.callback.length>=3?(Ve("Converting legacy callback function to promise"),this.promisifiedCallback=bc.default(this.callback)):this.promisifiedCallback=this.callback),typeof a=="number"&&a>0&&(l=setTimeout(c,a)),"port"in s&&typeof s.port!="number"&&(s.port=Number(s.port));try{Ve("Resolving socket for %o request: %o",s.protocol,`${o.method} ${o.path}`),Promise.resolve(this.promisifiedCallback(o,s)).then(f,u)}catch(p){Promise.reject(p).catch(u)}}freeSocket(o,n){Ve("Freeing socket %o %o",o.constructor.name,n),o.destroy()}destroy(){Ve("Destroying agent %o",this.constructor.name)}}t.Agent=e,t.prototype=t.Agent.prototype})(bt||(bt={}));var Pc=bt,Pr={},$c=H&&H.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(Pr,"__esModule",{value:!0});const Ac=$c(Cr),qe=Ac.default("https-proxy-agent:parse-proxy-response");function kc(t){return new Promise((e,r)=>{let o=0;const n=[];function s(){const u=t.read();u?c(u):t.once("readable",s)}function i(){t.removeListener("end",a),t.removeListener("error",d),t.removeListener("close",l),t.removeListener("readable",s)}function l(u){qe("onclose had error %o",u)}function a(){qe("onend")}function d(u){i(),qe("onerror %o",u),r(u)}function c(u){n.push(u),o+=u.length;const f=Buffer.concat(n,o);if(f.indexOf(`\r
|
|
76
|
-
\r
|
|
77
|
-
`)===-1){qe("have not received end of HTTP headers yet..."),s();return}const h=f.toString("ascii",0,f.indexOf(`\r
|
|
78
|
-
`)),g=+h.split(" ")[1];qe("got proxy server response: %o",h),e({statusCode:g,buffered:f})}t.on("error",d),t.on("close",l),t.on("end",a),s()})}Pr.default=kc;var Sc=H&&H.__awaiter||function(t,e,r,o){function n(s){return s instanceof r?s:new r(function(i){i(s)})}return new(r||(r=Promise))(function(s,i){function l(c){try{d(o.next(c))}catch(u){i(u)}}function a(c){try{d(o.throw(c))}catch(u){i(u)}}function d(c){c.done?s(c.value):n(c.value).then(l,a)}d((o=o.apply(t,e||[])).next())})},Oe=H&&H.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(pr,"__esModule",{value:!0});const yn=Oe(qn),wn=Oe(Xn),xc=Oe(Qn),Ic=Oe(Hr),Mc=Oe(Cr),Rc=Pc,Dc=Oe(Pr),Xe=Mc.default("https-proxy-agent:agent");class Oc extends Rc.Agent{constructor(e){let r;if(typeof e=="string"?r=xc.default.parse(e):r=e,!r)throw new Error("an HTTP(S) proxy server `host` and `port` must be specified!");Xe("creating new HttpsProxyAgent instance: %o",r),super(r);const o=Object.assign({},r);this.secureProxy=r.secureProxy||_c(o.protocol),o.host=o.hostname||o.host,typeof o.port=="string"&&(o.port=parseInt(o.port,10)),!o.port&&o.host&&(o.port=this.secureProxy?443:80),this.secureProxy&&!("ALPNProtocols"in o)&&(o.ALPNProtocols=["http 1.1"]),o.host&&o.path&&(delete o.path,delete o.pathname),this.proxy=o}callback(e,r){return Sc(this,void 0,void 0,function*(){const{proxy:o,secureProxy:n}=this;let s;n?(Xe("Creating `tls.Socket`: %o",o),s=wn.default.connect(o)):(Xe("Creating `net.Socket`: %o",o),s=yn.default.connect(o));const i=Object.assign({},o.headers);let a=`CONNECT ${`${r.host}:${r.port}`} HTTP/1.1\r
|
|
79
|
-
`;o.auth&&(i["Proxy-Authorization"]=`Basic ${Buffer.from(o.auth).toString("base64")}`);let{host:d,port:c,secureEndpoint:u}=r;Fc(c,u)||(d+=`:${c}`),i.Host=d,i.Connection="close";for(const y of Object.keys(i))a+=`${y}: ${i[y]}\r
|
|
80
|
-
`;const f=Dc.default(s);s.write(`${a}\r
|
|
81
|
-
`);const{statusCode:p,buffered:h}=yield f;if(p===200){if(e.once("socket",Nc),r.secureEndpoint){Xe("Upgrading socket connection to TLS");const y=r.servername||r.host;return wn.default.connect(Object.assign(Object.assign({},Lc(r,"host","hostname","path","port")),{socket:s,servername:y}))}return s}s.destroy();const g=new yn.default.Socket({writable:!1});return g.readable=!0,e.once("socket",y=>{Xe("replaying proxy buffer for failed request"),Ic.default(y.listenerCount("data")>0),y.push(h),y.push(null)}),g})}}pr.default=Oc;function Nc(t){t.resume()}function Fc(t,e){return!!(!e&&t===80||e&&t===443)}function _c(t){return typeof t=="string"?/^https:?$/i.test(t):!1}function Lc(t,...e){const r={};let o;for(o in t)e.includes(o)||(r[o]=t[o]);return r}var Tc=H&&H.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};const $r=Tc(pr);function Ar(t){return new $r.default(t)}(function(t){t.HttpsProxyAgent=$r.default,t.prototype=$r.default.prototype})(Ar||(Ar={}));var jc=Ar,Bc=Ee(jc);const Gc=async(t,e,r,o,n,s,i)=>new Promise((l,a)=>{const d=JSON.stringify(o),u=(t.protocol.includes("https")?Vr:Vn).request({port:i||void 0,hostname:t.hostname,path:e,method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(d),...r},timeout:n,agent:s?Bc(s):void 0},f=>{const p=[];f.on("data",h=>p.push(h)),f.on("end",()=>{l({request:u,response:f,data:Buffer.concat(p).toString()})})});u.on("error",a),u.on("timeout",()=>{u.destroy(),a(new w(`Time out error: request took over ${n}ms. Try increasing the \`timeout\` config`))}),u.write(d),u.end()}),Hc=async(t,e,r,o,n,s)=>{const i=new URL(t),{response:l,data:a}=await Gc(i,e,{Authorization:`Bearer ${r}`},o,n,s);if(!l.statusCode||l.statusCode<200||l.statusCode>299){let d=`API Error: ${l.statusCode} - ${l.statusMessage}`;throw a&&(d+=`
|
|
98
|
+
Focus on understanding the purpose and impact of these changes to create meaningful commit message(s).`,Qc=async(t,e,r,o,s,n,i)=>new Promise((a,c)=>{const d=JSON.stringify(o),u=(t.protocol.includes("https")?so:nn).request({port:i||void 0,hostname:t.hostname,path:e,method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(d),...r},timeout:s,agent:n?Vc(n):void 0},p=>{const f=[];p.on("data",h=>f.push(h)),p.on("end",()=>{a({request:u,response:p,data:Buffer.concat(f).toString()})})});u.on("error",c),u.on("timeout",()=>{u.destroy(),c(new v(`Time out error: request took over ${s}ms. Try increasing the \`timeout\` config`))}),u.write(d),u.end()}),Zc=async(t,e,r,o,s,n)=>{const i=new URL(t),{response:a,data:c}=await Qc(i,e,{Authorization:`Bearer ${r}`},o,s,n);if(!a.statusCode||a.statusCode<200||a.statusCode>299){let d=`API Error: ${a.statusCode} - ${a.statusMessage}`;throw c&&(d+=`
|
|
82
99
|
|
|
83
|
-
${
|
|
100
|
+
${c}`),a.statusCode===500&&(d+=`
|
|
84
101
|
|
|
85
|
-
Check the API status: ${t}`),new w(d)}return JSON.parse(a)},vn=t=>t.trim(),Uc=["gpt-5","gpt-5-mini","gpt-5-nano","gpt-5-codex","o1","o1-mini","o1-pro","o3","o3-mini","o3-pro","o4-mini"],kr=t=>{const e=t.toLowerCase();return Uc.some(r=>e===r||e.startsWith(`${r}-`)||e.startsWith(`${r}.`))},zc=async(t,e,r,o,n,s,i,l,a,d,c,u,f,p)=>{try{const h=Ce(s,f),g=kr(n),y={model:n,messages:[{role:"system",content:c},{role:"user",content:h}],stream:!1,n:1,frequency_penalty:0,presence_penalty:0,...g?{max_completion_tokens:l,temperature:1}:{max_tokens:l,top_p:d,temperature:a}},v=new URL(e),E=`${v.protocol}//${v.host}${r}`,b={Authorization:`Bearer ${o}`,"Content-Type":"application/json"};Z(s,f,t,n,E,b,u),ee(s,f,t,c,h,u),se(s,f,t,y,u);const k=Date.now(),P=await Hc(e,r,o,y,i,p),$=Date.now()-k;W(s,f,t,P,u);const M=P.choices.filter(A=>A.message?.content).map(A=>vn(A.message.content)).join();return Y(s,f,t,$,M,u),P.choices.filter(A=>A.message?.content).map(A=>vn(A.message.content))}catch(h){j(s,f,t,h,u);const g=h;throw g.code==="ENOTFOUND"?new w(`Error connecting to ${g.hostname} (${g.syscall})`):g}};class Kc extends te{constructor(e){super(e),this.params=e,this.baseURL="https://models.github.ai",this.colors={primary:"#24292e",secondary:"#FFF"},this.serviceName=C.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[GitHub Models]"),this.errorPrefix=C.red.bold("[GitHub Models]")}getServiceSpecificErrorMessage(e){switch(e.code){case"MISSING_TOKEN":return"GitHub token is required. Run: aicommit2 github-login";case"AUTHENTICATION_FAILED":return"Authentication failed. Your GitHub token may be expired or invalid. Run: aicommit2 github-login";case"ACCESS_DENIED":return'Access denied. Make sure your GitHub token has "Models" permission in GitHub settings';case"NO_CONTENT":return"No content received from GitHub Models. The model may have failed to generate a response";default:return null}}generateCommitMessage$(){return L(this.generateMessage("commit")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),N(this.handleError$))}generateCodeReview$(){return L(this.generateMessage("review")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),N(this.handleError$))}async generateMessage(e){if(!this.params.config.key){const p=new Error("GitHub token is required for GitHub Models. Use: aicommit2 github-login");throw p.code="MISSING_TOKEN",p}const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,locale:i,generate:l,type:a,maxLength:d}=this.params.config,c={...J,locale:i,maxLength:d,type:a,generate:l,systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,vcs_branch:this.params.branchName||""},u=e==="review"?oe(c):re(c),f=await this.makeRequest(u,r,e);return e==="review"?this.sanitizeResponse(f):this.parseMessage(f,a,l)}async makeRequest(e,r,o){const n=Array.isArray(this.params.config.model)?this.params.config.model[0]:this.params.config.model||"gpt-4o-mini",s=[{role:"system",content:e},{role:"user",content:o==="review"?r:`Here's the diff:
|
|
102
|
+
Check the API status: ${t}`),new v(d)}return JSON.parse(c)},As=t=>t.trim(),el=["gpt-5","gpt-5-mini","gpt-5-nano","gpt-5-codex","o1","o1-mini","o1-pro","o3","o3-mini","o3-pro","o4-mini"],xr=t=>{const e=t.toLowerCase();return el.some(r=>e===r||e.startsWith(`${r}-`)||e.startsWith(`${r}.`))},tl=async(t,e,r,o,s,n,i,a,c,d,l,u,p,f)=>{try{const h=Ee(n,p),y=xr(s),w={model:s,messages:[{role:"system",content:l},{role:"user",content:h}],stream:!1,n:1,frequency_penalty:0,presence_penalty:0,...y?{max_completion_tokens:a,temperature:1}:{max_tokens:a,top_p:d,temperature:c}},C=new URL(e),b=`${C.protocol}//${C.host}${r}`,E={Authorization:`Bearer ${o}`,"Content-Type":"application/json"};ee(n,p,t,s,b,E,u),te(n,p,t,l,h,u),ne(n,p,t,w,u);const k=Date.now(),$=await Zc(e,r,o,w,i,f),P=Date.now()-k;V(n,p,t,$,u);const O=$.choices.filter(S=>S.message?.content).map(S=>As(S.message.content)).join();return q(n,p,t,P,O,u),$.choices.filter(S=>S.message?.content).map(S=>As(S.message.content))}catch(h){G(n,p,t,h,u);const y=h;throw y.code==="ENOTFOUND"?new v(`Error connecting to ${y.hostname} (${y.syscall})`):y}};class rl extends re{constructor(e){super(e),this.params=e;const r=this.params.keyName||"OPENAI_COMPATIBLE";this.colors=Za(r),this.serviceName=g.bgHex(this.colors.primary).hex(this.colors.secondary).bold(`[${yt(r)}]`),this.errorPrefix=g.red.bold(`[${yt(r)}]`),this.openAI=new ro({apiKey:this.params.config.key,baseURL:`${this.params.config.url}${this.params.config.path}`})}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("API key")||r.includes("api_key")?"Invalid API key. Check your OpenAI-compatible API key in configuration":r.includes("rate_limit")||r.includes("Rate limit")?"Rate limit exceeded. Wait a moment and try again, or check your service limits":r.includes("model")||r.includes("Model")?"Model not found or not accessible. Check if the model name is correct":r.includes("network")||r.includes("connection")?"Network error. Check your internet connection and API endpoint":r.includes("quota")||r.includes("usage")?"API quota exceeded. Check your usage limits":r.includes("403")||r.includes("Forbidden")?"Access denied. Your API key may not have permission for this model":r.includes("404")||r.includes("Not Found")?"Model or endpoint not found. Check your API configuration":r.includes("500")||r.includes("Internal Server Error")?"Server error. Try again later":r.includes("overloaded")||r.includes("capacity")?"Service is overloaded. Try again in a few minutes":null}generateCommitMessage$(){return j(this.generateMessage("commit")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),L(this.handleError$))}generateCodeReview$(){return j(this.generateMessage("review")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),L(this.handleError$))}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,logging:i,locale:a,temperature:c,generate:d,type:l,maxLength:u,timeout:p,stream:f=!1}=this.params.config,h=this.params.config.maxTokens,y={...J,locale:a,maxLength:u,type:l,generate:d,systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,vcs_branch:this.params.branchName||""},w=e==="review"?se(y):oe(y),C=`Here is the diff: ${r}`,b=this.params.keyName||"OpenAI-Compatible",E=`${this.params.config.url}${this.params.config.path}`,k={Authorization:`Bearer ${this.params.config.key}`,"Content-Type":"application/json"};ee(r,e,b,this.params.config.model,E,k,i),te(r,e,b,w,C,i);const $=xr(this.params.config.model),P={messages:[{role:"system",content:w},{role:"user",content:C}],model:this.params.config.model,stream:f,...$?{max_completion_tokens:h,temperature:1}:{max_tokens:h,top_p:this.params.config.topP,temperature:c}};ne(r,e,b,P,i);const O=Date.now();try{const S=await this.openAI.chat.completions.create(P,{timeout:p});let U="";if(f&&S){const fe=S;for await(const Q of fe){const Lt=Q.choices?.[0]?.delta?.content||"",he=Q.choices?.[0]?.delta?.reasoning_content||"",Ft=`${Lt}${he}`;U+=Ft}}else U=S.choices?.[0]?.message.content||"";const _=Date.now()-O;return V(r,e,b,S,i),q(r,e,b,_,U,i),e==="review"?this.sanitizeResponse(U):this.parseMessage(U,l,d)}catch(S){throw G(r,e,b,S,i),S}}}const ol=["claude-4","claude-haiku-4","claude-sonnet-4","claude-opus-4"],sl=t=>{const e=t.toLowerCase();return ol.some(r=>e===r||e.startsWith(`${r}-`)||e.startsWith(`${r}.`))},nl=10*60*1e3;class il extends re{constructor(e){super(e),this.params=e,this.colors={primary:"#AE5630",secondary:"#fff"},this.serviceName=g.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[Anthropic]"),this.errorPrefix=g.red.bold("[Anthropic]"),this.anthropic=new mn({apiKey:this.params.config.key,...this.params.config.timeout>nl&&{timeout:this.params.config.timeout}})}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("API key")||r.includes("api_key")?"Invalid API key. Check your Anthropic API key in configuration":r.includes("quota")||r.includes("usage")?"API quota exceeded. Check your Anthropic usage limits":r.includes("model_not_found")||r.includes("Model not found")||/model.*does not exist/i.test(r)?"Model not found or not accessible. Check if the Claude model name is correct":r.includes("403")||r.includes("Forbidden")?"Access denied. Your API key may not have permission for this Claude model":r.includes("404")||r.includes("Not Found")?"Model or endpoint not found. Check your Claude model configuration":r.includes("500")||r.includes("Internal Server Error")?"Anthropic server error. Try again later":null}generateCommitMessage$(){return j(this.generateMessage("commit")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),L(this.handleError$))}generateCodeReview$(){return j(this.generateMessage("review")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),L(this.handleError$))}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,logging:i,temperature:a,locale:c,generate:d,type:l,maxLength:u,maxTokens:p,topP:f,model:h}=this.params.config,y={...J,locale:c,maxLength:u,type:l,generate:d,systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,vcs_branch:this.params.branchName||""},w=e==="review"?se(y):oe(y),C=Ee(r,e),E=`${this.params.config.url||"https://api.anthropic.com"}/v1/messages`,k={"Content-Type":"application/json","x-api-key":this.params.config.key,"anthropic-version":"2023-06-01"};ee(r,e,"Anthropic",h,E,k,i),te(r,e,"Anthropic",w,C,i);const $=sl(h),P={max_tokens:p,temperature:a,system:w,messages:[{role:"user",content:C}],model:h,...$?{}:{top_p:f}};ne(r,e,"Anthropic",P,i);const O=Date.now();try{const S=await this.anthropic.messages.create(P),U=Date.now()-O;V(r,e,"Anthropic",S,i);const _=S.content.map(({text:fe})=>fe).join("");return q(r,e,"Anthropic",U,_,i),e==="review"?this.sanitizeResponse(_):this.parseMessage(_,l,d)}catch(S){throw G(r,e,"Anthropic",S,i),S}}}const ae="Bedrock",ye={MISSING_DEPENDENCY:"MissingDependencyError",MISSING_REGION:"MissingRegionError",MISSING_MODEL_ID:"MissingModelIdError",MISSING_API_KEY:"MissingApiKeyError",MISSING_APPLICATION_KEY:"MissingApplicationKeyError",INVALID_RESPONSE:"InvalidResponseError",EMPTY_RESPONSE:"EmptyResponseError"},W=t=>typeof t=="string"&&t.length>0;let Ze=null,et=null;const Ss=t=>{const e=new Error('Amazon Bedrock support requires "@aws-sdk/client-bedrock-runtime" and "@aws-sdk/credential-providers". Install them with `pnpm add @aws-sdk/client-bedrock-runtime @aws-sdk/credential-providers`.');return e.name=ye.MISSING_DEPENDENCY,e.originalError=t,e},al=async()=>{if(Ze)return Ze;try{return Ze=await import("@aws-sdk/client-bedrock-runtime"),Ze}catch(t){throw Ze=null,Ss(t)}},ks=async()=>{if(et)return et;try{return et=await import("@aws-sdk/credential-providers"),et}catch(t){throw et=null,Ss(t)}};class cl extends re{constructor(e){super(e),this.params=e,this.credentialCache=void 0,this.credentialCacheTimestamp=0,this.CREDENTIAL_CACHE_TTL=5*60*1e3,this.bedrockConfig=this.params.config,this.colors={primary:"#232F3E",secondary:"#FF9900"},this.serviceName=g.bgHex(this.colors.primary).hex(this.colors.secondary).bold(`[${ae}]`),this.errorPrefix=g.red.bold(`[${ae}]`),this.validateConfiguration()}validateConfiguration(){const e=this.bedrockConfig;if(!W(e.model)){const s=new Error("Model ID or inference profile ARN is required.");throw s.name=ye.MISSING_MODEL_ID,s}if(!this.getRegion()){const s=new Error("AWS region is required. Configure BEDROCK.region or set AWS_REGION/AWS_DEFAULT_REGION.");throw s.name=ye.MISSING_REGION,s}const r=W(e.key),o=this.canUseAwsSdk();if(!r&&!o){const s=new Error("Authentication required: Configure AWS credentials (profile, access keys, IAM role) or API key (BEDROCK.key).");throw s.name=ye.MISSING_API_KEY,s}if(r&&!o&&!this.getRegion()&&!W(e.applicationBaseUrl)){const s=new Error("Bearer token authentication requires region or applicationBaseUrl to construct endpoint.");throw s.name=ye.MISSING_REGION,s}}canUseAwsSdk(){const e=this.bedrockConfig,r=W(e.profile)||W(process.env.AWS_PROFILE),o=W(e.accessKeyId)&&W(e.secretAccessKey)||W(process.env.AWS_ACCESS_KEY_ID)&&W(process.env.AWS_SECRET_ACCESS_KEY);return r||o}determineAuthMethod(){const e=W(this.bedrockConfig.key);if(this.canUseAwsSdk())return"aws-sdk";if(e)return"bearer-token";throw new Error("No authentication method configured")}getServiceSpecificErrorMessage(e){const r=e?.name||e.code,o=e.message||"";switch(r){case"UnrecognizedClientException":case"InvalidSignatureException":return"Authentication with AWS failed. Check your IAM credentials or Bedrock API key settings.";case"AccessDeniedException":return"Access denied. Ensure the IAM principal or application key has permission to invoke the Bedrock resource.";case"ValidationException":return"Invalid request for the selected Bedrock model. Verify the model ID and payload.";case"ResourceNotFoundException":return"The specified Bedrock model, endpoint, or inference profile could not be found.";case"ThrottlingException":return"Request throttled by Bedrock. Reduce request rate or check service quotas."}return o.includes("Region")?"AWS region is required for Bedrock. Configure BEDROCK.region or set AWS_REGION/AWS_DEFAULT_REGION.":null}generateCommitMessage$(){return j(this.generateMessage("commit")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),L(this.handleError$))}generateCodeReview$(){return j(this.generateMessage("review")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),L(this.handleError$))}async generateMessage(e){const r=this.params.stagedDiff.diff,o=this.bedrockConfig,s=o.model,{logging:n,inferenceParameters:i}=o,a={...J,locale:o.locale,maxLength:o.maxLength,type:o.type,generate:o.generate,systemPrompt:o.systemPrompt,systemPromptPath:o.systemPromptPath,codeReviewPromptPath:o.codeReviewPromptPath},c=e==="review"?se(a):oe(a),d=Ee(r,e),l={region:this.getRegion(),profile:o.profile,modelId:s},u=`https://bedrock-runtime.${this.getRegion()||"unknown"}.amazonaws.com/model/${encodeURIComponent(s)}/converse`;ee(r,e,ae,s,u,l,n),te(r,e,ae,c,d,n);const p={modelId:s,systemPrompt:c,userPrompt:d,...i&&Object.keys(i).length>0&&{inferenceConfig:i}};ne(r,e,ae,p,n);const f=Date.now();try{const h=this.determineAuthMethod();At()&&(console.log(g.cyan(`[Bedrock] Authentication method: ${h}`)),console.log(g.cyan(`[Bedrock] Model ID: ${s}`)),console.log(g.cyan(`[Bedrock] Region: ${this.getRegion()}`)),console.log(g.cyan(`[Bedrock] Has AWS credentials: ${this.canUseAwsSdk()}`)),console.log(g.cyan(`[Bedrock] Has API key: ${W(o.key)}`)));const y=h==="bearer-token"?await this.invokeWithBearerToken({model:s,systemPrompt:c,userPrompt:d,logging:n,requestType:e,diff:r,inferenceConfig:i}):await this.invokeWithAwsSdk({model:s,systemPrompt:c,userPrompt:d,logging:n,requestType:e,diff:r,inferenceConfig:i}),w=Date.now()-f;return q(r,e,ae,w,y,n),e==="review"?this.sanitizeResponse(y):this.parseMessage(y,o.type,o.generate)}catch(h){throw G(r,e,ae,h,n),h instanceof Error&&(h.status=h?.status||h?.$metadata?.httpStatusCode),h}}async invokeWithAwsSdk(e){const r=this.getRegion(),{model:o,systemPrompt:s,userPrompt:n,inferenceConfig:i,logging:a,requestType:c,diff:d}=e,{BedrockRuntimeClient:l,ConverseCommand:u}=await al(),p=this.bedrockConfig,f={region:r,requestHandler:{requestTimeout:p.timeout||12e4}},h=await this.resolveCredentials();h&&(f.credentials=h);const y=new l(f),w=new u({modelId:o,messages:[{role:"user",content:[{text:n}]}],...s?{system:[{text:s}]}:{},...i&&Object.keys(i).length>0&&{inferenceConfig:i}});At()&&console.log(g.cyan(`[Bedrock] Sending ConverseCommand with modelId: ${o}`));let C;try{C=await y.send(w),V(d,c,ae,C,a)}catch(E){throw At()&&(console.error(g.red(`[Bedrock] AWS SDK Error: ${E.name}`)),console.error(g.red(`[Bedrock] Error message: ${E.message}`)),E.$metadata&&(console.error(g.red(`[Bedrock] Request ID: ${E.$metadata.requestId}`)),console.error(g.red(`[Bedrock] HTTP Status: ${E.$metadata.httpStatusCode}`))),E.$fault&&console.error(g.red(`[Bedrock] Fault: ${E.$fault}`))),E}const b=C.output?.message?.content?.[0]?.text||"";if(!b){const E=new Error("No text content found in Bedrock response.");throw E.name=ye.EMPTY_RESPONSE,E.content=C,E}return b}invokeWithBearerToken(e){const{model:r,systemPrompt:o,userPrompt:s,inferenceConfig:n,logging:i,requestType:a,diff:c}=e,d=this.bedrockConfig,l=this.getRegion(),u=encodeURIComponent(r),p=d.applicationBaseUrl||`https://bedrock-runtime.${l}.amazonaws.com/model/${u}/converse`,f=new URL(p),h={modelId:r,messages:[{role:"user",content:[{text:s}]}],...n&&Object.keys(n).length>0&&{inferenceConfig:n}};o&&(h.system=[{text:o}]);const y=JSON.stringify(h),w={"Content-Type":"application/json","Content-Length":Buffer.byteLength(y).toString()};return W(d.key)&&(w.Authorization=`Bearer ${d.key}`),W(d.applicationInferenceProfileArn)&&(w["x-amzn-bedrock-inference-profile-arn"]=d.applicationInferenceProfileArn),W(d.applicationEndpointId)&&(w["x-amzn-bedrock-endpoint-id"]=d.applicationEndpointId),new Promise((C,b)=>{const E=so.request({method:"POST",protocol:f.protocol,hostname:f.hostname,port:f.port,path:f.pathname+f.search,headers:w,timeout:d.timeout},k=>{const $=[];k.on("data",P=>$.push(P)),k.on("end",()=>{const P=Buffer.concat($).toString("utf8");if(k.statusCode&&k.statusCode>=400){const _=new Error(`Bedrock application endpoint responded with status ${k.statusCode}.`);return _.status=k.statusCode,_.content=P,G(c,a,ae,_,i),b(_)}const O=ns(P);if(!O.ok){const _=new Error("Failed to parse Bedrock application response as JSON. The Bedrock Converse API should always return valid JSON.");return _.name=ye.INVALID_RESPONSE,_.content=P,G(c,a,ae,_,i),b(_)}const S=O.data;V(c,a,ae,S,i);const U=S.output?.message?.content?.[0]?.text||"";if(!U){const _=new Error("No text content found in Bedrock response.");return _.name=ye.EMPTY_RESPONSE,_.content=S,G(c,a,ae,_,i),b(_)}C(U)})});E.on("error",k=>{const $=k;G(c,a,ae,$,i),b($)}),E.write(y),E.end()})}getRegion(){return this.bedrockConfig.region||process.env.AWS_REGION||process.env.AWS_DEFAULT_REGION||""}async resolveCredentials(){const e=Date.now();if(this.credentialCache&&e-this.credentialCacheTimestamp<this.CREDENTIAL_CACHE_TTL)return this.credentialCache;const r=this.bedrockConfig,o=r.profile,s=r.accessKeyId,n=r.secretAccessKey,i=r.sessionToken;let a;if(W(o)){const{fromIni:c}=await ks();a=c({profile:o})}else if(W(s)&&W(n))a=async()=>({accessKeyId:s,secretAccessKey:n,sessionToken:i||process.env.AWS_SESSION_TOKEN||void 0});else if(process.env.AWS_PROFILE){const{fromIni:c}=await ks();a=c({profile:process.env.AWS_PROFILE})}return a&&(this.credentialCache=a,this.credentialCacheTimestamp=e),a}}class Ne{constructor(e={}){if(!e.method)throw new Error("method should be defined!");if(!e.baseURL)throw new Error("baseURL should be defined!");this.config={...e},this.axiosInstance=pn.create(this.config)}setHeaders(e){return this.config.headers=e,this}setParams(e){return this.config.params=e,this}setBody(e){return this.config.data=e,this}addBody(e){return this.config.data={...this.config.data,...e},this}setMethod(e){return this.config.method=e,this}async execute(){try{return await this.axiosInstance.request(this.config)}catch(e){throw e}}}class ll extends re{constructor(e){super(e),this.params=e,this.apiKey="",this.colors={primary:"#e28c58",secondary:"#fff"},this.serviceName=g.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[Codestral]"),this.errorPrefix=g.red.bold("[Codestral]"),this.apiKey=this.params.config.key}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("API key")||r.includes("api_key")?"Invalid API key. Check your Codestral API key in configuration":r.includes("rate_limit")||r.includes("Rate limit")?"Rate limit exceeded. Wait a moment and try again, or upgrade your Codestral plan":r.includes("model")||r.includes("Model")?"Model not found or not accessible. Check if the Codestral model name is correct":r.includes("Invalid model type")?"Invalid model type. Use supported models: codestral-latest, codestral-2501":r.includes("overloaded")||r.includes("capacity")?"Codestral service is overloaded. Try again in a few minutes":r.includes("403")||r.includes("Forbidden")?"Access denied. Your API key may not have permission for this Codestral model":r.includes("404")||r.includes("Not Found")?"Model or endpoint not found. Check your Codestral model configuration":r.includes("500")||r.includes("Internal Server Error")?"Codestral server error. Try again later":null}generateCommitMessage$(){return j(this.generateMessage("commit")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),L(this.handleError$))}generateCodeReview$(){return j(this.generateMessage("review")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),L(this.handleError$))}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,logging:i,locale:a,generate:c,type:d,maxLength:l}=this.params.config,u={...J,locale:a,maxLength:l,type:d,generate:c,systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,vcs_branch:this.params.branchName||""},p=e==="review"?se(u):oe(u);this.checkAvailableModels();const f=Ee(r,e),y=`${this.params.config.url||"https://codestral.mistral.ai"}/v1/chat/completions`,w={Authorization:`Bearer ${this.apiKey}`,"content-type":"application/json"};ee(r,e,"Codestral",this.params.config.model,y,w,i),te(r,e,"Codestral",p,f,i);const C=await this.createChatCompletions(p,e);return e==="review"?this.sanitizeResponse(C):this.parseMessage(C,d,c)}checkAvailableModels(){if(["codestral-latest","codestral-2501"].includes(this.params.config.model))return!0;throw new Error("Invalid model type of Codestral AI")}async createChatCompletions(e,r){const o=this.params.stagedDiff.diff,{logging:s}=this.params.config,n=this.params.config.url||"https://codestral.mistral.ai",i={model:this.params.config.model,messages:[{role:"system",content:e},{role:"user",content:Ee(this.params.stagedDiff.diff,r)}],temperature:this.params.config.temperature,top_p:this.params.config.topP,max_tokens:this.params.config.maxTokens,stream:!1,safe_prompt:!1,random_seed:wt(10,1e3)};r==="commit"&&(i.response_format={type:"json_object"}),ne(o,r,"Codestral",i,s);const a=Date.now();try{const d=await new Ne({method:"POST",baseURL:`${n}/v1/chat/completions`,timeout:this.params.config.timeout}).setHeaders({Authorization:`Bearer ${this.apiKey}`,"content-type":"application/json"}).setBody(i).execute(),l=Date.now()-a,u=d.data;if(V(o,r,"Codestral",u,s),!u.choices||u.choices.length===0||!u.choices[0].message?.content)throw G(o,r,"Codestral",{message:"No Content on response",result:u},s),new Error("No Content on response. Please open a Bug report");const f=u.choices[0].message.content;return q(o,r,"Codestral",l,f,s),f}catch(c){throw G(o,r,"Codestral",c,s),c}}}class ul extends re{constructor(e){super(e),this.params=e,this.colors={primary:"#D18EE2",secondary:"#fff"},this.serviceName=g.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[Cohere]"),this.errorPrefix=g.red.bold("[Cohere]"),this.cohere=new fn({token:this.params.config.key})}isValidCohereV2Response(e){const r=e;return r?.message?.content!==void 0&&Array.isArray(r.message.content)&&r.message.content.length>0&&typeof r.message.content[0]?.text=="string"}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("API key")||r.includes("api_key")?"Invalid API key. Check your Cohere API key in configuration":r.includes("rate_limit")||r.includes("Rate limit")?"Rate limit exceeded. Wait a moment and try again, or upgrade your Cohere plan":r.includes("model")||r.includes("Model")?"Model not found or not accessible. Check if the Cohere model name is correct":r.includes("overloaded")||r.includes("capacity")?"Cohere service is overloaded. Try again in a few minutes":r.includes("403")||r.includes("Forbidden")?"Access denied. Your API key may not have permission for this Cohere model":r.includes("404")||r.includes("Not Found")?"Model or endpoint not found. Check your Cohere model configuration":r.includes("500")||r.includes("Internal Server Error")?"Cohere server error. Try again later":null}generateCommitMessage$(){return j(this.generateMessage("commit")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),L(this.handleError$))}generateCodeReview$(){return j(this.generateMessage("review")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),L(this.handleError$))}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,logging:i,temperature:a,locale:c,generate:d,type:l,maxLength:u,maxTokens:p}=this.params.config,f={...J,locale:c,maxLength:u,type:l,generate:d,systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,vcs_branch:this.params.branchName||""},h=e==="review"?se(f):oe(f),y=`Here is the diff: ${r}`,w=[...h?[{role:"system",content:h}]:[],{role:"user",content:y}],b=`${this.params.config.url}/v2/chat`;ee(r,e,"Cohere",this.params.config.model,b,{},i),te(r,e,"Cohere",h,y,i);const E={model:this.params.config.model,messages:w,max_tokens:p,temperature:a,seed:wt(10,1e3),p:this.params.config.topP};ne(r,e,"Cohere",E,i);const k=Date.now();try{const $=await this.cohere.chat(E,{timeoutInSeconds:Math.floor(this.params.config.timeout/1e3)}),P=Date.now()-k;if(!this.isValidCohereV2Response($))throw new Error("Invalid response structure from Cohere v2 API");const O=$.message.content[0].text;return V(r,e,"Cohere",$,i),q(r,e,"Cohere",P,O,i),e==="review"?this.sanitizeResponse(O):this.parseMessage(O,l,d)}catch($){throw G(r,e,"Cohere",$,i),$}}}class dl extends re{constructor(e){super(e),this.params=e,this.colors={primary:"#53a3f9",secondary:"#fff"},this.serviceName=g.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[DeepSeek]"),this.errorPrefix=g.red.bold("[DeepSeek]");const r=this.params.config.url||"https://api.deepseek.com";this.deepSeek=new ro({baseURL:r,apiKey:this.params.config.key})}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("API key")||r.includes("api_key")?"Invalid API key. Check your DeepSeek API key in configuration":r.includes("rate_limit")||r.includes("Rate limit")?"Rate limit exceeded. Wait a moment and try again, or upgrade your DeepSeek plan":r.includes("model")||r.includes("Model")?"Model not found or not accessible. Check if the DeepSeek model name is correct":r.includes("Invalid model type")?"Invalid model type. Use supported models: deepseek-reasoner, deepseek-chat":r.includes("overloaded")||r.includes("capacity")?"DeepSeek service is overloaded. Try again in a few minutes":r.includes("403")||r.includes("Forbidden")?"Access denied. Your API key may not have permission for this DeepSeek model":r.includes("404")||r.includes("Not Found")?"Model or endpoint not found. Check your DeepSeek model configuration":r.includes("500")||r.includes("Internal Server Error")?"DeepSeek server error. Try again later":null}generateCommitMessage$(){return j(this.generateMessage("commit")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),L(this.handleError$))}generateCodeReview$(){return j(this.generateMessage("review")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),L(this.handleError$))}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,logging:i,locale:a,generate:c,type:d,maxLength:l}=this.params.config,u={...J,locale:a,maxLength:l,type:d,generate:c,systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,vcs_branch:this.params.branchName||""},p=e==="review"?se(u):oe(u);this.checkAvailableModels();const f=Ee(r,e),y=`${this.params.config.url||"https://api.deepseek.com"}/chat/completions`,w={Authorization:`Bearer ${this.params.config.key}`,"Content-Type":"application/json"};ee(r,e,"DeepSeek",this.params.config.model,y,w,i),te(r,e,"DeepSeek",p,f,i);const C=await this.createChatCompletions(p,f,e);return e==="review"?this.sanitizeResponse(C):this.parseMessage(C,d,c)}checkAvailableModels(){if(["deepseek-reasoner","deepseek-chat"].includes(this.params.config.model))return!0;throw new Error("Invalid model type of DeepSeek")}async createChatCompletions(e,r,o){const s=this.params.stagedDiff.diff,{logging:n}=this.params.config,i={messages:[{role:"system",content:e},{role:"user",content:r}],model:this.params.config.model,max_tokens:this.params.config.maxTokens,top_p:this.params.config.topP,temperature:this.params.config.temperature};ne(s,o,"DeepSeek",i,n);const a=Date.now();try{const c=await this.deepSeek.chat.completions.create(i,{timeout:this.params.config.timeout}),d=Date.now()-a,l=c.choices?.[0];if(!l?.message)throw new Error("DeepSeek API returned invalid response structure");const u=l.message.content||l.message.reasoning_content||"";if(!u)throw new Error("DeepSeek API returned empty response");return V(s,o,"DeepSeek",c,n),q(s,o,"DeepSeek",d,u,n),u}catch(c){throw G(s,o,"DeepSeek",c,n),c}}}class ml extends re{constructor(e){super(e),this.params=e,this.colors={primary:"#0077FF",secondary:"#fff"},this.serviceName=g.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[Gemini]"),this.errorPrefix=g.red.bold("[Gemini]"),this.genAI=new hn(this.params.config.key)}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("API key")||r.includes("api_key")?"Invalid API key. Check your Google AI Studio API key in configuration":r.includes("quota")||r.includes("QUOTA_EXCEEDED")?"API quota exceeded. Check your Google AI Studio usage limits":r.includes("model")||r.includes("Model")?"Model not found or not accessible. Check if the Gemini model name is correct":r.includes("SAFETY")||r.includes("safety")?"Content blocked by safety filters. Try rephrasing your request":r.includes("RECITATION")||r.includes("recitation")?"Content blocked due to recitation concerns. Try a different approach":r.includes("403")||r.includes("Forbidden")?"Access denied. Your API key may not have permission for this Gemini model":r.includes("404")||r.includes("Not Found")?"Model or endpoint not found. Check your Gemini model configuration":r.includes("500")||r.includes("Internal Server Error")?"Google AI service error. Try again later":r.includes("MAX_TOKENS")||r.includes("truncated")||r.includes("maxOutputTokens")?"Response truncated due to token limit. Gemini 2.5+ models use thinking tokens. Try increasing maxTokens (recommended: 8192+)":null}generateCommitMessage$(){return j(this.generateMessage("commit")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),L(this.handleError$))}generateCodeReview$(){return j(this.generateMessage("review")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),L(this.handleError$))}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:s,logging:n,locale:i,codeReviewPromptPath:a,generate:c,type:d,maxLength:l}=this.params.config,u=this.params.config.maxTokens,p={...J,locale:i,maxLength:l,type:d,generate:c,systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:a,vcs_branch:this.params.branchName||""},f=e==="review"?se(p):oe(p),h={maxOutputTokens:u,temperature:this.params.config.temperature,topP:this.params.config.topP},y=this.genAI.getGenerativeModel({model:this.params.config.model,systemInstruction:f,generationConfig:h,safetySettings:[{category:st.HARM_CATEGORY_HATE_SPEECH,threshold:nt.BLOCK_LOW_AND_ABOVE},{category:st.HARM_CATEGORY_SEXUALLY_EXPLICIT,threshold:nt.BLOCK_LOW_AND_ABOVE},{category:st.HARM_CATEGORY_HARASSMENT,threshold:nt.BLOCK_LOW_AND_ABOVE},{category:st.HARM_CATEGORY_DANGEROUS_CONTENT,threshold:nt.BLOCK_LOW_AND_ABOVE}]}),w=Ee(r,e),b=`${this.params.config.url||"https://generativelanguage.googleapis.com"}/v1beta/models/${this.params.config.model}:generateContent`,E={"Content-Type":"application/json","x-goog-api-key":this.params.config.key};ee(r,e,"Gemini",this.params.config.model,b,E,n),te(r,e,"Gemini",f,w,n),ne(r,e,"Gemini",{systemInstruction:{parts:[{text:f}]},contents:[{parts:[{text:w}]}],generationConfig:h},n);const $=Date.now();try{const P=this.params.config.timeout>1e4?{request:{timeout:this.params.config.timeout}}:void 0,O=await y.generateContent(w,P),S=O.response;if(S.candidates?.[0]?.finishReason==="MAX_TOKENS"){const Q=S.usageMetadata;throw new Error(`Response truncated: maxOutputTokens exceeded. Thinking tokens: ${Q?.thoughtsTokenCount??"N/A"}, Output tokens: ${Q?.candidatesTokenCount??"N/A"}. Increase maxTokens config for Gemini 2.5+ thinking models.`)}const _=S.text(),fe=Date.now()-$;return V(r,e,"Gemini",{response:_,candidates:O.response.candidates,usageMetadata:O.response.usageMetadata},n),q(r,e,"Gemini",fe,_,n),e==="review"?this.sanitizeResponse(_):this.parseMessage(_,d,c)}catch(P){throw G(r,e,"Gemini",P,n),P}}}class pl extends re{constructor(e){super(e),this.params=e,this.baseURL="https://models.github.ai",this.colors={primary:"#24292e",secondary:"#FFF"},this.serviceName=g.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[GitHub Models]"),this.errorPrefix=g.red.bold("[GitHub Models]")}getServiceSpecificErrorMessage(e){switch(e.code){case"MISSING_TOKEN":return"GitHub token is required. Run: aicommit2 github-login";case"AUTHENTICATION_FAILED":return"Authentication failed. Your GitHub token may be expired or invalid. Run: aicommit2 github-login";case"ACCESS_DENIED":return'Access denied. Make sure your GitHub token has "Models" permission in GitHub settings';case"NO_CONTENT":return"No content received from GitHub Models. The model may have failed to generate a response";default:return null}}generateCommitMessage$(){return j(this.generateMessage("commit")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),L(this.handleError$))}generateCodeReview$(){return j(this.generateMessage("review")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),L(this.handleError$))}async generateMessage(e){if(!this.params.config.key){const f=new Error("GitHub token is required for GitHub Models. Use: aicommit2 github-login");throw f.code="MISSING_TOKEN",f}const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,locale:i,generate:a,type:c,maxLength:d}=this.params.config,l={...J,locale:i,maxLength:d,type:c,generate:a,systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,vcs_branch:this.params.branchName||""},u=e==="review"?se(l):oe(l),p=await this.makeRequest(u,r,e);return e==="review"?this.sanitizeResponse(p):this.parseMessage(p,c,a)}async makeRequest(e,r,o){const s=Array.isArray(this.params.config.model)?this.params.config.model[0]:this.params.config.model||"gpt-4o-mini",n=[{role:"system",content:e},{role:"user",content:o==="review"?r:`Here's the diff:
|
|
86
103
|
|
|
87
|
-
${r}`}],i=
|
|
104
|
+
${r}`}],i=xr(s),a={messages:n,model:s,stream:!1,...i?{max_completion_tokens:this.params.config.maxTokens||1024,temperature:1}:{max_tokens:this.params.config.maxTokens||1024,top_p:this.params.config.topP||.95,temperature:this.params.config.temperature||.7}},c=`${this.baseURL}/inference/chat/completions`,d={"Content-Type":"application/json",Accept:"application/vnd.github+json",Authorization:`Bearer ${this.params.config.key}`},{logging:l}=this.params.config;ee(r,o,"GitHub Models",s,c,d,l),te(r,o,"GitHub Models",e,o==="review"?r:`Here's the diff:
|
|
88
105
|
|
|
89
|
-
${r}`,c),se(r,o,"GitHub Models",l,c);const u=new AbortController,f=setTimeout(()=>u.abort(),this.params.config.timeout);try{const p=Date.now(),h=await fetch(a,{method:"POST",headers:d,body:JSON.stringify(l),signal:u.signal});if(clearTimeout(f),!h.ok){const E=await h.text(),b={status:h.status,statusText:h.statusText,url:a,headers:Object.fromEntries(h.headers),body:E};j(r,o,"GitHub Models",b,c);let k=`GitHub API request failed: ${h.status} ${h.statusText}`;try{const $=JSON.parse(E);$.error?.message?k+=` - ${$.error.message}`:$.message&&(k+=` - ${$.message}`)}catch{E&&(k+=` - ${E}`)}if(h.status===401){const $=new Error("GitHub authentication failed. Please run: aicommit2 github-login");throw $.status=h.status,$.code="AUTHENTICATION_FAILED",$.content=E,$}else if(h.status===403){const $=new Error('GitHub Models access denied. Make sure your token has "Models" permission.');throw $.status=h.status,$.code="ACCESS_DENIED",$.content=E,$}else if(h.status===404){const $=new Error(`Model "${n}" not found. Please check the model name.`);throw $.status=h.status,$.code="MODEL_NOT_FOUND",$.content=E,$}else if(h.status===429){const $=new Error("Rate limit exceeded. Please try again later.");throw $.status=h.status,$.code="RATE_LIMIT_EXCEEDED",$.content=E,$}const P=new Error(k);throw P.status=h.status,P.code="API_ERROR",P.content=E,P}const g=await h.json(),y=Date.now()-p;W(r,o,"GitHub Models",g,c);const v=g.choices?.[0]?.message?.content?.trim();if(!v){j(r,o,"GitHub Models",{message:"No content found in GitHub Models response",result:g},c);const b=new Error("No response content received from GitHub Models");throw b.code="NO_CONTENT",b.content=JSON.stringify(g,null,2),b}return Y(r,o,"GitHub Models",y,v,c),v}catch(p){if(clearTimeout(f),p instanceof Error&&p.name==="AbortError"){const y={message:`GitHub Models request timeout after ${this.params.config.timeout}ms`,error:p};j(r,o,"GitHub Models",y,c);const v=new Error(`GitHub Models request timed out after ${this.params.config.timeout}ms`);throw v.code="REQUEST_TIMEOUT",v.originalError=p,v}if(p.code)throw p;j(r,o,"GitHub Models",{message:"GitHub Models request failed",error:p},c);const g=new Error(`GitHub Models request failed: ${p instanceof Error?p.message:String(p)}`);throw g.code="REQUEST_FAILED",g.originalError=p,g}}}class Wc extends te{constructor(e){super(e),this.params=e,this.colors={primary:"#f55036",secondary:"#fff"},this.serviceName=C.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[Groq]"),this.errorPrefix=C.red.bold("[Groq]"),this.groq=new ts({apiKey:this.params.config.key})}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("API key")||r.includes("api_key")?"Invalid API key. Check your Groq API key in configuration":r.includes("rate_limit")||r.includes("Rate limit")?"Rate limit exceeded. Wait a moment and try again, or upgrade your Groq plan":r.includes("model")||r.includes("Model")?"Model not found or not accessible. Check if the Groq model name is correct":r.includes("overloaded")||r.includes("capacity")?"Groq service is overloaded. Try again in a few minutes":r.includes("403")||r.includes("Forbidden")?"Access denied. Your API key may not have permission for this Groq model":r.includes("404")||r.includes("Not Found")?"Model or endpoint not found. Check your Groq model configuration":r.includes("500")||r.includes("Internal Server Error")?"Groq server error. Try again later":null}generateCommitMessage$(){return L(this.generateMessage("commit")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),N(this.handleError$))}generateCodeReview$(){return L(this.generateMessage("review")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),N(this.handleError$))}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,logging:i,locale:l,temperature:a,generate:d,type:c,maxLength:u}=this.params.config,f=this.params.config.maxTokens,p={...J,locale:l,maxLength:u,type:c,generate:d,systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,vcs_branch:this.params.branchName||""},h=e==="review"?oe(p):re(p),g=`Here is the diff: ${r}`,v=`${this.params.config.url||"https://api.groq.com"}/openai/v1/chat/completions`,E={Authorization:`Bearer ${this.params.config.key}`,"Content-Type":"application/json"};Z(r,e,"Groq",this.params.config.model,v,E,i),ee(r,e,"Groq",h,g,i);const b={messages:[{role:"system",content:h},{role:"user",content:g}],model:this.params.config.model,max_tokens:f,top_p:this.params.config.topP,temperature:a};se(r,e,"Groq",b,i);const k=Date.now();try{const P=await this.groq.chat.completions.create(b,{timeout:this.params.config.timeout}),$=Date.now()-k,M=P.choices[0].message.content||"";return W(r,e,"Groq",P,i),Y(r,e,"Groq",$,M,i),e==="review"?this.sanitizeResponse(M):this.parseMessage(M,c,d)}catch(P){throw j(r,e,"Groq",P,i),P}}}class Yc extends te{constructor(e){super(e),this.params=e,this.headers={},this.models=[],this.currentModelId=null,this.currentConversation=void 0,this.currentConversionID=void 0,this.cookie="",this.colors={primary:"#FED21F",secondary:"#000"},this.serviceName=C.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[HuggingFace]"),this.errorPrefix=C.red.bold("[HuggingFace]"),this.cookie=this.params.config.cookie;const r=this.params.config.url||"https://huggingface.co";this.headers={accept:"*/*","accept-language":"en-US,en;q=0.9","sec-ch-ua":'"Chromium";v="116", "Not)A;Brand";v="24", "Google Chrome";v="116"',"sec-ch-ua-mobile":"?0","sec-ch-ua-platform":'"Windows"',"sec-fetch-dest":"empty","sec-fetch-mode":"cors","sec-fetch-site":"same-origin",origin:r,"Referrer-Policy":"strict-origin-when-cross-origin"}}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("cookie")||r.includes("Cookie")?"Invalid cookie. Check your Hugging Face session cookie in configuration":r.includes("model")||r.includes("Model")?"Model not found or not accessible. Check if the Hugging Face model name is correct":r.includes("conversation")||r.includes("conversion")?"Failed to create conversation. Try again or check your session":r.includes("401")||r.includes("Unauthorized")?"Authentication failed. Your Hugging Face session may have expired":r.includes("403")||r.includes("Forbidden")?"Access denied. You may not have permission to access this model":r.includes("404")||r.includes("Not Found")?"Model not found. Check your Hugging Face model configuration":r.includes("500")||r.includes("Internal Server Error")?"Hugging Face server error. Try again later":r.includes("overloaded")||r.includes("capacity")?"Hugging Face service is overloaded. Try again in a few minutes":null}generateCommitMessage$(){return L(this.generateMessage("commit")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),N(this.handleError$))}generateCodeReview$(){return L(this.generateMessage("review")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),N(this.handleError$))}async generateMessage(e){await this.initialize();const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,logging:i,locale:l,generate:a,type:d,maxLength:c,temperature:u,maxTokens:f,topP:p,timeout:h}=this.params.config,g={...J,locale:l,maxLength:c,type:d,generate:a,systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,vcs_branch:this.params.branchName||""},y=e==="review"?oe(g):re(g),v=`Here is the diff: ${r}`,b=`${this.params.config.url||"https://huggingface.co"}/chat/conversation`,k={...this.headers,cookie:this.cookie};Z(r,e,"HuggingFace",this.params.config.model,b,k,i),ee(r,e,"HuggingFace",y,v,i);const P=Date.now();try{const $=await this.getNewChat(y),A=await(await this.sendMessage(v,$.id)).completeResponsePromise();await this.deleteConversation($.id);const G=Date.now()-P;return W(r,e,"HuggingFace",{response:A},i),Y(r,e,"HuggingFace",G,A,i),e==="review"?this.sanitizeResponse(A):this.parseMessage(A,d,a)}catch($){throw j(r,e,"HuggingFace",$,i),$}}async initialize(){const e=await this.getRemoteLlms(),r=e.find(o=>o.name?.toLowerCase()===this.params.config.model.toLowerCase());if(r){this.currentModel=r,this.currentModelId=r.id;return}this.currentModel=e[0],this.currentModelId=e[0].id}async getRemoteLlms(){const e=this.params.config.url||"https://huggingface.co",r=await fetch(`${e}/chat/__data.json`,{headers:{...this.headers,cookie:this.cookie},body:null,method:"GET"});if(r.status!==200)throw new Error(`Failed to get remote LLMs with status code: ${r.status}`);const n=(await r.json()).nodes[0].data,s=n[n[0].models],i=[],l=a=>a===-1?null:n[a];for(const a of s){const d=n[a];if(n[d.unlisted])continue;const c={id:l(d.id),name:l(d.name),displayName:l(d.displayName),preprompt:l(d.preprompt),promptExamples:[],websiteUrl:l(d.websiteUrl),description:l(d.description),datasetName:l(d.datasetName),datasetUrl:l(d.datasetUrl),modelUrl:l(d.modelUrl),parameters:{}},u=l(d.promptExamples);if(u!==null){const h=u.map(g=>l(g));c.promptExamples=h.map(g=>({title:n[g.title],prompt:n[g.prompt]}))}const f=l(d.parameters),p={};for(const[h,g]of Object.entries(f)){if(g===-1){p[h]=null;continue}if(Array.isArray(n[g])){p[h]=n[g].map(y=>n[y]);continue}p[h]=n[g]}c.parameters=p,i.push(c)}return this.models=i,i}async getNewChat(e){const r={model:this.currentModelId,preprompt:e};let o=0;const n=this.params.config.url||"https://huggingface.co";for(;o<5;){const s=await fetch(`${n}/chat/conversation`,{headers:{...this.headers,"content-type":"application/json",cookie:this.cookie,Referer:`${n}/chat/`},body:JSON.stringify(r),method:"POST"}),{conversationId:i}=await s.json();if(i){this.currentConversionID=i;break}else o++}if(!this.currentConversionID)throw new Error("Failed to create new conversion");return await this.getConversationHistory(this.currentConversionID)}async getConversationHistory(e){if(!e)throw new Error("conversationId is required for getConversationHistory");const r=this.params.config.url||"https://huggingface.co",o=await fetch(`${r}/chat/conversation/${e}/__data.json`,{headers:{...this.headers,cookie:this.cookie,Referer:`${r}/chat/`},body:null,method:"GET"});if(o.status!=200)throw new Error("Unable get conversation details "+o);{const n=await o.json();return this.metadataParser(n,e)}}metadataParser(e,r){const o={id:"",model:"",systemPrompt:"",title:"",history:[]},n=e.nodes[1].data,s=n[n[0].model],i=n[n[0].preprompt],l=n[n[0].title],a=n[n[0].messages],d=[];for(const c of a){const u=n[c],f=new Date(n[u.createdAt][1]).getTime()/1e3,p=new Date(n[u.updatedAt][1]).getTime()/1e3;d.push({id:n[u.id],role:n[u.from],content:n[u.content],createdAt:f,updatedAt:p})}return o.id=r,o.model=s,o.systemPrompt=i,o.title=l,o.history=d,this.currentConversation=o,o}async sendMessage(e,r){if(e==="")throw new Error("the prompt can not be empty.");if(!r&&!this.currentConversionID?await this.getNewChat():r?(this.currentConversionID=r,await this.getConversationHistory(r)):this.currentConversionID&&await this.getConversationHistory(this.currentConversionID),!this.currentConversation)throw new Error("Failed to create new conversion");const o={inputs:e,id:this.currentConversation.history[this.currentConversation.history.length-1].id,is_retry:!1,is_continue:!1,web_search:!1,tools:[]},n=new FormData;n.append("data",JSON.stringify(o));const s=this.params.config.url||"https://huggingface.co",i=new AbortController,l=setTimeout(()=>i.abort(),this.params.config.timeout),a=await fetch(`${s}/chat/conversation/${this.currentConversionID}`,{headers:{...this.headers,cookie:this.cookie,Referer:`${s}/chat/conversation/${this.currentConversionID}`},body:n,method:"POST",signal:i.signal});clearTimeout(l);function d(g){try{const y=g.split(`
|
|
90
|
-
`),v=[];for(const E of y)E.trim()&&v.push(JSON.parse(E));return v}catch{return[{}]}}const c=new TextDecoder;let u="";const f=new TransformStream({async transform(g,y){const v=c.decode(g);try{const E=d(v);for(const b of E)b.type==="finalAnswer"?(u=b?.text||"",y.terminate()):b.type==="stream"&&y.enqueue(b?.token||"")}catch{throw new Error("Error during parsing response")}}}),p=a.body?.pipeThrough(f);async function h(){return new Promise(async(g,y)=>{try{if(!p)y("ModifiedStream undefined");else{const v=p.getReader();for(;;){const{done:E,value:b}=await v.read();if(E){g(u);break}}}}catch(v){y(v)}})}return{id:this.currentConversionID,stream:p,completeResponsePromise:h}}async deleteConversation(e){const r=this.params.config.url||"https://huggingface.co";return(await fetch(`${r}/chat/conversation/${e}`,{headers:{...this.headers,cookie:this.cookie,Referer:`${r}/chat/`},body:null,method:"DELETE"})).json()}}class Jc extends te{constructor(e){super(e),this.params=e,this.apiKey="",this.colors={primary:"#ff7000",secondary:"#fff"},this.serviceName=C.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[MistralAI]"),this.errorPrefix=C.red.bold("[MistralAI]"),this.apiKey=this.params.config.key}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("API key")||r.includes("api_key")?"Invalid API key. Check your Mistral AI API key in configuration":r.includes("quota")||r.includes("usage")?"API quota exceeded. Check your Mistral AI usage limits":r.includes("model")||r.includes("Model")?"Model not found or not accessible. Check if the Mistral model name is correct":r.includes("403")||r.includes("Forbidden")?"Access denied. Your API key may not have permission for this Mistral model":r.includes("404")||r.includes("Not Found")?"Model or endpoint not found. Check your Mistral model configuration":r.includes("500")||r.includes("Internal Server Error")?"Mistral AI server error. Try again later":null}generateCommitMessage$(){return L(this.generateMessage("commit")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),N(this.handleError$))}generateCodeReview$(){return L(this.generateMessage("review")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),N(this.handleError$))}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,logging:i,locale:l,generate:a,type:d,maxLength:c}=this.params.config,u={...J,locale:l,maxLength:c,type:d,generate:a,systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,vcs_branch:this.params.branchName||""},f=e==="review"?oe(u):re(u);await this.checkAvailableModels();const p=`Here is the diff: ${r}`,g=`${this.params.config.url||"https://api.mistral.ai"}/v1/chat/completions`,y={Authorization:`Bearer ${this.apiKey}`,"content-type":"application/json"};Z(r,e,"MistralAI",this.params.config.model,g,y,i),ee(r,e,"MistralAI",f,p,i);const v=await this.createChatCompletions(f,p,e);return e==="review"?this.sanitizeResponse(v):this.parseMessage(v,d,a)}async checkAvailableModels(){if((await this.getAvailableModels()).includes(this.params.config.model))return!0;throw new Error(`Invalid model type of Mistral AI: ${this.params.config.model}`)}async getAvailableModels(){const e=this.params.config.url||"https://api.mistral.ai";return(await new We({method:"GET",baseURL:`${e}/v1/models`,timeout:this.params.config.timeout}).setHeaders({Authorization:`Bearer ${this.apiKey}`,"content-type":"application/json"}).execute()).data.data.filter(o=>o.object==="model").map(o=>o.id)}async createChatCompletions(e,r,o){const n=this.params.stagedDiff.diff,{logging:s}=this.params.config,i={model:this.params.config.model,messages:[{role:"system",content:e},{role:"user",content:r}],temperature:this.params.config.temperature,top_p:this.params.config.topP,max_tokens:this.params.config.maxTokens,stream:!1,safe_prompt:!1,random_seed:pt(10,1e3)};se(n,o,"MistralAI",i,s);const l=Date.now();try{const a=this.params.config.url||"https://api.mistral.ai",d=await new We({method:"POST",baseURL:`${a}/v1/chat/completions`,timeout:this.params.config.timeout}).setHeaders({Authorization:`Bearer ${this.apiKey}`,"content-type":"application/json"}).setBody(i).execute(),c=Date.now()-l,u=d.data;if(W(n,o,"MistralAI",u,s),!u.choices||u.choices.length===0||!u.choices[0].message?.content)throw j(n,o,"MistralAI",{message:"No Content on response",result:u},s),new Error("No Content on response. Please open a Bug report");const p=u.choices[0].message.content;return Y(n,o,"MistralAI",c,p,s),p}catch(a){throw j(n,o,"MistralAI",a,s),a}}}class Vc extends te{constructor(e){super(e),this.params=e,this.host=ar,this.model="",this.key="",this.auth="",this.setupFetch=(r,o={})=>os(r,{...o,dispatcher:new ns({headersTimeout:this.params.config.timeout})}),this.colors={primary:"#FFF",secondary:"#000"},this.model=this.params.keyName,this.serviceName=C.bgHex(this.colors.primary).hex(this.colors.secondary).bold(`[${ft(this.model)}]`),this.errorPrefix=C.red.bold(`[${ft(this.model)}]`),this.host=this.params.config.host||ar,this.auth=this.params.config.auth||"Bearer",this.key=this.params.config.key||"",this.ollama=new rs({host:this.host,fetch:this.setupFetch,...this.key&&{headers:{Authorization:`${this.auth} ${this.key}`}}})}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("ECONNREFUSED")||r.includes("connection")?`Cannot connect to Ollama server at ${this.host}. Make sure Ollama is running`:r.includes("model")||r.includes("Model")?`Model '${this.model}' not found. Pull the model with: ollama pull ${this.model}`:r.includes("401")||r.includes("Unauthorized")?"Authentication failed. Check your Ollama API key if authentication is enabled":r.includes("403")||r.includes("Forbidden")?"Access denied. Check your Ollama server permissions":r.includes("404")||r.includes("Not Found")?`Model '${this.model}' not found on Ollama server. Pull it first with: ollama pull ${this.model}`:r.includes("500")||r.includes("Internal Server Error")?"Ollama server error. Check server logs and try again":r.includes("overloaded")||r.includes("capacity")?"Ollama server is overloaded. Try again in a few minutes":null}generateCommitMessage$(){return L(this.generateMessage("commit")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),N(this.handleError$))}generateCodeReview$(){return L(this.generateMessage("review")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),N(this.handleError$))}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,logging:i,locale:l,generate:a,type:d,maxLength:c}=this.params.config,u={...J,locale:l,maxLength:c,type:d,generate:a,systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,vcs_branch:this.params.branchName||""},f=e==="review"?oe(u):re(u);await this.checkIsAvailableOllama();const p=`Here is the diff: ${r}`,h=`Ollama_${this.model}`,g=`${this.host}/api/chat`,y=this.key?{Authorization:`${this.auth} ${this.key}`}:{};Z(r,e,h,this.model,g,y,i),ee(r,e,h,f,p,i);const v=await this.createChatCompletions(f,p,e);return e==="review"?this.sanitizeResponse(v):this.parseMessage(v,d,a)}async checkIsAvailableOllama(){const e=new We({method:"GET",baseURL:`${this.host}`,timeout:this.params.config.timeout});return this.key&&e.setHeaders({Authorization:`${this.auth} ${this.key}`}),(await e.execute()).data}async createChatCompletions(e,r,o){const{stream:n,numCtx:s,temperature:i,topP:l,timeout:a,maxTokens:d,logging:c}=this.params.config,u=n||!1,f=this.params.stagedDiff.diff,p=`Ollama_${this.model}`,h={model:this.model,messages:[{role:"system",content:e},{role:"user",content:r}],stream:u,keep_alive:a,options:{num_ctx:s,temperature:i,top_p:l,seed:pt(10,1e3),num_predict:d??-1}};se(f,o,p,h,c);const g=Date.now();try{const y=await this.ollama.chat(h),v=Date.now()-g;let E="";if(u){if(y)for await(const b of y)E+=b.message.content}else E=y.message.content;return W(f,o,p,{response:E,fullResponse:y},c),Y(f,o,p,v,E,c),E}catch(y){throw j(f,o,p,y,c),y}}}class qc extends te{constructor(e){super(e),this.params=e;const r=this.params.keyName||"OPENAI_COMPATIBLE";this.colors=Ta(r),this.serviceName=C.bgHex(this.colors.primary).hex(this.colors.secondary).bold(`[${ft(r)}]`),this.errorPrefix=C.red.bold(`[${ft(r)}]`),this.openAI=new qr({apiKey:this.params.config.key,baseURL:`${this.params.config.url}${this.params.config.path}`})}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("API key")||r.includes("api_key")?"Invalid API key. Check your OpenAI-compatible API key in configuration":r.includes("rate_limit")||r.includes("Rate limit")?"Rate limit exceeded. Wait a moment and try again, or check your service limits":r.includes("model")||r.includes("Model")?"Model not found or not accessible. Check if the model name is correct":r.includes("network")||r.includes("connection")?"Network error. Check your internet connection and API endpoint":r.includes("quota")||r.includes("usage")?"API quota exceeded. Check your usage limits":r.includes("403")||r.includes("Forbidden")?"Access denied. Your API key may not have permission for this model":r.includes("404")||r.includes("Not Found")?"Model or endpoint not found. Check your API configuration":r.includes("500")||r.includes("Internal Server Error")?"Server error. Try again later":r.includes("overloaded")||r.includes("capacity")?"Service is overloaded. Try again in a few minutes":null}generateCommitMessage$(){return L(this.generateMessage("commit")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),N(this.handleError$))}generateCodeReview$(){return L(this.generateMessage("review")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),N(this.handleError$))}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,logging:i,locale:l,temperature:a,generate:d,type:c,maxLength:u,timeout:f,stream:p=!1}=this.params.config,h=this.params.config.maxTokens,g={...J,locale:l,maxLength:u,type:c,generate:d,systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,vcs_branch:this.params.branchName||""},y=e==="review"?oe(g):re(g),v=`Here is the diff: ${r}`,E=this.params.keyName||"OpenAI-Compatible",b=`${this.params.config.url}${this.params.config.path}`,k={Authorization:`Bearer ${this.params.config.key}`,"Content-Type":"application/json"};Z(r,e,E,this.params.config.model,b,k,i),ee(r,e,E,y,v,i);const P=kr(this.params.config.model),$={messages:[{role:"system",content:y},{role:"user",content:v}],model:this.params.config.model,stream:p,...P?{max_completion_tokens:h,temperature:1}:{max_tokens:h,top_p:this.params.config.topP,temperature:a}};se(r,e,E,$,i);const M=Date.now();try{const A=await this.openAI.chat.completions.create($,{timeout:f});let G="";if(p&&A){const fe=A;for await(const q of fe){const Mt=q.choices?.[0]?.delta?.content||"",B=q.choices?.[0]?.delta?.reasoning_content||"",ne=`${Mt}${B}`;G+=ne}}else G=A.choices?.[0]?.message.content||"";const R=Date.now()-M;return W(r,e,E,A,i),Y(r,e,E,R,G,i),e==="review"?this.sanitizeResponse(G):this.parseMessage(G,c,d)}catch(A){throw j(r,e,E,A,i),A}}}class Xc extends te{constructor(e){super(e),this.params=e,this.colors={primary:"#74AA9C",secondary:"#FFF"},this.serviceName=C.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[ChatGPT]"),this.errorPrefix=C.red.bold("[ChatGPT]")}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("API key")?"Invalid API key. Check your OpenAI API key in configuration":r.includes("quota")?"API quota exceeded. Check your OpenAI usage limits":r.includes("500")?"OpenAI server error. Try again later":null}generateCommitMessage$(){return L(this.generateMessage("commit")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),N(this.handleError$))}generateCodeReview$(){return L(this.generateMessage("review")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),N(this.handleError$))}extractJSONFromError(e){const r=/[{[]{1}([,:{}[\]0-9.\-+Eaeflnr-u \n\r\t]|".*?")+[}\]]{1}/gis,o=e.match(r);return o?Object.assign({},...o.map(n=>JSON.parse(n))):{error:{message:"Unknown error"}}}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,temperature:i,logging:l,locale:a,generate:d,type:c,maxLength:u,proxy:f,maxTokens:p,timeout:h}=this.params.config,g={...J,locale:a,maxLength:u,type:c,generate:d,systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,vcs_branch:this.params.branchName||""},y=e==="review"?oe(g):re(g),v=await zc("ChatGPT",this.params.config.url,this.params.config.path,this.params.config.key,this.params.config.model,r,h,p,i,this.params.config.topP,y,l,e,f);return ht(e==="review"?v.map(E=>this.sanitizeResponse(E)):v.map(E=>this.parseMessage(E,c,d)))}}class Qc extends te{constructor(e){super(e),this.params=e,this.apiKey="",this.colors={primary:"#20808D",secondary:"#FFF"},this.serviceName=C.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[Perplexity]"),this.errorPrefix=C.red.bold("[Perplexity]"),this.apiKey=this.params.config.key}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("API key")||r.includes("api_key")?"Invalid API key. Check your Perplexity API key in configuration":r.includes("rate_limit")||r.includes("Rate limit")?"Rate limit exceeded. Wait a moment and try again, or upgrade your Perplexity plan":r.includes("model")||r.includes("Model")?"Model not found or not accessible. Check if the Perplexity model name is correct":r.includes("overloaded")||r.includes("capacity")?"Perplexity service is overloaded. Try again in a few minutes":r.includes("403")||r.includes("Forbidden")?"Access denied. Your API key may not have permission for this Perplexity model":r.includes("404")||r.includes("Not Found")?"Model or endpoint not found. Check your Perplexity model configuration":r.includes("500")||r.includes("Internal Server Error")?"Perplexity server error. Try again later":null}generateCommitMessage$(){return L(this.generateMessage("commit")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),N(this.handleError$))}generateCodeReview$(){return L(this.generateMessage("review")).pipe(F(e=>D(e)),O(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),N(this.handleError$))}extractJSONFromError(e){const r=/[{[]{1}([,:{}[\]0-9.\-+Eaeflnr-u \n\r\t]|".*?")+[}\]]{1}/gis,o=e.match(r);return o?Object.assign({},...o.map(n=>JSON.parse(n))):{error:{message:"Unknown error"}}}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,logging:i,locale:l,generate:a,type:d,maxLength:c}=this.params.config,u={...J,locale:l,maxLength:c,type:d,generate:a,systemPrompt:o,systemPromptPath:n,codeReviewPromptPath:s,vcs_branch:this.params.branchName||""},f=e==="review"?oe(u):re(u),p=`Here is the diff: ${r}`,g=`${this.params.config.url||"https://api.perplexity.ai"}/chat/completions`,y={Authorization:`Bearer ${this.apiKey}`,"content-type":"application/json"};Z(r,e,"Perplexity",this.params.config.model,g,y,i),ee(r,e,"Perplexity",f,p,i);const v=await this.createChatCompletions(f,p,e);return this.parseMessage(v,d,a)}async createChatCompletions(e,r,o){const n=this.params.stagedDiff.diff,{logging:s}=this.params.config,i={model:this.params.config.model,messages:[{role:"system",content:e},{role:"user",content:r}],temperature:this.params.config.temperature,top_p:this.params.config.topP,max_tokens:this.params.config.maxTokens,stream:!1};se(n,o,"Perplexity",i,s);const l=Date.now();try{const a=this.params.config.url||"https://api.perplexity.ai",d=await new We({method:"POST",baseURL:`${a}/chat/completions`,timeout:this.params.config.timeout}).setHeaders({Authorization:`Bearer ${this.apiKey}`,"content-type":"application/json"}).setBody(i).execute(),c=Date.now()-l,u=d.data;if(W(n,o,"Perplexity",u,s),!u.choices||u.choices.length===0||!u.choices[0].message?.content)throw j(n,o,"Perplexity",{message:"No Content on response",result:u},s),new Error("No Content on response. Please open a Bug report");const p=u.choices[0].message.content;return Y(n,o,"Perplexity",c,p,s),p}catch(a){throw j(n,o,"Perplexity",a,s),a}}}class Et{constructor(e,r,o=""){this.config=e,this.stagedDiff=r,this.branchName=o}createCommitMsgRequests$(e){return this.createServiceRequests$(e,"commit")}createCodeReviewRequests$(e){return this.createServiceRequests$(e,"review")}createServiceRequests$(e,r){return D(e).pipe(Kr(o=>{const n=this.config[o],s=Array.isArray(n.model)?n.model:[n.model];return D(s).pipe(Kr(i=>{if(n.compatible){const l=Q.create(qc,{config:{...n,url:n.url||"",path:n.path||"",model:i},stagedDiff:this.stagedDiff,keyName:i,branchName:this.branchName});return r==="commit"?l.generateCommitMessage$():l.generateCodeReview$()}switch(o){case"OPENAI":{const a=Q.create(Xc,{config:{...this.config.OPENAI,model:i},stagedDiff:this.stagedDiff,keyName:i,branchName:this.branchName});return r==="commit"?a.generateCommitMessage$():a.generateCodeReview$()}case"GEMINI":{const a=Q.create(mc,{config:{...this.config.GEMINI,model:i},stagedDiff:this.stagedDiff,keyName:i,branchName:this.branchName});return r==="commit"?a.generateCommitMessage$():a.generateCodeReview$()}case"ANTHROPIC":{const a=Q.create(ic,{config:{...this.config.ANTHROPIC,model:i},stagedDiff:this.stagedDiff,keyName:i,branchName:this.branchName});return r==="commit"?a.generateCommitMessage$():a.generateCodeReview$()}case"HUGGINGFACE":{const a=Q.create(Yc,{config:{...this.config.HUGGINGFACE,model:i},stagedDiff:this.stagedDiff,keyName:i,branchName:this.branchName});return r==="commit"?a.generateCommitMessage$():a.generateCodeReview$()}case"MISTRAL":{const a=Q.create(Jc,{config:{...this.config.MISTRAL,model:i},stagedDiff:this.stagedDiff,keyName:i,branchName:this.branchName});return r==="commit"?a.generateCommitMessage$():a.generateCodeReview$()}case"CODESTRAL":{const a=Q.create(lc,{config:{...this.config.CODESTRAL,model:i},stagedDiff:this.stagedDiff,keyName:i,branchName:this.branchName});return r==="commit"?a.generateCommitMessage$():a.generateCodeReview$()}case"OLLAMA":{const a=Q.create(Vc,{config:{...this.config.OLLAMA,model:i},keyName:i,stagedDiff:this.stagedDiff,branchName:this.branchName});return r==="commit"?a.generateCommitMessage$():a.generateCodeReview$()}case"COHERE":{const a=Q.create(uc,{config:{...this.config.COHERE,model:i},stagedDiff:this.stagedDiff,keyName:i,branchName:this.branchName});return r==="commit"?a.generateCommitMessage$():a.generateCodeReview$()}case"GROQ":{const a=Q.create(Wc,{config:{...this.config.GROQ,model:i},stagedDiff:this.stagedDiff,keyName:i,branchName:this.branchName});return r==="commit"?a.generateCommitMessage$():a.generateCodeReview$()}case"PERPLEXITY":{const a=Q.create(Qc,{config:{...this.config.PERPLEXITY,model:i},stagedDiff:this.stagedDiff,keyName:i,branchName:this.branchName});return r==="commit"?a.generateCommitMessage$():a.generateCodeReview$()}case"BEDROCK":{const a=Q.create(cc,{config:{...this.config.BEDROCK,model:i},stagedDiff:this.stagedDiff,keyName:i});return r==="commit"?a.generateCommitMessage$():a.generateCodeReview$()}case"GITHUB_MODELS":{const a=Q.create(Kc,{config:{...this.config.GITHUB_MODELS,model:i},stagedDiff:this.stagedDiff,keyName:i,branchName:this.branchName});return r==="commit"?a.generateCommitMessage$():a.generateCodeReview$()}case"DEEPSEEK":{const a=Q.create(dc,{config:{...this.config.DEEPSEEK,model:i},stagedDiff:this.stagedDiff,keyName:i,branchName:this.branchName});return r==="commit"?a.generateCommitMessage$():a.generateCodeReview$()}default:const l=C.red.bold(`[${o}]`);return Ot({name:l+" Invalid AI type",value:"Invalid AI type",isError:!0,disabled:!0})}}))}),N(o=>{const n=C.red.bold("[UNKNOWN]");return Ot({name:n+` ${o.message||""}`,value:"Unknown error",isError:!0,disabled:!0})}))}}class Sr{getDetectedMessage(e){return`Detected ${e.files.length.toLocaleString()} changed file${e.files.length>1?"s":""} (${e.diff.length.toLocaleString()} characters)`}getDetectedFiles(e){return`Detected ${e.length.toLocaleString()} changed file${e.length>1?"s":""}`}}class Pt extends Sr{constructor(){super(...arguments),this.name="git",this.excludeFromDiff=e=>`:(exclude)${e}`,this.filesToExclude=["package-lock.json","pnpm-lock.yaml","*.lock","*.lockb"].map(this.excludeFromDiff)}async assertRepo(){try{const{stdout:e}=await S("git",["rev-parse","--show-toplevel"],{reject:!0});return e.trim()}catch(e){const r=e;if(r.code==="ENOENT")throw new w(`Git command not found!
|
|
106
|
+
${r}`,l),ne(r,o,"GitHub Models",a,l);const u=new AbortController,p=setTimeout(()=>u.abort(),this.params.config.timeout);try{const f=Date.now(),h=await fetch(c,{method:"POST",headers:d,body:JSON.stringify(a),signal:u.signal});if(clearTimeout(p),!h.ok){const b=await h.text(),E={status:h.status,statusText:h.statusText,url:c,headers:Object.fromEntries(h.headers),body:b};G(r,o,"GitHub Models",E,l);let k=`GitHub API request failed: ${h.status} ${h.statusText}`;try{const P=JSON.parse(b);P.error?.message?k+=` - ${P.error.message}`:P.message&&(k+=` - ${P.message}`)}catch{b&&(k+=` - ${b}`)}if(h.status===401){const P=new Error("GitHub authentication failed. Please run: aicommit2 github-login");throw P.status=h.status,P.code="AUTHENTICATION_FAILED",P.content=b,P}else if(h.status===403){const P=new Error('GitHub Models access denied. Make sure your token has "Models" permission.');throw P.status=h.status,P.code="ACCESS_DENIED",P.content=b,P}else if(h.status===404){const P=new Error(`Model "${s}" not found. Please check the model name.`);throw P.status=h.status,P.code="MODEL_NOT_FOUND",P.content=b,P}else if(h.status===429){const P=new Error("Rate limit exceeded. Please try again later.");throw P.status=h.status,P.code="RATE_LIMIT_EXCEEDED",P.content=b,P}const $=new Error(k);throw $.status=h.status,$.code="API_ERROR",$.content=b,$}const y=await h.json(),w=Date.now()-f;V(r,o,"GitHub Models",y,l);const C=y.choices?.[0]?.message?.content?.trim();if(!C){G(r,o,"GitHub Models",{message:"No content found in GitHub Models response",result:y},l);const E=new Error("No response content received from GitHub Models");throw E.code="NO_CONTENT",E.content=JSON.stringify(y,null,2),E}return q(r,o,"GitHub Models",w,C,l),C}catch(f){if(clearTimeout(p),f instanceof Error&&f.name==="AbortError"){const w={message:`GitHub Models request timeout after ${this.params.config.timeout}ms`,error:f};G(r,o,"GitHub Models",w,l);const C=new Error(`GitHub Models request timed out after ${this.params.config.timeout}ms`);throw C.code="REQUEST_TIMEOUT",C.originalError=f,C}if(f.code)throw f;G(r,o,"GitHub Models",{message:"GitHub Models request failed",error:f},l);const y=new Error(`GitHub Models request failed: ${f instanceof Error?f.message:String(f)}`);throw y.code="REQUEST_FAILED",y.originalError=f,y}}}class fl extends re{constructor(e){super(e),this.params=e,this.colors={primary:"#f55036",secondary:"#fff"},this.serviceName=g.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[Groq]"),this.errorPrefix=g.red.bold("[Groq]"),this.groq=new gn({apiKey:this.params.config.key})}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("API key")||r.includes("api_key")?"Invalid API key. Check your Groq API key in configuration":r.includes("rate_limit")||r.includes("Rate limit")?"Rate limit exceeded. Wait a moment and try again, or upgrade your Groq plan":r.includes("model")||r.includes("Model")?"Model not found or not accessible. Check if the Groq model name is correct":r.includes("overloaded")||r.includes("capacity")?"Groq service is overloaded. Try again in a few minutes":r.includes("403")||r.includes("Forbidden")?"Access denied. Your API key may not have permission for this Groq model":r.includes("404")||r.includes("Not Found")?"Model or endpoint not found. Check your Groq model configuration":r.includes("500")||r.includes("Internal Server Error")?"Groq server error. Try again later":null}generateCommitMessage$(){return j(this.generateMessage("commit")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),L(this.handleError$))}generateCodeReview$(){return j(this.generateMessage("review")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),L(this.handleError$))}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,logging:i,locale:a,temperature:c,generate:d,type:l,maxLength:u}=this.params.config,p=this.params.config.maxTokens,f={...J,locale:a,maxLength:u,type:l,generate:d,systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,vcs_branch:this.params.branchName||""},h=e==="review"?se(f):oe(f),y=`Here is the diff: ${r}`,C=`${this.params.config.url||"https://api.groq.com"}/openai/v1/chat/completions`,b={Authorization:`Bearer ${this.params.config.key}`,"Content-Type":"application/json"};ee(r,e,"Groq",this.params.config.model,C,b,i),te(r,e,"Groq",h,y,i);const E={messages:[{role:"system",content:h},{role:"user",content:y}],model:this.params.config.model,max_tokens:p,top_p:this.params.config.topP,temperature:c};ne(r,e,"Groq",E,i);const k=Date.now();try{const $=await this.groq.chat.completions.create(E,{timeout:this.params.config.timeout}),P=Date.now()-k,O=$.choices[0].message.content||"";return V(r,e,"Groq",$,i),q(r,e,"Groq",P,O,i),e==="review"?this.sanitizeResponse(O):this.parseMessage(O,l,d)}catch($){throw G(r,e,"Groq",$,i),$}}}class hl extends re{constructor(e){super(e),this.params=e,this.headers={},this.models=[],this.currentModelId=null,this.currentConversation=void 0,this.currentConversionID=void 0,this.cookie="",this.colors={primary:"#FED21F",secondary:"#000"},this.serviceName=g.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[HuggingFace]"),this.errorPrefix=g.red.bold("[HuggingFace]"),this.cookie=this.params.config.cookie;const r=this.params.config.url||"https://huggingface.co";this.headers={accept:"*/*","accept-language":"en-US,en;q=0.9","sec-ch-ua":'"Chromium";v="116", "Not)A;Brand";v="24", "Google Chrome";v="116"',"sec-ch-ua-mobile":"?0","sec-ch-ua-platform":'"Windows"',"sec-fetch-dest":"empty","sec-fetch-mode":"cors","sec-fetch-site":"same-origin",origin:r,"Referrer-Policy":"strict-origin-when-cross-origin"}}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("cookie")||r.includes("Cookie")?"Invalid cookie. Check your Hugging Face session cookie in configuration":r.includes("model")||r.includes("Model")?"Model not found or not accessible. Check if the Hugging Face model name is correct":r.includes("conversation")||r.includes("conversion")?"Failed to create conversation. Try again or check your session":r.includes("401")||r.includes("Unauthorized")?"Authentication failed. Your Hugging Face session may have expired":r.includes("403")||r.includes("Forbidden")?"Access denied. You may not have permission to access this model":r.includes("404")||r.includes("Not Found")?"Model not found. Check your Hugging Face model configuration":r.includes("500")||r.includes("Internal Server Error")?"Hugging Face server error. Try again later":r.includes("overloaded")||r.includes("capacity")?"Hugging Face service is overloaded. Try again in a few minutes":null}generateCommitMessage$(){return j(this.generateMessage("commit")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),L(this.handleError$))}generateCodeReview$(){return j(this.generateMessage("review")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),L(this.handleError$))}async generateMessage(e){await this.initialize();const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,logging:i,locale:a,generate:c,type:d,maxLength:l,temperature:u,maxTokens:p,topP:f,timeout:h}=this.params.config,y={...J,locale:a,maxLength:l,type:d,generate:c,systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,vcs_branch:this.params.branchName||""},w=e==="review"?se(y):oe(y),C=`Here is the diff: ${r}`,E=`${this.params.config.url||"https://huggingface.co"}/chat/conversation`,k={...this.headers,cookie:this.cookie};ee(r,e,"HuggingFace",this.params.config.model,E,k,i),te(r,e,"HuggingFace",w,C,i);const $=Date.now();try{const P=await this.getNewChat(w),S=await(await this.sendMessage(C,P.id)).completeResponsePromise();await this.deleteConversation(P.id);const U=Date.now()-$;return V(r,e,"HuggingFace",{response:S},i),q(r,e,"HuggingFace",U,S,i),e==="review"?this.sanitizeResponse(S):this.parseMessage(S,d,c)}catch(P){throw G(r,e,"HuggingFace",P,i),P}}async initialize(){const e=await this.getRemoteLlms(),r=e.find(o=>o.name?.toLowerCase()===this.params.config.model.toLowerCase());if(r){this.currentModel=r,this.currentModelId=r.id;return}this.currentModel=e[0],this.currentModelId=e[0].id}async getRemoteLlms(){const e=this.params.config.url||"https://huggingface.co",r=await fetch(`${e}/chat/__data.json`,{headers:{...this.headers,cookie:this.cookie},body:null,method:"GET"});if(r.status!==200)throw new Error(`Failed to get remote LLMs with status code: ${r.status}`);const s=(await r.json()).nodes[0].data,n=s[s[0].models],i=[],a=c=>c===-1?null:s[c];for(const c of n){const d=s[c];if(s[d.unlisted])continue;const l={id:a(d.id),name:a(d.name),displayName:a(d.displayName),preprompt:a(d.preprompt),promptExamples:[],websiteUrl:a(d.websiteUrl),description:a(d.description),datasetName:a(d.datasetName),datasetUrl:a(d.datasetUrl),modelUrl:a(d.modelUrl),parameters:{}},u=a(d.promptExamples);if(u!==null){const h=u.map(y=>a(y));l.promptExamples=h.map(y=>({title:s[y.title],prompt:s[y.prompt]}))}const p=a(d.parameters),f={};for(const[h,y]of Object.entries(p)){if(y===-1){f[h]=null;continue}if(Array.isArray(s[y])){f[h]=s[y].map(w=>s[w]);continue}f[h]=s[y]}l.parameters=f,i.push(l)}return this.models=i,i}async getNewChat(e){const r={model:this.currentModelId,preprompt:e};let o=0;const s=this.params.config.url||"https://huggingface.co";for(;o<5;){const n=await fetch(`${s}/chat/conversation`,{headers:{...this.headers,"content-type":"application/json",cookie:this.cookie,Referer:`${s}/chat/`},body:JSON.stringify(r),method:"POST"}),{conversationId:i}=await n.json();if(i){this.currentConversionID=i;break}else o++}if(!this.currentConversionID)throw new Error("Failed to create new conversion");return await this.getConversationHistory(this.currentConversionID)}async getConversationHistory(e){if(!e)throw new Error("conversationId is required for getConversationHistory");const r=this.params.config.url||"https://huggingface.co",o=await fetch(`${r}/chat/conversation/${e}/__data.json`,{headers:{...this.headers,cookie:this.cookie,Referer:`${r}/chat/`},body:null,method:"GET"});if(o.status!=200)throw new Error("Unable get conversation details "+o);{const s=await o.json();return this.metadataParser(s,e)}}metadataParser(e,r){const o={id:"",model:"",systemPrompt:"",title:"",history:[]},s=e.nodes[1].data,n=s[s[0].model],i=s[s[0].preprompt],a=s[s[0].title],c=s[s[0].messages],d=[];for(const l of c){const u=s[l],p=new Date(s[u.createdAt][1]).getTime()/1e3,f=new Date(s[u.updatedAt][1]).getTime()/1e3;d.push({id:s[u.id],role:s[u.from],content:s[u.content],createdAt:p,updatedAt:f})}return o.id=r,o.model=n,o.systemPrompt=i,o.title=a,o.history=d,this.currentConversation=o,o}async sendMessage(e,r){if(e==="")throw new Error("the prompt can not be empty.");if(!r&&!this.currentConversionID?await this.getNewChat():r?(this.currentConversionID=r,await this.getConversationHistory(r)):this.currentConversionID&&await this.getConversationHistory(this.currentConversionID),!this.currentConversation)throw new Error("Failed to create new conversion");const o={inputs:e,id:this.currentConversation.history[this.currentConversation.history.length-1].id,is_retry:!1,is_continue:!1,web_search:!1,tools:[]},s=new FormData;s.append("data",JSON.stringify(o));const n=this.params.config.url||"https://huggingface.co",i=new AbortController,a=setTimeout(()=>i.abort(),this.params.config.timeout),c=await fetch(`${n}/chat/conversation/${this.currentConversionID}`,{headers:{...this.headers,cookie:this.cookie,Referer:`${n}/chat/conversation/${this.currentConversionID}`},body:s,method:"POST",signal:i.signal});clearTimeout(a);function d(y){try{const w=y.split(`
|
|
107
|
+
`),C=[];for(const b of w)b.trim()&&C.push(JSON.parse(b));return C}catch{return[{}]}}const l=new TextDecoder;let u="";const p=new TransformStream({async transform(y,w){const C=l.decode(y);try{const b=d(C);for(const E of b)E.type==="finalAnswer"?(u=E?.text||"",w.terminate()):E.type==="stream"&&w.enqueue(E?.token||"")}catch{throw new Error("Error during parsing response")}}}),f=c.body?.pipeThrough(p);async function h(){return new Promise(async(y,w)=>{try{if(!f)w("ModifiedStream undefined");else{const C=f.getReader();for(;;){const{done:b,value:E}=await C.read();if(b){y(u);break}}}}catch(C){w(C)}})}return{id:this.currentConversionID,stream:f,completeResponsePromise:h}}async deleteConversation(e){const r=this.params.config.url||"https://huggingface.co";return(await fetch(`${r}/chat/conversation/${e}`,{headers:{...this.headers,cookie:this.cookie,Referer:`${r}/chat/`},body:null,method:"DELETE"})).json()}}class gl extends re{constructor(e){super(e),this.params=e,this.apiKey="",this.colors={primary:"#ff7000",secondary:"#fff"},this.serviceName=g.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[MistralAI]"),this.errorPrefix=g.red.bold("[MistralAI]"),this.apiKey=this.params.config.key}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("API key")||r.includes("api_key")?"Invalid API key. Check your Mistral AI API key in configuration":r.includes("quota")||r.includes("usage")?"API quota exceeded. Check your Mistral AI usage limits":r.includes("model")||r.includes("Model")?"Model not found or not accessible. Check if the Mistral model name is correct":r.includes("403")||r.includes("Forbidden")?"Access denied. Your API key may not have permission for this Mistral model":r.includes("404")||r.includes("Not Found")?"Model or endpoint not found. Check your Mistral model configuration":r.includes("500")||r.includes("Internal Server Error")?"Mistral AI server error. Try again later":null}generateCommitMessage$(){return j(this.generateMessage("commit")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),L(this.handleError$))}generateCodeReview$(){return j(this.generateMessage("review")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),L(this.handleError$))}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,logging:i,locale:a,generate:c,type:d,maxLength:l}=this.params.config,u={...J,locale:a,maxLength:l,type:d,generate:c,systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,vcs_branch:this.params.branchName||""},p=e==="review"?se(u):oe(u);await this.checkAvailableModels();const f=`Here is the diff: ${r}`,y=`${this.params.config.url||"https://api.mistral.ai"}/v1/chat/completions`,w={Authorization:`Bearer ${this.apiKey}`,"content-type":"application/json"};ee(r,e,"MistralAI",this.params.config.model,y,w,i),te(r,e,"MistralAI",p,f,i);const C=await this.createChatCompletions(p,f,e);return e==="review"?this.sanitizeResponse(C):this.parseMessage(C,d,c)}async checkAvailableModels(){if((await this.getAvailableModels()).includes(this.params.config.model))return!0;throw new Error(`Invalid model type of Mistral AI: ${this.params.config.model}`)}async getAvailableModels(){const e=this.params.config.url||"https://api.mistral.ai";return(await new Ne({method:"GET",baseURL:`${e}/v1/models`,timeout:this.params.config.timeout}).setHeaders({Authorization:`Bearer ${this.apiKey}`,"content-type":"application/json"}).execute()).data.data.filter(o=>o.object==="model").map(o=>o.id)}async createChatCompletions(e,r,o){const s=this.params.stagedDiff.diff,{logging:n}=this.params.config,i={model:this.params.config.model,messages:[{role:"system",content:e},{role:"user",content:r}],temperature:this.params.config.temperature,top_p:this.params.config.topP,max_tokens:this.params.config.maxTokens,stream:!1,safe_prompt:!1,random_seed:wt(10,1e3)};ne(s,o,"MistralAI",i,n);const a=Date.now();try{const c=this.params.config.url||"https://api.mistral.ai",d=await new Ne({method:"POST",baseURL:`${c}/v1/chat/completions`,timeout:this.params.config.timeout}).setHeaders({Authorization:`Bearer ${this.apiKey}`,"content-type":"application/json"}).setBody(i).execute(),l=Date.now()-a,u=d.data;if(V(s,o,"MistralAI",u,n),!u.choices||u.choices.length===0||!u.choices[0].message?.content)throw G(s,o,"MistralAI",{message:"No Content on response",result:u},n),new Error("No Content on response. Please open a Bug report");const f=u.choices[0].message.content;return q(s,o,"MistralAI",l,f,n),f}catch(c){throw G(s,o,"MistralAI",c,n),c}}}class yl extends re{constructor(e){super(e),this.params=e,this.host=bt,this.model="",this.key="",this.auth="",this.setupFetch=(r,o={})=>wn(r,{...o,dispatcher:new vn({headersTimeout:this.params.config.timeout})}),this.colors={primary:"#FFF",secondary:"#000"},this.model=this.params.keyName,this.serviceName=g.bgHex(this.colors.primary).hex(this.colors.secondary).bold(`[${yt(this.model)}]`),this.errorPrefix=g.red.bold(`[${yt(this.model)}]`),this.host=this.params.config.host||bt,this.auth=this.params.config.auth||"Bearer",this.key=this.params.config.key||"",this.ollama=new yn({host:this.host,fetch:this.setupFetch,...this.key&&{headers:{Authorization:`${this.auth} ${this.key}`}}})}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("ECONNREFUSED")||r.includes("connection refused")?ie.ollamaNotRunning():r.includes("model")&&(r.includes("not found")||r.includes("404"))?ie.ollamaModelNotPulled(this.model):null}generateCommitMessage$(){return j(this.generateMessage("commit")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),L(this.handleError$))}generateCodeReview$(){return j(this.generateMessage("review")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),L(this.handleError$))}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,logging:i,locale:a,generate:c,type:d,maxLength:l}=this.params.config,u={...J,locale:a,maxLength:l,type:d,generate:c,systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,vcs_branch:this.params.branchName||""},p=e==="review"?se(u):oe(u);await this.checkIsAvailableOllama();const f=`Here is the diff: ${r}`,h=`Ollama_${this.model}`,y=`${this.host}/api/chat`,w=this.key?{Authorization:`${this.auth} ${this.key}`}:{};ee(r,e,h,this.model,y,w,i),te(r,e,h,p,f,i);const C=await this.createChatCompletions(p,f,e);return e==="review"?this.sanitizeResponse(C):this.parseMessage(C,d,c)}async checkIsAvailableOllama(){const e=new Ne({method:"GET",baseURL:`${this.host}`,timeout:this.params.config.timeout});return this.key&&e.setHeaders({Authorization:`${this.auth} ${this.key}`}),(await e.execute()).data}async createChatCompletions(e,r,o){const{stream:s,numCtx:n,temperature:i,topP:a,timeout:c,maxTokens:d,logging:l}=this.params.config,u=s||!1,p=this.params.stagedDiff.diff,f=`Ollama_${this.model}`,h={model:this.model,messages:[{role:"system",content:e},{role:"user",content:r}],stream:u,keep_alive:c,options:{num_ctx:n,temperature:i,top_p:a,seed:wt(10,1e3),num_predict:d??-1}};ne(p,o,f,h,l);const y=Date.now();try{const w=await this.ollama.chat(h),C=Date.now()-y;let b="";if(u){if(w)for await(const E of w)b+=E.message.content}else b=w.message.content;return V(p,o,f,{response:b,fullResponse:w},l),q(p,o,f,C,b,l),b}catch(w){throw G(p,o,f,w,l),w}}}class wl extends re{constructor(e){super(e),this.params=e,this.colors={primary:"#74AA9C",secondary:"#FFF"},this.serviceName=g.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[ChatGPT]"),this.errorPrefix=g.red.bold("[ChatGPT]")}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("API key")?"Invalid API key. Check your OpenAI API key in configuration":r.includes("quota")?"API quota exceeded. Check your OpenAI usage limits":r.includes("500")?"OpenAI server error. Try again later":null}generateCommitMessage$(){return j(this.generateMessage("commit")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),L(this.handleError$))}generateCodeReview$(){return j(this.generateMessage("review")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),L(this.handleError$))}extractJSONFromError(e){const r=/[{[]{1}([,:{}[\]0-9.\-+Eaeflnr-u \n\r\t]|".*?")+[}\]]{1}/gis,o=e.match(r);return o?Object.assign({},...o.map(s=>JSON.parse(s))):{error:{message:"Unknown error"}}}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,temperature:i,logging:a,locale:c,generate:d,type:l,maxLength:u,proxy:p,maxTokens:f,timeout:h}=this.params.config,y={...J,locale:c,maxLength:u,type:l,generate:d,systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,vcs_branch:this.params.branchName||""},w=e==="review"?se(y):oe(y),C=await tl("ChatGPT",this.params.config.url,this.params.config.path,this.params.config.key,this.params.config.model,r,h,f,i,this.params.config.topP,w,a,e,p);return vt(e==="review"?C.map(b=>this.sanitizeResponse(b)):C.map(b=>this.parseMessage(b,l,d)))}}class vl extends re{constructor(e){super(e),this.params=e,this.apiKey="",this.colors={primary:"#20808D",secondary:"#FFF"},this.serviceName=g.bgHex(this.colors.primary).hex(this.colors.secondary).bold("[Perplexity]"),this.errorPrefix=g.red.bold("[Perplexity]"),this.apiKey=this.params.config.key}getServiceSpecificErrorMessage(e){const r=e.message||"";return r.includes("API key")||r.includes("api_key")?"Invalid API key. Check your Perplexity API key in configuration":r.includes("rate_limit")||r.includes("Rate limit")?"Rate limit exceeded. Wait a moment and try again, or upgrade your Perplexity plan":r.includes("model")||r.includes("Model")?"Model not found or not accessible. Check if the Perplexity model name is correct":r.includes("overloaded")||r.includes("capacity")?"Perplexity service is overloaded. Try again in a few minutes":r.includes("403")||r.includes("Forbidden")?"Access denied. Your API key may not have permission for this Perplexity model":r.includes("404")||r.includes("Not Found")?"Model or endpoint not found. Check your Perplexity model configuration":r.includes("500")||r.includes("Internal Server Error")?"Perplexity server error. Try again later":null}generateCommitMessage$(){return j(this.generateMessage("commit")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:this.params.config.includeBody?e.value:e.title,description:this.params.config.includeBody?e.value:"",isError:!1})),L(this.handleError$))}generateCodeReview$(){return j(this.generateMessage("review")).pipe(F(e=>N(e)),T(e=>({name:`${this.serviceName} ${e.title}`,short:e.title,value:e.value,description:e.value,isError:!1})),L(this.handleError$))}extractJSONFromError(e){const r=/[{[]{1}([,:{}[\]0-9.\-+Eaeflnr-u \n\r\t]|".*?")+[}\]]{1}/gis,o=e.match(r);return o?Object.assign({},...o.map(s=>JSON.parse(s))):{error:{message:"Unknown error"}}}async generateMessage(e){const r=this.params.stagedDiff.diff,{systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,logging:i,locale:a,generate:c,type:d,maxLength:l}=this.params.config,u={...J,locale:a,maxLength:l,type:d,generate:c,systemPrompt:o,systemPromptPath:s,codeReviewPromptPath:n,vcs_branch:this.params.branchName||""},p=e==="review"?se(u):oe(u),f=`Here is the diff: ${r}`,y=`${this.params.config.url||"https://api.perplexity.ai"}/chat/completions`,w={Authorization:`Bearer ${this.apiKey}`,"content-type":"application/json"};ee(r,e,"Perplexity",this.params.config.model,y,w,i),te(r,e,"Perplexity",p,f,i);const C=await this.createChatCompletions(p,f,e);return this.parseMessage(C,d,c)}async createChatCompletions(e,r,o){const s=this.params.stagedDiff.diff,{logging:n}=this.params.config,i={model:this.params.config.model,messages:[{role:"system",content:e},{role:"user",content:r}],temperature:this.params.config.temperature,top_p:this.params.config.topP,max_tokens:this.params.config.maxTokens,stream:!1};ne(s,o,"Perplexity",i,n);const a=Date.now();try{const c=this.params.config.url||"https://api.perplexity.ai",d=await new Ne({method:"POST",baseURL:`${c}/chat/completions`,timeout:this.params.config.timeout}).setHeaders({Authorization:`Bearer ${this.apiKey}`,"content-type":"application/json"}).setBody(i).execute(),l=Date.now()-a,u=d.data;if(V(s,o,"Perplexity",u,n),!u.choices||u.choices.length===0||!u.choices[0].message?.content)throw G(s,o,"Perplexity",{message:"No Content on response",result:u},n),new Error("No Content on response. Please open a Bug report");const f=u.choices[0].message.content;return q(s,o,"Perplexity",l,f,n),f}catch(c){throw G(s,o,"Perplexity",c,n),c}}}const Cl="stats.json",It=1,bl=30,Rr=()=>M.join(as,Cl),Or=async()=>{const t=Rr();if(!await gt(t))return{version:It,metrics:[]};try{const e=await D.readFile(t,"utf-8"),r=JSON.parse(e);return!r.version||r.version<It?{version:It,metrics:r.metrics||[]}:r}catch{return{version:It,metrics:[]}}},El=async t=>{const e=Rr(),r=M.dirname(e);await D.mkdir(r,{recursive:!0}),await D.writeFile(e,JSON.stringify(t,null,2),"utf-8")},Is=async t=>{const e={timestamp:Date.now(),provider:t.provider,model:t.model,responseTimeMs:t.responseTimeMs,success:t.success,errorCode:t.errorCode,tokensUsed:t.tokensUsed},r=await Or();r.metrics.push(e),await El(r)},$l=(t,e)=>{const r=e.filter(n=>n.provider===t);if(r.length===0)return{provider:t,totalRequests:0,successCount:0,failureCount:0,avgResponseTimeMs:0,minResponseTimeMs:0,maxResponseTimeMs:0};const o=r.filter(n=>n.success),s=r.map(n=>n.responseTimeMs);return{provider:t,totalRequests:r.length,successCount:o.length,failureCount:r.length-o.length,avgResponseTimeMs:Math.round(s.reduce((n,i)=>n+i,0)/s.length),minResponseTimeMs:Math.min(...s),maxResponseTimeMs:Math.max(...s)}},Pl=async(t=bl)=>{const e=await Or(),r=Date.now()-t*24*60*60*1e3,o=e.metrics.filter(c=>c.timestamp>=r);if(o.length===0)return{totalRequests:0,successRate:0,avgResponseTimeMs:0,providerStats:[],periodStart:r,periodEnd:Date.now()};const n=[...new Set(o.map(c=>c.provider))].map(c=>$l(c,o)).sort((c,d)=>d.totalRequests-c.totalRequests),i=o.filter(c=>c.success).length,a=o.reduce((c,d)=>c+d.responseTimeMs,0);return{totalRequests:o.length,successRate:Math.round(i/o.length*1e3)/10,avgResponseTimeMs:Math.round(a/o.length),providerStats:n,periodStart:Math.min(...o.map(c=>c.timestamp)),periodEnd:Math.max(...o.map(c=>c.timestamp))}},Al=async()=>{const t=Rr();await gt(t)&&await D.unlink(t)},Sl=async()=>(await Or()).metrics.length>0,Ms=(t,e)=>{const r=g.red.bold(`[${t}]`);return Xr({name:`${r} ${e}`,value:e,isError:!0,disabled:!0})};class kl{constructor(){this.providers=new Map,this.register=(e,r)=>{this.providers.set(e,r)},this.has=e=>this.providers.has(e),this.createService=(e,r)=>{const o=this.providers.get(e);return o?new o(r):null},this.createRequest$=(e,r,o)=>{const s=this.createService(e,r);if(!s)return Ms(e,"Invalid AI type");const n=Date.now(),i=Array.isArray(r.config.model)?r.config.model[0]:r.config.model;let a=!1;return(o==="commit"?s.generateCommitMessage$():s.generateCodeReview$()).pipe(Qr({next:d=>{if(a)return;a=!0;const l=d.isError===!0;Is({provider:e,model:i||"unknown",responseTimeMs:Date.now()-n,success:!l,errorCode:l?"REQUEST_ERROR":void 0}).catch(()=>{})}}))},this.getRegisteredProviders=()=>Array.from(this.providers.keys()),this.registerBuiltinProviders=()=>{this.register("OPENAI",wl),this.register("GEMINI",ml),this.register("ANTHROPIC",il),this.register("HUGGINGFACE",hl),this.register("MISTRAL",gl),this.register("CODESTRAL",ll),this.register("OLLAMA",yl),this.register("COHERE",ul),this.register("GROQ",fl),this.register("PERPLEXITY",vl),this.register("BEDROCK",cl),this.register("GITHUB_MODELS",pl),this.register("DEEPSEEK",dl)},this.registerBuiltinProviders()}}const Il=new kl;class Mt{constructor(e,r,o=""){this.config=e,this.stagedDiff=r,this.branchName=o,this.extractProviderName=s=>{if(!s)return"compatible";try{return new URL(s).hostname}catch{return"compatible"}},this.createCommitMsgRequests$=s=>this.createServiceRequests$(s,"commit"),this.createCodeReviewRequests$=s=>this.createServiceRequests$(s,"review"),this.createServiceRequests$=(s,n)=>N(s).pipe(Zr(i=>this.createProviderRequests$(i,n)),L(i=>Ms("UNKNOWN",i.message||"Unknown error"))),this.createProviderRequests$=(s,n)=>{const i=this.config[s],a=Array.isArray(i.model)?i.model:[i.model];return N(a).pipe(Zr(c=>this.createModelRequest$(s,c,n)))},this.createModelRequest$=(s,n,i)=>{const a=this.config[s];return a.compatible?this.createCompatibleServiceRequest$(a,n,i):Il.createRequest$(s,{config:{...a,model:n},stagedDiff:this.stagedDiff,keyName:n,branchName:this.branchName},i)},this.createCompatibleServiceRequest$=(s,n,i)=>{const a=mc.create(rl,{config:{...s,url:s.url||"",path:s.path||"",model:n},stagedDiff:this.stagedDiff,keyName:n,branchName:this.branchName}),c=Date.now(),d=this.extractProviderName(s.url);let l=!1;return(i==="commit"?a.generateCommitMessage$():a.generateCodeReview$()).pipe(Qr({next:p=>{if(l)return;l=!0;const f=p.isError===!0;Is({provider:d,model:n,responseTimeMs:Date.now()-c,success:!f,errorCode:f?"REQUEST_ERROR":void 0}).catch(()=>{})}}))}}}class Dr{getDetectedMessage(e){return`Detected ${e.files.length.toLocaleString()} changed file${e.files.length>1?"s":""} (${e.diff.length.toLocaleString()} characters)`}getDetectedFiles(e){return`Detected ${e.length.toLocaleString()} changed file${e.length>1?"s":""}`}}class xt extends Dr{constructor(){super(...arguments),this.name="git",this.excludeFromDiff=e=>`:(exclude)${e}`,this.filesToExclude=["package-lock.json","pnpm-lock.yaml","*.lock","*.lockb"].map(this.excludeFromDiff)}async assertRepo(){try{const{stdout:e}=await I("git",["rev-parse","--show-toplevel"],{reject:!0});return e.trim()}catch(e){const r=e;if(r.code==="ENOENT")throw new v(`Git command not found!
|
|
91
108
|
|
|
92
|
-
Please install Git first: https://git-scm.com/downloads`);if(r.stderr){if(r.stderr.includes("not a git repository"))throw new
|
|
109
|
+
Please install Git first: https://git-scm.com/downloads`);if(r.stderr){if(r.stderr.includes("not a git repository"))throw new v(`Not in a Git repository!
|
|
93
110
|
|
|
94
111
|
Initialize with: git init
|
|
95
|
-
Or navigate to an existing Git repository.`);if(r.stderr.includes("permission denied"))throw new
|
|
112
|
+
Or navigate to an existing Git repository.`);if(r.stderr.includes("permission denied"))throw new v(`Git permission denied: ${r.stderr.trim()}
|
|
96
113
|
|
|
97
|
-
Check file permissions and repository access.`)}throw new
|
|
98
|
-
`).filter(Boolean),{stdout:
|
|
99
|
-
`).filter(Boolean);for(const
|
|
114
|
+
Check file permissions and repository access.`)}throw new v(`Failed to verify Git repository: ${r.message||"Unknown error"}`)}}async getStagedDiff(e,r){const o=["diff","--cached","--diff-algorithm=minimal"],{stdout:s}=await I("git",[...o,"--name-only",...this.filesToExclude,...e?e.map(this.excludeFromDiff):[],...r?r.map(this.excludeFromDiff):[]]);if(!s)return null;const{stdout:n}=await I("git",[...o,...this.filesToExclude,...e?e.map(this.excludeFromDiff):[],...r?r.map(this.excludeFromDiff):[]]),i=s.split(`
|
|
115
|
+
`).filter(Boolean),{stdout:a}=await I("git",[...o,"--numstat",...e?e.map(this.excludeFromDiff):[],...r?r.map(this.excludeFromDiff):[]]),c=[],d=a.split(`
|
|
116
|
+
`).filter(Boolean);for(const p of d){const f=p.split(" ");f[0]==="-"&&f[1]==="-"&&f[2]&&c.push(f[2])}let l=n;if(c.length>0){n.trim()||(l=""),l+=`
|
|
100
117
|
|
|
101
118
|
--- Binary Files Changed ---
|
|
102
|
-
`;for(const
|
|
103
|
-
`}}const u=[...new Set([...i,...
|
|
104
|
-
`).filter(Boolean);for(const
|
|
119
|
+
`;for(const p of c){const{stdout:f}=await I("git",["status","--porcelain",p]),h=f.substring(0,2).trim();l+=`Binary file ${p} ${h==="A"?"added":h==="M"?"modified":h==="D"?"deleted":"changed"}
|
|
120
|
+
`}}const u=[...new Set([...i,...c])];return{files:u,diff:l||`Files changed: ${u.join(", ")}`}}async getCommitDiff(e,r,o){const s=["diff-tree","-r","--no-commit-id","--name-only",e],{stdout:n}=await I("git",[...s,...this.filesToExclude,...r?r.map(this.excludeFromDiff):[],...o?o.map(this.excludeFromDiff):[]]);if(!n)return null;const{stdout:i}=await I("git",["show",e,"--",...this.filesToExclude,...r?r.map(this.excludeFromDiff):[],...o?o.map(this.excludeFromDiff):[]]),{stdout:a}=await I("git",["diff-tree","-r","--numstat",e,...r?r.map(this.excludeFromDiff):[],...o?o.map(this.excludeFromDiff):[]]),c=[],d=a.split(`
|
|
121
|
+
`).filter(Boolean);for(const p of d){const f=p.split(" ");f[0]==="-"&&f[1]==="-"&&f[2]&&c.push(f[2])}let l=i;if(c.length>0){i.trim()||(l=""),l+=`
|
|
105
122
|
|
|
106
123
|
--- Binary Files Changed ---
|
|
107
|
-
`;for(const
|
|
108
|
-
`}const u=[...new Set([...
|
|
109
|
-
`).filter(Boolean),...
|
|
124
|
+
`;for(const p of c)l+=`Binary file ${p} changed
|
|
125
|
+
`}const u=[...new Set([...n.split(`
|
|
126
|
+
`).filter(Boolean),...c])];return{files:u,diff:l||`Files changed: ${u.join(", ")}`}}async commit(e,r=[],o={}){try{await I("git",["commit","-m",e,...r],{stdio:"inherit"})}catch(s){const n=s;throw n.stderr?n.stderr.includes("nothing to commit")?new v(`Nothing to commit.
|
|
110
127
|
|
|
111
128
|
Stage your changes with: git add <files>
|
|
112
|
-
Or use the --all flag to stage all changes.`):
|
|
129
|
+
Or use the --all flag to stage all changes.`):n.stderr.includes("Please enter the commit message")?new v(`Commit message cannot be empty.
|
|
113
130
|
|
|
114
|
-
Provide a meaningful commit message.`):
|
|
131
|
+
Provide a meaningful commit message.`):n.stderr.includes("Author identity unknown")?new v(`Git author identity not configured.
|
|
115
132
|
|
|
116
133
|
Configure with:
|
|
117
134
|
git config --global user.name "Your Name"
|
|
118
|
-
git config --global user.email "your.email@example.com"`):
|
|
135
|
+
git config --global user.email "your.email@example.com"`):n.stderr.includes("Permission denied")?new v(`Git permission error: ${n.stderr.trim()}
|
|
119
136
|
|
|
120
|
-
Check repository permissions and file access.`):new
|
|
137
|
+
Check repository permissions and file access.`):new v(`Git commit failed: ${n.stderr.trim()}`):n.exitCode===1?new v("Git commit failed. Check your staged changes and try again."):new v(`Failed to commit with Git: ${n.message||"Unknown error"}`)}}async getCommentChar(){try{const{stdout:e}=await I("git",["config","--get","core.commentChar"]);return e}catch{return"#"}}async getBranchName(){try{const{stdout:e}=await I("git",["branch","--show-current"]),r=e.trim();if(!r){const{stdout:o}=await I("git",["rev-parse","--short","HEAD"]);return`HEAD@${o.trim()}`}return r}catch{return"HEAD"}}}class _r extends Dr{constructor(){super(...arguments),this.name="jujutsu",this.excludeFromDiff=e=>e.includes("*")||e.includes("?")||e.includes("[")?`~glob:"${e}"`:`~"${e}"`,this.filesToExclude=["package-lock.json","pnpm-lock.yaml","*.lock","*.lockb"]}async assertRepo(){try{const{stdout:e}=await I("jj",["--version"],{reject:!0});process.env.DEBUG&&console.log(`Jujutsu version: ${e}`)}catch(e){const r=e;throw r.code==="ENOENT"?new v(`Jujutsu (jj) command not found!
|
|
121
138
|
|
|
122
139
|
Please install Jujutsu:
|
|
123
140
|
- macOS: brew install jj
|
|
124
141
|
- Linux: cargo install jj-cli
|
|
125
142
|
- Windows: cargo install jj-cli
|
|
126
|
-
- See: https://github.com/jj-vcs/jj#installation`):new
|
|
143
|
+
- See: https://github.com/jj-vcs/jj#installation`):new v(`Failed to execute jj command: ${r.message}`)}try{const{stdout:e,stderr:r}=await I("jj",["workspace","root"],{reject:!0}),o=e.trim();if(!o)throw new v("jj workspace root returned empty path");const s=M.join(o,".jj");if(!Z.existsSync(s))throw new v(`Jujutsu repository directory not found at ${s}
|
|
127
144
|
|
|
128
|
-
Initialize a jj repository with: jj init`);return o}catch(e){if(e instanceof
|
|
145
|
+
Initialize a jj repository with: jj init`);return o}catch(e){if(e instanceof v)throw e;const r=e;throw r.stderr?r.stderr.includes("not in a jj repo")?new v(`Not in a Jujutsu repository!
|
|
129
146
|
|
|
130
147
|
Initialize with: jj init
|
|
131
|
-
Or navigate to an existing jj repository.`):r.stderr.includes("No workspace found")?new
|
|
148
|
+
Or navigate to an existing jj repository.`):r.stderr.includes("No workspace found")?new v(`No Jujutsu workspace found!
|
|
132
149
|
|
|
133
|
-
This may be a bare repository. Navigate to a workspace directory.`):new
|
|
134
|
-
`).filter(Boolean),h=[],
|
|
135
|
-
`);for(const
|
|
150
|
+
This may be a bare repository. Navigate to a workspace directory.`):new v(`Jujutsu error: ${r.stderr.trim()}`):new v(`Failed to verify Jujutsu repository: ${r.message||"Unknown error"}`)}}async getStagedDiff(e,r){try{const{stdout:o}=await I("jj",["status","--no-pager"]);if(process.env.DEBUG&&(console.log("jj status output:",JSON.stringify(o)),console.log("excludeFiles:",e),console.log("exclude:",r)),o.includes("No changes.")||o.includes("The working copy is clean"))return null;const s=this.filesToExclude.map(this.excludeFromDiff),n=[...e?e.map(this.excludeFromDiff):[],...r?r.map(this.excludeFromDiff):[]],i=[...s,...n];let a="all()";i.length>0&&(a=`all() & ${i.join(" & ")}`);const c=["diff","--name-only"],d=["diff","--git"];i.length>0&&(c.push(a),d.push(a)),process.env.DEBUG&&(console.log("jj diff command with fileset:",c),console.log("fileset expression:",a));const{stdout:l}=await I("jj",c);if(process.env.DEBUG&&console.log("jj diff --name-only output:",JSON.stringify(l)),!l.trim())return null;const{stdout:u}=await I("jj",d),{stdout:p}=await I("jj",["status","--no-pager"]),f=l.split(`
|
|
151
|
+
`).filter(Boolean),h=[],y=p.split(`
|
|
152
|
+
`);for(const b of y)if(b.includes("(binary)")||b.includes("Binary file")){const E=b.match(/([^\s]+)\s*\(binary\)/);E&&E[1]&&h.push(E[1])}let w=u;if(h.length>0){w+=`
|
|
136
153
|
|
|
137
154
|
--- Binary Files Changed ---
|
|
138
|
-
`;for(const
|
|
139
|
-
`}const
|
|
155
|
+
`;for(const b of h)w+=`Binary file ${b} changed
|
|
156
|
+
`}const C=[...new Set([...f,...h])];return{files:C,diff:w||`Files changed: ${C.join(", ")}`}}catch(o){const s=o;if(s.stderr){if(s.stderr.includes("No changes to show"))return null;if(s.stderr.includes("Operation not allowed"))throw new v(`Jujutsu diff failed: ${s.stderr.trim()}
|
|
140
157
|
|
|
141
|
-
Try: jj status --no-pager`);if(
|
|
158
|
+
Try: jj status --no-pager`);if(s.stderr.includes("Invalid revision"))throw new v(`Jujutsu revision error: ${s.stderr.trim()}
|
|
142
159
|
|
|
143
|
-
Check if you're in a valid workspace.`)}if(
|
|
144
|
-
stderr: ${
|
|
145
|
-
exitCode: ${
|
|
146
|
-
`).filter(Boolean);return{files:d,diff:
|
|
160
|
+
Check if you're in a valid workspace.`)}if(s.exitCode===1&&!s.stderr)return null;if(process.env.DEBUG)throw new v(`Jujutsu diff failed: ${s.message}
|
|
161
|
+
stderr: ${s.stderr}
|
|
162
|
+
exitCode: ${s.exitCode}`);return null}}async getCommitDiff(e,r,o){const s=[...r?r.map(this.excludeFromDiff):[],...o?o.map(this.excludeFromDiff):[]];try{const n=["diff","--name-only","--revision",e],i=["diff","--git","--revision",e];if(s.length>0){const l=`all() & ${s.join(" & ")}`;n.push(l),i.push(l),process.env.DEBUG&&console.log("jj getCommitDiff fileset expression:",l)}const{stdout:a}=await I("jj",n);if(!a.trim())return null;const{stdout:c}=await I("jj",i),d=a.split(`
|
|
163
|
+
`).filter(Boolean);return{files:d,diff:c||`Files changed: ${d.join(", ")}`}}catch(n){if(process.env.DEBUG){const i=n;console.log("jj getCommitDiff error:",i.message,i.stderr)}return null}}async commit(e,r=[],o={}){try{await I("jj",["describe","-m",e,...r],{stdio:"inherit"}),o.autoNew&&await I("jj",["new"],{stdio:"inherit"})}catch(s){const n=s;throw n.stderr?n.stderr.includes("Empty commit message")?new v(`Commit message cannot be empty.
|
|
147
164
|
|
|
148
|
-
Provide a meaningful commit message.`):
|
|
165
|
+
Provide a meaningful commit message.`):n.stderr.includes("No changes to commit")?new v(`No changes to commit.
|
|
149
166
|
|
|
150
|
-
Make some changes first, then try again.`):
|
|
167
|
+
Make some changes first, then try again.`):n.stderr.includes("Invalid revision")?new v(`Jujutsu commit error: ${n.stderr.trim()}
|
|
151
168
|
|
|
152
|
-
Ensure you're in a valid workspace with changes.`):
|
|
169
|
+
Ensure you're in a valid workspace with changes.`):n.stderr.includes("Operation not allowed")?new v(`Jujutsu operation not allowed: ${n.stderr.trim()}
|
|
153
170
|
|
|
154
|
-
Check repository state with: jj status`):new
|
|
155
|
-
`)[0].split(":")[0].trim();if(
|
|
171
|
+
Check repository state with: jj status`):new v(`Jujutsu describe failed: ${n.stderr.trim()}`):n.exitCode===1?new v("Jujutsu commit failed. Check your changes and repository state."):new v(`Failed to commit with Jujutsu: ${n.message||"Unknown error"}`)}}async getCommentChar(){try{const{stdout:e}=await I("jj",["config","get","ui.comment-char"]);return e.trim()||"#"}catch{return"#"}}async getBranchName(){try{const{stdout:e}=await I("jj",["bookmark","list","--revisions","@"]);if(e.trim()){const s=e.split(`
|
|
172
|
+
`)[0].split(":")[0].trim();if(s)return s}const{stdout:r}=await I("jj",["log","-r","@","--no-graph","-T","change_id.short()"]);return r.trim()||"HEAD"}catch{return"HEAD"}}}class Nr extends Dr{constructor(){super(...arguments),this.name="yadm",this.excludeFromDiff=e=>`:(exclude)${e}`,this.filesToExclude=["package-lock.json","pnpm-lock.yaml","*.lock","*.lockb"].map(this.excludeFromDiff)}async assertRepo(){try{const{stdout:e}=await I("yadm",["rev-parse","--show-toplevel"],{reject:!0}),r=e.trim(),o=process.env.HOME||process.env.USERPROFILE;if(!o)throw new v("HOME environment variable not set. Cannot determine YADM repository.");const s=await import("path"),n=s.resolve(r),i=s.resolve(o);if(n!==i)throw new v(`Not a YADM repository (work tree is not $HOME).
|
|
156
173
|
|
|
157
|
-
YADM work tree: ${
|
|
174
|
+
YADM work tree: ${n}
|
|
158
175
|
Expected: ${i}
|
|
159
176
|
|
|
160
|
-
This appears to be a regular Git repository.`);const{stdout:
|
|
177
|
+
This appears to be a regular Git repository.`);const{stdout:a}=await I("yadm",["rev-parse","--git-dir"],{reject:!0}),c=a.trim();if(!c.includes("yadm"))throw new v(`Not a YADM repository (git-dir does not contain "yadm").
|
|
161
178
|
|
|
162
|
-
Git directory: ${
|
|
179
|
+
Git directory: ${c}
|
|
163
180
|
|
|
164
|
-
This appears to be a regular Git repository.`);return r}catch(e){if(e instanceof
|
|
181
|
+
This appears to be a regular Git repository.`);return r}catch(e){if(e instanceof v)throw e;const r=e;if(r.code==="ENOENT")throw new v(`YADM command not found!
|
|
165
182
|
|
|
166
|
-
Please install YADM first: https://yadm.io/`);if(r.stderr){if(r.stderr.includes("not a git repository"))throw new
|
|
183
|
+
Please install YADM first: https://yadm.io/`);if(r.stderr){if(r.stderr.includes("not a git repository"))throw new v(`Not in a YADM repository!
|
|
167
184
|
|
|
168
185
|
Initialize with: yadm init
|
|
169
|
-
Or clone your dotfiles: yadm clone <url>`);if(r.stderr.includes("permission denied"))throw new
|
|
186
|
+
Or clone your dotfiles: yadm clone <url>`);if(r.stderr.includes("permission denied"))throw new v(`YADM permission denied: ${r.stderr.trim()}
|
|
170
187
|
|
|
171
|
-
Check file permissions and repository access.`)}throw new
|
|
172
|
-
`).filter(Boolean),{stdout:
|
|
173
|
-
`).filter(Boolean);for(const
|
|
188
|
+
Check file permissions and repository access.`)}throw new v(`Failed to verify YADM repository: ${r.message||"Unknown error"}`)}}async getStagedDiff(e,r){const o=["diff","--cached","--diff-algorithm=minimal"],{stdout:s}=await I("yadm",[...o,"--name-only",...this.filesToExclude,...e?e.map(this.excludeFromDiff):[],...r?r.map(this.excludeFromDiff):[]]);if(!s)return null;const{stdout:n}=await I("yadm",[...o,...this.filesToExclude,...e?e.map(this.excludeFromDiff):[],...r?r.map(this.excludeFromDiff):[]]),i=s.split(`
|
|
189
|
+
`).filter(Boolean),{stdout:a}=await I("yadm",[...o,"--numstat",...e?e.map(this.excludeFromDiff):[],...r?r.map(this.excludeFromDiff):[]]),c=[],d=a.split(`
|
|
190
|
+
`).filter(Boolean);for(const p of d){const f=p.split(" ");f[0]==="-"&&f[1]==="-"&&f[2]&&c.push(f[2])}let l=n;if(c.length>0){n.trim()||(l=""),l+=`
|
|
174
191
|
|
|
175
192
|
--- Binary Files Changed ---
|
|
176
|
-
`;for(const
|
|
177
|
-
`}}const u=[...new Set([...i,...
|
|
178
|
-
`).filter(Boolean);for(const
|
|
193
|
+
`;for(const p of c){const{stdout:f}=await I("yadm",["status","--porcelain",p]),h=f.substring(0,2).trim();l+=`Binary file ${p} ${h==="A"?"added":h==="M"?"modified":h==="D"?"deleted":"changed"}
|
|
194
|
+
`}}const u=[...new Set([...i,...c])];return{files:u,diff:l||`Files changed: ${u.join(", ")}`}}async getCommitDiff(e,r,o){const s=["diff-tree","-r","--no-commit-id","--name-only",e],{stdout:n}=await I("yadm",[...s,...this.filesToExclude,...r?r.map(this.excludeFromDiff):[],...o?o.map(this.excludeFromDiff):[]]);if(!n)return null;const{stdout:i}=await I("yadm",["show",e,"--",...this.filesToExclude,...r?r.map(this.excludeFromDiff):[],...o?o.map(this.excludeFromDiff):[]]),{stdout:a}=await I("yadm",["diff-tree","-r","--numstat",e,...r?r.map(this.excludeFromDiff):[],...o?o.map(this.excludeFromDiff):[]]),c=[],d=a.split(`
|
|
195
|
+
`).filter(Boolean);for(const p of d){const f=p.split(" ");f[0]==="-"&&f[1]==="-"&&f[2]&&c.push(f[2])}let l=i;if(c.length>0){i.trim()||(l=""),l+=`
|
|
179
196
|
|
|
180
197
|
--- Binary Files Changed ---
|
|
181
|
-
`;for(const
|
|
182
|
-
`}const u=[...new Set([...
|
|
183
|
-
`).filter(Boolean),...
|
|
198
|
+
`;for(const p of c)l+=`Binary file ${p} changed
|
|
199
|
+
`}const u=[...new Set([...n.split(`
|
|
200
|
+
`).filter(Boolean),...c])];return{files:u,diff:l||`Files changed: ${u.join(", ")}`}}async commit(e,r=[],o={}){try{await I("yadm",["commit","-m",e,...r],{stdio:"inherit"})}catch(s){const n=s;throw n.stderr?n.stderr.includes("nothing to commit")?new v(`Nothing to commit.
|
|
184
201
|
|
|
185
202
|
Stage your changes with: yadm add <file>
|
|
186
203
|
Or stage tracked file modifications: aicommit2 --all
|
|
187
204
|
|
|
188
|
-
Note: The --all flag only stages already-tracked files (YADM best practice).`):
|
|
205
|
+
Note: The --all flag only stages already-tracked files (YADM best practice).`):n.stderr.includes("Please enter the commit message")?new v(`Commit message cannot be empty.
|
|
189
206
|
|
|
190
|
-
Provide a meaningful commit message.`):
|
|
207
|
+
Provide a meaningful commit message.`):n.stderr.includes("Author identity unknown")?new v(`YADM author identity not configured.
|
|
191
208
|
|
|
192
209
|
Configure with:
|
|
193
210
|
yadm config --global user.name "Your Name"
|
|
194
|
-
yadm config --global user.email "your.email@example.com"`):
|
|
211
|
+
yadm config --global user.email "your.email@example.com"`):n.stderr.includes("Permission denied")?new v(`YADM permission error: ${n.stderr.trim()}
|
|
195
212
|
|
|
196
|
-
Check repository permissions and file access.`):new
|
|
197
|
-
${
|
|
198
|
-
${
|
|
199
|
-
${
|
|
200
|
-
${
|
|
201
|
-
${
|
|
202
|
-
${
|
|
203
|
-
${
|
|
213
|
+
Check repository permissions and file access.`):new v(`YADM commit failed: ${n.stderr.trim()}`):n.exitCode===1?new v("YADM commit failed. Check your staged changes and try again."):new v(`Failed to commit with YADM: ${n.message||"Unknown error"}`)}}async getCommentChar(){try{const{stdout:e}=await I("yadm",["config","--get","core.commentChar"]);return e}catch{return"#"}}async getBranchName(){try{const{stdout:e}=await I("yadm",["branch","--show-current"]),r=e.trim();if(!r){const{stdout:o}=await I("yadm",["rev-parse","--short","HEAD"]);return`HEAD@${o.trim()}`}return r}catch{return"HEAD"}}}let Tr=null;async function Ml(){const t=process.argv.includes("--git"),e=process.argv.includes("--yadm"),r=process.argv.includes("--jj");if(t)try{const l=new xt;return await l.assertRepo(),l}catch(l){throw new v(`--git flag is set, but Git is not available or not in a git repository.
|
|
214
|
+
${l instanceof Error?l.message:String(l)}`)}if(e)try{const l=new Nr;return await l.assertRepo(),l}catch(l){throw new v(`--yadm flag is set, but YADM is not available or not in a YADM repository.
|
|
215
|
+
${l instanceof Error?l.message:String(l)}`)}if(r)try{const l=new _r;return await l.assertRepo(),l}catch(l){throw new v(`--jj flag is set, but Jujutsu is not available or not in a jj repository.
|
|
216
|
+
${l instanceof Error?l.message:String(l)}`)}const o=process.env.FORCE_GIT==="true",s=process.env.FORCE_YADM==="true",n=process.env.FORCE_JJ==="true";if(o)try{const l=new xt;return await l.assertRepo(),l}catch(l){throw new v(`FORCE_GIT="true" environment variable is set, but Git is not available or not in a git repository.
|
|
217
|
+
${l instanceof Error?l.message:String(l)}`)}if(s)try{const l=new Nr;return await l.assertRepo(),l}catch(l){throw new v(`FORCE_YADM="true" environment variable is set, but YADM is not available or not in a YADM repository.
|
|
218
|
+
${l instanceof Error?l.message:String(l)}`)}if(n)try{const l=new _r;return await l.assertRepo(),l}catch(l){throw new v(`FORCE_JJ="true" environment variable is set, but Jujutsu is not available or not in a jj repository.
|
|
219
|
+
${l instanceof Error?l.message:String(l)}`)}let i=!1;try{i=(await ge({})).forceGit===!0}catch{i=!1}if(i)try{const l=new xt;return await l.assertRepo(),l}catch(l){throw new v(`forceGit=true is set in config, but Git is not available or not in a git repository.
|
|
220
|
+
${l instanceof Error?l.message:String(l)}`)}let a=null,c=null,d=null;try{const l=new _r;return await l.assertRepo(),l}catch(l){a=l instanceof Error?l:new Error(String(l))}try{const l=new xt;return await l.assertRepo(),l}catch(l){c=l instanceof Error?l:new Error(String(l))}try{const l=new Nr;return await l.assertRepo(),l}catch(l){d=l instanceof Error?l:new Error(String(l))}if(a&&c&&d){const l=a.message.replace("KnownError: ","").trim(),u=c.message.replace("KnownError: ","").trim(),p=d.message.replace("KnownError: ","").trim();throw new v(`No supported VCS repository found.
|
|
204
221
|
|
|
205
222
|
Jujutsu Error:
|
|
206
|
-
${
|
|
223
|
+
${l}
|
|
207
224
|
|
|
208
225
|
Git Error:
|
|
209
226
|
${u}
|
|
210
227
|
|
|
211
228
|
YADM Error:
|
|
212
|
-
${
|
|
229
|
+
${p}
|
|
213
230
|
|
|
214
231
|
Solutions:
|
|
215
232
|
\u2022 Initialize a Jujutsu repository: jj init
|
|
@@ -217,90 +234,84 @@ Solutions:
|
|
|
217
234
|
\u2022 Initialize a YADM repository: yadm init (or yadm clone <url>)
|
|
218
235
|
\u2022 Navigate to an existing Jujutsu, Git, or YADM repository
|
|
219
236
|
\u2022 Set FORCE_GIT="true" environment variable to force Git detection
|
|
220
|
-
\u2022 Set forceGit=true in config file to prefer Git detection`)}throw new
|
|
237
|
+
\u2022 Set forceGit=true in config file to prefer Git detection`)}throw new v("Unexpected error during VCS detection")}async function $e(){return Tr||(Tr=await Ml()),Tr}const Lr=async()=>(await $e()).assertRepo(),Fr=async(t,e)=>(await $e()).getStagedDiff(t,e),xl=async(t,e,r)=>{const o=await $e();if(!o.getCommitDiff)throw new v(`Commit diff not supported for ${o.name}`);return o.getCommitDiff(t,e,r)},Rl=async()=>(await $e()).getCommentChar(),Ol=t=>`Detected ${t.files.length.toLocaleString()} changed file${t.files.length>1?"s":""} (${t.diff.length.toLocaleString()} characters)`,Rt=async()=>(await $e()).name,Dl=async(t,e,r)=>{await(await $e()).commit(t,e||[],r)},Ot=async()=>(await $e()).getBranchName();class de{constructor(){this.title="aicommit2"}printTitle(){try{const e=io.textSync(this.title,{font:"Small Slant"}),r=Cn(["#8B5CF6","#A020F0","#D946EF"]);console.log(g.bold(r.multiline(e)))}catch{console.log(g.bold(io.textSync(this.title,{font:"Small Slant"})))}}showLoader(e){if(this.loader){this.loader.text=e;return}this.loader=ao(e).start()}stopLoader(){this.loader?.stop(),this.loader=void 0}displaySpinner(e){return ao(e).start()}stopSpinner(e){e.stop(),e.clear()}printStagedFiles(e){console.log(g.bold.green("\u2714 ")+g.bold(`${Ol(e)}:`)),console.log(`${e.files.map(r=>` ${r}`).join(`
|
|
221
238
|
`)}
|
|
222
239
|
`)}printAnalyzed(){console.log(`
|
|
223
|
-
${
|
|
224
|
-
${
|
|
225
|
-
${
|
|
226
|
-
${
|
|
227
|
-
${
|
|
228
|
-
${
|
|
229
|
-
${
|
|
230
|
-
${
|
|
231
|
-
${
|
|
232
|
-
${
|
|
233
|
-
${
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
To track new dotfiles, explicitly add them first: yadm add <file>`):B==="git"?(ne+=`
|
|
240
|
-
|
|
241
|
-
Stage your changes with: git add <file>`,ne+=`
|
|
242
|
-
Or automatically stage all changes: aicommit2 --all`):B==="jujutsu"&&(ne+=`
|
|
243
|
-
|
|
244
|
-
Jujutsu automatically tracks all changes in the working copy.`,ne+=`
|
|
245
|
-
Make some changes to your files and try again.`),new w(ne)}v||V.printStagedFiles(M);const A=Re(b,"commit");if(A.length===0)throw new w("Please set at least one API key via the `aicommit2 config set` command");const G=await At(),R=new Et(b,M,G);v&&((await ll(R,A)).forEach(ne=>{process.stdout.write(JSON.stringify(ne)+`
|
|
246
|
-
`)}),process.exit(0));const fe=Re(b,"review");fe.length>0&&await il(R,fe);let q=await al(R,A,d);if(c){if(V.printInfo("Opening editor to modify commit message..."),q=await cl(q),!q.trim())throw new w("Commit message cannot be empty");V.printSuccess("Commit message edited successfully!"),V.print(`
|
|
247
|
-
${q}
|
|
248
|
-
`)}i&&(As("copy-paste").copy(q),V.printCopied(),p||process.exit()),p&&(process.stdout.write(q+`
|
|
249
|
-
`),process.exit()),(s||d&&A.length===1)&&(await En(q,y,P),process.exit());const{confirmationPrompt:Mt}=await et.prompt([{type:"confirm",name:"confirmationPrompt",message:"Use selected message?",default:!0}]);Mt?await En(q,y,P):V.printCancelledCommit(),process.exit()})().catch(v=>{if(g==="json"){const E={error:v.message||"Unknown error occurred"};process.stderr.write(JSON.stringify(E)+`
|
|
250
|
-
`),process.exit(1)}V.printError(v.message),pe(v),process.exit(1)});async function il(t,e){const r=new Fr(Cn);let o=null;try{const n=r.initPrompt({...Nr,name:"codeReviewPrompt",message:"Please check code reviews: ",emptyMessage:`\u26A0 ${bn}`,isDescriptionDim:!1,stopMessage:"Code review completed",descPageSize:20});if(r.startLoader(),o=t.createCodeReviewRequests$(e).subscribe({next:a=>r.refreshChoices(a),error:a=>{console.error("Code review request error:",a),r.checkErrorOnChoices()},complete:()=>r.checkErrorOnChoices()}),!(await n).codeReviewPrompt?.value)throw new w("An error occurred! No selected code review");V.moveCursorUp();const{continuePrompt:l}=await et.prompt([{type:"confirm",name:"continuePrompt",message:"Will you continue without changing the code?",default:!0}]);l||(V.printCancelledCommit(),process.exit())}finally{o&&o.unsubscribe(),r.destroy()}}async function al(t,e,r){const o=new Fr(nl);let n=null;try{if(r&&e.length===1){const a=[];o.startLoader(),n=t.createCommitMsgRequests$(e).subscribe({next:c=>{a.push(c),o.refreshChoices(c)},error:c=>{console.error("Commit message generation error:",c),o.checkErrorOnChoices(!1)},complete:()=>o.checkErrorOnChoices(!1)}),await new Promise(c=>{n?.add(()=>c())}),o.clearLoader(),V.moveCursorUp();const d=a.find(c=>c.value&&!c.isError&&!c.disabled);if(!d||!d.value)throw new w("No valid commit message was generated");return V.print(`
|
|
240
|
+
${g.bold.green("\u2714")} ${g.bold("Changes analyzed")}`)}printCommitted(){console.log(`
|
|
241
|
+
${g.bold.green("\u2714")} ${g.bold("Successfully committed!")}`)}printCopied(){console.log(`
|
|
242
|
+
${g.bold.green("\u2714")} ${g.bold("Successfully copied! Press 'Ctrl + V' to paste")}`)}printSavedCommitMessage(){console.log(`
|
|
243
|
+
${g.bold.green("\u2714")} ${g.bold("Saved commit message")}`)}printCancelledCommit(){console.log(`
|
|
244
|
+
${g.bold.yellow("\u26A0")} ${g.yellow("Commit cancelled")}`)}printError(e){console.log(`
|
|
245
|
+
${g.bold.red("\u2716")} ${g.red(`${e}`)}`)}printWarning(e){console.log(`
|
|
246
|
+
${g.bold.yellow("\u26A0")} ${g.red(`${e}`)}`)}printSuccess(e){console.log(`
|
|
247
|
+
${g.bold.green("\u2714")} ${g.green(`${e}`)}`)}printInfo(e){console.log(`
|
|
248
|
+
${g.bold.blue("\u2139")} ${g.blue(`${e}`)}`)}printSetupGitEvent(e){console.log(`
|
|
249
|
+
${g.bold.green("\u2714")} ${g.bold(`Git ${e} hook has been set up`)}`)}moveCursorUp(){const e=it.createInterface({input:process.stdin,output:process.stdout});it.moveCursor(process.stdout,0,-1),e.close()}moveCursorDown(){const e=it.createInterface({input:process.stdin,output:process.stdout});it.moveCursor(process.stdout,0,2),e.close()}print(e){console.log(e)}}const _l={isLoading:!1,startOption:{text:"AI is analyzing your changes"}},xs={isLoading:!1,startOption:{text:"AI is performing a code review"}},jr="No commit messages were generated",Rs="No code reviews were generated",Br={type:"reactiveListPrompt",name:"aicommit2Prompt",message:"Pick a commit message to use: ",emptyMessage:`\u26A0 ${jr}`,loop:!1,descPageSize:15,showDescription:!0,pickKey:"short",isDescriptionDim:!0,stopMessage:"Changes analyzed"};class Gr{constructor(e){this.choices$=new eo([]),this.destroyed$=new sn(1),this.stopMessage="Changes analyzed",this.isDestroyed=!1,this.subscriptions=new Gt,this.inquirerInstance=null,this.loader$=new eo(e)}addSubscription(e){if(this.isDestroyed){e.unsubscribe();return}this.subscriptions.add(e)}initPrompt(e=Br){return this.stopMessage=e.stopMessage,ot.registerPrompt("reactiveListPrompt",bn),this.inquirerInstance=ot.prompt({choices$:this.choices$,loader$:this.loader$,...e}),this.inquirerInstance}startLoader(){this.loader$.next({isLoading:!0})}clearLoader(){this.inquirerInstance&&this.loader$.next({isLoading:!1,clear:!0})}refreshChoices(e){this.isDestroyed||!e||!e.value||this.choices$.next([...this.currentChoices,e].sort(qa))}checkErrorOnChoices(e=!0){if(this.choices$.getValue().map(o=>o).every(o=>o?.isError||o?.disabled)){this.alertNoGeneratedMessage(),this.logEmptyCommitMessage(),e&&process.exit(1);return}this.stopLoaderOnSuccess()}completeSubject(){try{this.destroyed$.next(!0),this.destroyed$.complete(),this.choices$.closed||this.choices$.complete(),this.loader$.closed||this.loader$.complete()}catch(e){console.warn("Error completing subjects:",e)}}closeInquirerInstance(){if(!this.inquirerInstance)return;const e=this.inquirerInstance.ui;e?.rl&&!e.rl.closed&&e.close()}cancel(){this.inquirerInstance?.ui?.activePrompt&&this.inquirerInstance.ui.activePrompt.abortPrompt()}destroy(){if(!this.isDestroyed){this.isDestroyed=!0;try{this.cancel(),this.closeInquirerInstance(),this.subscriptions.unsubscribe(),this.completeSubject()}catch(e){At()&&console.warn("Error during ReactivePromptManager destruction:",e)}finally{this.inquirerInstance=null}}}alertNoGeneratedMessage(){this.loader$.next({isLoading:!1,message:jr,stopOption:{doneFrame:"\u26A0",color:"yellow"}})}stopLoaderOnSuccess(){this.loader$.next({isLoading:!1,message:this.stopMessage})}logEmptyCommitMessage(){console.log(`
|
|
250
|
+
${g.bold.yellow("\u26A0")} ${g.yellow(`${jr}`)}`)}get currentChoices(){return this.choices$.getValue().map(e=>e)}}const X=new de;var Nl=async(t,e,r,o,s,n,i,a,c,d,l,u,p,f,h,y,w)=>(async()=>{const C=y==="json";if(C||X.printTitle(),await Lr(),o){const he=await Rt();he==="git"?await I("git",["add","."]):he==="yadm"&&await I("yadm",["add","--update"])}const b={locale:t?.toString(),generate:e?.toString(),type:s?.toString(),systemPrompt:a?.toString(),...c===!0&&{includeBody:"true"},...u===!0&&{disableLowerCase:"true"}};p&&(b.logLevel="verbose");const E=await ge(b,w);(c===!0||E.includeBody===!0)&&sc(E),u&&nc(E),await Ps(E);const $={autoNew:h||E.jjAutoNew},P=C?null:X.displaySpinner("Detecting staged files"),O=await Fr(r,E.exclude);if(P?.stop(),!O){const he=await Rt();throw new v(gr.noStagedChanges(he),{code:x.NO_STAGED_CHANGES})}C||X.printStagedFiles(O);const S=Oe(E,"commit");if(S.length===0)throw new v(gr.noApiKeysConfigured(),{code:x.MISSING_API_KEY});const U=await Ot(),_=new Mt(E,O,U);C&&((await jl(_,S)).forEach(Ft=>{process.stdout.write(JSON.stringify(Ft)+`
|
|
251
|
+
`)}),process.exit(0));const fe=Oe(E,"review");fe.length>0&&await Tl(_,fe);let Q=await Ll(_,S,d);if(l){if(X.printInfo("Opening editor to modify commit message..."),Q=await Fl(Q),!Q.trim())throw new v(gr.emptyCommitMessage(),{code:x.EMPTY_COMMIT_MESSAGE});X.printSuccess("Commit message edited successfully!"),X.print(`
|
|
252
|
+
${Q}
|
|
253
|
+
`)}i&&(Bn("copy-paste").copy(Q),X.printCopied(),f||process.exit()),f&&(process.stdout.write(Q+`
|
|
254
|
+
`),process.exit()),(n||d&&S.length===1)&&(await Os(Q,w,$),process.exit());const{confirmationPrompt:Lt}=await ot.prompt([{type:"confirm",name:"confirmationPrompt",message:"Use selected message?",default:!0}]);Lt?await Os(Q,w,$):X.printCancelledCommit(),process.exit()})().catch(C=>{if(y==="json"){const b={error:C.message||"Unknown error occurred"};process.stderr.write(JSON.stringify(b)+`
|
|
255
|
+
`),process.exit(1)}X.printError(C.message),me(C),process.exit(1)});async function Tl(t,e){const r=new Gr(xs);let o=null;try{const s=r.initPrompt({...Br,name:"codeReviewPrompt",message:"Please check code reviews: ",emptyMessage:`\u26A0 ${Rs}`,isDescriptionDim:!1,stopMessage:"Code review completed",descPageSize:20});if(r.startLoader(),o=t.createCodeReviewRequests$(e).subscribe({next:c=>r.refreshChoices(c),error:c=>{console.error("Code review request error:",c),r.checkErrorOnChoices()},complete:()=>r.checkErrorOnChoices()}),!(await s).codeReviewPrompt?.value)throw new v("An error occurred! No selected code review");X.moveCursorUp();const{continuePrompt:a}=await ot.prompt([{type:"confirm",name:"continuePrompt",message:"Will you continue without changing the code?",default:!0}]);a||(X.printCancelledCommit(),process.exit())}finally{o&&o.unsubscribe(),r.destroy()}}async function Ll(t,e,r){const o=new Gr(_l);let s=null;try{if(r&&e.length===1){const c=[];o.startLoader(),s=t.createCommitMsgRequests$(e).subscribe({next:l=>{c.push(l),o.refreshChoices(l)},error:l=>{console.error("Commit message generation error:",l),o.checkErrorOnChoices(!1)},complete:()=>o.checkErrorOnChoices(!1)}),await new Promise(l=>{s?.add(()=>l())}),o.clearLoader(),X.moveCursorUp();const d=c.find(l=>l.value&&!l.isError&&!l.disabled);if(!d||!d.value)throw new v("No valid commit message was generated");return X.print(`
|
|
251
256
|
${d.name}
|
|
252
|
-
`),d.value}const
|
|
257
|
+
`),d.value}const n=o.initPrompt();o.startLoader(),s=t.createCommitMsgRequests$(e).subscribe({next:c=>o.refreshChoices(c),error:c=>{console.error("Commit message generation error:",c),o.checkErrorOnChoices()},complete:()=>o.checkErrorOnChoices()});const i=await n;X.moveCursorUp();const a=i.aicommit2Prompt?.value;if(!a)throw new v("An error occurred! No selected message");return a}finally{s&&s.unsubscribe(),o.destroy()}}async function Fl(t){const e=process.env.VISUAL||process.env.EDITOR||(process.platform==="win32"?"notepad":"vi"),r=M.join(Le.tmpdir(),`aicommit2-${Date.now()}-${Ws.randomBytes(4).toString("hex")}.txt`);try{Z.writeFileSync(r,t,"utf8");const o=e.split(" "),[s,...n]=o;await I(s,[...n,r],{stdio:"inherit"});const i=Z.readFileSync(r,"utf8").trim();if(Z.unlinkSync(r),!i)throw new v("Commit cancelled - empty message");return i}catch(o){throw Z.existsSync(r)&&Z.unlinkSync(r),o instanceof v?o:o&&typeof o=="object"&&"exitCode"in o&&o.exitCode!==0?new v("Commit cancelled"):process.env.VISUAL||process.env.EDITOR?new v(`Failed to open editor "${e}". Please check:
|
|
253
258
|
- Editor binary exists in PATH
|
|
254
259
|
- Editor flags are correct
|
|
255
|
-
- EDITOR/VISUAL is set correctly`):new
|
|
256
|
-
`);return{subject:
|
|
257
|
-
`).trim()}})};var
|
|
260
|
+
- EDITOR/VISUAL is set correctly`):new v(`Failed to open editor "${e}". Please set your EDITOR or VISUAL environment variable to a valid editor command.`)}}const Os=async(t,e,r)=>{await Dl(t,e,r),X.printCommitted()},jl=async(t,e)=>{const o=(await Ut(t.createCommitMsgRequests$(e).pipe(Ht()),{defaultValue:[]})).filter(s=>s.value&&!s.isError&&!s.disabled);if(o.length===0)throw new v("No valid commit messages were generated");return o.map(({value:s=""})=>{const[n="",...i]=s.split(`
|
|
261
|
+
`);return{subject:n,body:i.join(`
|
|
262
|
+
`).trim()}})};var Bl=ce({name:"config",parameters:["<mode>","[key=value...]"],help:{description:"Manage configuration settings",examples:["aic2 config set <key>=<value> [<key>=<value> ...]","aic2 config get [<key> [<key> ...]]","aic2 config add <key>=<value> [<key>=<value> ...]","aic2 config del <key>","aic2 config list"]},commands:[ce({name:"set",parameters:["<key>=<value>","[<key>=<value> ...]"],help:{description:"Set configuration values. Multiple key-value pairs can be set at once.",examples:["aic2 config set OPENAI.key=<your key>","aic2 config set ANTHROPIC.topP=0.8 ANTHROPIC.generate=2"]}}),ce({name:"get",parameters:["[<key>","[<key> ...]]"],help:{description:"Retrieve configuration values for specified AI provider.",examples:["aic2 config get OPENAI","aic2 config get ANTHROPIC"]}}),ce({name:"add",parameters:["<key>=<value>","[<key>=<value> ...]"],help:{description:"Add new model to existing configuration. Only Ollama.model can be added.",examples:['aic2 config add OLLAMA.model="gemma2"']}}),ce({name:"list",parameters:[],help:{description:"Display all configuration keys and their values.",examples:["aic2 config list"]}}),ce({name:"del",parameters:["<config-name>"],help:{description:"Delete a configuration setting or section.",examples:["aic2 config del <config-name>","aic2 config del OPENAI.key","aic2 config del OPENAI"]}}),ce({name:"path",parameters:[],help:{description:"Display the path of the loaded configuration file.",examples:["aic2 config path"]}})]},t=>{(async()=>{const{mode:e,keyValue:r}=t._,o=t._[1];if(e==="get"){const s=await ge({},[]);if(r.length===0){console.log(s);return}for(const n of r){const i=n.split(".");let a=s,c=!0;for(const d of i)if(pr(a,d))a=a[d];else{c=!1;break}c?console.log(n,a):console.log(`${n} not found`)}return}if(e==="set"){await fr(r.map(s=>{const n=s.indexOf("=");if(n===-1)throw new v("Invalid format. Use: key=value");const i=s.slice(0,n),a=s.slice(n+1);return[i,a]}));return}if(e==="add"){await lc(r.map(s=>{const n=s.indexOf("=");if(n===-1)throw new v("Invalid format. Use: key=value");const i=s.slice(0,n),a=s.slice(n+1);return[i,a]}));return}if(e==="list"){await uc();return}if(e==="del"){if(!o)throw new v("Please provide the config name to delete.");const s=await We(),n=o.split(".");if(n.length===2){const[i,a]=n;if(s[i]&&typeof s[i]=="object"&&pr(s[i],a)){delete s[i][a],Object.keys(s[i]).length===0&&delete s[i];const c=await Re();await D.writeFile(c,xe.stringify(s),"utf8"),console.log(`Successfully deleted config: ${o}`);const d=await D.readFile(c,"utf8");console.log("--- Updated Config Content ---"),console.log(d),console.log("----------------------------")}else throw new v(`Config not found: ${o}`)}else if(n.length===1){const i=n[0];if(pr(s,i)){delete s[i];const a=await Re();await D.writeFile(a,xe.stringify(s),"utf8"),console.log(`Successfully deleted config: ${o}`);const c=await D.readFile(a,"utf8");console.log("--- Updated Config Content ---"),console.log(c),console.log("----------------------------")}else throw new v(`Config not found: ${o}`)}else throw new v(`Invalid config name format: ${o}`);return}if(e==="path"){await dc();return}throw new v(`Invalid mode: ${e}`)})().catch(e=>{new de().printError(e.message),me(e),process.exit(1)})});const Gl={healthy:g.green("\u2705"),error:g.red("\u274C"),warning:g.yellow("\u26A0\uFE0F"),skipped:g.gray("\u23ED\uFE0F")},Ul={healthy:g.green,error:g.red,warning:g.yellow,skipped:g.gray},Hl=t=>typeof t.key=="string"&&t.key.trim().length>0,Kl=async(t,e)=>{try{return await new Ne({method:"GET",baseURL:t,timeout:e}).execute(),{ok:!0}}catch(r){const o=r instanceof Error?r.message:String(r);return o.includes("ECONNREFUSED")?{ok:!1,error:"Not running"}:{ok:!1,error:o}}},zl=async(t,e,r)=>{if(t==="OLLAMA"){if(!Ce(e))return{provider:t,status:"skipped",message:"No models configured"};const o=typeof e.host=="string"&&e.host.trim()?e.host:bt,s=await Kl(o,r);return s.ok?{provider:t,status:"healthy",message:"Running",details:`Host: ${o}`}:{provider:t,status:"warning",message:s.error||"Connection failed",details:`Host: ${o}`}}return t==="HUGGINGFACE"?e.cookie?{provider:t,status:"healthy",message:"Cookie configured"}:{provider:t,status:"skipped",message:"No cookie configured"}:t==="BEDROCK"?$t(e)?{provider:t,status:"healthy",message:"Credentials configured"}:{provider:t,status:"skipped",message:"Not configured"}:Hl(e)?{provider:t,status:"healthy",message:"API key configured"}:{provider:t,status:"skipped",message:"Not configured"}},Wl=async t=>{const e=[],r=t.timeout||1e4;for(const o of He){const s=t[o];if(!s||typeof s!="object"){e.push({provider:o,status:"skipped",message:"Not configured"});continue}if(s.disabled){e.push({provider:o,status:"skipped",message:"Disabled"});continue}const n=await zl(o,s,r);e.push(n)}return e},Yl=Math.max(...He.map(t=>t.length)),Vl=t=>t.padEnd(Yl),ql=t=>{console.log(""),console.log(g.bold("\u{1FA7A} AICommit2 Health Check")),console.log(""),console.log(g.bold("Providers:"));for(const r of t){const o=Gl[r.status],s=Vl(r.provider),n=Ul[r.status](r.message),i=r.details?g.gray(` (${r.details})`):"";console.log(` ${o} ${s} ${n}${i}`)}const e={healthy:t.filter(r=>r.status==="healthy").length,error:t.filter(r=>r.status==="error").length,warning:t.filter(r=>r.status==="warning").length,skipped:t.filter(r=>r.status==="skipped").length};console.log(""),console.log(g.bold("Summary: ")+g.green(`${e.healthy} healthy`)+", "+g.red(`${e.error} error`)+", "+g.yellow(`${e.warning} warning`)+", "+g.gray(`${e.skipped} skipped`)),console.log(""),e.error>0&&(process.exitCode=1)},Jl=ce({name:"doctor",parameters:[],help:{description:"Check health status of configured AI providers",examples:["aicommit2 doctor"]}},()=>{(async()=>{const t=await ge({},[]),e=await Wl(t);ql(e)})().catch(t=>{console.error(g.red(t.message)),me(t),process.exit(1)})});var Xl=ce({name:"github-login",parameters:[],flags:{token:{type:String,description:"Manually provide a GitHub token for authentication",alias:"t"}},help:{description:"Login to GitHub and setup access to GitHub Models",examples:["aic2 github-login","aic2 github-login --token ghp_xxxxxxxxxxxxxxxxxxxx"]}},t=>{(async()=>{const e=new de;if(t.flags.token){try{await Ql(t.flags.token,e)}catch(r){throw new v(`Token authentication failed: ${r.message}`)}return}try{await Zl(e)}catch(r){throw new v(`Browser authentication failed: ${r.message}`)}})().catch(e=>{new de().printError(e.message),me(e),process.exit(1)})});async function Ql(t,e){if(e.printWarning("Authenticating with provided token..."),!t.startsWith("ghp_")&&!t.startsWith("gho_")&&!t.startsWith("ghu_"))throw new Error("Invalid token format. GitHub tokens should start with ghp_, gho_, or ghu_");try{const r=await fetch("https://api.github.com/user",{headers:{Authorization:`Bearer ${t}`,Accept:"application/vnd.github.v3+json","User-Agent":"aicommit2-github-models"}});if(!r.ok)throw new Error(`GitHub API request failed: ${r.status} ${r.statusText}`);const o=await r.json();try{(await fetch("https://models.github.ai/inference/chat/completions",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/vnd.github+json",Authorization:`Bearer ${t}`,"User-Agent":"aicommit2-github-models"},body:JSON.stringify({messages:[{role:"user",content:"test"}],model:"gpt-4o-mini",max_tokens:1})})).ok?e.printSuccess("GitHub Models access verified!"):e.printWarning("Could not verify GitHub Models access, but proceeding with authentication...")}catch{e.printWarning("Could not verify GitHub Models access, but proceeding with authentication...")}await fr([["GITHUB_MODELS.key",t]]),e.printSuccess(`Successfully authenticated as ${o.login}`)}catch(r){throw new Error(`Token validation failed: ${r.message}`)}}async function Zl(t){t.printInfo("Starting GitHub browser authentication for GitHub Models...");try{try{rt("gh --version",{stdio:"ignore"})}catch{throw new Error("GitHub CLI (gh) is not installed. Please install it first: https://cli.github.com/")}try{rt("gh auth status",{encoding:"utf8",stdio:"pipe"}).includes("Logged in to github.com")&&t.printInfo("Already authenticated with GitHub CLI")}catch{t.printInfo("Authenticating with GitHub CLI..."),t.printInfo("Please follow the instructions in your browser to complete authentication.");try{rt("gh auth login --web -h github.com",{stdio:"inherit"})}catch{throw new Error("GitHub CLI authentication failed")}}t.printInfo("Verifying GitHub Models access...");try{const e=rt("gh auth token",{encoding:"utf8"}).trim();e&&(await fr([["GITHUB_MODELS.key",e]]),t.printSuccess("GitHub token stored for GitHub Models access"))}catch{t.printWarning("Could not extract token from GitHub CLI, but authentication completed")}t.printSuccess("GitHub authentication completed and GitHub Models access verified!"),t.printInfo("See usage guide: https://github.com/tak-bro/aicommit2/blob/main/docs/providers/github-models.md"),t.printInfo("Available models: gpt-4o-mini, gpt-4o, meta-llama-3.1-405b-instruct, etc."),t.printInfo("Using GitHub Models API: https://models.github.ai")}catch(e){throw e}}const Te="prepare-commit-msg",eu=async()=>{const t=await Rt();if(t==="git")return`.git/hooks/${Te}`;if(t==="yadm"){const e=process.env.HOME||process.env.USERPROFILE;if(!e)throw new v("HOME environment variable not set. Cannot determine YADM hook path.");try{const{execa:s}=await Promise.resolve().then(function(){return Ya}),{stdout:n}=await s("yadm",["introspect","repo"]),i=n.trim();if(i)return M.join(i,"hooks",Te)}catch{}const r=M.join(e,".config/yadm/hooks"),o=M.join(e,".yadm/hooks");try{return await D.access(r),M.join(r,Te)}catch{return M.join(o,Te)}}throw t==="jujutsu"?new v("Hooks are not supported for Jujutsu repositories."):new v(`Hooks are not supported for ${t} repositories.`)},Dt=un(new URL("cli.mjs",import.meta.url)),tu=process.argv[1].replace(/\\/g,"/").includes(`/hooks/${Te}`),Ds=process.platform==="win32",_s=`
|
|
258
263
|
#!/usr/bin/env node
|
|
259
|
-
import(${JSON.stringify(
|
|
260
|
-
`.trim();var
|
|
261
|
-
`);const r=await Promise.all(e.map(async o=>{const
|
|
262
|
-
${
|
|
263
|
-
`,
|
|
264
|
-
`,
|
|
265
|
-
`,
|
|
266
|
-
`,
|
|
267
|
-
`,
|
|
268
|
-
`):(
|
|
269
|
-
`,
|
|
270
|
-
`,
|
|
271
|
-
`),
|
|
272
|
-
`),
|
|
264
|
+
import(${JSON.stringify(dn(Dt))})
|
|
265
|
+
`.trim();var ru=ce({name:"hook",parameters:["<install/uninstall>"],help:{description:"Install or uninstall the Git prepare-commit-msg hook",examples:["aic2 hook install","aic2 hook uninstall"]}},t=>{(async()=>{const e=await Lr(),{installUninstall:r}=t._,o=await eu(),s=M.isAbsolute(o)?o:M.join(e,o),n=await gt(s);if(r==="install"){if(n){if(await D.realpath(s).catch(()=>{})===Dt){console.warn("The hook is already installed");return}throw new v(`A different ${Te} hook seems to be installed. Please remove it before installing aicommit2.`)}await D.mkdir(M.dirname(s),{recursive:!0}),Ds?await D.writeFile(s,_s):(await D.symlink(Dt,s,"file"),await D.chmod(s,493)),console.log(`${g.green("\u2714")} Hook installed`);return}if(r==="uninstall"){if(!n){console.warn("Hook is not installed");return}if(Ds){if(await D.readFile(s,"utf8")!==_s){console.warn("Hook is not installed");return}}else if(await D.realpath(s)!==Dt){console.warn("Hook is not installed");return}await D.rm(s),console.log(`${g.green("\u2714")} Hook uninstalled`);return}throw new v(`Invalid mode: ${r}`)})().catch(e=>{console.error(`${g.red("\u2716")} ${e.message}`),me(e),process.exit(1)})});const ou=on(Ys),su=t=>{const e=["B","KB","MB","GB"];if(t===0)return"0 B";const r=Math.floor(Math.log(t)/Math.log(1024));return Math.round(t/Math.pow(1024,r)*100)/100+" "+e[r]},nu=t=>t.toLocaleDateString()+" "+t.toLocaleTimeString(),iu=async t=>{try{const e=await co(ue);if(e.length===0){console.log(`${g.yellow("No log files found.")}`);return}console.log(`${g.blue("Log files in")} ${ue}:
|
|
266
|
+
`);const r=await Promise.all(e.map(async o=>{const s=we.join(ue,o),n=await En(s);return{name:o,size:su(n.size),modified:nu(n.mtime)}}));r.sort((o,s)=>new Date(s.modified).getTime()-new Date(o.modified).getTime()),r.forEach((o,s)=>{console.log(`${s===0?"\u{1F4C4}":" "} ${g.cyan(o.name)} ${g.gray(`(${o.size}, ${o.modified})`)}`)}),console.log(`
|
|
267
|
+
${g.green("Total:")} ${e.length} file${e.length!==1?"s":""}`)}catch(e){if(e.code==="ENOENT")console.log(`${g.yellow("Logs directory does not exist yet.")}`);else throw e}},au=async t=>{try{await co(ue);const e=process.platform;let r;switch(e){case"darwin":r=`open "${ue}"`;break;case"win32":r=`start "" "${ue}"`;break;default:r=`xdg-open "${ue}"`;break}await ou(r),console.log(`${g.green("\u2714")} Opened logs directory in file manager`)}catch(e){e.code==="ENOENT"?console.log(`${g.yellow("Logs directory does not exist yet.")}`):t.printError(`Failed to open logs directory: ${e.message}`)}},cu=async t=>{try{await $n(ue,{recursive:!0,force:!0}),console.log(`${g.green("\u2714")} All log files removed!`)}catch(e){t.printError(`Failed to remove log files: ${e.message}`)}};var lu=ce({name:"log",parameters:["<action>"],help:{description:"Manage log files generated by the application",examples:["aic2 log list # List all log files","aic2 log path # Show logs directory path","aic2 log open # Open logs directory","aic2 log removeAll # Remove all log files"]}},t=>{(async()=>{const{action:e}=t._,r=new de;switch(e){case"list":await iu();break;case"path":console.log(`${g.blue("Logs directory:")} ${ue}`);break;case"open":await au(r);break;case"removeAll":await cu(r);break;default:throw new v(`Invalid action: ${e}. Use 'list', 'path', 'open', or 'removeAll'`)}})().catch(e=>{new de().printError(e.message),me(e),process.exit(1)})});const uu=process.argv.slice(2).filter(t=>!t.startsWith("--pre-commit")),[_t,Ns]=uu;var du=(t=!1)=>(async()=>{if(!_t)throw new v('Commit message file path is missing. This file should be called from the "pre-commit framework"');if(Ns){console.log(`Skipping aicommit2 message generation for ${Ns} commit`);return}const e=await Fr();if(!e)return;const r=new de;r.printTitle();const o={};t&&(o.logLevel="verbose");const s=await ge(o);if(s.systemPromptPath)try{await D.readFile(M.resolve(s.systemPromptPath),"utf-8")}catch{throw new v(`Error reading system prompt file: ${s.systemPromptPath}`)}const n=Oe(s,"commit");if(n.length===0)throw new v("Please set at least one API key via the `aicommit2 config set` command");const a=await Ot(),c=new Mt(s,e,a);let d;try{d=await Ut(c.createCommitMsgRequests$(n).pipe(to(w=>!w.isError),T(w=>w.value),Ht()))}finally{r.printAnalyzed()}const u=await D.readFile(_t,"utf8")!=="",p=d.length>1;let f="";u&&(f=`# \u{1F916} Generated by aicommit2 (https://github.com/tak-bro/aicommit2)
|
|
268
|
+
`,f+=`# ----------------------------------------
|
|
269
|
+
`,f+=`# How to use:
|
|
270
|
+
`,p?(f+=`# 1. Remove the "#" from your chosen message
|
|
271
|
+
`,f+=`# 2. Edit the message if needed
|
|
272
|
+
`,f+=`# 3. Save and close the editor
|
|
273
|
+
`):(f+=`# 1. The message below will be used
|
|
274
|
+
`,f+=`# 2. Edit the message if needed
|
|
275
|
+
`,f+=`# 3. Save and close the editor
|
|
276
|
+
`),f+=`# ----------------------------------------
|
|
277
|
+
`),p?(u&&(f+=`
|
|
273
278
|
# \u{1F4DD} Choose one of these messages:
|
|
274
|
-
`),
|
|
275
|
-
${d.map(
|
|
276
|
-
`)}`):(u&&(
|
|
279
|
+
`),f+=`
|
|
280
|
+
${d.map(w=>`# ${w}`).join(`
|
|
281
|
+
`)}`):(u&&(f+=`
|
|
277
282
|
# \u{1F4DD} Generated commit message:
|
|
278
|
-
`),
|
|
283
|
+
`),f+=`
|
|
279
284
|
${d[0]}
|
|
280
|
-
`);const h=await
|
|
281
|
-
`+h;await
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
`,
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
`):(
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
`)
|
|
291
|
-
`),
|
|
285
|
+
`);const h=await D.readFile(_t,"utf8"),y=f+`
|
|
286
|
+
`+h;await D.writeFile(_t,y),r.printSavedCommitMessage()})().catch(e=>{new de().printError(e.message),me(e),process.exit(1)});const Ur=process.argv.slice(2),Ts=[];let Hr=!1;for(let t=0;t<Ur.length;t++){const e=Ur[t];if(Hr){Hr=!1;continue}if(e!=="--hook-mode"){if(e.startsWith("-")){const r=Ur[t+1];r&&!r.startsWith("-")&&(Hr=!0);continue}Ts.push(e)}}const[Nt,Ls]=Ts;var mu=(t,e,r,o,s,n,i)=>(async()=>{if(!Nt)throw new v('Commit message file path is missing. This file should be called from the "prepare-commit-msg" git hook or with --hook-mode flag');if(Ls){console.log(`Skipping aicommit2 message generation for ${Ls} commit`);return}const a=await Fr();if(!a)return;const c=new de;c.printTitle();const d={locale:t?.toString(),generate:e?.toString(),type:o?.toString(),systemPrompt:s?.toString(),...n===!0&&{includeBody:"true"}};i&&(d.logLevel="verbose");const l=await ge(d,r);if(l.systemPromptPath)try{await D.readFile(M.resolve(l.systemPromptPath),"utf-8")}catch{throw new v(`Error reading system prompt file: ${l.systemPromptPath}`)}const u=Oe(l,"commit");if(u.length===0)throw new v("Please set at least one API key via the `aicommit2 config set` command");const f=await Ot(),h=new Mt(l,a,f),y=c.displaySpinner("The AI is analyzing your changes");let w;try{w=await Ut(h.createCommitMsgRequests$(u).pipe(to(S=>!S.isError),T(S=>S.value),Ht()))}finally{y.stop(),y.clear(),c.printAnalyzed()}const b=await D.readFile(Nt,"utf8")!=="",E=w.length>1,k=await Rl();let $="";b&&($=`${k} \u{1F916} Generated by aicommit2 (https://github.com/tak-bro/aicommit2)
|
|
287
|
+
`,$+=`${k} ----------------------------------------
|
|
288
|
+
`,$+=`${k} How to use:
|
|
289
|
+
`,E?($+=`${k} 1. Remove the "${k}" from your chosen message
|
|
290
|
+
`,$+=`${k} 2. Edit the message if needed
|
|
291
|
+
`,$+=`${k} 3. Save and close the editor
|
|
292
|
+
`):($+=`${k} 1. The message below will be used
|
|
293
|
+
`,$+=`${k} 2. Edit the message if needed
|
|
294
|
+
`,$+=`${k} 3. Save and close the editor
|
|
295
|
+
`),$+=`${k} ----------------------------------------
|
|
296
|
+
`),E?(b&&($+=`
|
|
292
297
|
${k} \u{1F4DD} Choose one of these messages:
|
|
293
|
-
`)
|
|
294
|
-
${
|
|
295
|
-
`)}`):(
|
|
298
|
+
`),$+=`
|
|
299
|
+
${w.map(S=>`${k} ${S}`).join(`
|
|
300
|
+
`)}`):(b&&($+=`
|
|
296
301
|
${k} \u{1F4DD} Generated commit message:
|
|
297
|
-
`)
|
|
298
|
-
${
|
|
299
|
-
`);const
|
|
300
|
-
|
|
302
|
+
`),$+=`
|
|
303
|
+
${w[0]}
|
|
304
|
+
`);const P=await D.readFile(Nt,"utf8"),O=$+`
|
|
305
|
+
`+P;await D.writeFile(Nt,O),c.printSavedCommitMessage()})().catch(a=>{new de().printError(a.message),me(a),process.exit(1)});const Fs=20,js=t=>t<1e3?`${t}ms`:`${(t/1e3).toFixed(1)}s`,Bs=t=>new Date(t).toLocaleDateString(),pu=t=>{const e=Math.round(t/100*Fs),r=Fs-e;return g.cyan("\u2588".repeat(e))+g.gray("\u2591".repeat(r))},fu=(t,e)=>{const r=Math.round(t.totalRequests/e*100),o=pu(r),s=t.totalRequests>0?Math.round(t.successCount/t.totalRequests*100):0,n=t.provider.padEnd(14),i=`${t.totalRequests}`.padStart(4),a=`(${r}%)`.padStart(6),c=js(t.avgResponseTimeMs).padStart(6),d=`${s}%`.padStart(4);console.log(` ${g.bold(n)} ${o} ${i} ${g.gray(a)} ${c} ${g.green(d)}`)},hu=async t=>{if(!await Sl()){console.log(g.yellow(`
|
|
306
|
+
No statistics recorded yet.`)),console.log(g.gray(`Statistics will be collected as you generate commit messages.
|
|
307
|
+
`));return}const r=await Pl(t);if(r.totalRequests===0){console.log(g.yellow(`
|
|
308
|
+
No statistics in the last ${t} days.
|
|
309
|
+
`));return}if(console.log(""),console.log(g.bold("\u{1F4CA} AICommit2 Statistics")),console.log(g.gray(` Period: ${Bs(r.periodStart)} - ${Bs(r.periodEnd)}`)),console.log(""),console.log(g.bold("Overview:")),console.log(` Total requests: ${g.cyan(r.totalRequests)}`),console.log(` Success rate: ${g.green(r.successRate+"%")}`),console.log(` Avg response time: ${g.yellow(js(r.avgResponseTimeMs))}`),console.log(""),r.providerStats.length>0){const o=Math.max(...r.providerStats.map(s=>s.totalRequests));console.log(g.bold("Provider Usage:")),console.log(g.gray(" Avg Success")),console.log(g.gray(" Provider Progress Count Time Rate"));for(const s of r.providerStats)fu(s,o);console.log("")}},gu=async()=>{await Al(),console.log(g.green(`
|
|
310
|
+
Statistics cleared successfully.
|
|
311
|
+
`))},yu=ce({name:"stats",parameters:["[action]"],flags:{days:{type:Number,description:"Number of days to include in statistics (default: 30)",alias:"d",default:30}},help:{description:"View AI request statistics and performance metrics",examples:["aicommit2 stats Show statistics for last 30 days","aicommit2 stats -d 7 Show statistics for last 7 days","aicommit2 stats clear Clear all statistics"]}},t=>{(async()=>{const e=t._[0],{days:r}=t.flags;switch(e){case"clear":await gu();break;default:await hu(r);break}})().catch(e=>{console.error(g.red(e.message)),me(e),process.exit(1)})});class Gs{constructor(e="SubscriptionManager"){this.destroyed$=new Kt,this.subscriptions=new Gt,this.isDestroyed=!1,this.name=e}add(e,r){if(this.isDestroyed){console.warn(`${this.name}: Cannot add subscription - manager is destroyed`);const s=new Gt;return s.unsubscribe(),s}const o=e.pipe(lo(this.destroyed$),uo(()=>{process.env.NODE_ENV==="development"&&console.log(`${this.name}: Observable finalized`)})).subscribe({next:r?.next,error:s=>{console.error(`${this.name}: Observable error:`,s),r?.error?.(s)},complete:r?.complete});return this.subscriptions.add(o),o}pipe(e){return this.isDestroyed?(console.warn(`${this.name}: Cannot pipe - manager is destroyed`),e):e.pipe(lo(this.destroyed$),uo(()=>{process.env.NODE_ENV==="development"&&console.log(`${this.name}: Piped observable finalized`)}))}addSubscription(e){if(this.isDestroyed){console.warn(`${this.name}: Cannot add subscription - manager is destroyed`),e.unsubscribe();return}this.subscriptions.add(e)}get destroySignal$(){return this.destroyed$.asObservable()}get isActive(){return!this.isDestroyed}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.subscriptions.unsubscribe(),this.destroyed$.next(),this.destroyed$.complete(),process.env.NODE_ENV==="development"&&console.log(`${this.name}: Destroyed successfully`))}}const wu=new Gs("Global"),tt=()=>{wu.destroy()};process.on("exit",tt),process.on("SIGINT",tt),process.on("SIGTERM",tt),process.on("uncaughtException",t=>{console.error("Uncaught exception:",t),tt(),process.exit(1)}),process.on("unhandledRejection",(t,e)=>{console.error("Unhandled rejection at:",e,"reason:",t),tt(),process.exit(1)});class vu{constructor(){this.destroyed$=new Kt,this.consoleManager=new de,this.subscriptionManager=new Gs,this.currentCodeReviewSubscription=null,this.currentCodeReviewPromptManager=null,this.watcher=null,this.lastCommitHash=null,this.isProcessingCommit=!1,this.REPO_PATH=process.cwd(),this.GIT_PATH=M.join(this.REPO_PATH,".git"),this.HEAD_PATH=M.join(this.GIT_PATH,"HEAD"),this.REFS_PATH=M.join(this.GIT_PATH,"refs","heads"),this.COMMIT_MSG_PATH=M.join(this.GIT_PATH,"COMMIT_EDITMSG"),this.setupProcessHandlers()}setupProcessHandlers(){const e=()=>{this.destroy(),process.exit(0)};process.on("SIGINT",e),process.on("SIGTERM",e),process.on("SIGQUIT",e)}async watch(e,r,o,s,n,i){this.consoleManager.printTitle(),await Lr();const a=await Rt();if(a!=="git")throw new v(`Watch mode is only supported for Git repositories. Current VCS: ${a}`);const c=await this.initializeConfig(e,r,s,n,i);await this.initializeCurrentCommit();try{await this.watchGitEvents(c)}catch(d){return await this.handleWatchGitError(d),this.watch(e,r,o,s,n,i)}}async initializeConfig(e,r,o,s,n){const i={locale:e?.toString(),generate:r?.toString(),systemPrompt:o?.toString()};s&&(i.logLevel="verbose");const a=await ge(i,n);return await Ps(a),Oe(a,"watch").length===0&&(this.consoleManager.printError(`Please set at least one API key and watchMode via the config command:
|
|
301
312
|
aicommit2 config set [MODEL].key="YOUR_API_KEY"
|
|
302
|
-
aicommit2 config set [MODEL].watchMode="true"`),process.exit()),
|
|
313
|
+
aicommit2 config set [MODEL].watchMode="true"`),process.exit()),a}async handleWatchGitError(e){this.consoleManager.printError(`An error occurred: ${e.message}`),me(e),await new Promise(r=>setTimeout(r,3e3)),this.consoleManager.printWarning("Restarting the commit monitoring process...")}async initializeCurrentCommit(){try{const e=await this.executeGitCommand("git rev-parse HEAD");this.lastCommitHash=e.trim(),this.consoleManager.printInfo(`Starting watch from commit: ${this.lastCommitHash.substring(0,8)}`)}catch{this.consoleManager.printWarning("No commits found in repository"),this.lastCommitHash=null}}async executeGitCommand(e){const r=tn(qs),{stdout:o}=await r(e,{cwd:this.REPO_PATH});return o}clearTerminal(){process.stdout.write("\x1Bc")}async handleCommitEvent(e,r){try{const o=await xl(r);if(!o){this.consoleManager.printWarning("No changes found in this commit");return}this.consoleManager.stopLoader(),this.consoleManager.printStagedFiles(o);const s=Oe(e,"watch");if(s.length===0){this.consoleManager.printError(`Please set at least one API key and watchMode via the config command:
|
|
303
314
|
aicommit2 config set [MODEL].key="YOUR_API_KEY"
|
|
304
|
-
aicommit2 config set [MODEL].watchMode="true"`),process.exit();return}await this.performCodeReview(e,o,
|
|
315
|
+
aicommit2 config set [MODEL].watchMode="true"`),process.exit();return}await this.performCodeReview(e,o,s)}catch(o){this.consoleManager.printError(`Error processing commit ${r}: ${o.message}`)}}async performCodeReview(e,r,o){this.cleanupPreviousCodeReview();const s=await Ot(),n=new Mt(e,r,s);this.currentCodeReviewPromptManager=new Gr(xs);try{const i=this.initializeCodeReviewInquirer();this.currentCodeReviewPromptManager.startLoader(),this.currentCodeReviewSubscription=this.subscribeToCodeReviewRequests(n,o),await i}finally{this.cleanupCodeReview()}}cleanupPreviousCodeReview(){this.cleanupCurrentReviewResources(),this.destroyed$.closed||(this.destroyed$.next(),this.destroyed$.complete()),this.destroyed$=new Kt}initializeCodeReviewInquirer(){return this.currentCodeReviewPromptManager.initPrompt({...Br,name:"codeReviewPrompt",message:"Please check code reviews: ",emptyMessage:`\u26A0 ${Rs}`,isDescriptionDim:!1,stopMessage:"Code review completed",descPageSize:20})}subscribeToCodeReviewRequests(e,r){return this.subscriptionManager.add(e.createCodeReviewRequests$(r),{next:o=>{this.currentCodeReviewPromptManager?.refreshChoices(o)},error:o=>{console.error("Code review request error:",o),this.currentCodeReviewPromptManager?.checkErrorOnChoices(!1)},complete:()=>{this.currentCodeReviewPromptManager?.checkErrorOnChoices(!1)}})}cleanupCurrentReviewResources(){this.currentCodeReviewSubscription&&(this.currentCodeReviewSubscription.unsubscribe(),this.currentCodeReviewSubscription=null),this.currentCodeReviewPromptManager&&(this.currentCodeReviewPromptManager.destroy(),this.currentCodeReviewPromptManager=null)}cleanupCodeReview(){this.cleanupCurrentReviewResources(),this.clearTerminal(),this.consoleManager.showLoader("Watching for new Git commits...")}async isGitReset(e){if(!this.lastCommitHash)return!1;try{const r=await this.executeGitCommand(`git merge-base --is-ancestor ${e} ${this.lastCommitHash}`);return!0}catch{return!1}}cancelCurrentReview(){this.currentCodeReviewPromptManager&&this.currentCodeReviewPromptManager.cancel(),this.cleanupCurrentReviewResources(),this.destroyed$.next()}async watchGitEvents(e){this.consoleManager.showLoader("Watching for new Git commits...");const o=[this.HEAD_PATH,this.REFS_PATH,this.COMMIT_MSG_PATH,M.join(this.GIT_PATH,"logs","HEAD")].filter(s=>{try{return Z.accessSync(s),!0}catch{return!1}});this.watcher=Pn.watch(o,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:500,pollInterval:100}}),this.watcher.on("change",async s=>{await this.handleGitChange(e,s)}),this.watcher.on("add",async s=>{await this.handleGitChange(e,s)}),this.watcher.on("error",s=>{this.consoleManager.printError(`Watcher error: ${s.message}`),setTimeout(()=>this.watchGitEvents(e),1e3)})}async handleGitChange(e,r){try{const s=(await this.executeGitCommand("git rev-parse HEAD")).trim();if(s!==this.lastCommitHash){if(await this.isGitReset(s)){this.clearTerminal(),this.consoleManager.printInfo(`\u21A9\uFE0F Git reset detected: ${s.substring(0,8)}`),this.lastCommitHash=s,this.isProcessingCommit&&(this.cancelCurrentReview(),this.isProcessingCommit=!1);return}if(this.isProcessingCommit){this.consoleManager.printInfo(`
|
|
305
316
|
\u{1F504} New commit detected, cancelling current review...`);try{this.cancelCurrentReview(),await new Promise(i=>setTimeout(i,200))}catch(i){console.warn("Error during review cancellation:",i)}}this.isProcessingCommit=!0;try{this.consoleManager.stopLoader(),this.consoleManager.printInfo(`
|
|
306
|
-
\u{1F50D} New commit detected: ${
|
|
317
|
+
\u{1F50D} New commit detected: ${s.substring(0,8)}`);const i=this.lastCommitHash;this.lastCommitHash=s,this.clearTerminal(),await this.handleCommitEvent(e,s)}catch(i){this.consoleManager.printError(`Error processing commit ${s.substring(0,8)}: ${i.message}`)}finally{this.isProcessingCommit=!1}}}catch(o){this.isProcessingCommit=!1,o.message?.includes("fatal: not a git repository")||this.consoleManager.printError(`Error checking for new commits: ${o.message}`)}}destroy(){this.isProcessingCommit=!1,this.lastCommitHash=null;try{this.subscriptionManager.destroy(),this.cleanupCurrentReviewResources(),this.watcher&&(this.watcher.close(),this.watcher=null),this.consoleManager.stopLoader(),this.destroyed$.next(),this.destroyed$.complete()}catch(e){console.warn("Error during WatchGitManager destruction:",e)}}}const Cu=new vu,bu=async(t,e,r,o,s,n)=>Cu.watch(t,e,r,o,s,n),Us={"Message Options":["locale","generate","type","prompt","include-body"],Behavior:["all","confirm","auto-select","edit","clipboard","dry-run","output"],"VCS Selection":["git","yadm","jj","jj-auto-new"],"Hook Integration":["hook-mode","pre-commit","watch-commit"],Formatting:["disable-lowercase","exclude"],Debug:["verbose"]},Eu=t=>{if(!t||typeof t!="object")return!1;const e=t;return e.data?.name!==void 0&&typeof e.data.name=="string"},$u=t=>Eu(t)?t.data.name:null,Pu=t=>{for(const[e,r]of Object.entries(Us))if(r.includes(t))return e;return null},Au=t=>t.type==="section"&&t.data?.title==="Flags:",Su=t=>t.data?.body?.data?.tableData!==void 0,ku=t=>{const e=new Map;for(const r of Object.keys(Us))e.set(r,[]);if(e.set("Other",[]),!Array.isArray(t))return e;for(const r of t){if(!Array.isArray(r))continue;const o=$u(r[0]),s=o&&Pu(o)||"Other";e.get(s)?.push(r)}return e},Iu=(t,e,r,o,s)=>({type:"section",data:{title:s?`Flags - ${t}:`:` ${t}:`,body:{type:"table",data:{tableData:e,tableOptions:r,tableBreakpoints:o}}}}),Mu=(t,e)=>{const r=[];for(const o of t){if(!Au(o)||!Su(o)){r.push(o);continue}const{tableData:s,tableOptions:n,tableBreakpoints:i}=o.data.body.data;[...ku(s).entries()].filter(([,d])=>d.length>0).forEach(([d,l],u)=>{r.push(Iu(d,l,n,i,u===0))})}return e.render(r)},Tt=process.argv.slice(2),{version:Hs,description:xu}=jn;Ks({name:"aicommit2",version:Hs,flags:{locale:{type:String,description:"Locale to use for the generated commit messages (default: en)",alias:"l"},generate:{type:Number,description:"Number of messages to generate (Warning: generating multiple costs more) (default: 1)",alias:"g"},exclude:{type:[String],description:"Files to exclude from AI analysis",alias:"x"},all:{type:Boolean,description:"Automatically stage changes in tracked files for the commit",alias:"a",default:!1},type:{type:String,description:"Type of commit message to generate (default: conventional)",alias:"t"},confirm:{type:Boolean,description:"Skip confirmation when committing after message generation (default: false)",alias:"y",default:!1},clipboard:{type:Boolean,description:"Copy the selected message to the clipboard",alias:"c",default:!1},prompt:{type:String,description:"Custom prompt to let users fine-tune provided prompt",alias:"p"},"watch-commit":{type:Boolean,default:!1},"hook-mode":{type:Boolean,description:"Run in git hook mode, allowing chaining with other hooks",default:!1},"pre-commit":{type:Boolean,description:"Run in pre-commit Framework, allowing chaining with other hooks",default:!1},"include-body":{type:Boolean,description:"Force include commit body in all generated messages",alias:"i",default:!1},"auto-select":{type:Boolean,description:"Automatically select the message when only one is generated",alias:"s",default:!1},edit:{type:Boolean,description:"Open the AI-generated commit message in your default editor",alias:"e",default:!1},"disable-lowercase":{type:Boolean,description:"Disable automatic lowercase conversion of commit messages",default:!1},verbose:{type:Boolean,description:"Enable verbose logging for this run",alias:"v",default:!1},git:{type:Boolean,description:"Force use Git (overrides auto-detection)",default:!1},yadm:{type:Boolean,description:"Force use YADM (overrides auto-detection)",default:!1},jj:{type:Boolean,description:"Force use Jujutsu (overrides auto-detection)",default:!1},"jj-auto-new":{type:Boolean,description:"Run jj new after jj describe (default: false, only describe)",default:!1},"dry-run":{type:Boolean,description:"Generate commit message without committing (output only)",alias:"d",default:!1},output:{type:String,description:"Output format for non-interactive mode (json). For LazyGit integration",alias:"o"}},commands:[Bl,Jl,Xl,ru,lu,yu],help:{description:xu,render:Mu},ignoreArgv:t=>t==="unknown-flag"||t==="argument"},async t=>{const e={};t.flags.verbose&&(e.logLevel="verbose");const r=await ge(e,Tt);if(await Cc(r),De.info(`aicommit2 version: ${Hs}`),t.flags["pre-commit"]){du(t.flags.verbose);return}if(t.flags["hook-mode"]||tu){mu(t.flags.locale,t.flags.generate,t.flags.exclude,t.flags.type,t.flags.prompt,t.flags["include-body"],t.flags.verbose);return}if(t.flags["watch-commit"]){bu(t.flags.locale,t.flags.generate,t.flags.exclude,t.flags.prompt,t.flags.verbose,Tt);return}Nl(t.flags.locale,t.flags.generate,t.flags.exclude,t.flags.all,t.flags.type,t.flags.confirm,t.flags.clipboard,t.flags.prompt,t.flags["include-body"],t.flags["auto-select"],t.flags.edit,t.flags["disable-lowercase"],t.flags.verbose,t.flags["dry-run"],t.flags["jj-auto-new"],t.flags.output,Tt)},Tt);
|