@negoziator/ai-commit 2.37.1 → 2.38.0

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-DqbY1hdM.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-DbiVqdzf.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-DqbY1hdM.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-DbiVqdzf.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 Vc=Object.defineProperty;var o=(e,t)=>Vc(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 Hl(t.map(i=>i.map(s=>this.render(s))),r?Xl(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(Ge,"_ne"),Ge);x(Li,"Renderers");let ud=Li;const vn=x(e=>e.length>0&&!e.includes(" "),"isValidScriptName"),{stringify:Q}=JSON,cd=/[|\\{}()[\]^$+*?.]/;function Bn(e){const t=[];let n,r;for(const i of e){if(r)throw new Error(`Invalid parameter: Spread parameter ${Q(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 ${Q(i)} cannot come after optional parameter ${Q(n)}`);if(s==="["&&a==="]"&&(u=!1,n=i),u===void 0)throw new Error(`Invalid parameter: ${Q(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(cd);if(l)throw new Error(`Invalid parameter: ${Q(i)}. Invalid character found ${Q(l[0])}`);t.push({name:c,required:u,spread:d})}return t}o(Bn,"P$1"),x(Bn,"parseParameters");function $n(e,t,n,r){for(let i=0;i<t.length;i+=1){const{name:s,required:a,spread:u}=t[i],c=rd(s);if(c in e)throw new Error(`Invalid parameter: ${Q(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 ${Q(s)}
22
- `),r(),process.exit(1);e[c]=d}}o($n,"S$1"),x($n,"mapParametersToArguments");function ki(e){return e!==!1}o(ki,"se"),x(ki,"helpEnabled");const ld=x(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"),dd=x((e,t)=>{if(e.length<3||t.length===0)return;const n=nd(e,t);return Bi(e,n)<=2?n:void 0},"findClosestFlag"),fd=x((e,t)=>{const n=Object.keys(e);if(n.length!==0){for(const r of n){const i=dd(r,t),s=i?` (Did you mean --${i}?)`:"";console.error(`Error: Unknown flag: --${r}.${s}`)}process.exit(1)}},"handleUnknownFlags");function An(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=ki(a);u&&!("help"in i)&&(i.help={type:Boolean,alias:"h",description:"Show help"});const c=Al(i,r,{ignore:t.ignoreArgv}),d=x(()=>{console.log(t.version)},"showVersion");if(s&&c.flags.version===!0)return d(),process.exit(0);const l=new ud,f=u&&a?.render?a.render:m=>l.render(m),h=x(m=>{const g=sd({...t,...m?{help:m}:{},flags:i});console.log(f(g,l))},"showHelp");if(u&&c.flags.help===!0)return h(),process.exit(0);if((t.strictFlags??t.parent?.strictFlags)&&fd(c.unknownFlags,ld(i)),t.parameters){let{parameters:m}=t,g=c._;const F=m.indexOf("--"),w=m.slice(F+1),y=Object.create(null);let E=[];F>-1&&w.length>0&&(m=m.slice(0,F),E=c._["--"],g=g.slice(0,-E.length||void 0)),$n(y,Bn(m),g,h),F>-1&&w.length>0&&$n(y,Bn(w),E,h),Object.assign(c._,y)}const D={...c,showVersion:d,showHelp:h},p={command:e,...D};if(typeof n=="function"){const m=n(D);if(m&&"then"in m)return Object.assign(Promise.resolve(m),p)}return p}o(An,"I"),x(An,"cliBase");function Ni(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: ${Q(a)}`);n.set(a,r)}}return n.get(e)}o(Ni,"ce"),x(Ni,"getCommand");function ji(e,t,n=process.argv.slice(2)){if(!e)throw new Error("Options is required");if("name"in e&&(!e.name||!vn(e.name)))throw new Error(`Invalid script name: ${Q(e.name)}`);const r=n[0];if(e.commands&&r&&vn(r)){const i=Ni(r,e.commands);if(i)return An(i.options.name,{...i.options,parent:e},i.callback,n.slice(1))}return An(void 0,e,t,n)}o(ji,"fe$1"),x(ji,"cli");function xn(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(!vn(n))throw new Error(`Invalid command name ${JSON.stringify(n)}. Command names must be one word.`);return{options:e,callback:t}}o(xn,"de"),x(xn,"command");var hd="2.37.1",pd="Writes your git commit messages for you with AI",Tn={version:hd,description:pd};function H(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(H,"isPlainObject");const On=o((e,t)=>{const n=Wi(Dd(e));if(typeof n!="string")throw new TypeError(`${t} must be a string or a file URL: ${n}.`);return n},"safeNormalizeFileUrl"),Dd=o(e=>Ui(e)?e.toString():e,"normalizeDenoExecPath"),Ui=o(e=>typeof e!="string"&&e&&Object.getPrototypeOf(e)===String.prototype,"isDenoExecPath"),Wi=o(e=>e instanceof URL?jo(e):e,"normalizeFileUrl"),Gi=o((e,t=[],n={})=>{const r=On(e,"First argument"),[i,s]=H(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(!H(s))throw new TypeError(`Last argument must be an options object: ${s}`);return[r,a,s]},"normalizeParameters"),{toString:zi}=Object.prototype,md=o(e=>zi.call(e)==="[object ArrayBuffer]","isArrayBuffer"),J=o(e=>zi.call(e)==="[object Uint8Array]","isUint8Array"),qe=o(e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength),"bufferToUint8Array"),gd=new TextEncoder,Vi=o(e=>gd.encode(e),"stringToUint8Array"),Fd=new TextDecoder,Yi=o(e=>Fd.decode(e),"uint8ArrayToString"),wd=o((e,t)=>yd(e,t).join(""),"joinToString"),yd=o((e,t)=>{if(t==="utf8"&&e.every(s=>typeof s=="string"))return e;const n=new Wo(t),r=e.map(s=>typeof s=="string"?Vi(s):s).map(s=>n.write(s)),i=n.end();return i===""?r:[...r,i]},"uint8ArraysToStrings"),In=o(e=>e.length===1&&J(e[0])?e[0]:qi(Ed(e)),"joinToUint8Array"),Ed=o(e=>e.map(t=>typeof t=="string"?Vi(t):t),"stringsToUint8Arrays"),qi=o(e=>{const t=new Uint8Array(bd(e));let n=0;for(const r of e)t.set(r,n),n+=r.length;return t},"concatUint8Arrays"),bd=o(e=>{let t=0;for(const n of e)t+=n.length;return t},"getJoinLength"),Cd=o(e=>Array.isArray(e)&&Array.isArray(e.raw),"isTemplateString"),Sd=o((e,t)=>{let n=[];for(const[s,a]of e.entries())n=vd({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"),vd=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}=Bd(i,e.raw[r]),c=Hi(n,s,a);if(r===t.length)return c;const d=t[r],l=Array.isArray(d)?d.map(f=>Zi(f)):[Zi(d)];return Hi(c,l,u)},"parseTemplate"),Bd=o((e,t)=>{if(t.length===0)return{nextTokens:[],leadingWhitespaces:!1,trailingWhitespaces:!1};const n=[];let r=0;const i=Ki.has(t[0]);for(let a=0,u=0;a<e.length;a+=1,u+=1){const c=t[u];if(Ki.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($n,"S$1"),x($n,"mapParametersToArguments");function ki(e){return e!==!1}o(ki,"se"),x(ki,"helpEnabled");const ld=x(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"),dd=x((e,t)=>{if(e.length<3||t.length===0)return;const n=nd(e,t);return Bi(e,n)<=2?n:void 0},"findClosestFlag"),fd=x((e,t)=>{const n=Object.keys(e);if(n.length!==0){for(const r of n){const i=dd(r,t),s=i?` (Did you mean --${i}?)`:"";console.error(`Error: Unknown flag: --${r}.${s}`)}process.exit(1)}},"handleUnknownFlags");function An(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=ki(a);u&&!("help"in i)&&(i.help={type:Boolean,alias:"h",description:"Show help"});const c=Al(i,r,{ignore:t.ignoreArgv}),d=x(()=>{console.log(t.version)},"showVersion");if(s&&c.flags.version===!0)return d(),process.exit(0);const l=new ud,f=u&&a?.render?a.render:m=>l.render(m),h=x(m=>{const g=sd({...t,...m?{help:m}:{},flags:i});console.log(f(g,l))},"showHelp");if(u&&c.flags.help===!0)return h(),process.exit(0);if((t.strictFlags??t.parent?.strictFlags)&&fd(c.unknownFlags,ld(i)),t.parameters){let{parameters:m}=t,g=c._;const F=m.indexOf("--"),w=m.slice(F+1),y=Object.create(null);let E=[];F>-1&&w.length>0&&(m=m.slice(0,F),E=c._["--"],g=g.slice(0,-E.length||void 0)),$n(y,Bn(m),g,h),F>-1&&w.length>0&&$n(y,Bn(w),E,h),Object.assign(c._,y)}const D={...c,showVersion:d,showHelp:h},p={command:e,...D};if(typeof n=="function"){const m=n(D);if(m&&"then"in m)return Object.assign(Promise.resolve(m),p)}return p}o(An,"I"),x(An,"cliBase");function Ni(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: ${Q(a)}`);n.set(a,r)}}return n.get(e)}o(Ni,"ce"),x(Ni,"getCommand");function ji(e,t,n=process.argv.slice(2)){if(!e)throw new Error("Options is required");if("name"in e&&(!e.name||!vn(e.name)))throw new Error(`Invalid script name: ${Q(e.name)}`);const r=n[0];if(e.commands&&r&&vn(r)){const i=Ni(r,e.commands);if(i)return An(i.options.name,{...i.options,parent:e},i.callback,n.slice(1))}return An(void 0,e,t,n)}o(ji,"fe$1"),x(ji,"cli");function xn(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(!vn(n))throw new Error(`Invalid command name ${JSON.stringify(n)}. Command names must be one word.`);return{options:e,callback:t}}o(xn,"de"),x(xn,"command");var hd="2.38.0",pd="Writes your git commit messages for you with AI",Tn={version:hd,description:pd};function H(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(H,"isPlainObject");const On=o((e,t)=>{const n=Wi(Dd(e));if(typeof n!="string")throw new TypeError(`${t} must be a string or a file URL: ${n}.`);return n},"safeNormalizeFileUrl"),Dd=o(e=>Ui(e)?e.toString():e,"normalizeDenoExecPath"),Ui=o(e=>typeof e!="string"&&e&&Object.getPrototypeOf(e)===String.prototype,"isDenoExecPath"),Wi=o(e=>e instanceof URL?jo(e):e,"normalizeFileUrl"),Gi=o((e,t=[],n={})=>{const r=On(e,"First argument"),[i,s]=H(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(!H(s))throw new TypeError(`Last argument must be an options object: ${s}`);return[r,a,s]},"normalizeParameters"),{toString:zi}=Object.prototype,md=o(e=>zi.call(e)==="[object ArrayBuffer]","isArrayBuffer"),J=o(e=>zi.call(e)==="[object Uint8Array]","isUint8Array"),qe=o(e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength),"bufferToUint8Array"),gd=new TextEncoder,Vi=o(e=>gd.encode(e),"stringToUint8Array"),Fd=new TextDecoder,Yi=o(e=>Fd.decode(e),"uint8ArrayToString"),wd=o((e,t)=>yd(e,t).join(""),"joinToString"),yd=o((e,t)=>{if(t==="utf8"&&e.every(s=>typeof s=="string"))return e;const n=new Wo(t),r=e.map(s=>typeof s=="string"?Vi(s):s).map(s=>n.write(s)),i=n.end();return i===""?r:[...r,i]},"uint8ArraysToStrings"),In=o(e=>e.length===1&&J(e[0])?e[0]:qi(Ed(e)),"joinToUint8Array"),Ed=o(e=>e.map(t=>typeof t=="string"?Vi(t):t),"stringsToUint8Arrays"),qi=o(e=>{const t=new Uint8Array(bd(e));let n=0;for(const r of e)t.set(r,n),n+=r.length;return t},"concatUint8Arrays"),bd=o(e=>{let t=0;for(const n of e)t+=n.length;return t},"getJoinLength"),Cd=o(e=>Array.isArray(e)&&Array.isArray(e.raw),"isTemplateString"),Sd=o((e,t)=>{let n=[];for(const[s,a]of e.entries())n=vd({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"),vd=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}=Bd(i,e.raw[r]),c=Hi(n,s,a);if(r===t.length)return c;const d=t[r],l=Array.isArray(d)?d.map(f=>Zi(f)):[Zi(d)];return Hi(c,l,u)},"parseTemplate"),Bd=o((e,t)=>{if(t.length===0)return{nextTokens:[],leadingWhitespaces:!1,trailingWhitespaces:!1};const n=[];let r=0;const i=Ki.has(t[0]);for(let a=0,u=0;a<e.length;a+=1,u+=1){const c=t[u];if(Ki.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+=$d[d]??1}}const s=r===e.length;return s||n.push(e.slice(r)),{nextTokens:n,leadingWhitespaces:i,trailingWhitespaces:s}},"splitByWhitespaces"),Ki=new Set([" "," ","\r",`
24
24
  `]),$d={x:3,u:5},Hi=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"),Zi=o(e=>{const t=typeof e;if(t==="string")return e;if(t==="number")return String(e);if(H(e)&&("stdout"in e||"isMaxBuffer"in e))return Ad(e);throw e instanceof Uo||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"),Ad=o(({stdout:e})=>{if(typeof e=="string")return e;if(J(e))return Yi(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=>Rn.includes(e),"isStandardStream"),Rn=[O.stdin,O.stdout,O.stderr],ee=["stdin","stdout","stderr"],Ji=o(e=>ee[e]??`stdio[${e}]`,"getStreamName"),xd=o(e=>{const t={...e};for(const n of ts)t[n]=Xi(e,n);return t},"normalizeFdSpecificOptions"),Xi=o((e,t)=>{const n=Array.from({length:Td(e)+1}),r=Od(e[t],n,t);return Pd(r,t)},"normalizeFdSpecificOption"),Td=o(({stdio:e})=>Array.isArray(e)?Math.max(e.length,ee.length):ee.length,"getStdioLength"),Od=o((e,t,n)=>H(e)?Id(e,t,n):t.fill(e),"normalizeFdSpecificValue"),Id=o((e,t,n)=>{for(const r of Object.keys(e).sort(Rd))for(const i of Md(r,n,t))t[i]=e[r];return t},"normalizeOptionObject"),Rd=o((e,t)=>Qi(e)<Qi(t)?1:-1,"compareFdName"),Qi=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=es(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.
@@ -119,7 +119,7 @@ ${yo}Please open a Bug report with the information above:`),console.error(`${yo}
119
119
  `),diff:r}},"getStagedDiff"),Yg=o(e=>`Detected ${e.length.toLocaleString()} staged file${e.length>1?"s":""}`,"getDetectedMessage");var Co,Tc;function qg(){if(Tc)return Co;Tc=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
120
120
  `:`
121
121
  `,l=c.whitespace?" = ":"=",f=[],h=c.sort?Object.keys(u).sort():Object.keys(u);let D=0;c.align&&(D=s(h.filter(g=>u[g]===null||Array.isArray(u[g])||typeof u[g]!="object").map(g=>Array.isArray(u[g])?`${g}[]`:g).concat([""]).reduce((g,F)=>s(g).length>=s(F).length?g:F)).length);let p="";const m=c.bracketedArray?"[]":"";for(const g of h){const F=u[g];if(F&&Array.isArray(F))for(const w of F)p+=s(`${g}${m}`).padEnd(D," ")+l+s(w)+d;else F&&typeof F=="object"?f.push(g):p+=s(g).padEnd(D," ")+l+s(F)+d}c.section&&p.length&&(p="["+s(c.section)+"]"+(c.newline?d+d:d)+p);for(const g of f){const F=n(g,".").join("\\."),w=(c.section?c.section+".":"")+F,y=t(u[g],{...c,section:w});p.length&&y.length&&(p+=d),p+=y}return p},"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,D=u.split(/[\r\n]+/g),p={};for(const g of D){if(!g||g.match(/^\s*[;#]/)||g.match(/^\s*$/))continue;const F=g.match(h);if(!F)continue;if(F[1]!==void 0){if(f=a(F[1]),f==="__proto__"){l=Object.create(null);continue}l=d[f]=d[f]||Object.create(null);continue}const w=a(F[2]);let y;c.bracketedArray?y=w.length>2&&w.slice(-2)==="[]":(p[w]=(p?.[w]||0)+1,y=p[w]>1);const E=y&&w.endsWith("[]")?w.slice(0,-2):w;if(E==="__proto__")continue;const S=F[3]?a(F[4]):!0,B=S==="true"||S==="false"||S==="null"?JSON.parse(S):S;y&&(e.call(l,E)?Array.isArray(l[E])||(l[E]=[l[E]]):l[E]=[]),Array.isArray(l[E])?l[E].push(B):l[E]=B}const m=[];for(const g of Object.keys(d)){if(!e.call(d,g)||typeof d[g]!="object"||Array.isArray(d[g]))continue;const F=n(g,".");l=d;const w=F.pop(),y=w.replace(/\\\./g,".");for(const E of F)E!=="__proto__"&&((!e.call(l,E)||typeof l[E]!="object")&&(l[E]=Object.create(null)),l=l[E]);l===d&&y===w||(l[y]=d[g],m.push(g))}for(const g of m)delete d[g];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 Co={parse:r,decode:r,stringify:t,encode:t,safe:s,unsafe:a},Co}o(qg,"requireIni");var Kg=qg(),Oc=Wn(Kg);const cn=o(e=>G.lstat(e).then(()=>!0,()=>!1),"fileExists"),So=o(async e=>{try{let t;try{t=e||await Eo()}catch(a){if(a instanceof I&&a.message.includes("Git repository"))return;throw a}const n=ce.join(t,".ai-commit.json");if(!await cn(n))return;const i=await G.readFile(n,"utf8");return JSON.parse(i)}catch(t){if(t instanceof I)throw t;return}},"getProjectConfig");function Hg(e){const t={},n=e.split(`
122
- `);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(Hg,"parseEnvContent");async function Ic(e){const{filename:t=".env",directory:n=process.cwd(),override:r=!1}=e||{},i=ce.join(n,t);if(!await cn(i))return{};try{const a=await G.readFile(i,"utf8"),u=Hg(a);for(const[c,d]of Object.entries(u))(r||process.env[c]===void 0)&&(process.env[c]=d);return u}catch{return{}}}o(Ic,"loadEnvFile");async function Zg(){process.env.NODE_ENV==="test"?await Ic({filename:".env.local"}):await Ic({filename:".env"})}o(Zg,"loadEnvironment");const Rc=["openai","anthropic","azure-openai","ollama","custom"],Jg=["","conventional"],{hasOwnProperty:Xg}=Object.prototype,Mc=o((e,t)=>Xg.call(e,t),"hasOwn"),M=o((e,t,n)=>{if(!t)throw new I(`Invalid config property ${e}: ${n}`)},"parseAssert"),ln={provider(e){return e?(M("provider",Rc.includes(e),`Must be one of: ${Rc.join(", ")}`),e):"openai"},OPENAI_KEY(e){if(e)return M("OPENAI_KEY",e.startsWith("sk-"),'Must start with "sk-"'),e},ANTHROPIC_KEY(e){if(e)return M("ANTHROPIC_KEY",e.startsWith("sk-ant-"),'Must start with "sk-ant-"'),e},AZURE_OPENAI_KEY(e){return e},AZURE_ENDPOINT(e){if(e)return M("AZURE_ENDPOINT",/^https?:\/\//.test(e),"Must be a valid URL"),e},OLLAMA_ENDPOINT(e){return e?(M("OLLAMA_ENDPOINT",/^https?:\/\//.test(e),"Must be a valid URL"),e):"http://localhost:11434"},CUSTOM_ENDPOINT(e){if(e)return M("CUSTOM_ENDPOINT",/^https?:\/\//.test(e),"Must be a valid URL"),e},CUSTOM_KEY(e){return e},locale(e){return e?(M("locale",e,"Cannot be empty"),M("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;M("generate",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return M("generate",t>0,"Must be greater than 0"),M("generate",t<=5,"Must be less or equal to 5"),t},type(e){return e?(M("type",Jg.includes(e),"Invalid commit type"),e):""},proxy(e){if(!(!e||e.length===0))return M("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;M("timeout",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return M("timeout",t>=500,"Must be greater than 500ms"),t},temperature(e){if(!e)return .2;M("temperature",/^(2|\d)(\.\d{1,2})?$/.test(e),"Must be decimal between 0 and 2");const t=Number(e);return M("temperature",t>0,"Must be greater than 0"),M("temperature",t<=2,"Must be less than or equal to 2"),t},"max-length"(e){if(!e)return 50;M("max-length",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return M("max-length",t>=20,"Must be greater than 20 characters"),t},"max-completion-tokens"(e){if(!e)return 1e4;M("max-completion-tokens",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return M("max-completion-tokens",t>0,"Must be greater than 0"),t},"auto-confirm"(e){return e?typeof e=="boolean"?e:(M("auto-confirm",/^(?:true|false)$/.test(e),"Must be a boolean"),e==="true"):!1},"prepend-reference"(e){return e?typeof e=="boolean"?e:(M("prepend-reference",/^(?:true|false)$/.test(e),"Must be a boolean"),e==="true"):!1}},vo=ce.join(fl.homedir(),".aicommit"),_c=o(async()=>{if(!await cn(vo))return Object.create(null);const t=await G.readFile(vo,"utf8");return Oc.parse(t)},"readConfigFile"),Qg=o(e=>{const t=e.provider;switch(t){case"openai":if(!e.OPENAI_KEY)throw new I("Please set your OpenAI API key via `aicommit config set OPENAI_KEY=<your token>`");break;case"anthropic":if(!e.ANTHROPIC_KEY)throw new I("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 I("Please set your Azure OpenAI API key via `aicommit config set AZURE_OPENAI_KEY=<your token>`");if(!e.AZURE_ENDPOINT)throw new I("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 I("Please set your custom endpoint via `aicommit config set CUSTOM_ENDPOINT=<your endpoint>`");break;default:throw new I(`Unknown provider: ${t}`)}},"validateProviderConfig"),Bo=o(async(e,t)=>{await Zg();const n=await _c(),r=await So(),i={};for(const a of Object.keys(ln)){const u=ln[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||Qg(s),s},"getConfig"),e8=o(async e=>{const t=await _c();for(const[n,r]of e){if(!Mc(ln,n))throw new I(`Invalid config property: ${n}`);const i=ln[n](r);t[n]=i}await G.writeFile(vo,Oc.stringify(t),"utf8")},"setConfigs"),Pc={openai:o(()=>import("./openai-kM3ArV-z.mjs"),"openai"),anthropic:o(()=>import("./anthropic-DXBvFaIh.mjs"),"anthropic"),"azure-openai":o(()=>import("./azure-openai-D_4KWW9i.mjs"),"azure-openai"),ollama:o(()=>import("./ollama-CmsxGbaV.mjs"),"ollama"),custom:o(()=>import("./custom-DYiuOobP.mjs"),"custom")};async function Lc(e,t){const n=Pc[e];if(!n)throw new I(`Unknown provider type: ${e}. Supported providers: ${Object.keys(Pc).join(", ")}`);try{const i=(await n()).default;return new i(t)}catch(r){throw r instanceof I?r:r.code==="ERR_MODULE_NOT_FOUND"?new I(`Provider "${e}" is not yet implemented. Currently supported: openai`):new I(`Failed to initialize provider "${e}": ${r.message}`)}}o(Lc,"createProvider");var t8=o(async(e,t,n,r,i)=>(async()=>{$c(rc(nc(" aicommit "))),await Eo();const s=wo();n&&await Ue("git",["add","--update"]),s.start("Detecting staged files");const a=await xc(t);if(!a)throw s.stop("Detecting staged files"),new I("No staged changes found. Stage your changes manually, or automatically stage all changes with the `--all` flag.");s.stop(`${Yg(a.files)}:
122
+ `);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(Hg,"parseEnvContent");async function Ic(e){const{filename:t=".env",directory:n=process.cwd(),override:r=!1}=e||{},i=ce.join(n,t);if(!await cn(i))return{};try{const a=await G.readFile(i,"utf8"),u=Hg(a);for(const[c,d]of Object.entries(u))(r||process.env[c]===void 0)&&(process.env[c]=d);return u}catch{return{}}}o(Ic,"loadEnvFile");async function Zg(){process.env.NODE_ENV==="test"?await Ic({filename:".env.local"}):await Ic({filename:".env"})}o(Zg,"loadEnvironment");const Rc=["openai","anthropic","azure-openai","ollama","custom"],Jg=["","conventional"],{hasOwnProperty:Xg}=Object.prototype,Mc=o((e,t)=>Xg.call(e,t),"hasOwn"),M=o((e,t,n)=>{if(!t)throw new I(`Invalid config property ${e}: ${n}`)},"parseAssert"),ln={provider(e){return e?(M("provider",Rc.includes(e),`Must be one of: ${Rc.join(", ")}`),e):"openai"},OPENAI_KEY(e){if(e)return M("OPENAI_KEY",e.startsWith("sk-"),'Must start with "sk-"'),e},ANTHROPIC_KEY(e){if(e)return M("ANTHROPIC_KEY",e.startsWith("sk-ant-"),'Must start with "sk-ant-"'),e},AZURE_OPENAI_KEY(e){return e},AZURE_ENDPOINT(e){if(e)return M("AZURE_ENDPOINT",/^https?:\/\//.test(e),"Must be a valid URL"),e},OLLAMA_ENDPOINT(e){return e?(M("OLLAMA_ENDPOINT",/^https?:\/\//.test(e),"Must be a valid URL"),e):"http://localhost:11434"},CUSTOM_ENDPOINT(e){if(e)return M("CUSTOM_ENDPOINT",/^https?:\/\//.test(e),"Must be a valid URL"),e},CUSTOM_KEY(e){return e},locale(e){return e?(M("locale",e,"Cannot be empty"),M("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;M("generate",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return M("generate",t>0,"Must be greater than 0"),M("generate",t<=5,"Must be less or equal to 5"),t},type(e){return e?(M("type",Jg.includes(e),"Invalid commit type"),e):""},proxy(e){if(!(!e||e.length===0))return M("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;M("timeout",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return M("timeout",t>=500,"Must be greater than 500ms"),t},temperature(e){if(!e)return .2;M("temperature",/^(2|\d)(\.\d{1,2})?$/.test(e),"Must be decimal between 0 and 2");const t=Number(e);return M("temperature",t>0,"Must be greater than 0"),M("temperature",t<=2,"Must be less than or equal to 2"),t},"max-length"(e){if(!e)return 50;M("max-length",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return M("max-length",t>=20,"Must be greater than 20 characters"),t},"max-completion-tokens"(e){if(!e)return 1e4;M("max-completion-tokens",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return M("max-completion-tokens",t>0,"Must be greater than 0"),t},"auto-confirm"(e){return e?typeof e=="boolean"?e:(M("auto-confirm",/^(?:true|false)$/.test(e),"Must be a boolean"),e==="true"):!1},"prepend-reference"(e){return e?typeof e=="boolean"?e:(M("prepend-reference",/^(?:true|false)$/.test(e),"Must be a boolean"),e==="true"):!1}},vo=ce.join(fl.homedir(),".aicommit"),_c=o(async()=>{if(!await cn(vo))return Object.create(null);const t=await G.readFile(vo,"utf8");return Oc.parse(t)},"readConfigFile"),Qg=o(e=>{const t=e.provider;switch(t){case"openai":if(!e.OPENAI_KEY)throw new I("Please set your OpenAI API key via `aicommit config set OPENAI_KEY=<your token>`");break;case"anthropic":if(!e.ANTHROPIC_KEY)throw new I("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 I("Please set your Azure OpenAI API key via `aicommit config set AZURE_OPENAI_KEY=<your token>`");if(!e.AZURE_ENDPOINT)throw new I("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 I("Please set your custom endpoint via `aicommit config set CUSTOM_ENDPOINT=<your endpoint>`");break;default:throw new I(`Unknown provider: ${t}`)}},"validateProviderConfig"),Bo=o(async(e,t)=>{await Zg();const n=await _c(),r=await So(),i={};for(const a of Object.keys(ln)){const u=ln[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||Qg(s),s},"getConfig"),e8=o(async e=>{const t=await _c();for(const[n,r]of e){if(!Mc(ln,n))throw new I(`Invalid config property: ${n}`);const i=ln[n](r);t[n]=i}await G.writeFile(vo,Oc.stringify(t),"utf8")},"setConfigs"),Pc={openai:o(()=>import("./openai-CiD2OXYs.mjs"),"openai"),anthropic:o(()=>import("./anthropic-BML3fhQA.mjs"),"anthropic"),"azure-openai":o(()=>import("./azure-openai-wPGFYYwG.mjs"),"azure-openai"),ollama:o(()=>import("./ollama-D31QMNBt.mjs"),"ollama"),custom:o(()=>import("./custom-lUClfjdS.mjs"),"custom")};async function Lc(e,t){const n=Pc[e];if(!n)throw new I(`Unknown provider type: ${e}. Supported providers: ${Object.keys(Pc).join(", ")}`);try{const i=(await n()).default;return new i(t)}catch(r){throw r instanceof I?r:r.code==="ERR_MODULE_NOT_FOUND"?new I(`Provider "${e}" is not yet implemented. Currently supported: openai`):new I(`Failed to initialize provider "${e}": ${r.message}`)}}o(Lc,"createProvider");var t8=o(async(e,t,n,r,i)=>(async()=>{$c(rc(nc(" aicommit "))),await Eo();const s=wo();n&&await Ue("git",["add","--update"]),s.start("Detecting staged files");const a=await xc(t);if(!a)throw s.stop("Detecting staged files"),new I("No staged changes found. Stage your changes manually, or automatically stage all changes with the `--all` flag.");s.stop(`${Yg(a.files)}:
123
123
  ${a.files.map(h=>` ${h}`).join(`
124
124
  `)}`);const{env:u}=process,c=await Bo({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=wo();d.start("The AI is analyzing your changes");let l;try{const h={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={...h,apiKey:c.OPENAI_KEY};break;case"anthropic":D={...h,apiKey:c.ANTHROPIC_KEY};break;case"azure-openai":D={...h,apiKey:c.AZURE_OPENAI_KEY,endpoint:c.AZURE_ENDPOINT};break;case"ollama":D={...h,endpoint:c.OLLAMA_ENDPOINT};break;case"custom":D={...h,endpoint:c.CUSTOM_ENDPOINT,apiKey:c.CUSTOM_KEY};break;default:D={...h,apiKey:c.OPENAI_KEY}}const p=await Lc(c.provider,D),m=await So();l=(await p.generateCommitMessage({diff:a.diff,completions:c.generate,projectConfig:m})).messages}finally{d.stop("Changes analyzed")}if(l.length===0)throw new I("No commit messages were generated. Try again.");let f;if(l.length===1){[f]=l;let h;if(c["auto-confirm"]?(h=!0,Oe(`${dt("\u2714")} Auto confirmed commit message.
125
125
 
package/dist/cli.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import"./cli-DqbY1hdM.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-DbiVqdzf.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-DqbY1hdM.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-DbiVqdzf.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-DqbY1hdM.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-DbiVqdzf.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-DqbY1hdM.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-DbiVqdzf.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.37.1",
3
+ "version": "2.38.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },