@negoziator/ai-commit 2.56.0 → 2.56.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.
@@ -1,4 +1,4 @@
1
- var y=Object.defineProperty;var u=(f,t)=>y(f,"name",{value:t,configurable:!0});import l from"https";import{d as w}from"./index-B3_BP8RZ.mjs";import{L as A,g as C}from"./prompt-BGI0PV0L.mjs";import{K as a}from"./cli-BKUAQIcs.mjs";import"net";import"tls";import"assert";import"tty";import"util";import"os";import"http";import"url";import"node:url";import"node:child_process";import"node:string_decoder";import"node:util";import"node:process";import"node:tty";import"node:path";import"child_process";import"path";import"fs";import"node:timers/promises";import"node:os";import"node:events";import"node:v8";import"node:fs";import"node:stream";import"node:buffer";import"node:stream/promises";import"node:readline";import"fs/promises";const h=class h extends A{get name(){return"anthropic"}validateConfig(){const{apiKey:t}=this.config;if(!t)throw new a("Please set your Anthropic API key via `aicommit config set ANTHROPIC_KEY=<your token>`\nGet your API key from: https://console.anthropic.com/");if(!t.startsWith("sk-ant-"))throw new a('Invalid Anthropic API key: Must start with "sk-ant-"')}async generateCommitMessage(t){try{const i=C(this.config.locale,this.config.maxLength,this.config.type,t.projectConfig),o=[{role:"user",content:t.diff}],e=[];for(let s=0;s<t.completions;s++){const r=(await this.createMessage(i,o)).content[0]?.text;r&&e.push(this.sanitizeMessage(r))}return{messages:this.deduplicateMessages(e)}}catch(i){const o=i;throw o.code==="ENOTFOUND"?new a(`Error connecting to ${o.hostname} (${o.syscall}). Are you connected to the internet?`):o}}async createMessage(t,i){const o={model:this.config.model,max_tokens:this.config.maxCompletionTokens,temperature:this.config.temperature,system:t,messages:i},{response:e,data:n}=await this.httpsPost("api.anthropic.com","/v1/messages",{"x-api-key":this.config.apiKey,"anthropic-version":"2023-06-01"},o);if(!e.statusCode||e.statusCode<200||e.statusCode>299){let s=`Anthropic API Error: ${e.statusCode} - ${e.statusMessage}`;throw n&&(s+=`
1
+ var y=Object.defineProperty;var u=(f,t)=>y(f,"name",{value:t,configurable:!0});import l from"https";import{d as w}from"./index-B3_BP8RZ.mjs";import{L as A,g as C}from"./prompt-BGI0PV0L.mjs";import{K as a}from"./cli-DMMbGriJ.mjs";import"net";import"tls";import"assert";import"tty";import"util";import"os";import"http";import"url";import"node:url";import"node:child_process";import"node:string_decoder";import"node:util";import"node:process";import"node:tty";import"node:path";import"child_process";import"path";import"fs";import"node:timers/promises";import"node:os";import"node:events";import"node:v8";import"node:fs";import"node:stream";import"node:buffer";import"node:stream/promises";import"node:readline";import"fs/promises";const h=class h extends A{get name(){return"anthropic"}validateConfig(){const{apiKey:t}=this.config;if(!t)throw new a("Please set your Anthropic API key via `aicommit config set ANTHROPIC_KEY=<your token>`\nGet your API key from: https://console.anthropic.com/");if(!t.startsWith("sk-ant-"))throw new a('Invalid Anthropic API key: Must start with "sk-ant-"')}async generateCommitMessage(t){try{const i=C(this.config.locale,this.config.maxLength,this.config.type,t.projectConfig),o=[{role:"user",content:t.diff}],e=[];for(let s=0;s<t.completions;s++){const r=(await this.createMessage(i,o)).content[0]?.text;r&&e.push(this.sanitizeMessage(r))}return{messages:this.deduplicateMessages(e)}}catch(i){const o=i;throw o.code==="ENOTFOUND"?new a(`Error connecting to ${o.hostname} (${o.syscall}). Are you connected to the internet?`):o}}async createMessage(t,i){const o={model:this.config.model,max_tokens:this.config.maxCompletionTokens,temperature:this.config.temperature,system:t,messages:i},{response:e,data:n}=await this.httpsPost("api.anthropic.com","/v1/messages",{"x-api-key":this.config.apiKey,"anthropic-version":"2023-06-01"},o);if(!e.statusCode||e.statusCode<200||e.statusCode>299){let s=`Anthropic API Error: ${e.statusCode} - ${e.statusMessage}`;throw n&&(s+=`
2
2
 
3
3
  ${n}`),e.statusCode===500&&(s+=`
4
4
 
@@ -1,3 +1,3 @@
1
- var l=Object.defineProperty;var f=(u,t)=>l(u,"name",{value:t,configurable:!0});import y from"https";import{d as w}from"./index-B3_BP8RZ.mjs";import{L as C,g as A}from"./prompt-BGI0PV0L.mjs";import{K as a}from"./cli-BKUAQIcs.mjs";import"net";import"tls";import"assert";import"tty";import"util";import"os";import"http";import"url";import"node:url";import"node:child_process";import"node:string_decoder";import"node:util";import"node:process";import"node:tty";import"node:path";import"child_process";import"path";import"fs";import"node:timers/promises";import"node:os";import"node:events";import"node:v8";import"node:fs";import"node:stream";import"node:buffer";import"node:stream/promises";import"node:readline";import"fs/promises";const g=class g extends C{get name(){return"azure-openai"}validateConfig(){const{apiKey:t,endpoint:i}=this.config;if(!t)throw new a("Please set your Azure OpenAI API key via `aicommit config set AZURE_OPENAI_KEY=<your token>`");if(!i)throw new a("Please set your Azure OpenAI endpoint via `aicommit config set AZURE_ENDPOINT=<your endpoint>`")}async generateCommitMessage(t){try{const i=await this.createChatCompletion({model:this.config.model,messages:[{role:"system",content:A(this.config.locale,this.config.maxLength,this.config.type,t.projectConfig)},{role:"user",content:t.diff}],temperature:this.config.temperature,top_p:1,frequency_penalty:0,presence_penalty:0,max_tokens:this.config.maxCompletionTokens,n:t.completions});return{messages:this.deduplicateMessages(i.choices.filter(r=>r.message?.content).map(r=>this.sanitizeMessage(r.message.content)))}}catch(i){const e=i;throw e.code==="ENOTFOUND"?new a(`Error connecting to ${e.hostname} (${e.syscall}). Are you connected to the internet?`):e}}async createChatCompletion(t){const e=new URL(this.config.endpoint).hostname,m=`/openai/deployments/${this.config.deploymentName||this.config.model}/chat/completions?api-version=2024-02-01`,{response:n,data:s}=await this.httpsPost(e,m,{"api-key":this.config.apiKey},t);if(!n.statusCode||n.statusCode<200||n.statusCode>299){let o=`Azure OpenAI API Error: ${n.statusCode} - ${n.statusMessage}`;throw s&&(o+=`
1
+ var l=Object.defineProperty;var f=(u,t)=>l(u,"name",{value:t,configurable:!0});import y from"https";import{d as w}from"./index-B3_BP8RZ.mjs";import{L as C,g as A}from"./prompt-BGI0PV0L.mjs";import{K as a}from"./cli-DMMbGriJ.mjs";import"net";import"tls";import"assert";import"tty";import"util";import"os";import"http";import"url";import"node:url";import"node:child_process";import"node:string_decoder";import"node:util";import"node:process";import"node:tty";import"node:path";import"child_process";import"path";import"fs";import"node:timers/promises";import"node:os";import"node:events";import"node:v8";import"node:fs";import"node:stream";import"node:buffer";import"node:stream/promises";import"node:readline";import"fs/promises";const g=class g extends C{get name(){return"azure-openai"}validateConfig(){const{apiKey:t,endpoint:i}=this.config;if(!t)throw new a("Please set your Azure OpenAI API key via `aicommit config set AZURE_OPENAI_KEY=<your token>`");if(!i)throw new a("Please set your Azure OpenAI endpoint via `aicommit config set AZURE_ENDPOINT=<your endpoint>`")}async generateCommitMessage(t){try{const i=await this.createChatCompletion({model:this.config.model,messages:[{role:"system",content:A(this.config.locale,this.config.maxLength,this.config.type,t.projectConfig)},{role:"user",content:t.diff}],temperature:this.config.temperature,top_p:1,frequency_penalty:0,presence_penalty:0,max_tokens:this.config.maxCompletionTokens,n:t.completions});return{messages:this.deduplicateMessages(i.choices.filter(r=>r.message?.content).map(r=>this.sanitizeMessage(r.message.content)))}}catch(i){const e=i;throw e.code==="ENOTFOUND"?new a(`Error connecting to ${e.hostname} (${e.syscall}). Are you connected to the internet?`):e}}async createChatCompletion(t){const e=new URL(this.config.endpoint).hostname,m=`/openai/deployments/${this.config.deploymentName||this.config.model}/chat/completions?api-version=2024-02-01`,{response:n,data:s}=await this.httpsPost(e,m,{"api-key":this.config.apiKey},t);if(!n.statusCode||n.statusCode<200||n.statusCode>299){let o=`Azure OpenAI API Error: ${n.statusCode} - ${n.statusMessage}`;throw s&&(o+=`
2
2
 
3
3
  ${s}`),new a(o)}return JSON.parse(s)}async httpsPost(t,i,e,r){return new Promise((m,n)=>{const s=JSON.stringify(r),o=y.request({hostname:t,path:i,method:"POST",headers:{...e,"Content-Type":"application/json","Content-Length":Buffer.byteLength(s)},timeout:this.config.timeout,agent:this.config.proxy?new w.HttpsProxyAgent(this.config.proxy):void 0},p=>{const h=[];p.on("data",d=>h.push(d)),p.on("end",()=>{m({request:o,response:p,data:Buffer.concat(h).toString()})})});o.on("error",n),o.on("timeout",()=>{o.destroy(),n(new a(`Time out error: request took over ${this.config.timeout}ms. Try increasing the \`timeout\` config`))}),o.write(s),o.end()})}sanitizeMessage(t){return t.trim().replace(/[\n\r]/g,"").replace(/(\w)\.$/,"$1")}deduplicateMessages(t){return Array.from(new Set(t))}};f(g,"AzureOpenAIProvider");let c=g;export{c as default};
