aicommit2 2.2.18 → 2.2.19
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/dist/cli.mjs +2 -2
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{command as Y,cli as Ho}from"cleye";import{createRequire as Uo}from"module";import{Buffer as qo}from"node:buffer";import te from"node:path";import Vt,{ChildProcess as zo}from"node:child_process";import U from"node:process";import Ko from"child_process";import P from"path";import _ from"fs";import{fileURLToPath as Xt}from"node:url";import Wo,{constants as Jt}from"node:os";import Qt from"assert";import Zt from"events";import{createWriteStream as Yo,createReadStream as Vo}from"node:fs";import Xo from"buffer";import ot from"stream";import er from"util";import{debuglog as Jo}from"node:util";import ke from"inquirer";import st from"ora";import w from"chalk";import{of as de,concatMap as k,from as $,map as A,catchError as S,mergeMap as Me,BehaviorSubject as tr,ReplaySubject as Qo,lastValueFrom as rr,filter as or,toArray as sr,Subject as nr}from"rxjs";import Zo from"@anthropic-ai/sdk";import{fromPromise as M}from"rxjs/internal/observable/innerFrom";import q from"winston";import"winston-daily-rotate-file";import x from"fs/promises";import Ie from"os";import{xxh64 as es}from"@pacote/xxhash";import ts from"axios";import{CohereClient as rs}from"cohere-ai";import ir from"openai";import{GoogleGenerativeAI as os,HarmCategory as Re,HarmBlockThreshold as Oe}from"@google/generative-ai";import ss from"groq-sdk";import{Ollama as ns}from"ollama";import{fetch as is,Agent as as}from"undici";import cs from"http";import ls from"https";import ms from"net";import us from"tls";import ps,{fileURLToPath as fs,pathToFileURL as ds}from"url";import ar from"tty";import Le from"readline";import hs from"figlet";import gs from"inquirer-reactive-list-prompt";import{rm as ys}from"node:fs/promises";import ws from"chokidar";import{takeUntil as vs}from"rxjs/operators";var bs="aicommit2",cr="2.2.18",Cs="A Reactive CLI that generates git commit messages with various AI",Ps=["cli","ai","git","commit","git-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"],$s="MIT",Es="tak-bro/aicommit2",xs="Hyungtak Jin(@tak-bro)",As="module",Ss=["dist"],ks={aicommit2:"./dist/cli.mjs",aic2:"./dist/cli.mjs"},Ms={prepare:"simple-git-hooks",build:"pkgroll --minify",lint:"eslint --cache .","type-check":"tsc",test:"tsx tests",prepack:"pnpm build && clean-pkg-json",prettier:"prettier"},Is={"@anthropic-ai/sdk":"^0.39.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.17.1","copy-paste":"^1.5.3",figlet:"^1.8.1","formdata-node":"^6.0.3","groq-sdk":"^0.7.0",inquirer:"9.2.8","inquirer-reactive-list-prompt":"^1.0.15",ollama:"^0.5.15",openai:"^4.102.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"},Rs={"@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"},Os={extends:["@pvtnbr","prettier"],rules:{"unicorn/no-process-exit":"off"},overrides:[{files:"./src/commands/prepare-commit-msg-hook.ts",rules:{"unicorn/prevent-abbreviations":"off"}}]},Ls={branches:["main"],plugins:[["@semantic-release/commit-analyzer",{preset:"conventionalcommits",releaseRules:[{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"]},Ts={name:bs,version:cr,description:Cs,keywords:Ps,license:$s,repository:Es,author:xs,type:As,files:Ss,bin:ks,scripts:Ms,"simple-git-hooks":{"pre-commit":"pnpm lint-staged"},"lint-staged":{"*.ts":["prettier --config ./.prettierrc --write","eslint --fix"]},dependencies:Is,devDependencies:Rs,eslintConfig:Os,release:Ls},Ns=Uo(import.meta.url),O=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function re(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var oe={exports:{}},nt,lr;function _s(){if(lr)return nt;lr=1,nt=r,r.sync=n;var t=_;function e(s,i){var c=i.pathExt!==void 0?i.pathExt:process.env.PATHEXT;if(!c||(c=c.split(";"),c.indexOf("")!==-1))return!0;for(var l=0;l<c.length;l++){var u=c[l].toLowerCase();if(u&&s.substr(-u.length).toLowerCase()===u)return!0}return!1}function o(s,i,c){return!s.isSymbolicLink()&&!s.isFile()?!1:e(i,c)}function r(s,i,c){t.stat(s,function(l,u){c(l,l?!1:o(u,s,i))})}function n(s,i){return o(t.statSync(s),s,i)}return nt}var it,mr;function Fs(){if(mr)return it;mr=1,it=e,e.sync=o;var t=_;function e(s,i,c){t.stat(s,function(l,u){c(l,l?!1:r(u,i))})}function o(s,i){return r(t.statSync(s),i)}function r(s,i){return s.isFile()&&n(s,i)}function n(s,i){var c=s.mode,l=s.uid,u=s.gid,p=i.uid!==void 0?i.uid:process.getuid&&process.getuid(),a=i.gid!==void 0?i.gid:process.getgid&&process.getgid(),m=parseInt("100",8),d=parseInt("010",8),h=parseInt("001",8),g=m|d,y=c&h||c&d&&u===a||c&m&&l===p||c&g&&p===0;return y}return it}var Te;process.platform==="win32"||O.TESTING_WINDOWS?Te=_s():Te=Fs();var Ds=at;at.sync=Gs;function at(t,e,o){if(typeof e=="function"&&(o=e,e={}),!o){if(typeof Promise!="function")throw new TypeError("callback not provided");return new Promise(function(r,n){at(t,e||{},function(s,i){s?n(s):r(i)})})}Te(t,e||{},function(r,n){r&&(r.code==="EACCES"||e&&e.ignoreErrors)&&(r=null,n=!1),o(r,n)})}function Gs(t,e){try{return Te.sync(t,e||{})}catch(o){if(e&&e.ignoreErrors||o.code==="EACCES")return!1;throw o}}const se=process.platform==="win32"||process.env.OSTYPE==="cygwin"||process.env.OSTYPE==="msys",ur=P,js=se?";":":",pr=Ds,fr=t=>Object.assign(new Error(`not found: ${t}`),{code:"ENOENT"}),dr=(t,e)=>{const o=e.colon||js,r=t.match(/\//)||se&&t.match(/\\/)?[""]:[...se?[process.cwd()]:[],...(e.path||process.env.PATH||"").split(o)],n=se?e.pathExt||process.env.PATHEXT||".EXE;.CMD;.BAT;.COM":"",s=se?n.split(o):[""];return se&&t.indexOf(".")!==-1&&s[0]!==""&&s.unshift(""),{pathEnv:r,pathExt:s,pathExtExe:n}},hr=(t,e,o)=>{typeof e=="function"&&(o=e,e={}),e||(e={});const{pathEnv:r,pathExt:n,pathExtExe:s}=dr(t,e),i=[],c=u=>new Promise((p,a)=>{if(u===r.length)return e.all&&i.length?p(i):a(fr(t));const m=r[u],d=/^".*"$/.test(m)?m.slice(1,-1):m,h=ur.join(d,t),g=!d&&/^\.[\\\/]/.test(t)?t.slice(0,2)+h:h;p(l(g,u,0))}),l=(u,p,a)=>new Promise((m,d)=>{if(a===n.length)return m(c(p+1));const h=n[a];pr(u+h,{pathExt:s},(g,y)=>{if(!g&&y)if(e.all)i.push(u+h);else return m(u+h);return m(l(u,p,a+1))})});return o?c(0).then(u=>o(null,u),o):c(0)},Bs=(t,e)=>{e=e||{};const{pathEnv:o,pathExt:r,pathExtExe:n}=dr(t,e),s=[];for(let i=0;i<o.length;i++){const c=o[i],l=/^".*"$/.test(c)?c.slice(1,-1):c,u=ur.join(l,t),p=!l&&/^\.[\\\/]/.test(t)?t.slice(0,2)+u:u;for(let a=0;a<r.length;a++){const m=p+r[a];try{if(pr.sync(m,{pathExt:n}))if(e.all)s.push(m);else return m}catch{}}}if(e.all&&s.length)return s;if(e.nothrow)return null;throw fr(t)};var Hs=hr;hr.sync=Bs;var ct={exports:{}};const gr=(t={})=>{const e=t.env||process.env;return(t.platform||process.platform)!=="win32"?"PATH":Object.keys(e).reverse().find(r=>r.toUpperCase()==="PATH")||"Path"};ct.exports=gr,ct.exports.default=gr;var Us=ct.exports;const yr=P,qs=Hs,zs=Us;function wr(t,e){const o=t.options.env||process.env,r=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=qs.sync(t.command,{path:o[zs({env:o})],pathExt:e?yr.delimiter:void 0})}catch{}finally{s&&process.chdir(r)}return i&&(i=yr.resolve(n?t.options.cwd:"",i)),i}function Ks(t){return wr(t)||wr(t,!0)}var Ws=Ks,lt={};const mt=/([()\][%!^"`<>&|;, *?])/g;function Ys(t){return t=t.replace(mt,"^$1"),t}function Vs(t,e){return t=`${t}`,t=t.replace(/(?=(\\+?)?)\1"/g,'$1$1\\"'),t=t.replace(/(?=(\\+?)?)\1$/,"$1$1"),t=`"${t}"`,t=t.replace(mt,"^$1"),e&&(t=t.replace(mt,"^$1")),t}lt.command=Ys,lt.argument=Vs;var Xs=/^#!(.*)/;const Js=Xs;var Qs=(t="")=>{const e=t.match(Js);if(!e)return null;const[o,r]=e[0].replace(/#! ?/,"").split(" "),n=o.split("/").pop();return n==="env"?r:r?`${n} ${r}`:n};const ut=_,Zs=Qs;function en(t){const o=Buffer.alloc(150);let r;try{r=ut.openSync(t,"r"),ut.readSync(r,o,0,150,0),ut.closeSync(r)}catch{}return Zs(o.toString())}var tn=en;const rn=P,vr=Ws,br=lt,on=tn,sn=process.platform==="win32",nn=/\.(?:com|exe)$/i,an=/node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;function cn(t){t.file=vr(t);const e=t.file&&on(t.file);return e?(t.args.unshift(t.file),t.command=e,vr(t)):t.file}function ln(t){if(!sn)return t;const e=cn(t),o=!nn.test(e);if(t.options.forceShell||o){const r=an.test(e);t.command=rn.normalize(t.command),t.command=br.command(t.command),t.args=t.args.map(s=>br.argument(s,r));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 mn(t,e,o){e&&!Array.isArray(e)&&(o=e,e=null),e=e?e.slice(0):[],o=Object.assign({},o);const r={command:t,args:e,options:o,file:void 0,original:{command:t,args:e}};return o.shell?r:ln(r)}var un=mn;const pt=process.platform==="win32";function ft(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 pn(t,e){if(!pt)return;const o=t.emit;t.emit=function(r,n){if(r==="exit"){const s=Cr(n,e);if(s)return o.call(t,"error",s)}return o.apply(t,arguments)}}function Cr(t,e){return pt&&t===1&&!e.file?ft(e.original,"spawn"):null}function fn(t,e){return pt&&t===1&&!e.file?ft(e.original,"spawnSync"):null}var dn={hookChildProcess:pn,verifyENOENT:Cr,verifyENOENTSync:fn,notFoundError:ft};const Pr=Ko,dt=un,ht=dn;function $r(t,e,o){const r=dt(t,e,o),n=Pr.spawn(r.command,r.args,r.options);return ht.hookChildProcess(n,r),n}function hn(t,e,o){const r=dt(t,e,o),n=Pr.spawnSync(r.command,r.args,r.options);return n.error=n.error||ht.verifyENOENTSync(n.status,r),n}oe.exports=$r,oe.exports.spawn=$r,oe.exports.sync=hn,oe.exports._parse=dt,oe.exports._enoent=ht;var gn=oe.exports,yn=re(gn);function wn(t){const e=typeof t=="string"?`
|
|
2
|
+
import{command as Y,cli as Ho}from"cleye";import{createRequire as Uo}from"module";import{Buffer as qo}from"node:buffer";import te from"node:path";import Vt,{ChildProcess as zo}from"node:child_process";import U from"node:process";import Ko from"child_process";import P from"path";import _ from"fs";import{fileURLToPath as Xt}from"node:url";import Wo,{constants as Jt}from"node:os";import Qt from"assert";import Zt from"events";import{createWriteStream as Yo,createReadStream as Vo}from"node:fs";import Xo from"buffer";import ot from"stream";import er from"util";import{debuglog as Jo}from"node:util";import ke from"inquirer";import st from"ora";import w from"chalk";import{of as de,concatMap as k,from as $,map as A,catchError as S,mergeMap as Me,BehaviorSubject as tr,ReplaySubject as Qo,lastValueFrom as rr,filter as or,toArray as sr,Subject as nr}from"rxjs";import Zo from"@anthropic-ai/sdk";import{fromPromise as M}from"rxjs/internal/observable/innerFrom";import q from"winston";import"winston-daily-rotate-file";import x from"fs/promises";import Ie from"os";import{xxh64 as es}from"@pacote/xxhash";import ts from"axios";import{CohereClient as rs}from"cohere-ai";import ir from"openai";import{GoogleGenerativeAI as os,HarmCategory as Re,HarmBlockThreshold as Oe}from"@google/generative-ai";import ss from"groq-sdk";import{Ollama as ns}from"ollama";import{fetch as is,Agent as as}from"undici";import cs from"http";import ls from"https";import ms from"net";import us from"tls";import ps,{fileURLToPath as fs,pathToFileURL as ds}from"url";import ar from"tty";import Le from"readline";import hs from"figlet";import gs from"inquirer-reactive-list-prompt";import{rm as ys}from"node:fs/promises";import ws from"chokidar";import{takeUntil as vs}from"rxjs/operators";var bs="aicommit2",cr="2.2.19",Cs="A Reactive CLI that generates git commit messages with various AI",Ps=["cli","ai","git","commit","git-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"],$s="MIT",Es="tak-bro/aicommit2",xs="Hyungtak Jin(@tak-bro)",As="module",Ss=["dist"],ks={aicommit2:"./dist/cli.mjs",aic2:"./dist/cli.mjs"},Ms={prepare:"simple-git-hooks",build:"pkgroll --minify",lint:"eslint --cache .","type-check":"tsc",test:"tsx tests",prepack:"pnpm build && clean-pkg-json",prettier:"prettier"},Is={"@anthropic-ai/sdk":"^0.39.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.17.1","copy-paste":"^1.5.3",figlet:"^1.8.1","formdata-node":"^6.0.3","groq-sdk":"^0.7.0",inquirer:"9.2.8","inquirer-reactive-list-prompt":"^1.0.15",ollama:"^0.5.15",openai:"^4.102.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"},Rs={"@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"},Os={extends:["@pvtnbr","prettier"],rules:{"unicorn/no-process-exit":"off"},overrides:[{files:"./src/commands/prepare-commit-msg-hook.ts",rules:{"unicorn/prevent-abbreviations":"off"}}]},Ls={branches:["main"],plugins:[["@semantic-release/commit-analyzer",{preset:"conventionalcommits",releaseRules:[{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"]},Ts={name:bs,version:cr,description:Cs,keywords:Ps,license:$s,repository:Es,author:xs,type:As,files:Ss,bin:ks,scripts:Ms,"simple-git-hooks":{"pre-commit":"pnpm lint-staged"},"lint-staged":{"*.ts":["prettier --config ./.prettierrc --write","eslint --fix"]},dependencies:Is,devDependencies:Rs,eslintConfig:Os,release:Ls},Ns=Uo(import.meta.url),O=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function re(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var oe={exports:{}},nt,lr;function _s(){if(lr)return nt;lr=1,nt=r,r.sync=n;var t=_;function e(s,i){var c=i.pathExt!==void 0?i.pathExt:process.env.PATHEXT;if(!c||(c=c.split(";"),c.indexOf("")!==-1))return!0;for(var l=0;l<c.length;l++){var u=c[l].toLowerCase();if(u&&s.substr(-u.length).toLowerCase()===u)return!0}return!1}function o(s,i,c){return!s.isSymbolicLink()&&!s.isFile()?!1:e(i,c)}function r(s,i,c){t.stat(s,function(l,u){c(l,l?!1:o(u,s,i))})}function n(s,i){return o(t.statSync(s),s,i)}return nt}var it,mr;function Fs(){if(mr)return it;mr=1,it=e,e.sync=o;var t=_;function e(s,i,c){t.stat(s,function(l,u){c(l,l?!1:r(u,i))})}function o(s,i){return r(t.statSync(s),i)}function r(s,i){return s.isFile()&&n(s,i)}function n(s,i){var c=s.mode,l=s.uid,u=s.gid,p=i.uid!==void 0?i.uid:process.getuid&&process.getuid(),a=i.gid!==void 0?i.gid:process.getgid&&process.getgid(),m=parseInt("100",8),d=parseInt("010",8),h=parseInt("001",8),g=m|d,y=c&h||c&d&&u===a||c&m&&l===p||c&g&&p===0;return y}return it}var Te;process.platform==="win32"||O.TESTING_WINDOWS?Te=_s():Te=Fs();var Ds=at;at.sync=Gs;function at(t,e,o){if(typeof e=="function"&&(o=e,e={}),!o){if(typeof Promise!="function")throw new TypeError("callback not provided");return new Promise(function(r,n){at(t,e||{},function(s,i){s?n(s):r(i)})})}Te(t,e||{},function(r,n){r&&(r.code==="EACCES"||e&&e.ignoreErrors)&&(r=null,n=!1),o(r,n)})}function Gs(t,e){try{return Te.sync(t,e||{})}catch(o){if(e&&e.ignoreErrors||o.code==="EACCES")return!1;throw o}}const se=process.platform==="win32"||process.env.OSTYPE==="cygwin"||process.env.OSTYPE==="msys",ur=P,js=se?";":":",pr=Ds,fr=t=>Object.assign(new Error(`not found: ${t}`),{code:"ENOENT"}),dr=(t,e)=>{const o=e.colon||js,r=t.match(/\//)||se&&t.match(/\\/)?[""]:[...se?[process.cwd()]:[],...(e.path||process.env.PATH||"").split(o)],n=se?e.pathExt||process.env.PATHEXT||".EXE;.CMD;.BAT;.COM":"",s=se?n.split(o):[""];return se&&t.indexOf(".")!==-1&&s[0]!==""&&s.unshift(""),{pathEnv:r,pathExt:s,pathExtExe:n}},hr=(t,e,o)=>{typeof e=="function"&&(o=e,e={}),e||(e={});const{pathEnv:r,pathExt:n,pathExtExe:s}=dr(t,e),i=[],c=u=>new Promise((p,a)=>{if(u===r.length)return e.all&&i.length?p(i):a(fr(t));const m=r[u],d=/^".*"$/.test(m)?m.slice(1,-1):m,h=ur.join(d,t),g=!d&&/^\.[\\\/]/.test(t)?t.slice(0,2)+h:h;p(l(g,u,0))}),l=(u,p,a)=>new Promise((m,d)=>{if(a===n.length)return m(c(p+1));const h=n[a];pr(u+h,{pathExt:s},(g,y)=>{if(!g&&y)if(e.all)i.push(u+h);else return m(u+h);return m(l(u,p,a+1))})});return o?c(0).then(u=>o(null,u),o):c(0)},Bs=(t,e)=>{e=e||{};const{pathEnv:o,pathExt:r,pathExtExe:n}=dr(t,e),s=[];for(let i=0;i<o.length;i++){const c=o[i],l=/^".*"$/.test(c)?c.slice(1,-1):c,u=ur.join(l,t),p=!l&&/^\.[\\\/]/.test(t)?t.slice(0,2)+u:u;for(let a=0;a<r.length;a++){const m=p+r[a];try{if(pr.sync(m,{pathExt:n}))if(e.all)s.push(m);else return m}catch{}}}if(e.all&&s.length)return s;if(e.nothrow)return null;throw fr(t)};var Hs=hr;hr.sync=Bs;var ct={exports:{}};const gr=(t={})=>{const e=t.env||process.env;return(t.platform||process.platform)!=="win32"?"PATH":Object.keys(e).reverse().find(r=>r.toUpperCase()==="PATH")||"Path"};ct.exports=gr,ct.exports.default=gr;var Us=ct.exports;const yr=P,qs=Hs,zs=Us;function wr(t,e){const o=t.options.env||process.env,r=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=qs.sync(t.command,{path:o[zs({env:o})],pathExt:e?yr.delimiter:void 0})}catch{}finally{s&&process.chdir(r)}return i&&(i=yr.resolve(n?t.options.cwd:"",i)),i}function Ks(t){return wr(t)||wr(t,!0)}var Ws=Ks,lt={};const mt=/([()\][%!^"`<>&|;, *?])/g;function Ys(t){return t=t.replace(mt,"^$1"),t}function Vs(t,e){return t=`${t}`,t=t.replace(/(?=(\\+?)?)\1"/g,'$1$1\\"'),t=t.replace(/(?=(\\+?)?)\1$/,"$1$1"),t=`"${t}"`,t=t.replace(mt,"^$1"),e&&(t=t.replace(mt,"^$1")),t}lt.command=Ys,lt.argument=Vs;var Xs=/^#!(.*)/;const Js=Xs;var Qs=(t="")=>{const e=t.match(Js);if(!e)return null;const[o,r]=e[0].replace(/#! ?/,"").split(" "),n=o.split("/").pop();return n==="env"?r:r?`${n} ${r}`:n};const ut=_,Zs=Qs;function en(t){const o=Buffer.alloc(150);let r;try{r=ut.openSync(t,"r"),ut.readSync(r,o,0,150,0),ut.closeSync(r)}catch{}return Zs(o.toString())}var tn=en;const rn=P,vr=Ws,br=lt,on=tn,sn=process.platform==="win32",nn=/\.(?:com|exe)$/i,an=/node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;function cn(t){t.file=vr(t);const e=t.file&&on(t.file);return e?(t.args.unshift(t.file),t.command=e,vr(t)):t.file}function ln(t){if(!sn)return t;const e=cn(t),o=!nn.test(e);if(t.options.forceShell||o){const r=an.test(e);t.command=rn.normalize(t.command),t.command=br.command(t.command),t.args=t.args.map(s=>br.argument(s,r));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 mn(t,e,o){e&&!Array.isArray(e)&&(o=e,e=null),e=e?e.slice(0):[],o=Object.assign({},o);const r={command:t,args:e,options:o,file:void 0,original:{command:t,args:e}};return o.shell?r:ln(r)}var un=mn;const pt=process.platform==="win32";function ft(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 pn(t,e){if(!pt)return;const o=t.emit;t.emit=function(r,n){if(r==="exit"){const s=Cr(n,e);if(s)return o.call(t,"error",s)}return o.apply(t,arguments)}}function Cr(t,e){return pt&&t===1&&!e.file?ft(e.original,"spawn"):null}function fn(t,e){return pt&&t===1&&!e.file?ft(e.original,"spawnSync"):null}var dn={hookChildProcess:pn,verifyENOENT:Cr,verifyENOENTSync:fn,notFoundError:ft};const Pr=Ko,dt=un,ht=dn;function $r(t,e,o){const r=dt(t,e,o),n=Pr.spawn(r.command,r.args,r.options);return ht.hookChildProcess(n,r),n}function hn(t,e,o){const r=dt(t,e,o),n=Pr.spawnSync(r.command,r.args,r.options);return n.error=n.error||ht.verifyENOENTSync(n.status,r),n}oe.exports=$r,oe.exports.spawn=$r,oe.exports.sync=hn,oe.exports._parse=dt,oe.exports._enoent=ht;var gn=oe.exports,yn=re(gn);function wn(t){const e=typeof t=="string"?`
|
|
3
3
|
`:`
|
|
4
4
|
`.charCodeAt(),o=typeof t=="string"?"\r":"\r".charCodeAt();return t[t.length-1]===e&&(t=t.slice(0,-1)),t[t.length-1]===o&&(t=t.slice(0,-1)),t}function Er(t={}){const{env:e=process.env,platform:o=process.platform}=t;return o!=="win32"?"PATH":Object.keys(e).reverse().find(r=>r.toUpperCase()==="PATH")||"Path"}const vn=({cwd:t=U.cwd(),path:e=U.env[Er()],preferLocal:o=!0,execPath:r=U.execPath,addExecPath:n=!0}={})=>{const s=t instanceof URL?Xt(t):t,i=te.resolve(s),c=[];return o&&bn(c,i),n&&Cn(c,r,i),[...c,e].join(te.delimiter)},bn=(t,e)=>{let o;for(;o!==e;)t.push(te.join(e,"node_modules/.bin")),o=e,e=te.resolve(e,"..")},Cn=(t,e,o)=>{const r=e instanceof URL?Xt(e):e;t.push(te.resolve(o,r,".."))},Pn=({env:t=U.env,...e}={})=>{t={...t};const o=Er({env:t});return e.path=t[o],t[o]=vn(e),t},$n=(t,e,o,r)=>{if(o==="length"||o==="prototype"||o==="arguments"||o==="caller")return;const n=Object.getOwnPropertyDescriptor(t,o),s=Object.getOwnPropertyDescriptor(e,o);!En(n,s)&&r||Object.defineProperty(t,o,s)},En=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)},xn=(t,e)=>{const o=Object.getPrototypeOf(e);o!==Object.getPrototypeOf(t)&&Object.setPrototypeOf(t,o)},An=(t,e)=>`/* Wrapped ${t}*/
|
|
5
5
|
${e}`,Sn=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),kn=Object.getOwnPropertyDescriptor(Function.prototype.toString,"name"),Mn=(t,e,o)=>{const r=o===""?"":`with ${o.trim()}() `,n=An.bind(null,r,e.toString());Object.defineProperty(n,"name",kn),Object.defineProperty(t,"toString",{...Sn,value:n})};function In(t,e,{ignoreNonConfigurable:o=!1}={}){const{name:r}=t;for(const n of Reflect.ownKeys(e))$n(t,e,n,o);return xn(t,e),Mn(t,e,r),t}const Ne=new WeakMap,xr=(t,e={})=>{if(typeof t!="function")throw new TypeError("Expected a function");let o,r=0;const n=t.displayName||t.name||"<anonymous>",s=function(...i){if(Ne.set(s,++r),r===1)o=t.apply(this,i),t=null;else if(e.throw===!0)throw new Error(`Function \`${n}\` can only be called once`);return o};return In(s,t),Ne.set(s,r),s};xr.callCount=t=>{if(!Ne.has(t))throw new Error(`The given function \`${t.name}\` is not wrapped by the \`onetime\` package`);return Ne.get(t)};const Rn=()=>{const t=Sr-Ar+1;return Array.from({length:t},On)},On=(t,e)=>({name:`SIGRT${e+1}`,number:Ar+e,action:"terminate",description:"Application-specific signal (realtime)",standard:"posix"}),Ar=34,Sr=64,Ln=[{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"}],kr=()=>{const t=Rn();return[...Ln,...t].map(Tn)},Tn=({name:t,number:e,description:o,action:r,forced:n=!1,standard:s})=>{const{signals:{[t]:i}}=Jt,c=i!==void 0;return{name:t,number:c?i:e,description:o,supported:c,action:r,forced:n,standard:s}},Nn=()=>{const t=kr();return Object.fromEntries(t.map(_n))},_n=({name:t,number:e,description:o,supported:r,action:n,forced:s,standard:i})=>[t,{name:t,number:e,description:o,supported:r,action:n,forced:s,standard:i}],Fn=Nn(),Dn=()=>{const t=kr(),e=Sr+1,o=Array.from({length:e},(r,n)=>Gn(n,t));return Object.assign({},...o)},Gn=(t,e)=>{const o=jn(t,e);if(o===void 0)return{};const{name:r,description:n,supported:s,action:i,forced:c,standard:l}=o;return{[t]:{name:r,number:t,description:n,supported:s,action:i,forced:c,standard:l}}},jn=(t,e)=>{const o=e.find(({name:r})=>Jt.signals[r]===t);return o!==void 0?o:e.find(r=>r.number===t)};Dn();const Bn=({timedOut:t,timeout:e,errorCode:o,signal:r,signalDescription:n,exitCode:s,isCanceled:i})=>t?`timed out after ${e} milliseconds`:i?"was canceled":o!==void 0?`failed with ${o}`:r!==void 0?`was killed with ${r} (${n})`:s!==void 0?`failed with exit code ${s}`:"failed",Mr=({stdout:t,stderr:e,all:o,error:r,signal:n,exitCode:s,command:i,escapedCommand:c,timedOut:l,isCanceled:u,killed:p,parsed:{options:{timeout:a,cwd:m=U.cwd()}}})=>{s=s===null?void 0:s,n=n===null?void 0:n;const d=n===void 0?void 0:Fn[n].description,h=r&&r.code,y=`Command ${Bn({timedOut:l,timeout:a,errorCode:h,signal:n,signalDescription:d,exitCode:s,isCanceled:u})}: ${i}`,v=Object.prototype.toString.call(r)==="[object Error]",E=v?`${y}
|
|
@@ -11,7 +11,7 @@ ${r.message}`:y,N=[E,e,t].filter(Boolean).join(`
|
|
|
11
11
|
`).slice(1).join(`
|
|
12
12
|
`))),console.error(`
|
|
13
13
|
${At}${w.dim(`aicommit2 v${cr}`)}`),console.error(`
|
|
14
|
-
${At}Please open a Bug report with the information above:`),console.error(`${At}https://github.com/tak-bro/aicommit2/issues/new/choose`)))},Hr=t=>x.lstat(t).then(()=>!0,()=>!1),Ur=async t=>{try{await x.mkdir(t,{recursive:!0})}catch(e){if(e.code!=="EEXIST")throw e}},He=t=>t&&`${t[0].toUpperCase()}${t.slice(1)}`,Ue=(t,e)=>{const o=Math.ceil(t),r=Math.floor(e);return Math.floor(Math.random()*(r-o+1))+o},Bi=(t,e)=>t.disabled&&!e.disabled?1:!t.disabled&&e.disabled?-1:0,qe=t=>t.reduce((e,o)=>Array.isArray(o)?e.concat(qe(o)):e.concat(o),[]),qr=(t,e=5)=>t.replace(/[\n\r]/g,"").split(" ").slice(0,e).join(" "),Hi=t=>{let e=0;for(let o=0;o<t.length;o++){const r=t.charCodeAt(o);e=(e<<5)-e+r,e=e&e}return Math.abs(e)},Ui=t=>{const e=t%360,o=65+t%15,r=45+t%10;return`hsl(${e}, ${o}%, ${r}%)`},qi=t=>{const[e,o,r]=t.match(/\d+/g).map((a,m)=>m===0?Number(a):Number(a)/100),n=(1-Math.abs(2*r-1))*o,s=n*(1-Math.abs(e/60%2-1)),i=r-n/2;let c,l,u;e<60?[c,l,u]=[n,s,0]:e<120?[c,l,u]=[s,n,0]:e<180?[c,l,u]=[0,n,s]:e<240?[c,l,u]=[0,s,n]:e<300?[c,l,u]=[s,0,n]:[c,l,u]=[n,0,s];const p=a=>{const m=Math.round((a+i)*255).toString(16);return m.length===1?"0"+m:m};return`#${p(c)}${p(l)}${p(u)}`},zi=t=>{const e=Hi(t),o=Ui(e);return{primary:qi(o),secondary:"#FFFFFF"}},ze=t=>{if(!t||typeof t!="string")return"";if(P.isAbsolute(t))return P.resolve(t);if(ve){const e=P.dirname(ve),o=P.join(e,t);return P.resolve(o)}else return""},Ki=["","conventional","gitmoji"],St="http://localhost:11434",{hasOwnProperty:Wi}=Object.prototype,kt=(t,e)=>Wi.call(t,e),le=["OPENAI","OLLAMA","HUGGINGFACE","GEMINI","ANTHROPIC","MISTRAL","CODESTRAL","COHERE","GROQ","PERPLEXITY","DEEPSEEK"],zr=t=>{const e=Ie.platform(),o=Ie.homedir();let r,n;switch(t){case"config":r=process.env.XDG_CONFIG_HOME;break;case"data":r=process.env.XDG_DATA_HOME;break;case"cache":r=process.env.XDG_CACHE_HOME;break;case"state":r=process.env.XDG_STATE_HOME;break;default:r=void 0}if(e==="darwin")t==="cache"?n=P.join(o,"Library","Caches"):n=P.join(o,"Application Support");else if(e==="win32")n=process.env.LOCALAPPDATA||o;else switch(t){case"config":n=P.join(o,".config");break;case"data":n=P.join(o,".local","share");break;case"cache":n=P.join(o,".cache");break;case"state":n=P.join(o,".local","state");break;default:n=o}return r||n},Yi=P.join(zr("config"),"aicommit2"),Ke=P.join(zr("state"),"aicommit2","logs"),Kr=P.join(Yi,"config.ini"),Wr=P.join(Ke,"aicommit2-%DATE%.log"),Yr=P.join(Ke,"exceptions-%DATE%.log"),Vi=t=>{const e=Object.keys(t),o=new Set([...le,...e.filter(r=>/^[A-Z][A-Z0-9_]*$/.test(r))]);return Array.from(o)},b=(t,e,o)=>{if(!e)throw new C(`Invalid config property ${t}: ${o}`)},f={systemPrompt(t){return t||""},systemPromptPath(t){return t||""},codeReviewPromptPath(t){return t||""},timeout(t){if(!t)return 1e4;b("timeout",/^\d+$/.test(t),"Must be an integer");const e=Number(t);return b("timeout",e>=500,"Must be greater than 500ms"),e},temperature(t){if(!t)return .7;b("temperature",/^(2|\d)(\.\d{1,2})?$/.test(t),"Must be decimal between 0 and 2");const e=Number(t);return b("temperature",e>0,"Must be greater than 0"),b("temperature",e<=2,"Must be less than or equal to 2"),e},maxTokens(t){return t?(b("maxTokens",/^\d+$/.test(t),"Must be an integer"),Number(t)):1024},logging(t){return typeof t=="boolean"?t:t==null?!0:(b("logging",/^(?:true|false)$/.test(t),"Must be a boolean(true or false)"),t==="true")},logLevel(t){return t?(b("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||Wr},exceptionLogFilePath(t){return t||Yr},locale(t){return t?(b("locale",t,"Cannot be empty"),b("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;b("generate",/^\d+$/.test(t),"Must be an integer");const e=Number(t);return b("generate",e>0,"Must be greater than 0"),b("generate",e<=5,"Must be less or equal to 5"),e},type(t){return t?(b("type",Ki.includes(t),"Invalid commit type"),t):"conventional"},maxLength(t){if(!t)return 50;b("maxLength",/^\d+$/.test(t),"Must be an integer");const e=Number(t);return b("maxLength",e>=20,"Must be greater than 20 characters"),e},includeBody(t){return typeof t=="boolean"?t:t==null?!1:(b("includeBody",/^(?:true|false)$/.test(t),"Must be a boolean(true or false)"),t==="true")},exclude:t=>t?(typeof t=="string"?t?.split(","):t).map(o=>o.trim()).filter(o=>!!o&&o.length>0):[],topP:t=>{if(!t)return .9;b("topP",/^(1|\d)(\.\d{1,2})?$/.test(t),"Must be decimal between 0 and 1");const e=Number(t);return b("topP",e>0,"Must be greater than 0"),b("topP",e<=1,"Must be less than or equal to 1"),e},codeReview(t){return typeof t=="boolean"?t:t==null?!1:(b("codeReview",/^(?:true|false)$/.test(t),"Must be a boolean(true or false)"),t==="true")},disabled(t){return typeof t=="boolean"?t:t==null?!1:(b("disabled",/^(?:true|false)$/.test(t),"Must be a boolean(true or false)"),t==="true")},watchMode(t){return typeof t=="boolean"?t:t==null?!1:(b("watchMode",/^(?:true|false)$/.test(t),"Must be a boolean(true or false)"),t==="true")}},we={OPENAI:{key:t=>t||"",envKey:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(o=>o.trim()).filter(o=>!!o&&o.length>0):["gpt-4o-mini"],url:t=>t?(b("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:f.topP,systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,timeout:f.timeout,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode},HUGGINGFACE:{cookie:t=>t||"",model:t=>{if(!t)return["CohereForAI/c4ai-command-r-plus"];const e=typeof t=="string"?t?.split(","):t,o=["CohereForAI/c4ai-command-r-plus","meta-llama/Meta-Llama-3-70B-Instruct","HuggingFaceH4/zephyr-orpo-141b-A35b-v0.1","mistralai/Mixtral-8x7B-Instruct-v0.1","NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO","01-ai/Yi-1.5-34B-Chat","mistralai/Mistral-7B-Instruct-v0.2","microsoft/Phi-3-mini-4k-instruct"];for(const r of e)b("HUGGINGFACE.model",o.includes(r.trim()),`Invalid model type of HuggingFace chat: ${r.trim()}`);return e.map(r=>r.trim()).filter(r=>!!r&&r.length>0)},systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode},GEMINI:{key:t=>t||"",envKey:t=>t||"",model:t=>{if(!t)return["gemini-2.0-flash"];const e=typeof t=="string"?t?.split(","):t,o=["gemini-2.5-flash-preview-04-17","gemini-2.5-flash-preview-05-20","gemini-2.5-pro-preview-05-06","gemini-2.0-flash","gemini-2.0-flash-lite","gemini-2.0-flash-preview-image-generation","gemini-1.5-pro","gemini-1.5-flash","gemini-1.5-flash-8b"];for(const r of e)b("GEMINI.model",o.includes(r.trim()),`Invalid model type of Gemini: ${r.trim()}`);return e.map(r=>r.trim()).filter(r=>!!r&&r.length>0)},systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,topP:f.topP,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode},ANTHROPIC:{key:t=>t||"",envKey:t=>t||"",model:t=>{if(!t)return["claude-3-5-haiku-20241022"];const e=typeof t=="string"?t?.split(","):t,o=["claude-3-7-sonnet-20250219","claude-3-5-sonnet-20241022","claude-3-5-haiku-20241022","claude-3-opus-20240229","claude-3-sonnet-20240229","claude-3-haiku-20240307"];for(const r of e)b("ANTHROPIC.model",o.includes(r.trim()),`Invalid model type of Anthropic: ${r.trim()}`);return e.map(r=>r.trim()).filter(r=>!!r&&r.length>0)},systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,topP:f.topP,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode},MISTRAL:{key:t=>t||"",envKey:t=>t||"",model:t=>{if(!t)return["pixtral-12b-2409"];const e=typeof t=="string"?t?.split(","):t,o=["codestral-latest","mistral-large-latest","pixtral-large-latest","ministral-8b-latest","mistral-small-latest","mistral-embed","mistral-moderation-latest"];for(const r of e)b("MISTRAL.model",o.includes(r.trim()),`Invalid model type of Mistral AI: ${r.trim()}`);return e.map(r=>r.trim()).filter(r=>!!r&&r.length>0)},systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,timeout:f.timeout,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,topP:f.topP,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode},CODESTRAL:{key:t=>t||"",envKey:t=>t||"",model:t=>{if(!t)return["codestral-latest"];const e=typeof t=="string"?t?.split(","):t,o=["codestral-latest","codestral-2501"];for(const r of e)b("CODESTRAL.model",o.includes(r.trim()),`Invalid model type of Codestral: ${r.trim()}`);return e.map(r=>r.trim()).filter(r=>!!r&&r.length>0)},topP:f.topP,systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,timeout:f.timeout,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode},OLLAMA:{model:t=>t?(typeof t=="string"?t?.split(","):t).map(o=>o.trim()).filter(o=>!!o&&o.length>0):[],host:t=>t?(b("OLLAMA.host",/^https?:\/\//.test(t),"Must be a valid URL"),t):St,timeout:t=>{if(!t)return 1e5;b("OLLAMA.timeout",/^\d+$/.test(t),"Must be an integer");const e=Number(t);return b("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;b("OLLAMA.numCtx",/^\d+$/.test(t),"Must be an integer");const e=Number(t);return b("OLLAMA.numCtx",e>=2048,"Must be greater than 2048"),e},systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,topP:f.topP,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode},COHERE:{key:t=>t||"",envKey:t=>t||"",model:t=>{if(!t)return["command"];const e=typeof t=="string"?t?.split(","):t,o=["command-r7b-12-2024","command-r-plus-08-2024","command-r-plus-04-2024","command-r-plus","command-r-08-2024","command-r-03-2024","command-r","command","command-nightly","command-light","command-light-nightly","c4ai-aya-expanse-8b","c4ai-aya-expanse-32b"];for(const r of e)b("COHERE.model",o.includes(r.trim()),`Invalid model type of Cohere: ${r.trim()}`);return e.map(r=>r.trim()).filter(r=>!!r&&r.length>0)},systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,topP:f.topP,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode},GROQ:{key:t=>t||"",envKey:t=>t||"",model:t=>{if(!t)return["llama-3.3-70b-versatile"];const e=typeof t=="string"?t?.split(","):t,o=["allam-2-7b","compound-beta","compound-beta-mini","deepseek-r1-distill-llama-70b","distil-whisper-large-v3-en","gemma2-9b-it","llama-3.1-8b-instant","llama-3.3-70b-versatile","llama-guard-3-8b","llama3-70b-8192","llama3-8b-8192","meta-llama/llama-4-maverick-17b-128e-instruct","meta-llama/llama-4-scout-17b-16e-instruct","mistral-saba-24b","playai-tts","playai-tts-arabic","qwen-qwq-32b","whisper-large-v3","whisper-large-v3-turbo"];for(const r of e)b("GROQ.model",o.includes(r.trim()),`Invalid model type of Groq: ${r.trim()}`);return e.map(r=>r.trim()).filter(r=>!!r&&r.length>0)},systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,timeout:f.timeout,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,topP:f.topP,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode},PERPLEXITY:{key:t=>t||"",model:t=>{if(!t)return["sonar"];const e=typeof t=="string"?t?.split(","):t,o=["sonar-pro","sonar","llama-3.1-sonar-small-128k-online","llama-3.1-sonar-large-128k-online","llama-3.1-sonar-huge-128k-online"];for(const r of e)b("PERPLEXITY.model",o.includes(r.trim()),`Invalid model type of Perplexity: ${r.trim()}`);return e.map(r=>r.trim()).filter(r=>!!r&&r.length>0)},topP:f.topP,systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,timeout:f.timeout,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode},DEEPSEEK:{key:t=>t||"",envKey:t=>t||"",model:t=>{if(!t)return["deepseek-chat"];const e=typeof t=="string"?t?.split(","):t,o=["deepseek-reasoner","deepseek-chat"];for(const r of e)b("DEEPSEEK.model",o.includes(r.trim()),`Invalid model type of DeepSeek: ${r.trim()}`);return e.map(r=>r.trim()).filter(r=>!!r&&r.length>0)},topP:f.topP,systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,timeout:f.timeout,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode}};let ve;const Xi=(t=[])=>{const e={};for(const o of t)if(o.startsWith("--")){const[r,n]=o.slice(2).split("="),[s,i]=r.split(".");s&&i&&s in we?(e[s]||(e[s]={}),e[s][i]=n):e[r]=n}return e},Ji=()=>{const t=Ie.homedir(),e=process.env.AICOMMIT_CONFIG_PATH,o=Kr,r=P.join(t,".aicommit2");return[e,o,r].filter(n=>!!n)},me=async()=>{const t=Ji();for(const e of t)if(await Hr(e))return e;return Kr},be=async()=>{const t=await me();ve=t;try{const e=await x.readFile(t,"utf8");return ce.parse(e)}catch(e){return e.code==="ENOENT"?(ve=void 0,{}):(console.error(`Error reading config file ${t}:`,e),ve=void 0,{})}},ue=async(t,e=[])=>{const o=await be(),r=Xi(e),n={...t,...r},s={},i=Vi(o),c={};for(const u of i){const a=o[u]?.envKey||`${u}_API_KEY`,m=process.env[a];m&&(c[u]={key:m})}const l=(u,p)=>{const a=n[`${u}.${p}`]??n[u]?.[p],m=c[u]?.[p],d=o[u]?.[p],h=n[p]??o[p];return a!==void 0?a:m!==void 0?m:d!==void 0?d:h};for(const[u,p]of Object.entries(f)){const a=n[u]??o[u];s[u]=p(a)}for(const u of i){s[u]={};const p=we[u]||We(u);for(const[a,m]of Object.entries(p)){const d=l(u,a);s[u][a]=m(d)}}return s},Qi=async t=>{const e=await be();for(const[n,s]of t){const[i,c]=n.split(".");if(!c){const p=f[n];if(!p)throw new C(`Invalid config property: ${n}`);e[n]=p(s);continue}if(e[i]||(e[i]={}),le.includes(i)){const p=we[i][c];if(!p)throw new C(`Invalid config property: ${n}`);e[i][c]=p(s);continue}if(!/^[A-Z][A-Z0-9_]*$/.test(i))throw new C(`Invalid service name: ${i}. Service names must be uppercase letters, numbers, and underscores.`);const u=We(i);if(!u[c])throw new C(`Invalid config property for custom service: ${n}`);try{e[i][c]=u[c](s)}catch(p){throw p instanceof C?p:new C(`Invalid value for ${n}: ${p.message}`)}}const o=await me(),r=P.dirname(o);await x.mkdir(r,{recursive:!0}),await x.writeFile(o,ce.stringify(e),"utf8")},Zi=async t=>{const e=await be();for(const[n,s]of t){const[i,c]=n.split("."),l=e[i];if(c==="model"){l||(e[i]={});const p=e[i][c]||[],a=typeof s=="string"?s.split(",").map(m=>m.trim()).filter(m=>!!m):s;e[i][c]=qe([...p,...a]);continue}if(l&&l.compatible===!0){l||(e[i]={});const p=We(i);if(!p[c])throw new C(`Invalid config property: ${n}`);try{e[i][c]=p[c](s)}catch(a){throw a instanceof C?a:new C(`Invalid value for ${n}: ${a.message}`)}continue}if(i in we){l||(e[i]={});const p=we[i][c];if(!p)throw new C(`Invalid config property: ${n}`);e[i][c]=p(s)}else{const p=We(i);if(!p[c])throw new C(`Invalid config property: ${n}`);e[i]||(e[i]={}),e[i][c]=p[c](s)}}const o=await me(),r=P.dirname(o);await x.mkdir(r,{recursive:!0}),await x.writeFile(o,ce.stringify(e),"utf8")},ea=async()=>{const t=await be();console.log(ce.stringify(t))},ta=async()=>{console.log(await me())},We=t=>({compatible:e=>typeof e=="boolean"?e:e==null?!1:(b("compatible",/^(?:true|false)$/.test(e),"Must be a boolean(true or false)"),e==="true"),stream:e=>typeof e=="boolean"?e:e==null?!1:(b("stream",/^(?:true|false)$/.test(e),"Must be a boolean(true or false)"),e==="true"),url:e=>e?(b(`${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(r=>r.trim()).filter(r=>!!r&&r.length>0):[],systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,timeout:f.timeout,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,topP:f.topP,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode});let Ye;async function ra(t){if(Ye){console.warn("Logger already initialized. Skipping re-initialization.");return}const e=t?.logLevel||"info",o=t?.logFilePath||Wr,r=t?.exceptionLogFilePath||Yr,n=t?.logging??!0;await Ur(P.dirname(o)),await Ur(P.dirname(r));const s=[];n&&s.push(new q.transports.DailyRotateFile({filename:o,datePattern:"YYYY-MM-DD",zippedArchive:!0,maxSize:"20m",maxFiles:"14d",level:e,format:q.format.combine(q.format.timestamp(),q.format.printf(({level:i,message:c,timestamp:l})=>`[${l}] ${i}: ${c}`))})),Ye=q.createLogger({level:e,format:q.format.json(),transports:s,exceptionHandlers:n?[new q.transports.DailyRotateFile({filename:r,datePattern:"YYYY-MM-DD",zippedArchive:!0,maxSize:"20m",maxFiles:"14d",format:q.format.combine(q.format.timestamp(),q.format.json())})]:[],exitOnError:!1})}const Vr=new Proxy({},{get:(t,e,o)=>{if(!Ye)throw new Error("Logger not initialized. Call initializeLogger() first.");return Reflect.get(Ye,e,o)}});class G{constructor(e){this.handleError$=o=>{let r=o.name??"Unknown Error";return Vr.error(`${this.errorPrefix} ${o.toString()}`),o.status?r=`${o.status} ${r}`:o.code&&(r=`${o.code} ${r}`),de({name:`${this.errorPrefix} ${r}`,value:r,isError:!0,disabled:!0})},this.serviceName="AI",this.errorPrefix="ERROR",this.colors={primary:""}}parseMessage(e,o,r){const n=a=>a.replace(/[\u0000-\u001F\u007F-\u009F]/g,"").replace(/\\(?!["\\/bfnrtu])/g,"\\\\"),s=/(\[\s*\{[\s\S]*?\}\s*\]|\{[\s\S]*?\})/,i=e.match(s);if(!i){const a=new Error("AI response did not contain a valid JSON object or array.");throw a.name="InvalidJsonResponse",a}const c=n(i[0]),l=JSON.parse(c),u=Array.isArray(l)?l:[l];if(!u.length||!u.every(a=>typeof a.subject=="string")){const a=new Error("AI response contained malformed commit message data.");throw a.name="MalformedCommitMessage",a}return u.map(a=>this.extractMessageAsType(a,o)).map(a=>({title:`${a.subject}`,value:`${a.subject}${a.body?`
|
|
14
|
+
${At}Please open a Bug report with the information above:`),console.error(`${At}https://github.com/tak-bro/aicommit2/issues/new/choose`)))},Hr=t=>x.lstat(t).then(()=>!0,()=>!1),Ur=async t=>{try{await x.mkdir(t,{recursive:!0})}catch(e){if(e.code!=="EEXIST")throw e}},He=t=>t&&`${t[0].toUpperCase()}${t.slice(1)}`,Ue=(t,e)=>{const o=Math.ceil(t),r=Math.floor(e);return Math.floor(Math.random()*(r-o+1))+o},Bi=(t,e)=>t.disabled&&!e.disabled?1:!t.disabled&&e.disabled?-1:0,qe=t=>t.reduce((e,o)=>Array.isArray(o)?e.concat(qe(o)):e.concat(o),[]),qr=(t,e=5)=>t.replace(/[\n\r]/g,"").split(" ").slice(0,e).join(" "),Hi=t=>{let e=0;for(let o=0;o<t.length;o++){const r=t.charCodeAt(o);e=(e<<5)-e+r,e=e&e}return Math.abs(e)},Ui=t=>{const e=t%360,o=65+t%15,r=45+t%10;return`hsl(${e}, ${o}%, ${r}%)`},qi=t=>{const[e,o,r]=t.match(/\d+/g).map((a,m)=>m===0?Number(a):Number(a)/100),n=(1-Math.abs(2*r-1))*o,s=n*(1-Math.abs(e/60%2-1)),i=r-n/2;let c,l,u;e<60?[c,l,u]=[n,s,0]:e<120?[c,l,u]=[s,n,0]:e<180?[c,l,u]=[0,n,s]:e<240?[c,l,u]=[0,s,n]:e<300?[c,l,u]=[s,0,n]:[c,l,u]=[n,0,s];const p=a=>{const m=Math.round((a+i)*255).toString(16);return m.length===1?"0"+m:m};return`#${p(c)}${p(l)}${p(u)}`},zi=t=>{const e=Hi(t),o=Ui(e);return{primary:qi(o),secondary:"#FFFFFF"}},ze=t=>{if(!t||typeof t!="string")return"";if(P.isAbsolute(t))return P.resolve(t);if(ve){const e=P.dirname(ve),o=P.join(e,t);return P.resolve(o)}else return""},Ki=["","conventional","gitmoji"],St="http://localhost:11434",{hasOwnProperty:Wi}=Object.prototype,kt=(t,e)=>Wi.call(t,e),le=["OPENAI","OLLAMA","HUGGINGFACE","GEMINI","ANTHROPIC","MISTRAL","CODESTRAL","COHERE","GROQ","PERPLEXITY","DEEPSEEK"],zr=t=>{const e=Ie.platform(),o=Ie.homedir();let r,n;switch(t){case"config":r=process.env.XDG_CONFIG_HOME;break;case"data":r=process.env.XDG_DATA_HOME;break;case"cache":r=process.env.XDG_CACHE_HOME;break;case"state":r=process.env.XDG_STATE_HOME;break;default:r=void 0}if(e==="darwin")t==="cache"?n=P.join(o,"Library","Caches"):n=P.join(o,"Application Support");else if(e==="win32")n=process.env.LOCALAPPDATA||o;else switch(t){case"config":n=P.join(o,".config");break;case"data":n=P.join(o,".local","share");break;case"cache":n=P.join(o,".cache");break;case"state":n=P.join(o,".local","state");break;default:n=o}return r||n},Yi=P.join(zr("config"),"aicommit2"),Ke=P.join(zr("state"),"aicommit2","logs"),Kr=P.join(Yi,"config.ini"),Wr=P.join(Ke,"aicommit2-%DATE%.log"),Yr=P.join(Ke,"exceptions-%DATE%.log"),Vi=t=>{const e=Object.keys(t),o=new Set([...le,...e.filter(r=>/^[A-Z][A-Z0-9_]*$/.test(r))]);return Array.from(o)},b=(t,e,o)=>{if(!e)throw new C(`Invalid config property ${t}: ${o}`)},f={systemPrompt(t){return t||""},systemPromptPath(t){return t||""},codeReviewPromptPath(t){return t||""},timeout(t){if(!t)return 1e4;b("timeout",/^\d+$/.test(t),"Must be an integer");const e=Number(t);return b("timeout",e>=500,"Must be greater than 500ms"),e},temperature(t){if(!t)return .7;b("temperature",/^(2|\d)(\.\d{1,2})?$/.test(t),"Must be decimal between 0 and 2");const e=Number(t);return b("temperature",e>0,"Must be greater than 0"),b("temperature",e<=2,"Must be less than or equal to 2"),e},maxTokens(t){return t?(b("maxTokens",/^\d+$/.test(t),"Must be an integer"),Number(t)):1024},logging(t){return typeof t=="boolean"?t:t==null?!0:(b("logging",/^(?:true|false)$/.test(t),"Must be a boolean(true or false)"),t==="true")},logLevel(t){return t?(b("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||Wr},exceptionLogFilePath(t){return t||Yr},locale(t){return t?(b("locale",t,"Cannot be empty"),b("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;b("generate",/^\d+$/.test(t),"Must be an integer");const e=Number(t);return b("generate",e>0,"Must be greater than 0"),b("generate",e<=5,"Must be less or equal to 5"),e},type(t){return t?(b("type",Ki.includes(t),"Invalid commit type"),t):"conventional"},maxLength(t){if(!t)return 50;b("maxLength",/^\d+$/.test(t),"Must be an integer");const e=Number(t);return b("maxLength",e>=20,"Must be greater than 20 characters"),e},includeBody(t){return typeof t=="boolean"?t:t==null?!1:(b("includeBody",/^(?:true|false)$/.test(t),"Must be a boolean(true or false)"),t==="true")},exclude:t=>t?(typeof t=="string"?t?.split(","):t).map(o=>o.trim()).filter(o=>!!o&&o.length>0):[],topP:t=>{if(!t)return .9;b("topP",/^(1|\d)(\.\d{1,2})?$/.test(t),"Must be decimal between 0 and 1");const e=Number(t);return b("topP",e>0,"Must be greater than 0"),b("topP",e<=1,"Must be less than or equal to 1"),e},codeReview(t){return typeof t=="boolean"?t:t==null?!1:(b("codeReview",/^(?:true|false)$/.test(t),"Must be a boolean(true or false)"),t==="true")},disabled(t){return typeof t=="boolean"?t:t==null?!1:(b("disabled",/^(?:true|false)$/.test(t),"Must be a boolean(true or false)"),t==="true")},watchMode(t){return typeof t=="boolean"?t:t==null?!1:(b("watchMode",/^(?:true|false)$/.test(t),"Must be a boolean(true or false)"),t==="true")}},we={OPENAI:{key:t=>t||"",envKey:t=>t||"",model:t=>t?(typeof t=="string"?t?.split(","):t).map(o=>o.trim()).filter(o=>!!o&&o.length>0):["gpt-4o-mini"],url:t=>t?(b("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:f.topP,systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,timeout:f.timeout,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode},HUGGINGFACE:{cookie:t=>t||"",model:t=>{if(!t)return["CohereForAI/c4ai-command-r-plus"];const e=typeof t=="string"?t?.split(","):t,o=["CohereForAI/c4ai-command-r-plus","meta-llama/Meta-Llama-3-70B-Instruct","HuggingFaceH4/zephyr-orpo-141b-A35b-v0.1","mistralai/Mixtral-8x7B-Instruct-v0.1","NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO","01-ai/Yi-1.5-34B-Chat","mistralai/Mistral-7B-Instruct-v0.2","microsoft/Phi-3-mini-4k-instruct"];for(const r of e)b("HUGGINGFACE.model",o.includes(r.trim()),`Invalid model type of HuggingFace chat: ${r.trim()}`);return e.map(r=>r.trim()).filter(r=>!!r&&r.length>0)},systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode},GEMINI:{key:t=>t||"",envKey:t=>t||"",model:t=>{if(!t)return["gemini-2.0-flash"];const e=typeof t=="string"?t?.split(","):t,o=["gemini-2.5-flash-preview-04-17","gemini-2.5-flash-preview-05-20","gemini-2.5-pro-preview-05-06","gemini-2.0-flash","gemini-2.0-flash-lite","gemini-2.0-flash-preview-image-generation","gemini-1.5-pro","gemini-1.5-flash","gemini-1.5-flash-8b"];for(const r of e)b("GEMINI.model",o.includes(r.trim()),`Invalid model type of Gemini: ${r.trim()}`);return e.map(r=>r.trim()).filter(r=>!!r&&r.length>0)},systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,topP:f.topP,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode},ANTHROPIC:{key:t=>t||"",envKey:t=>t||"",model:t=>{if(!t)return["claude-3-5-haiku-20241022"];const e=typeof t=="string"?t?.split(","):t,o=["claude-opus-4-20250514","claude-sonnet-4-20250514","claude-3-7-sonnet-20250219","claude-3-5-sonnet-20241022","claude-3-5-haiku-20241022","claude-3-opus-20240229","claude-3-sonnet-20240229","claude-3-haiku-20240307"];for(const r of e)b("ANTHROPIC.model",o.includes(r.trim()),`Invalid model type of Anthropic: ${r.trim()}`);return e.map(r=>r.trim()).filter(r=>!!r&&r.length>0)},systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,topP:f.topP,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode},MISTRAL:{key:t=>t||"",envKey:t=>t||"",model:t=>{if(!t)return["pixtral-12b-2409"];const e=typeof t=="string"?t?.split(","):t,o=["codestral-latest","mistral-large-latest","pixtral-large-latest","ministral-8b-latest","mistral-small-latest","mistral-embed","mistral-moderation-latest"];for(const r of e)b("MISTRAL.model",o.includes(r.trim()),`Invalid model type of Mistral AI: ${r.trim()}`);return e.map(r=>r.trim()).filter(r=>!!r&&r.length>0)},systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,timeout:f.timeout,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,topP:f.topP,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode},CODESTRAL:{key:t=>t||"",envKey:t=>t||"",model:t=>{if(!t)return["codestral-latest"];const e=typeof t=="string"?t?.split(","):t,o=["codestral-latest","codestral-2501"];for(const r of e)b("CODESTRAL.model",o.includes(r.trim()),`Invalid model type of Codestral: ${r.trim()}`);return e.map(r=>r.trim()).filter(r=>!!r&&r.length>0)},topP:f.topP,systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,timeout:f.timeout,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode},OLLAMA:{model:t=>t?(typeof t=="string"?t?.split(","):t).map(o=>o.trim()).filter(o=>!!o&&o.length>0):[],host:t=>t?(b("OLLAMA.host",/^https?:\/\//.test(t),"Must be a valid URL"),t):St,timeout:t=>{if(!t)return 1e5;b("OLLAMA.timeout",/^\d+$/.test(t),"Must be an integer");const e=Number(t);return b("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;b("OLLAMA.numCtx",/^\d+$/.test(t),"Must be an integer");const e=Number(t);return b("OLLAMA.numCtx",e>=2048,"Must be greater than 2048"),e},systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,topP:f.topP,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode},COHERE:{key:t=>t||"",envKey:t=>t||"",model:t=>{if(!t)return["command"];const e=typeof t=="string"?t?.split(","):t,o=["command-r7b-12-2024","command-r-plus-08-2024","command-r-plus-04-2024","command-r-plus","command-r-08-2024","command-r-03-2024","command-r","command","command-nightly","command-light","command-light-nightly","c4ai-aya-expanse-8b","c4ai-aya-expanse-32b"];for(const r of e)b("COHERE.model",o.includes(r.trim()),`Invalid model type of Cohere: ${r.trim()}`);return e.map(r=>r.trim()).filter(r=>!!r&&r.length>0)},systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,topP:f.topP,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode},GROQ:{key:t=>t||"",envKey:t=>t||"",model:t=>{if(!t)return["llama-3.3-70b-versatile"];const e=typeof t=="string"?t?.split(","):t,o=["allam-2-7b","compound-beta","compound-beta-mini","deepseek-r1-distill-llama-70b","distil-whisper-large-v3-en","gemma2-9b-it","llama-3.1-8b-instant","llama-3.3-70b-versatile","llama-guard-3-8b","llama3-70b-8192","llama3-8b-8192","meta-llama/llama-4-maverick-17b-128e-instruct","meta-llama/llama-4-scout-17b-16e-instruct","mistral-saba-24b","playai-tts","playai-tts-arabic","qwen-qwq-32b","whisper-large-v3","whisper-large-v3-turbo"];for(const r of e)b("GROQ.model",o.includes(r.trim()),`Invalid model type of Groq: ${r.trim()}`);return e.map(r=>r.trim()).filter(r=>!!r&&r.length>0)},systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,timeout:f.timeout,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,topP:f.topP,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode},PERPLEXITY:{key:t=>t||"",model:t=>{if(!t)return["sonar"];const e=typeof t=="string"?t?.split(","):t,o=["sonar-pro","sonar","llama-3.1-sonar-small-128k-online","llama-3.1-sonar-large-128k-online","llama-3.1-sonar-huge-128k-online"];for(const r of e)b("PERPLEXITY.model",o.includes(r.trim()),`Invalid model type of Perplexity: ${r.trim()}`);return e.map(r=>r.trim()).filter(r=>!!r&&r.length>0)},topP:f.topP,systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,timeout:f.timeout,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode},DEEPSEEK:{key:t=>t||"",envKey:t=>t||"",model:t=>{if(!t)return["deepseek-chat"];const e=typeof t=="string"?t?.split(","):t,o=["deepseek-reasoner","deepseek-chat"];for(const r of e)b("DEEPSEEK.model",o.includes(r.trim()),`Invalid model type of DeepSeek: ${r.trim()}`);return e.map(r=>r.trim()).filter(r=>!!r&&r.length>0)},topP:f.topP,systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,timeout:f.timeout,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode}};let ve;const Xi=(t=[])=>{const e={};for(const o of t)if(o.startsWith("--")){const[r,n]=o.slice(2).split("="),[s,i]=r.split(".");s&&i&&s in we?(e[s]||(e[s]={}),e[s][i]=n):e[r]=n}return e},Ji=()=>{const t=Ie.homedir(),e=process.env.AICOMMIT_CONFIG_PATH,o=Kr,r=P.join(t,".aicommit2");return[e,o,r].filter(n=>!!n)},me=async()=>{const t=Ji();for(const e of t)if(await Hr(e))return e;return Kr},be=async()=>{const t=await me();ve=t;try{const e=await x.readFile(t,"utf8");return ce.parse(e)}catch(e){return e.code==="ENOENT"?(ve=void 0,{}):(console.error(`Error reading config file ${t}:`,e),ve=void 0,{})}},ue=async(t,e=[])=>{const o=await be(),r=Xi(e),n={...t,...r},s={},i=Vi(o),c={};for(const u of i){const a=o[u]?.envKey||`${u}_API_KEY`,m=process.env[a];m&&(c[u]={key:m})}const l=(u,p)=>{const a=n[`${u}.${p}`]??n[u]?.[p],m=c[u]?.[p],d=o[u]?.[p],h=n[p]??o[p];return a!==void 0?a:m!==void 0?m:d!==void 0?d:h};for(const[u,p]of Object.entries(f)){const a=n[u]??o[u];s[u]=p(a)}for(const u of i){s[u]={};const p=we[u]||We(u);for(const[a,m]of Object.entries(p)){const d=l(u,a);s[u][a]=m(d)}}return s},Qi=async t=>{const e=await be();for(const[n,s]of t){const[i,c]=n.split(".");if(!c){const p=f[n];if(!p)throw new C(`Invalid config property: ${n}`);e[n]=p(s);continue}if(e[i]||(e[i]={}),le.includes(i)){const p=we[i][c];if(!p)throw new C(`Invalid config property: ${n}`);e[i][c]=p(s);continue}if(!/^[A-Z][A-Z0-9_]*$/.test(i))throw new C(`Invalid service name: ${i}. Service names must be uppercase letters, numbers, and underscores.`);const u=We(i);if(!u[c])throw new C(`Invalid config property for custom service: ${n}`);try{e[i][c]=u[c](s)}catch(p){throw p instanceof C?p:new C(`Invalid value for ${n}: ${p.message}`)}}const o=await me(),r=P.dirname(o);await x.mkdir(r,{recursive:!0}),await x.writeFile(o,ce.stringify(e),"utf8")},Zi=async t=>{const e=await be();for(const[n,s]of t){const[i,c]=n.split("."),l=e[i];if(c==="model"){l||(e[i]={});const p=e[i][c]||[],a=typeof s=="string"?s.split(",").map(m=>m.trim()).filter(m=>!!m):s;e[i][c]=qe([...p,...a]);continue}if(l&&l.compatible===!0){l||(e[i]={});const p=We(i);if(!p[c])throw new C(`Invalid config property: ${n}`);try{e[i][c]=p[c](s)}catch(a){throw a instanceof C?a:new C(`Invalid value for ${n}: ${a.message}`)}continue}if(i in we){l||(e[i]={});const p=we[i][c];if(!p)throw new C(`Invalid config property: ${n}`);e[i][c]=p(s)}else{const p=We(i);if(!p[c])throw new C(`Invalid config property: ${n}`);e[i]||(e[i]={}),e[i][c]=p[c](s)}}const o=await me(),r=P.dirname(o);await x.mkdir(r,{recursive:!0}),await x.writeFile(o,ce.stringify(e),"utf8")},ea=async()=>{const t=await be();console.log(ce.stringify(t))},ta=async()=>{console.log(await me())},We=t=>({compatible:e=>typeof e=="boolean"?e:e==null?!1:(b("compatible",/^(?:true|false)$/.test(e),"Must be a boolean(true or false)"),e==="true"),stream:e=>typeof e=="boolean"?e:e==null?!1:(b("stream",/^(?:true|false)$/.test(e),"Must be a boolean(true or false)"),e==="true"),url:e=>e?(b(`${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(r=>r.trim()).filter(r=>!!r&&r.length>0):[],systemPrompt:f.systemPrompt,systemPromptPath:f.systemPromptPath,codeReviewPromptPath:f.codeReviewPromptPath,timeout:f.timeout,temperature:f.temperature,maxTokens:f.maxTokens,logging:f.logging,locale:f.locale,generate:f.generate,type:f.type,maxLength:f.maxLength,includeBody:f.includeBody,topP:f.topP,codeReview:f.codeReview,disabled:f.disabled,watchMode:f.watchMode});let Ye;async function ra(t){if(Ye){console.warn("Logger already initialized. Skipping re-initialization.");return}const e=t?.logLevel||"info",o=t?.logFilePath||Wr,r=t?.exceptionLogFilePath||Yr,n=t?.logging??!0;await Ur(P.dirname(o)),await Ur(P.dirname(r));const s=[];n&&s.push(new q.transports.DailyRotateFile({filename:o,datePattern:"YYYY-MM-DD",zippedArchive:!0,maxSize:"20m",maxFiles:"14d",level:e,format:q.format.combine(q.format.timestamp(),q.format.printf(({level:i,message:c,timestamp:l})=>`[${l}] ${i}: ${c}`))})),Ye=q.createLogger({level:e,format:q.format.json(),transports:s,exceptionHandlers:n?[new q.transports.DailyRotateFile({filename:r,datePattern:"YYYY-MM-DD",zippedArchive:!0,maxSize:"20m",maxFiles:"14d",format:q.format.combine(q.format.timestamp(),q.format.json())})]:[],exitOnError:!1})}const Vr=new Proxy({},{get:(t,e,o)=>{if(!Ye)throw new Error("Logger not initialized. Call initializeLogger() first.");return Reflect.get(Ye,e,o)}});class G{constructor(e){this.handleError$=o=>{let r=o.name??"Unknown Error";return Vr.error(`${this.errorPrefix} ${o.toString()}`),o.status?r=`${o.status} ${r}`:o.code&&(r=`${o.code} ${r}`),de({name:`${this.errorPrefix} ${r}`,value:r,isError:!0,disabled:!0})},this.serviceName="AI",this.errorPrefix="ERROR",this.colors={primary:""}}parseMessage(e,o,r){const n=a=>a.replace(/[\u0000-\u001F\u007F-\u009F]/g,"").replace(/\\(?!["\\/bfnrtu])/g,"\\\\"),s=/(\[\s*\{[\s\S]*?\}\s*\]|\{[\s\S]*?\})/,i=e.match(s);if(!i){const a=new Error("AI response did not contain a valid JSON object or array.");throw a.name="InvalidJsonResponse",a}const c=n(i[0]),l=JSON.parse(c),u=Array.isArray(l)?l:[l];if(!u.length||!u.every(a=>typeof a.subject=="string")){const a=new Error("AI response contained malformed commit message data.");throw a.name="MalformedCommitMessage",a}return u.map(a=>this.extractMessageAsType(a,o)).map(a=>({title:`${a.subject}`,value:`${a.subject}${a.body?`
|
|
15
15
|
|
|
16
16
|
${a.body}`:""}${a.footer?`
|
|
17
17
|
|