@@ -19,7 +19,7 @@ var $c=Object.defineProperty;var o=(e,t)=>$c(e,"name",{value:t,configurable:!0})
19
19
  `:"")+(n?this.indentText({text:this.render(n),spaces:r}):"")}
20
20
  `}table({tableData:t,tableOptions:n,tableBreakpoints:r}){return Ol(t.map(i=>i.map(s=>this.render(s))),r?_l(r):n)}flagParameter(t){return t===Boolean?"":t===String?"<string>":t===Number?"<number>":Array.isArray(t)?this.flagParameter(t[0]):"<value>"}flagOperator(t){return" "}flagName(t){const{flag:n,flagFormatted:r,aliasesEnabled:i,aliasFormatted:s}=t;let a="";if(s?a+=`${s}, `:i&&(a+=" "),a+=r,"placeholder"in n&&typeof n.placeholder=="string")a+=`${this.flagOperator(t)}${n.placeholder}`;else{const u=this.flagParameter("type"in n?n.type:n);u&&(a+=`${this.flagOperator(t)}${u}`)}return a}flagDefault(t){return JSON.stringify(t)}flagDescription({flag:t}){let n="description"in t?t.description??"":"";if("default"in t){let{default:r}=t;typeof r=="function"&&(r=r()),r&&(n+=` (default: ${this.flagDefault(r)})`)}return n}render(t){if(typeof t=="string")return t;if(Array.isArray(t))return t.map(n=>this.render(n)).join(`
21
21
  `);if("type"in t&&this[t.type]){const n=this[t.type];if(typeof n=="function")return n.call(this,t.data)}throw new Error(`Invalid node type: ${JSON.stringify(t)}`)}},o(He,"_ne"),He);T(Si,"Renderers");let Vl=Si;const wn=T(e=>e.length>0&&!e.includes(" "),"isValidScriptName"),{stringify:x}=JSON,Hl=/[|\\{}()[\]^$+*?.]/;function yn(e){const t=[];let n,r;for(const i of e){if(r)throw new Error(`Invalid parameter: Spread parameter ${x(r)} must be last`);const s=i[0],a=i.at(-1);let u;if(s==="<"&&a===">"&&(u=!0,n))throw new Error(`Invalid parameter: Required parameter ${x(i)} cannot come after optional parameter ${x(n)}`);if(s==="["&&a==="]"&&(u=!1,n=i),u===void 0)throw new Error(`Invalid parameter: ${x(i)}. Must be wrapped in <> (required parameter) or [] (optional parameter)`);let c=i.slice(1,-1);const d=c.slice(-3)==="...";d&&(r=i,c=c.slice(0,-3));const l=c.match(Hl);if(l)throw new Error(`Invalid parameter: ${x(i)}. Invalid character found ${x(l[0])}`);t.push({name:c,required:u,spread:d})}return t}o(yn,"P"),T(yn,"parseParameters");function En(e,t,n,r){for(let i=0;i<t.length;i+=1){const{name:s,required:a,spread:u}=t[i],c=Ul(s);if(c in e)throw new Error(`Invalid parameter: ${x(s)} is used more than once.`);const d=u?n.slice(i):n[i];if(u&&(i=t.length),a&&(!d||u&&d.length===0))return console.error(`Error: Missing required parameter ${x(s)}
22
- `),r(),process.exit(1);e[c]=d}}o(En,"S"),T(En,"mapParametersToArguments");function vi(e){return e!==!1}o(vi,"se"),T(vi,"helpEnabled");const Yl=T(e=>{const t=[];for(const[n,r]of Object.entries(e))if(t.push(n),r&&typeof r=="object"&&"alias"in r){const{alias:i}=r;typeof i=="string"&&i?t.push(i):Array.isArray(i)&&t.push(...i.filter(Boolean))}return t},"getKnownFlagNames"),ql=T((e,t)=>{if(e.length<3||t.length===0)return;const n=kl(e,t);return hi(e,n)<=2?n:void 0},"findClosestFlag"),Kl=T((e,t)=>{const n=Object.keys(e);if(n.length!==0){for(const r of n){const i=ql(r,t),s=i?` (Did you mean --${i}?)`:"";console.error(`Error: Unknown flag: --${r}.${s}`)}process.exit(1)}},"handleUnknownFlags");function bn(e,t,n,r){const i={...t.flags},s=t.version&&!("version"in i);s&&(i.version={type:Boolean,description:"Show version"});const{help:a}=t,u=vi(a);u&&!("help"in i)&&(i.help={type:Boolean,alias:"h",description:"Show help"});const c=ll(i,r,{ignore:t.ignoreArgv,booleanNegation:t.booleanFlagNegation??t.parent?.booleanFlagNegation}),d=T(()=>{console.log(t.version)},"showVersion");if(s&&c.flags.version===!0)return d(),process.exit(0);const l=new Vl,f=u&&a?.render?a.render:m=>l.render(m),h=T(m=>{const F=Gl({...t,...m?{help:m}:{},flags:i});console.log(f(F,l))},"showHelp");if(u&&c.flags.help===!0)return h(),process.exit(0);if((t.strictFlags??t.parent?.strictFlags)&&Kl(c.unknownFlags,Yl(i)),t.parameters){let{parameters:m}=t,F=c._;const g=m.indexOf("--"),w=m.slice(g+1),E=Object.create(null);let y=[];g>-1&&w.length>0&&(m=m.slice(0,g),y=c._["--"],F=F.slice(0,-y.length||void 0)),En(E,yn(m),F,h),g>-1&&w.length>0&&En(E,yn(w),y,h),Object.assign(c._,E)}const p={...c,showVersion:d,showHelp:h},D={command:e,...p};if(typeof n=="function"){const m=n(p);if(m&&"then"in m)return Object.assign(Promise.resolve(m),D)}return D}o(bn,"I"),T(bn,"cliBase");function Ai(e,t){const n=new Map;for(const r of t){const i=[r.options.name],{alias:s}=r.options;s&&(Array.isArray(s)?i.push(...s):i.push(s));for(const a of i){if(n.has(a))throw new Error(`Duplicate command name found: ${x(a)}`);n.set(a,r)}}return n.get(e)}o(Ai,"ce"),T(Ai,"getCommand");function $i(e,t,n=process.argv.slice(2)){if(!e)throw new Error("Options is required");if("name"in e&&(!e.name||!wn(e.name)))throw new Error(`Invalid script name: ${x(e.name)}`);const r=n[0];if(e.commands&&r&&wn(r)){const i=Ai(r,e.commands);if(i)return bn(i.options.name,{...i.options,parent:e},i.callback,n.slice(1))}return bn(void 0,e,t,n)}o($i,"fe$1"),T($i,"cli");function Cn(e,t){if(!e)throw new Error("Command options are required");const{name:n}=e;if(n===void 0)throw new Error("Command name is required");if(!wn(n))throw new Error(`Invalid command name ${JSON.stringify(n)}. Command names must be one word.`);return{options:e,callback:t}}o(Cn,"de"),T(Cn,"command");var Zl="2.56.0",Jl="Writes your git commit messages for you with AI",Sn={version:Zl,description:Jl};function K(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}o(K,"isPlainObject");const vn=o((e,t)=>{const n=Ti(Xl(e));if(typeof n!="string")throw new TypeError(`${t} must be a string or a file URL: ${n}.`);return n},"safeNormalizeFileUrl"),Xl=o(e=>Bi(e)?e.toString():e,"normalizeDenoExecPath"),Bi=o(e=>typeof e!="string"&&e&&Object.getPrototypeOf(e)===String.prototype,"isDenoExecPath"),Ti=o(e=>e instanceof URL?$o(e):e,"normalizeFileUrl"),Ii=o((e,t=[],n={})=>{const r=vn(e,"First argument"),[i,s]=K(t)?[[],t]:[t,n];if(!Array.isArray(i))throw new TypeError(`Second argument must be either an array of arguments or an options object: ${i}`);if(i.some(c=>typeof c=="object"&&c!==null))throw new TypeError(`Second argument must be an array of strings: ${i}`);const a=i.map(String),u=a.find(c=>c.includes("\0"));if(u!==void 0)throw new TypeError(`Arguments cannot contain null bytes ("\\0"): ${u}`);if(!K(s))throw new TypeError(`Last argument must be an options object: ${s}`);return[r,a,s]},"normalizeParameters"),{toString:Oi}=Object.prototype,Ql=o(e=>Oi.call(e)==="[object ArrayBuffer]","isArrayBuffer"),X=o(e=>Oi.call(e)==="[object Uint8Array]","isUint8Array"),Ke=o(e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength),"bufferToUint8Array"),xl=new TextEncoder,Ri=o(e=>xl.encode(e),"stringToUint8Array"),ed=new TextDecoder,Mi=o(e=>ed.decode(e),"uint8ArrayToString"),td=o((e,t)=>nd(e,t).join(""),"joinToString"),nd=o((e,t)=>{if(t==="utf8"&&e.every(s=>typeof s=="string"))return e;const n=new To(t),r=e.map(s=>typeof s=="string"?Ri(s):s).map(s=>n.write(s)),i=n.end();return i===""?r:[...r,i]},"uint8ArraysToStrings"),An=o(e=>e.length===1&&X(e[0])?e[0]:_i(rd(e)),"joinToUint8Array"),rd=o(e=>e.map(t=>typeof t=="string"?Ri(t):t),"stringsToUint8Arrays"),_i=o(e=>{const t=new Uint8Array(od(e));let n=0;for(const r of e)t.set(r,n),n+=r.length;return t},"concatUint8Arrays"),od=o(e=>{let t=0;for(const n of e)t+=n.length;return t},"getJoinLength"),id=o(e=>Array.isArray(e)&&Array.isArray(e.raw),"isTemplateString"),sd=o((e,t)=>{let n=[];for(const[s,a]of e.entries())n=ad({templates:e,expressions:t,tokens:n,index:s,template:a});if(n.length===0)throw new TypeError("Template script must not be empty");const[r,...i]=n;return[r,i,{}]},"parseTemplates"),ad=o(({templates:e,expressions:t,tokens:n,index:r,template:i})=>{if(i===void 0)throw new TypeError(`Invalid backslash sequence: ${e.raw[r]}`);const{nextTokens:s,leadingWhitespaces:a,trailingWhitespaces:u}=ud(i,e.raw[r]),c=Li(n,s,a);if(r===t.length)return c;const d=t[r],l=Array.isArray(d)?d.map(f=>Ni(f)):[Ni(d)];return Li(c,l,u)},"parseTemplate"),ud=o((e,t)=>{if(t.length===0)return{nextTokens:[],leadingWhitespaces:!1,trailingWhitespaces:!1};const n=[];let r=0;const i=Pi.has(t[0]);for(let a=0,u=0;a<e.length;a+=1,u+=1){const c=t[u];if(Pi.has(c))r!==a&&n.push(e.slice(r,a)),r=a+1;else if(c==="\\"){const d=t[u+1];d===`
22
+ `),r(),process.exit(1);e[c]=d}}o(En,"S"),T(En,"mapParametersToArguments");function vi(e){return e!==!1}o(vi,"se"),T(vi,"helpEnabled");const Yl=T(e=>{const t=[];for(const[n,r]of Object.entries(e))if(t.push(n),r&&typeof r=="object"&&"alias"in r){const{alias:i}=r;typeof i=="string"&&i?t.push(i):Array.isArray(i)&&t.push(...i.filter(Boolean))}return t},"getKnownFlagNames"),ql=T((e,t)=>{if(e.length<3||t.length===0)return;const n=kl(e,t);return hi(e,n)<=2?n:void 0},"findClosestFlag"),Kl=T((e,t)=>{const n=Object.keys(e);if(n.length!==0){for(const r of n){const i=ql(r,t),s=i?` (Did you mean --${i}?)`:"";console.error(`Error: Unknown flag: --${r}.${s}`)}process.exit(1)}},"handleUnknownFlags");function bn(e,t,n,r){const i={...t.flags},s=t.version&&!("version"in i);s&&(i.version={type:Boolean,description:"Show version"});const{help:a}=t,u=vi(a);u&&!("help"in i)&&(i.help={type:Boolean,alias:"h",description:"Show help"});const c=ll(i,r,{ignore:t.ignoreArgv,booleanNegation:t.booleanFlagNegation??t.parent?.booleanFlagNegation}),d=T(()=>{console.log(t.version)},"showVersion");if(s&&c.flags.version===!0)return d(),process.exit(0);const l=new Vl,f=u&&a?.render?a.render:m=>l.render(m),h=T(m=>{const F=Gl({...t,...m?{help:m}:{},flags:i});console.log(f(F,l))},"showHelp");if(u&&c.flags.help===!0)return h(),process.exit(0);if((t.strictFlags??t.parent?.strictFlags)&&Kl(c.unknownFlags,Yl(i)),t.parameters){let{parameters:m}=t,F=c._;const g=m.indexOf("--"),w=m.slice(g+1),E=Object.create(null);let y=[];g>-1&&w.length>0&&(m=m.slice(0,g),y=c._["--"],F=F.slice(0,-y.length||void 0)),En(E,yn(m),F,h),g>-1&&w.length>0&&En(E,yn(w),y,h),Object.assign(c._,E)}const p={...c,showVersion:d,showHelp:h},D={command:e,...p};if(typeof n=="function"){const m=n(p);if(m&&"then"in m)return Object.assign(Promise.resolve(m),D)}return D}o(bn,"I"),T(bn,"cliBase");function Ai(e,t){const n=new Map;for(const r of t){const i=[r.options.name],{alias:s}=r.options;s&&(Array.isArray(s)?i.push(...s):i.push(s));for(const a of i){if(n.has(a))throw new Error(`Duplicate command name found: ${x(a)}`);n.set(a,r)}}return n.get(e)}o(Ai,"ce"),T(Ai,"getCommand");function $i(e,t,n=process.argv.slice(2)){if(!e)throw new Error("Options is required");if("name"in e&&(!e.name||!wn(e.name)))throw new Error(`Invalid script name: ${x(e.name)}`);const r=n[0];if(e.commands&&r&&wn(r)){const i=Ai(r,e.commands);if(i)return bn(i.options.name,{...i.options,parent:e},i.callback,n.slice(1))}return bn(void 0,e,t,n)}o($i,"fe$1"),T($i,"cli");function Cn(e,t){if(!e)throw new Error("Command options are required");const{name:n}=e;if(n===void 0)throw new Error("Command name is required");if(!wn(n))throw new Error(`Invalid command name ${JSON.stringify(n)}. Command names must be one word.`);return{options:e,callback:t}}o(Cn,"de"),T(Cn,"command");var Zl="2.56.1",Jl="Writes your git commit messages for you with AI",Sn={version:Zl,description:Jl};function K(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}o(K,"isPlainObject");const vn=o((e,t)=>{const n=Ti(Xl(e));if(typeof n!="string")throw new TypeError(`${t} must be a string or a file URL: ${n}.`);return n},"safeNormalizeFileUrl"),Xl=o(e=>Bi(e)?e.toString():e,"normalizeDenoExecPath"),Bi=o(e=>typeof e!="string"&&e&&Object.getPrototypeOf(e)===String.prototype,"isDenoExecPath"),Ti=o(e=>e instanceof URL?$o(e):e,"normalizeFileUrl"),Ii=o((e,t=[],n={})=>{const r=vn(e,"First argument"),[i,s]=K(t)?[[],t]:[t,n];if(!Array.isArray(i))throw new TypeError(`Second argument must be either an array of arguments or an options object: ${i}`);if(i.some(c=>typeof c=="object"&&c!==null))throw new TypeError(`Second argument must be an array of strings: ${i}`);const a=i.map(String),u=a.find(c=>c.includes("\0"));if(u!==void 0)throw new TypeError(`Arguments cannot contain null bytes ("\\0"): ${u}`);if(!K(s))throw new TypeError(`Last argument must be an options object: ${s}`);return[r,a,s]},"normalizeParameters"),{toString:Oi}=Object.prototype,Ql=o(e=>Oi.call(e)==="[object ArrayBuffer]","isArrayBuffer"),X=o(e=>Oi.call(e)==="[object Uint8Array]","isUint8Array"),Ke=o(e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength),"bufferToUint8Array"),xl=new TextEncoder,Ri=o(e=>xl.encode(e),"stringToUint8Array"),ed=new TextDecoder,Mi=o(e=>ed.decode(e),"uint8ArrayToString"),td=o((e,t)=>nd(e,t).join(""),"joinToString"),nd=o((e,t)=>{if(t==="utf8"&&e.every(s=>typeof s=="string"))return e;const n=new To(t),r=e.map(s=>typeof s=="string"?Ri(s):s).map(s=>n.write(s)),i=n.end();return i===""?r:[...r,i]},"uint8ArraysToStrings"),An=o(e=>e.length===1&&X(e[0])?e[0]:_i(rd(e)),"joinToUint8Array"),rd=o(e=>e.map(t=>typeof t=="string"?Ri(t):t),"stringsToUint8Arrays"),_i=o(e=>{const t=new Uint8Array(od(e));let n=0;for(const r of e)t.set(r,n),n+=r.length;return t},"concatUint8Arrays"),od=o(e=>{let t=0;for(const n of e)t+=n.length;return t},"getJoinLength"),id=o(e=>Array.isArray(e)&&Array.isArray(e.raw),"isTemplateString"),sd=o((e,t)=>{let n=[];for(const[s,a]of e.entries())n=ad({templates:e,expressions:t,tokens:n,index:s,template:a});if(n.length===0)throw new TypeError("Template script must not be empty");const[r,...i]=n;return[r,i,{}]},"parseTemplates"),ad=o(({templates:e,expressions:t,tokens:n,index:r,template:i})=>{if(i===void 0)throw new TypeError(`Invalid backslash sequence: ${e.raw[r]}`);const{nextTokens:s,leadingWhitespaces:a,trailingWhitespaces:u}=ud(i,e.raw[r]),c=Li(n,s,a);if(r===t.length)return c;const d=t[r],l=Array.isArray(d)?d.map(f=>Ni(f)):[Ni(d)];return Li(c,l,u)},"parseTemplate"),ud=o((e,t)=>{if(t.length===0)return{nextTokens:[],leadingWhitespaces:!1,trailingWhitespaces:!1};const n=[];let r=0;const i=Pi.has(t[0]);for(let a=0,u=0;a<e.length;a+=1,u+=1){const c=t[u];if(Pi.has(c))r!==a&&n.push(e.slice(r,a)),r=a+1;else if(c==="\\"){const d=t[u+1];d===`
23
23
  `?(a-=1,u+=1):d==="u"&&t[u+2]==="{"?u=t.indexOf("}",u+3):u+=cd[d]??1}}const s=r===e.length;return s||n.push(e.slice(r)),{nextTokens:n,leadingWhitespaces:i,trailingWhitespaces:s}},"splitByWhitespaces"),Pi=new Set([" "," ","\r",`
24
24
  `]),cd={x:3,u:5},Li=o((e,t,n)=>n||e.length===0||t.length===0?[...e,...t]:[...e.slice(0,-1),`${e.at(-1)}${t[0]}`,...t.slice(1)],"concatTokens"),Ni=o(e=>{const t=typeof e;if(t==="string")return e;if(t==="number")return String(e);if(K(e)&&("stdout"in e||"isMaxBuffer"in e))return ld(e);throw e instanceof Bo||Object.prototype.toString.call(e)==="[object Promise]"?new TypeError("Unexpected subprocess in template expression. Please use ${await subprocess} instead of ${subprocess}."):new TypeError(`Unexpected "${t}" in template expression`)},"parseExpression"),ld=o(({stdout:e})=>{if(typeof e=="string")return e;if(X(e))return Mi(e);throw e===void 0?new TypeError(`Missing result.stdout in template expression. This is probably due to the previous subprocess' "stdout" option.`):new TypeError(`Unexpected "${typeof e}" stdout in template expression`)},"getSubprocessResult"),Fe=o(e=>$n.includes(e),"isStandardStream"),$n=[I.stdin,I.stdout,I.stderr],ee=["stdin","stdout","stderr"],ki=o(e=>ee[e]??`stdio[${e}]`,"getStreamName"),dd=o(e=>{const t={...e};for(const n of Gi)t[n]=Ui(e,n);return t},"normalizeFdSpecificOptions"),Ui=o((e,t)=>{const n=Array.from({length:fd(e)+1}),r=hd(e[t],n,t);return Fd(r,t)},"normalizeFdSpecificOption"),fd=o(({stdio:e})=>Array.isArray(e)?Math.max(e.length,ee.length):ee.length,"getStdioLength"),hd=o((e,t,n)=>K(e)?Dd(e,t,n):t.fill(e),"normalizeFdSpecificValue"),Dd=o((e,t,n)=>{for(const r of Object.keys(e).sort(pd))for(const i of md(r,n,t))t[i]=e[r];return t},"normalizeOptionObject"),pd=o((e,t)=>ji(e)<ji(t)?1:-1,"compareFdName"),ji=o(e=>e==="stdout"||e==="stderr"?0:e==="all"?2:1,"getFdNameOrder"),md=o((e,t,n)=>{if(e==="ipc")return[n.length-1];const r=Wi(e);if(r===void 0||r===0)throw new TypeError(`"${t}.${e}" is invalid.
25
25
  It must be "${t}.stdout", "${t}.stderr", "${t}.all", "${t}.ipc", or "${t}.fd3", "${t}.fd4" (and so on).`);if(r>=n.length)throw new TypeError(`"${t}.${e}" is invalid: that file descriptor does not exist.
@@ -109,7 +109,7 @@ ${io}Please open a Bug report with the information above:`),console.error(`${io}
109
109
  `),diff:r}},"getStagedDiff"),f1=o(e=>`Detected ${e.length.toLocaleString()} staged file${e.length>1?"s":""}`,"getDetectedMessage");var uo,dc;function h1(){if(dc)return uo;dc=1;const{hasOwnProperty:e}=Object.prototype,t=o((u,c={})=>{typeof c=="string"&&(c={section:c}),c.align=c.align===!0,c.newline=c.newline===!0,c.sort=c.sort===!0,c.whitespace=c.whitespace===!0||c.align===!0,c.platform=c.platform||typeof process<"u"&&process.platform,c.bracketedArray=c.bracketedArray!==!1;const d=c.platform==="win32"?`\r
110
110
  `:`
111
111
  `,l=c.whitespace?" = ":"=",f=[],h=c.sort?Object.keys(u).sort():Object.keys(u);let p=0;c.align&&(p=s(h.filter(F=>u[F]===null||Array.isArray(u[F])||typeof u[F]!="object").map(F=>Array.isArray(u[F])?`${F}[]`:F).concat([""]).reduce((F,g)=>s(F).length>=s(g).length?F:g)).length);let D="";const m=c.bracketedArray?"[]":"";for(const F of h){const g=u[F];if(g&&Array.isArray(g))for(const w of g)D+=s(`${F}${m}`).padEnd(p," ")+l+s(w)+d;else g&&typeof g=="object"?f.push(F):D+=s(F).padEnd(p," ")+l+s(g)+d}c.section&&D.length&&(D="["+s(c.section)+"]"+(c.newline?d+d:d)+D);for(const F of f){const g=n(F,".").join("\\."),w=(c.section?c.section+".":"")+g,E=t(u[F],{...c,section:w});D.length&&E.length&&(D+=d),D+=E}return D},"encode");function n(u,c){var d=0,l=0,f=0,h=[];do if(f=u.indexOf(c,d),f!==-1){if(d=f+c.length,f>0&&u[f-1]==="\\")continue;h.push(u.slice(l,f)),l=f+c.length}while(f!==-1);return h.push(u.slice(l)),h}o(n,"splitSections");const r=o((u,c={})=>{c.bracketedArray=c.bracketedArray!==!1;const d=Object.create(null);let l=d,f=null;const h=/^\[([^\]]*)\]\s*$|^([^=]+)(=(.*))?$/i,p=u.split(/[\r\n]+/g),D={};for(const F of p){if(!F||F.match(/^\s*[;#]/)||F.match(/^\s*$/))continue;const g=F.match(h);if(!g)continue;if(g[1]!==void 0){if(f=a(g[1]),f==="__proto__"){l=Object.create(null);continue}l=d[f]=d[f]||Object.create(null);continue}const w=a(g[2]);let E;c.bracketedArray?E=w.length>2&&w.slice(-2)==="[]":(D[w]=(D?.[w]||0)+1,E=D[w]>1);const y=E&&w.endsWith("[]")?w.slice(0,-2):w;if(y==="__proto__")continue;const b=g[3]?a(g[4]):!0,v=b==="true"||b==="false"||b==="null"?JSON.parse(b):b;E&&(e.call(l,y)?Array.isArray(l[y])||(l[y]=[l[y]]):l[y]=[]),Array.isArray(l[y])?l[y].push(v):l[y]=v}const m=[];for(const F of Object.keys(d)){if(!e.call(d,F)||typeof d[F]!="object"||Array.isArray(d[F]))continue;const g=n(F,".");l=d;const w=g.pop(),E=w.replace(/\\\./g,".");for(const y of g)y!=="__proto__"&&((!e.call(l,y)||typeof l[y]!="object")&&(l[y]=Object.create(null)),l=l[y]);l===d&&E===w||(l[E]=d[F],m.push(F))}for(const F of m)delete d[F];return d},"decode"),i=o(u=>u.startsWith('"')&&u.endsWith('"')||u.startsWith("'")&&u.endsWith("'"),"isQuoted"),s=o(u=>typeof u!="string"||u.match(/[=\r\n]/)||u.match(/^\[/)||u.length>1&&i(u)||u!==u.trim()?JSON.stringify(u):u.split(";").join("\\;").split("#").join("\\#"),"safe"),a=o(u=>{if(u=(u||"").trim(),i(u)){u.charAt(0)==="'"&&(u=u.slice(1,-1));try{u=JSON.parse(u)}catch{}}else{let c=!1,d="";for(let l=0,f=u.length;l<f;l++){const h=u.charAt(l);if(c)"\\;#".indexOf(h)!==-1?d+=h:d+="\\"+h,c=!1;else{if(";#".indexOf(h)!==-1)break;h==="\\"?c=!0:d+=h}}return c&&(d+="\\"),d.trim()}return u},"unsafe");return uo={parse:r,decode:r,stringify:t,encode:t,safe:s,unsafe:a},uo}o(h1,"requireIni");var D1=h1(),fc=Xi(D1);const rn=o(e=>W.lstat(e).then(()=>!0,()=>!1),"fileExists"),co=o(async e=>{try{let t;try{t=e||await so()}catch(a){if(a instanceof O&&a.message.includes("Git repository"))return;throw a}const n=ce.join(t,".ai-commit.json");if(!await rn(n))return;const i=await W.readFile(n,"utf8");return JSON.parse(i)}catch(t){if(t instanceof O)throw t;return}},"getProjectConfig");function p1(e){const t={},n=e.split(`
112
- `);for(const r of n){const i=r.trim();if(!i||i.startsWith("#"))continue;const s=i.match(/^([A-Z_][A-Z0-9_]*)\s*=\s*(.*)$/i);if(!s)continue;const[,a,u]=s;let c=u.trim();(c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'"))&&(c=c.slice(1,-1)),t[a]=c}return t}o(p1,"parseEnvContent");async function hc(e){const{filename:t=".env",directory:n=process.cwd(),override:r=!1}=e||{},i=ce.join(n,t);if(!await rn(i))return{};try{const a=await W.readFile(i,"utf8"),u=p1(a);for(const[c,d]of Object.entries(u))(r||process.env[c]===void 0)&&(process.env[c]=d);return u}catch{return{}}}o(hc,"loadEnvFile");async function m1(){process.env.NODE_ENV==="test"?await hc({filename:".env.local"}):await hc({filename:".env"})}o(m1,"loadEnvironment");const Dc=["openai","anthropic","azure-openai","ollama","custom"],g1=["","conventional"],{hasOwnProperty:F1}=Object.prototype,pc=o((e,t)=>F1.call(e,t),"hasOwn"),R=o((e,t,n)=>{if(!t)throw new O(`Invalid config property ${e}: ${n}`)},"parseAssert"),on={provider(e){return e?(R("provider",Dc.includes(e),`Must be one of: ${Dc.join(", ")}`),e):"openai"},OPENAI_KEY(e){if(e)return R("OPENAI_KEY",e.startsWith("sk-"),'Must start with "sk-"'),e},ANTHROPIC_KEY(e){if(e)return R("ANTHROPIC_KEY",e.startsWith("sk-ant-"),'Must start with "sk-ant-"'),e},AZURE_OPENAI_KEY(e){return e},AZURE_ENDPOINT(e){if(e)return R("AZURE_ENDPOINT",/^https?:\/\//.test(e),"Must be a valid URL"),e},OLLAMA_ENDPOINT(e){return e?(R("OLLAMA_ENDPOINT",/^https?:\/\//.test(e),"Must be a valid URL"),e):"http://localhost:11434"},CUSTOM_ENDPOINT(e){if(e)return R("CUSTOM_ENDPOINT",/^https?:\/\//.test(e),"Must be a valid URL"),e},CUSTOM_KEY(e){return e},locale(e){return e?(R("locale",e,"Cannot be empty"),R("locale",/^[a-z-]+$/i.test(e),"Must be a valid locale (letters and dashes/underscores). You can consult the list of codes in: https://wikipedia.org/wiki/List_of_ISO_639-1_codes"),e):"en"},generate(e){if(!e)return 1;R("generate",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return R("generate",t>0,"Must be greater than 0"),R("generate",t<=5,"Must be less or equal to 5"),t},type(e){return e?(R("type",g1.includes(e),"Invalid commit type"),e):""},proxy(e){if(!(!e||e.length===0))return R("proxy",/^https?:\/\//.test(e),"Must be a valid URL"),e},model(e){return!e||e.length===0?"gpt-4o-mini":e},timeout(e){if(!e)return 1e4;R("timeout",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return R("timeout",t>=500,"Must be greater than 500ms"),t},temperature(e){if(!e)return .2;R("temperature",/^(2|\d)(\.\d{1,2})?$/.test(e),"Must be decimal between 0 and 2");const t=Number(e);return R("temperature",t>0,"Must be greater than 0"),R("temperature",t<=2,"Must be less than or equal to 2"),t},"max-length"(e){if(!e)return 50;R("max-length",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return R("max-length",t>=20,"Must be greater than 20 characters"),t},"max-completion-tokens"(e){if(!e)return 1e4;R("max-completion-tokens",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return R("max-completion-tokens",t>0,"Must be greater than 0"),t},"auto-confirm"(e){return e?typeof e=="boolean"?e:(R("auto-confirm",/^(?:true|false)$/.test(e),"Must be a boolean"),e==="true"):!1},"prepend-reference"(e){return e?typeof e=="boolean"?e:(R("prepend-reference",/^(?:true|false)$/.test(e),"Must be a boolean"),e==="true"):!1},signoff(e){return e?typeof e=="boolean"?e:(R("signoff",/^(?:true|false)$/.test(e),"Must be a boolean"),e==="true"):!1}},lo=ce.join(Kc.homedir(),".aicommit"),mc=o(async()=>{if(!await rn(lo))return Object.create(null);const t=await W.readFile(lo,"utf8");return fc.parse(t)},"readConfigFile"),w1=o(e=>{const t=e.provider;switch(t){case"openai":if(!e.OPENAI_KEY)throw new O("Please set your OpenAI API key via `aicommit config set OPENAI_KEY=<your token>`");break;case"anthropic":if(!e.ANTHROPIC_KEY)throw new O("Please set your Anthropic API key via `aicommit config set ANTHROPIC_KEY=<your token>`\nGet your API key from: https://console.anthropic.com/");break;case"azure-openai":if(!e.AZURE_OPENAI_KEY)throw new O("Please set your Azure OpenAI API key via `aicommit config set AZURE_OPENAI_KEY=<your token>`");if(!e.AZURE_ENDPOINT)throw new O("Please set your Azure OpenAI endpoint via `aicommit config set AZURE_ENDPOINT=<your endpoint>`");break;case"ollama":break;case"custom":if(!e.CUSTOM_ENDPOINT)throw new O("Please set your custom endpoint via `aicommit config set CUSTOM_ENDPOINT=<your endpoint>`");break;default:throw new O(`Unknown provider: ${t}`)}},"validateProviderConfig"),fo=o(async(e,t)=>{await m1();const n=await mc(),r=await co(),i={};for(const a of Object.keys(on)){const u=on[a];let c=r?.[a]??e?.[a]??process.env[a]??n[a];if(typeof c=="boolean"&&(c=c.toString()),t)try{i[a]=u(c)}catch{}else i[a]=u(c)}const s=i;return t||w1(s),s},"getConfig"),y1=o(async e=>{const t=await mc();for(const[n,r]of e){if(!pc(on,n))throw new O(`Invalid config property: ${n}`);const i=on[n](r);t[n]=i}await W.writeFile(lo,fc.stringify(t),"utf8")},"setConfigs"),gc={openai:o(()=>import("./openai-Zu2hwLw7.mjs"),"openai"),anthropic:o(()=>import("./anthropic-Bflyvw43.mjs"),"anthropic"),"azure-openai":o(()=>import("./azure-openai-DherjF_r.mjs"),"azure-openai"),ollama:o(()=>import("./ollama-B_kUc-33.mjs"),"ollama"),custom:o(()=>import("./custom-BGtaR9LL.mjs"),"custom")};async function Fc(e,t){const n=gc[e];if(!n)throw new O(`Unknown provider type: ${e}. Supported providers: ${Object.keys(gc).join(", ")}`);try{const i=(await n()).default;return new i(t)}catch(r){throw r instanceof O?r:r.code==="ERR_MODULE_NOT_FOUND"?new O(`Provider "${e}" is not yet implemented. Currently supported: openai`):new O(`Failed to initialize provider "${e}": ${r.message}`)}}o(Fc,"createProvider");var E1=o(async(e,t,n,r,i)=>(async()=>{uc(Hu(Vu(" aicommit "))),await so();const s=oo();n&&await Ge("git",["add","--update"]),s.start("Detecting staged files");const a=await lc(t);if(!a)throw s.stop("Detecting staged files"),new O("No staged changes found. Stage your changes manually, or automatically stage all changes with the `--all` flag.");s.stop(`${f1(a.files)}:
112
+ `);for(const r of n){const i=r.trim();if(!i||i.startsWith("#"))continue;const s=i.match(/^([A-Z_][A-Z0-9_]*)\s*=\s*(.*)$/i);if(!s)continue;const[,a,u]=s;let c=u.trim();(c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'"))&&(c=c.slice(1,-1)),t[a]=c}return t}o(p1,"parseEnvContent");async function hc(e){const{filename:t=".env",directory:n=process.cwd(),override:r=!1}=e||{},i=ce.join(n,t);if(!await rn(i))return{};try{const a=await W.readFile(i,"utf8"),u=p1(a);for(const[c,d]of Object.entries(u))(r||process.env[c]===void 0)&&(process.env[c]=d);return u}catch{return{}}}o(hc,"loadEnvFile");async function m1(){process.env.NODE_ENV==="test"?await hc({filename:".env.local"}):await hc({filename:".env"})}o(m1,"loadEnvironment");const Dc=["openai","anthropic","azure-openai","ollama","custom"],g1=["","conventional"],{hasOwnProperty:F1}=Object.prototype,pc=o((e,t)=>F1.call(e,t),"hasOwn"),R=o((e,t,n)=>{if(!t)throw new O(`Invalid config property ${e}: ${n}`)},"parseAssert"),on={provider(e){return e?(R("provider",Dc.includes(e),`Must be one of: ${Dc.join(", ")}`),e):"openai"},OPENAI_KEY(e){if(e)return R("OPENAI_KEY",e.startsWith("sk-"),'Must start with "sk-"'),e},ANTHROPIC_KEY(e){if(e)return R("ANTHROPIC_KEY",e.startsWith("sk-ant-"),'Must start with "sk-ant-"'),e},AZURE_OPENAI_KEY(e){return e},AZURE_ENDPOINT(e){if(e)return R("AZURE_ENDPOINT",/^https?:\/\//.test(e),"Must be a valid URL"),e},OLLAMA_ENDPOINT(e){return e?(R("OLLAMA_ENDPOINT",/^https?:\/\//.test(e),"Must be a valid URL"),e):"http://localhost:11434"},CUSTOM_ENDPOINT(e){if(e)return R("CUSTOM_ENDPOINT",/^https?:\/\//.test(e),"Must be a valid URL"),e},CUSTOM_KEY(e){return e},locale(e){return e?(R("locale",e,"Cannot be empty"),R("locale",/^[a-z-]+$/i.test(e),"Must be a valid locale (letters and dashes/underscores). You can consult the list of codes in: https://wikipedia.org/wiki/List_of_ISO_639-1_codes"),e):"en"},generate(e){if(!e)return 1;R("generate",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return R("generate",t>0,"Must be greater than 0"),R("generate",t<=5,"Must be less or equal to 5"),t},type(e){return e?(R("type",g1.includes(e),"Invalid commit type"),e):""},proxy(e){if(!(!e||e.length===0))return R("proxy",/^https?:\/\//.test(e),"Must be a valid URL"),e},model(e){return!e||e.length===0?"gpt-4o-mini":e},timeout(e){if(!e)return 1e4;R("timeout",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return R("timeout",t>=500,"Must be greater than 500ms"),t},temperature(e){if(!e)return .2;R("temperature",/^(2|\d)(\.\d{1,2})?$/.test(e),"Must be decimal between 0 and 2");const t=Number(e);return R("temperature",t>0,"Must be greater than 0"),R("temperature",t<=2,"Must be less than or equal to 2"),t},"max-length"(e){if(!e)return 50;R("max-length",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return R("max-length",t>=20,"Must be greater than 20 characters"),t},"max-completion-tokens"(e){if(!e)return 1e4;R("max-completion-tokens",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return R("max-completion-tokens",t>0,"Must be greater than 0"),t},"auto-confirm"(e){return e?typeof e=="boolean"?e:(R("auto-confirm",/^(?:true|false)$/.test(e),"Must be a boolean"),e==="true"):!1},"prepend-reference"(e){return e?typeof e=="boolean"?e:(R("prepend-reference",/^(?:true|false)$/.test(e),"Must be a boolean"),e==="true"):!1},signoff(e){return e?typeof e=="boolean"?e:(R("signoff",/^(?:true|false)$/.test(e),"Must be a boolean"),e==="true"):!1}},lo=ce.join(Kc.homedir(),".aicommit"),mc=o(async()=>{if(!await rn(lo))return Object.create(null);const t=await W.readFile(lo,"utf8");return fc.parse(t)},"readConfigFile"),w1=o(e=>{const t=e.provider;switch(t){case"openai":if(!e.OPENAI_KEY)throw new O("Please set your OpenAI API key via `aicommit config set OPENAI_KEY=<your token>`");break;case"anthropic":if(!e.ANTHROPIC_KEY)throw new O("Please set your Anthropic API key via `aicommit config set ANTHROPIC_KEY=<your token>`\nGet your API key from: https://console.anthropic.com/");break;case"azure-openai":if(!e.AZURE_OPENAI_KEY)throw new O("Please set your Azure OpenAI API key via `aicommit config set AZURE_OPENAI_KEY=<your token>`");if(!e.AZURE_ENDPOINT)throw new O("Please set your Azure OpenAI endpoint via `aicommit config set AZURE_ENDPOINT=<your endpoint>`");break;case"ollama":break;case"custom":if(!e.CUSTOM_ENDPOINT)throw new O("Please set your custom endpoint via `aicommit config set CUSTOM_ENDPOINT=<your endpoint>`");break;default:throw new O(`Unknown provider: ${t}`)}},"validateProviderConfig"),fo=o(async(e,t)=>{await m1();const n=await mc(),r=await co(),i={};for(const a of Object.keys(on)){const u=on[a];let c=r?.[a]??e?.[a]??process.env[a]??n[a];if(typeof c=="boolean"&&(c=c.toString()),t)try{i[a]=u(c)}catch{}else i[a]=u(c)}const s=i;return t||w1(s),s},"getConfig"),y1=o(async e=>{const t=await mc();for(const[n,r]of e){if(!pc(on,n))throw new O(`Invalid config property: ${n}`);const i=on[n](r);t[n]=i}await W.writeFile(lo,fc.stringify(t),"utf8")},"setConfigs"),gc={openai:o(()=>import("./openai-BdAvizjc.mjs"),"openai"),anthropic:o(()=>import("./anthropic-Ck4I7uv3.mjs"),"anthropic"),"azure-openai":o(()=>import("./azure-openai-X1fayFhc.mjs"),"azure-openai"),ollama:o(()=>import("./ollama-4LjS4HTe.mjs"),"ollama"),custom:o(()=>import("./custom-D0SH9FPr.mjs"),"custom")};async function Fc(e,t){const n=gc[e];if(!n)throw new O(`Unknown provider type: ${e}. Supported providers: ${Object.keys(gc).join(", ")}`);try{const i=(await n()).default;return new i(t)}catch(r){throw r instanceof O?r:r.code==="ERR_MODULE_NOT_FOUND"?new O(`Provider "${e}" is not yet implemented. Currently supported: openai`):new O(`Failed to initialize provider "${e}": ${r.message}`)}}o(Fc,"createProvider");var E1=o(async(e,t,n,r,i)=>(async()=>{uc(Hu(Vu(" aicommit "))),await so();const s=oo();n&&await Ge("git",["add","--update"]),s.start("Detecting staged files");const a=await lc(t);if(!a)throw s.stop("Detecting staged files"),new O("No staged changes found. Stage your changes manually, or automatically stage all changes with the `--all` flag.");s.stop(`${f1(a.files)}:
113
113
  ${a.files.map(p=>` ${p}`).join(`
114
114
  `)}`);const{env:u}=process,c=await fo({OPENAI_KEY:u.OPENAI_KEY||u.OPENAI_API_KEY,proxy:u.https_proxy||u.HTTPS_PROXY||u.http_proxy||u.HTTP_PROXY,generate:e?.toString(),type:r?.toString()}),d=oo();d.start("The AI is analyzing your changes");let l;try{const p={model:c.model,locale:c.locale,maxLength:c["max-length"],type:c.type,timeout:c.timeout,temperature:c.temperature,maxCompletionTokens:c["max-completion-tokens"],proxy:c.proxy};let D;switch(c.provider){case"openai":D={...p,apiKey:c.OPENAI_KEY};break;case"anthropic":D={...p,apiKey:c.ANTHROPIC_KEY};break;case"azure-openai":D={...p,apiKey:c.AZURE_OPENAI_KEY,endpoint:c.AZURE_ENDPOINT};break;case"ollama":D={...p,endpoint:c.OLLAMA_ENDPOINT};break;case"custom":D={...p,endpoint:c.CUSTOM_ENDPOINT,apiKey:c.CUSTOM_KEY};break;default:D={...p,apiKey:c.OPENAI_KEY}}const m=await Fc(c.provider,D),F=await co();l=(await m.generateCommitMessage({diff:a.diff,completions:c.generate,projectConfig:F})).messages}finally{d.stop("Changes analyzed")}if(l.length===0)throw new O("No commit messages were generated. Try again.");let f;if(l.length===1){[f]=l;let p;if(c["auto-confirm"]?(p=!0,Oe(`${ft("\u2714")} Auto confirmed commit message.
115
115
 
package/dist/cli.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import"./cli-BKUAQIcs.mjs";import"tty";import"node:url";import"node:child_process";import"node:string_decoder";import"node:util";import"node:process";import"node:tty";import"node:path";import"child_process";import"path";import"fs";import"node:timers/promises";import"node:os";import"node:events";import"node:v8";import"node:fs";import"node:stream";import"node:buffer";import"node:stream/promises";import"node:readline";import"fs/promises";import"os";import"url";
2
+ import"./cli-DMMbGriJ.mjs";import"tty";import"node:url";import"node:child_process";import"node:string_decoder";import"node:util";import"node:process";import"node:tty";import"node:path";import"child_process";import"path";import"fs";import"node:timers/promises";import"node:os";import"node:events";import"node:v8";import"node:fs";import"node:stream";import"node:buffer";import"node:stream/promises";import"node:readline";import"fs/promises";import"os";import"url";
@@ -1,3 +1,3 @@
1
- var M=Object.defineProperty;var d=(l,t)=>M(l,"name",{value:t,configurable:!0});import T from"http";import N from"https";import{L as O,g as P}from"./prompt-BGI0PV0L.mjs";import{K as m}from"./cli-BKUAQIcs.mjs";import"tty";import"node:url";import"node:child_process";import"node:string_decoder";import"node:util";import"node:process";import"node:tty";import"node:path";import"child_process";import"path";import"fs";import"node:timers/promises";import"node:os";import"node:events";import"node:v8";import"node:fs";import"node:stream";import"node:buffer";import"node:stream/promises";import"node:readline";import"fs/promises";import"os";import"url";const g=class g extends O{get name(){return"custom"}validateConfig(){const{endpoint:t}=this.config;if(!t)throw new m("Please set your custom endpoint via `aicommit config set CUSTOM_ENDPOINT=<your endpoint>`")}async generateCommitMessage(t){try{const o=[{role:"system",content:P(this.config.locale,this.config.maxLength,this.config.type,t.projectConfig)},{role:"user",content:t.diff}],s=[];for(let i=0;i<t.completions;i++){const e=await this.createChatCompletion(o);let n;e.choices&&e.choices[0]?.message?.content?n=e.choices[0].message.content:e.message?.content?n=e.message.content:e.content?n=e.content:typeof e=="string"&&(n=e),n&&s.push(this.sanitizeMessage(n))}return{messages:this.deduplicateMessages(s)}}catch(r){const o=r;throw o.code==="ECONNREFUSED"?new m(`Cannot connect to custom endpoint at ${this.config.endpoint}. Make sure your endpoint is running and accessible.`):o.code==="ENOTFOUND"?new m(`Error connecting to ${o.hostname} (${o.syscall}). Check your CUSTOM_ENDPOINT configuration.`):o}}async createChatCompletion(t){const r={model:this.config.model,messages:t,temperature:this.config.temperature,max_tokens:this.config.maxCompletionTokens},o={...this.config.headers||{}};this.config.apiKey&&(o.Authorization=`Bearer ${this.config.apiKey}`);const{response:s,data:a}=await this.httpPost(this.config.endpoint,"",o,r);if(!s.statusCode||s.statusCode<200||s.statusCode>299){let i=`Custom API Error: ${s.statusCode} - ${s.statusMessage}`;throw a&&(i+=`
1
+ var M=Object.defineProperty;var d=(l,t)=>M(l,"name",{value:t,configurable:!0});import T from"http";import N from"https";import{L as O,g as P}from"./prompt-BGI0PV0L.mjs";import{K as m}from"./cli-DMMbGriJ.mjs";import"tty";import"node:url";import"node:child_process";import"node:string_decoder";import"node:util";import"node:process";import"node:tty";import"node:path";import"child_process";import"path";import"fs";import"node:timers/promises";import"node:os";import"node:events";import"node:v8";import"node:fs";import"node:stream";import"node:buffer";import"node:stream/promises";import"node:readline";import"fs/promises";import"os";import"url";const g=class g extends O{get name(){return"custom"}validateConfig(){const{endpoint:t}=this.config;if(!t)throw new m("Please set your custom endpoint via `aicommit config set CUSTOM_ENDPOINT=<your endpoint>`")}async generateCommitMessage(t){try{const o=[{role:"system",content:P(this.config.locale,this.config.maxLength,this.config.type,t.projectConfig)},{role:"user",content:t.diff}],s=[];for(let i=0;i<t.completions;i++){const e=await this.createChatCompletion(o);let n;e.choices&&e.choices[0]?.message?.content?n=e.choices[0].message.content:e.message?.content?n=e.message.content:e.content?n=e.content:typeof e=="string"&&(n=e),n&&s.push(this.sanitizeMessage(n))}return{messages:this.deduplicateMessages(s)}}catch(r){const o=r;throw o.code==="ECONNREFUSED"?new m(`Cannot connect to custom endpoint at ${this.config.endpoint}. Make sure your endpoint is running and accessible.`):o.code==="ENOTFOUND"?new m(`Error connecting to ${o.hostname} (${o.syscall}). Check your CUSTOM_ENDPOINT configuration.`):o}}async createChatCompletion(t){const r={model:this.config.model,messages:t,temperature:this.config.temperature,max_tokens:this.config.maxCompletionTokens},o={...this.config.headers||{}};this.config.apiKey&&(o.Authorization=`Bearer ${this.config.apiKey}`);const{response:s,data:a}=await this.httpPost(this.config.endpoint,"",o,r);if(!s.statusCode||s.statusCode<200||s.statusCode>299){let i=`Custom API Error: ${s.statusCode} - ${s.statusMessage}`;throw a&&(i+=`
2
2
 
3
3
  ${a}`),new m(i)}return JSON.parse(a)}async httpPost(t,r,o,s){return new Promise((a,i)=>{const e=new URL(t),n=e.protocol==="https:",y=n?N:T,C=e.pathname+(r||""),f=JSON.stringify(s),c=y.request({hostname:e.hostname,port:e.port||(n?443:80),path:C,method:"POST",headers:{...o,"Content-Type":"application/json","Content-Length":Buffer.byteLength(f)},timeout:this.config.timeout},p=>{const u=[];p.on("data",w=>u.push(w)),p.on("end",()=>{a({request:c,response:p,data:Buffer.concat(u).toString()})})});c.on("error",i),c.on("timeout",()=>{c.destroy(),i(new m(`Time out error: request took over ${this.config.timeout}ms. Try increasing the \`timeout\` config.`))}),c.write(f),c.end()})}sanitizeMessage(t){return t.trim().replace(/[\n\r]/g,"").replace(/(\w)\.$/,"$1")}deduplicateMessages(t){return Array.from(new Set(t))}};d(g,"CustomProvider");let h=g;export{h as default};
@@ -1,4 +1,4 @@
1
- var C=Object.defineProperty;var f=(d,t)=>C(d,"name",{value:t,configurable:!0});import M from"http";import O from"https";import{L as $,g as L}from"./prompt-BGI0PV0L.mjs";import{K as m}from"./cli-BKUAQIcs.mjs";import"tty";import"node:url";import"node:child_process";import"node:string_decoder";import"node:util";import"node:process";import"node:tty";import"node:path";import"child_process";import"path";import"fs";import"node:timers/promises";import"node:os";import"node:events";import"node:v8";import"node:fs";import"node:stream";import"node:buffer";import"node:stream/promises";import"node:readline";import"fs/promises";import"os";import"url";const g=class g extends ${get name(){return"ollama"}validateConfig(){const{endpoint:t}=this.config;if(!t)throw new m("Ollama endpoint is not configured. Using default: http://localhost:11434")}async generateCommitMessage(t){try{const e=[{role:"system",content:L(this.config.locale,this.config.maxLength,this.config.type,t.projectConfig)},{role:"user",content:t.diff}],o=[];for(let s=0;s<t.completions;s++){const a=(await this.createChatCompletion(e)).message.content;a&&o.push(this.sanitizeMessage(a))}return{messages:this.deduplicateMessages(o)}}catch(r){const e=r;throw e.code==="ECONNREFUSED"?new m(`Cannot connect to Ollama at ${this.config.endpoint}. Make sure Ollama is running. Install from: https://ollama.com`):e.code==="ENOTFOUND"?new m(`Error connecting to ${e.hostname} (${e.syscall}). Check your OLLAMA_ENDPOINT configuration.`):e}}async createChatCompletion(t){const r={model:this.config.model,messages:t,stream:!1,options:{temperature:this.config.temperature,num_predict:this.config.maxCompletionTokens}},{response:e,data:o}=await this.httpPost(this.config.endpoint,"/api/chat",{},r);if(!e.statusCode||e.statusCode<200||e.statusCode>299){let n=`Ollama API Error: ${e.statusCode} - ${e.statusMessage}`;if(o)try{const s=JSON.parse(o);s.error&&(n+=`
1
+ var C=Object.defineProperty;var f=(d,t)=>C(d,"name",{value:t,configurable:!0});import M from"http";import O from"https";import{L as $,g as L}from"./prompt-BGI0PV0L.mjs";import{K as m}from"./cli-DMMbGriJ.mjs";import"tty";import"node:url";import"node:child_process";import"node:string_decoder";import"node:util";import"node:process";import"node:tty";import"node:path";import"child_process";import"path";import"fs";import"node:timers/promises";import"node:os";import"node:events";import"node:v8";import"node:fs";import"node:stream";import"node:buffer";import"node:stream/promises";import"node:readline";import"fs/promises";import"os";import"url";const g=class g extends ${get name(){return"ollama"}validateConfig(){const{endpoint:t}=this.config;if(!t)throw new m("Ollama endpoint is not configured. Using default: http://localhost:11434")}async generateCommitMessage(t){try{const e=[{role:"system",content:L(this.config.locale,this.config.maxLength,this.config.type,t.projectConfig)},{role:"user",content:t.diff}],o=[];for(let s=0;s<t.completions;s++){const a=(await this.createChatCompletion(e)).message.content;a&&o.push(this.sanitizeMessage(a))}return{messages:this.deduplicateMessages(o)}}catch(r){const e=r;throw e.code==="ECONNREFUSED"?new m(`Cannot connect to Ollama at ${this.config.endpoint}. Make sure Ollama is running. Install from: https://ollama.com`):e.code==="ENOTFOUND"?new m(`Error connecting to ${e.hostname} (${e.syscall}). Check your OLLAMA_ENDPOINT configuration.`):e}}async createChatCompletion(t){const r={model:this.config.model,messages:t,stream:!1,options:{temperature:this.config.temperature,num_predict:this.config.maxCompletionTokens}},{response:e,data:o}=await this.httpPost(this.config.endpoint,"/api/chat",{},r);if(!e.statusCode||e.statusCode<200||e.statusCode>299){let n=`Ollama API Error: ${e.statusCode} - ${e.statusMessage}`;if(o)try{const s=JSON.parse(o);s.error&&(n+=`
2
2
 
3
3
  ${s.error}`)}catch{n+=`
4
4
 
@@ -1,4 +1,4 @@
1
- var d=Object.defineProperty;var g=(u,t)=>d(u,"name",{value:t,configurable:!0});import y from"https";import{d as w}from"./index-B3_BP8RZ.mjs";import{L as C,g as A}from"./prompt-BGI0PV0L.mjs";import{K as i}from"./cli-BKUAQIcs.mjs";import"net";import"tls";import"assert";import"tty";import"util";import"os";import"http";import"url";import"node:url";import"node:child_process";import"node:string_decoder";import"node:util";import"node:process";import"node:tty";import"node:path";import"child_process";import"path";import"fs";import"node:timers/promises";import"node:os";import"node:events";import"node:v8";import"node:fs";import"node:stream";import"node:buffer";import"node:stream/promises";import"node:readline";import"fs/promises";const m=class m extends C{get name(){return"openai"}validateConfig(){const{apiKey:t}=this.config;if(!t)throw new i("Please set your OpenAI API key via `aicommit config set OPENAI_KEY=<your token>`");if(!t.startsWith("sk-"))throw new i('Invalid OpenAI API key: Must start with "sk-"')}async generateCommitMessage(t){try{const e=await this.createChatCompletion({model:this.config.model,messages:[{role:"system",content:A(this.config.locale,this.config.maxLength,this.config.type,t.projectConfig)},{role:"user",content:t.diff}],temperature:this.config.temperature,top_p:1,frequency_penalty:0,presence_penalty:0,max_completion_tokens:this.config.maxCompletionTokens,stream:!1,n:t.completions});return{messages:this.deduplicateMessages(e.choices.filter(s=>s.message?.content).map(s=>this.sanitizeMessage(s.message.content)))}}catch(e){const o=e;throw o.code==="ENOTFOUND"?new i(`Error connecting to ${o.hostname} (${o.syscall}). Are you connected to the internet?`):o}}async createChatCompletion(t){const{response:e,data:o}=await this.httpsPost("api.openai.com","/v1/chat/completions",{Authorization:`Bearer ${this.config.apiKey}`},t);if(!e.statusCode||e.statusCode<200||e.statusCode>299){let s=`OpenAI API Error: ${e.statusCode} - ${e.statusMessage}`;throw o&&(s+=`
1
+ var d=Object.defineProperty;var g=(u,t)=>d(u,"name",{value:t,configurable:!0});import y from"https";import{d as w}from"./index-B3_BP8RZ.mjs";import{L as C,g as A}from"./prompt-BGI0PV0L.mjs";import{K as i}from"./cli-DMMbGriJ.mjs";import"net";import"tls";import"assert";import"tty";import"util";import"os";import"http";import"url";import"node:url";import"node:child_process";import"node:string_decoder";import"node:util";import"node:process";import"node:tty";import"node:path";import"child_process";import"path";import"fs";import"node:timers/promises";import"node:os";import"node:events";import"node:v8";import"node:fs";import"node:stream";import"node:buffer";import"node:stream/promises";import"node:readline";import"fs/promises";const m=class m extends C{get name(){return"openai"}validateConfig(){const{apiKey:t}=this.config;if(!t)throw new i("Please set your OpenAI API key via `aicommit config set OPENAI_KEY=<your token>`");if(!t.startsWith("sk-"))throw new i('Invalid OpenAI API key: Must start with "sk-"')}async generateCommitMessage(t){try{const e=await this.createChatCompletion({model:this.config.model,messages:[{role:"system",content:A(this.config.locale,this.config.maxLength,this.config.type,t.projectConfig)},{role:"user",content:t.diff}],temperature:this.config.temperature,top_p:1,frequency_penalty:0,presence_penalty:0,max_completion_tokens:this.config.maxCompletionTokens,stream:!1,n:t.completions});return{messages:this.deduplicateMessages(e.choices.filter(s=>s.message?.content).map(s=>this.sanitizeMessage(s.message.content)))}}catch(e){const o=e;throw o.code==="ENOTFOUND"?new i(`Error connecting to ${o.hostname} (${o.syscall}). Are you connected to the internet?`):o}}async createChatCompletion(t){const{response:e,data:o}=await this.httpsPost("api.openai.com","/v1/chat/completions",{Authorization:`Bearer ${this.config.apiKey}`},t);if(!e.statusCode||e.statusCode<200||e.statusCode>299){let s=`OpenAI API Error: ${e.statusCode} - ${e.statusMessage}`;throw o&&(s+=`
2
2
 
3
3
  ${o}`),e.statusCode===500&&(s+=`
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@negoziator/ai-commit",
3
- "version": "2.56.0",
3
+ "version": "2.56.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },