@gilbert_oliveira/commit-wizard 2.9.5 → 2.9.7-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commit-wizard.js +14 -14
- package/package.json +1 -1
- package/src/types/clack.d.ts +9 -0
- package/src/utils/args.ts +4 -1
- package/src/utils/version.ts +40 -0
package/dist/commit-wizard.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
3
|
-
`).filter(i=>i.length>0),o=t.length>0?A("git diff --cached",{encoding:"utf-8",stdio:"pipe"}):"";return{hasStaged:t.length>0,stagedFiles:t,diff:o.trim()}}catch(e){throw new Error(`Erro ao obter status do Git: ${e instanceof Error?e.message:"Erro desconhecido"}`)}}function
|
|
4
|
-
`).filter(n=>n.length>0),o=0,i=0;return t.forEach(n=>{let[s,a]=n.split(" ");s&&s!=="-"&&(o+=parseInt(s)||0),a&&a!=="-"&&(i+=parseInt(a)||0)}),{added:o,removed:i,files:t.length}}catch{return{added:0,removed:0,files:0}}}var
|
|
2
|
+
var ke=Object.defineProperty;var $=(e,t)=>()=>(e&&(t=e(e=0)),t);var O=(e,t)=>{for(var o in t)ke(e,o,{get:t[o],enumerable:!0})};import Te from"path";import{fileURLToPath as qe}from"url";var Ne,Le,C,p=$(()=>{"use strict";Ne=()=>qe(import.meta.url),Le=()=>Te.dirname(Ne()),C=Le()});import{existsSync as ae,readFileSync as ce}from"fs";import{join as me}from"path";function ue(e){let t;try{t=me(process.cwd(),".commit-wizardrc")}catch{t="/tmp/.commit-wizardrc"}let o=me(process.env.HOME||process.env.USERPROFILE||"/tmp",".commit-wizardrc"),i={...Ue};try{if(ae(o)){let s=ce(o,"utf-8"),a=JSON.parse(s);i=le(i,a)}}catch{console.warn("\u26A0\uFE0F Erro ao ler configura\xE7\xE3o global: Erro desconhecido")}let n=e||t;try{if(ae(n)){let s=ce(n,"utf-8"),a=JSON.parse(s);i=le(i,a)}}catch{console.warn("\u26A0\uFE0F Erro ao ler .commit-wizardrc: Erro desconhecido")}return i.openai.apiKey=process.env.OPENAI_API_KEY,process.env.COMMIT_WIZARD_DEBUG,process.env.COMMIT_WIZARD_DRY_RUN==="true"&&(i.dryRun=!0),i}function le(e,t){return{...e,...t,openai:{...e.openai,...t.openai},smartSplit:{...e.smartSplit,...t.smartSplit},cache:{...e.cache,...t.cache}}}function pe(e){let t=[];return e.openai.apiKey||t.push("OPENAI_API_KEY n\xE3o encontrada nas vari\xE1veis de ambiente"),(e.openai.maxTokens<10||e.openai.maxTokens>4e3)&&t.push("maxTokens deve estar entre 10 e 4000"),(e.openai.temperature<0||e.openai.temperature>2)&&t.push("temperature deve estar entre 0 e 2"),["pt","en","es","fr","de","it","ja","ko","zh"].includes(e.language)||t.push("language deve ser um idioma suportado (pt, en, es, fr, de, it, ja, ko, zh)"),["conventional","simple","detailed"].includes(e.commitStyle)||t.push("commitStyle deve ser conventional, simple ou detailed"),e.smartSplit.minGroupSize<1&&t.push("smartSplit.minGroupSize deve ser pelo menos 1"),(e.smartSplit.maxGroups<1||e.smartSplit.maxGroups>10)&&t.push("smartSplit.maxGroups deve estar entre 1 e 10"),(e.smartSplit.confidenceThreshold<0||e.smartSplit.confidenceThreshold>1)&&t.push("smartSplit.confidenceThreshold deve estar entre 0 e 1"),e.cache.ttl<1&&t.push("cache.ttl deve ser pelo menos 1 minuto"),e.cache.maxSize<1&&t.push("cache.maxSize deve ser pelo menos 1"),t}var Ue,de=$(()=>{"use strict";p();Ue={openai:{model:"gpt-4o",maxTokens:150,temperature:.7,timeout:3e4,retries:2},language:"pt",commitStyle:"conventional",autoCommit:!1,splitCommits:!1,dryRun:!1,smartSplit:{enabled:!0,minGroupSize:1,maxGroups:5,confidenceThreshold:.7},cache:{enabled:!0,ttl:60,maxSize:100}}});var E={};O(E,{escapeShellArg:()=>k,executeCommit:()=>z,executeFileCommit:()=>j,getDiffStats:()=>K,getFileDiff:()=>_e,getGitStatus:()=>J,isGitRepository:()=>H});import{execSync as A}from"child_process";function k(e){return`'${e.replace(/'/g,`'"'"'`)}'`}function H(){try{return A("git rev-parse --git-dir",{stdio:"ignore"}),!0}catch{return!1}}function J(){try{let t=A("git diff --cached --name-only",{encoding:"utf-8",stdio:"pipe"}).trim().split(`
|
|
3
|
+
`).filter(i=>i.length>0),o=t.length>0?A("git diff --cached",{encoding:"utf-8",stdio:"pipe"}):"";return{hasStaged:t.length>0,stagedFiles:t,diff:o.trim()}}catch(e){throw new Error(`Erro ao obter status do Git: ${e instanceof Error?e.message:"Erro desconhecido"}`)}}function _e(e){try{return A(`git diff --cached -- "${e}"`,{encoding:"utf-8",stdio:"pipe"})}catch(t){throw new Error(`Erro ao obter diff do arquivo ${e}: ${t instanceof Error?t.message:"Erro desconhecido"}`)}}function z(e){try{let t=k(e);return A(`git commit -m ${t}`,{stdio:"pipe"}),{success:!0,hash:A("git rev-parse HEAD",{encoding:"utf-8",stdio:"pipe"}).trim(),message:e}}catch(t){return{success:!1,error:t instanceof Error?t.message:"Erro desconhecido ao executar commit"}}}function j(e,t){try{let o=k(t),i=k(e);return A(`git commit ${i} -m ${o}`,{stdio:"pipe"}),{success:!0,hash:A("git rev-parse HEAD",{encoding:"utf-8",stdio:"pipe"}).trim(),message:t}}catch(o){return{success:!1,error:o instanceof Error?o.message:"Erro desconhecido ao executar commit do arquivo"}}}function K(){try{let t=A("git diff --cached --numstat",{encoding:"utf-8",stdio:"pipe"}).trim().split(`
|
|
4
|
+
`).filter(n=>n.length>0),o=0,i=0;return t.forEach(n=>{let[s,a]=n.split(" ");s&&s!=="-"&&(o+=parseInt(s)||0),a&&a!=="-"&&(i+=parseInt(a)||0)}),{added:o,removed:i,files:t.length}}catch{return{added:0,removed:0,files:0}}}var b=$(()=>{"use strict";p()});var Ce={};O(Ce,{buildPrompt:()=>fe,detectCommitType:()=>he,extractCommitTypeFromMessage:()=>ge,generateCommitMessage:()=>xe,generateWithRetry:()=>T,processOpenAIMessage:()=>ye});function fe(e,t,o){let i=t.language==="pt"?"portugu\xEAs":"english",n=Ve(t.commitStyle,t.language),s=6e3,a=e.length>s?e.substring(0,s)+`
|
|
5
5
|
... (diff truncado)`:e,c=o.length>10?`${o.length} arquivos: ${o.slice(0,5).join(", ")}...`:o.join(", ");return`Gere mensagem de commit em ${i} (${t.commitStyle}).
|
|
6
6
|
|
|
7
7
|
Arquivos: ${c}
|
|
@@ -13,7 +13,7 @@ Diff:
|
|
|
13
13
|
${a}
|
|
14
14
|
\`\`\`
|
|
15
15
|
|
|
16
|
-
Mensagem:`}function
|
|
16
|
+
Mensagem:`}function Ve(e,t){let o={pt:{conventional:`- Use formato: tipo(escopo): descri\xE7\xE3o
|
|
17
17
|
- Tipos v\xE1lidos: feat, fix, docs, style, refactor, test, chore, build, ci
|
|
18
18
|
- Exemplo: "feat(auth): adicionar valida\xE7\xE3o de email"
|
|
19
19
|
- Mantenha a primeira linha com at\xE9 50 caracteres`,simple:`- Use formato simples e direto
|
|
@@ -31,17 +31,17 @@ Mensagem:`}function qe(e,t){let o={pt:{conventional:`- Use formato: tipo(escopo)
|
|
|
31
31
|
- Maximum 50 characters`,detailed:`- First line: summary under 50 characters
|
|
32
32
|
- Add explanatory body if needed
|
|
33
33
|
- Use imperative mood
|
|
34
|
-
- Be descriptive but concise`}},i=t==="pt"?"pt":"en";return o[i][e]||o[i].conventional}function
|
|
35
|
-
Mensagem: "${e.message}"`,"\u{1F4AD} Sugest\xE3o de Commit");let t=await
|
|
34
|
+
- Be descriptive but concise`}},i=t==="pt"?"pt":"en";return o[i][e]||o[i].conventional}function ge(e){let t={feat:/^(feat|feature)(\([^)]+\))?:/i,fix:/^(fix|bugfix)(\([^)]+\))?:/i,docs:/^(docs|documentation)(\([^)]+\))?:/i,style:/^(style|format)(\([^)]+\))?:/i,refactor:/^(refactor|refactoring)(\([^)]+\))?:/i,test:/^(test|testing)(\([^)]+\))?:/i,chore:/^(chore|maintenance)(\([^)]+\))?:/i,build:/^(build|ci)(\([^)]+\))?:/i,ci:/^(ci|continuous-integration)(\([^)]+\))?:/i};for(let[o,i]of Object.entries(t))if(i.test(e))return o;return null}function he(e,t){let o=e.toLowerCase(),i=t.join(" ").toLowerCase();return i.includes("test")||i.includes("spec")||o.includes("test(")?"test":i.includes("readme")||i.includes(".md")||i.includes("docs")?"docs":i.includes("package.json")||i.includes("dockerfile")||i.includes(".yml")||i.includes(".yaml")||i.includes("webpack")||i.includes("tsconfig")?"build":i.includes(".css")||i.includes(".scss")||o.includes("style")||o.includes("format")?"style":o.includes("fix")||o.includes("bug")||o.includes("error")||o.includes("issue")?"fix":o.includes("add")||o.includes("new")||o.includes("create")||o.includes("implement")?"feat":o.includes("refactor")||o.includes("restructure")||o.includes("rename")?"refactor":"chore"}function ye(e){return e.match(/^```[\s\S]*```$/)&&(e=e.replace(/^```(?:plaintext|javascript|typescript|python|java|html|css|json|xml|yaml|yml|bash|shell|text)?\s*/,"").replace(/\s*```$/,"")),e=e.trim(),e}async function xe(e,t,o){try{if(!t.openai.apiKey)return{success:!1,error:"Chave da OpenAI n\xE3o encontrada. Configure OPENAI_API_KEY nas vari\xE1veis de ambiente."};let i=fe(e,t,o),n=await fetch("https://api.openai.com/v1/chat/completions",{method:"POST",headers:{Authorization:`Bearer ${t.openai.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({model:t.openai.model,messages:[{role:"user",content:i}],max_tokens:Math.min(t.openai.maxTokens,150),temperature:t.openai.temperature})});if(!n.ok){let m=await n.json().catch(()=>({}));return{success:!1,error:`Erro da OpenAI (${n.status}): ${m.error?.message||"Erro desconhecido"}`}}let a=(await n.json()).choices?.[0]?.message?.content?.trim();if(!a)return{success:!1,error:"OpenAI retornou resposta vazia"};a=ye(a);let c=ge(a),r=he(e,o);return{success:!0,suggestion:{message:a,type:c||r,confidence:.8}}}catch(i){return{success:!1,error:`Erro ao conectar com OpenAI: ${i instanceof Error?i.message:"Erro desconhecido"}`}}}async function T(e,t,o,i=3){let n="";for(let s=0;s<i;s++){let a=await xe(e,t,o);if(a.success)return a;n=a.error||"Erro desconhecido",s<i-1&&await new Promise(c=>setTimeout(c,Math.pow(2,s)*1e3))}return{success:!1,error:`Falha ap\xF3s ${i} tentativas. \xDAltimo erro: ${n}`}}var W=$(()=>{"use strict";p()});var Q={};O(Q,{askContinueCommits:()=>Y,confirmCommit:()=>Be,copyToClipboard:()=>U,editCommitMessage:()=>L,selectFilesForCommit:()=>B,showCancellation:()=>G,showCommitPreview:()=>N,showCommitResult:()=>S});import{text as He,select as Je,confirm as q,log as R,note as Se,cancel as Ke,isCancel as F}from"@clack/prompts";import We from"clipboardy";async function N(e){Se(`Tipo: ${e.type}
|
|
35
|
+
Mensagem: "${e.message}"`,"\u{1F4AD} Sugest\xE3o de Commit");let t=await Je({message:"O que voc\xEA gostaria de fazer?",options:[{value:"commit",label:"\u2705 Fazer commit com esta mensagem",hint:"Executar git commit imediatamente"},{value:"edit",label:"\u270F\uFE0F Editar mensagem",hint:"Modificar a mensagem antes de commitar"},{value:"copy",label:"\u{1F4CB} Copiar para clipboard",hint:"Copiar mensagem e sair sem commitar"},{value:"cancel",label:"\u274C Cancelar",hint:"Sair sem fazer nada"}]});return F(t)?{action:"cancel"}:{action:t}}async function L(e){let t=await He({message:"Edite a mensagem do commit:",initialValue:e,placeholder:"Digite a mensagem do commit...",validate:i=>{if(!i||i.trim().length===0)return"A mensagem n\xE3o pode estar vazia";if(i.trim().length>72)return"A mensagem est\xE1 muito longa (m\xE1ximo 72 caracteres recomendado)"}});if(F(t))return{action:"cancel"};let o=await q({message:`Confirma a mensagem editada: "${t}"?`});return F(o)||!o?{action:"cancel"}:{action:"commit",message:t}}async function U(e){try{return await We.write(e),R.success("\u2705 Mensagem copiada para a \xE1rea de transfer\xEAncia!"),!0}catch(t){return R.error(`\u274C Erro ao copiar: ${t instanceof Error?t.message:"Erro desconhecido"}`),!1}}async function Be(e){Se(`"${e}"`,"\u{1F680} Confirmar Commit");let t=await q({message:"Executar o commit agora?"});return F(t)?!1:t}function S(e,t,o){e&&t?(R.success("\u2705 Commit realizado com sucesso!"),R.info(`\u{1F517} Hash: ${t.substring(0,8)}`)):R.error(`\u274C Erro ao realizar commit: ${o||"Erro desconhecido"}`)}async function B(e){R.info("\u{1F4CB} Modo Split: Selecione os arquivos para este commit");let t=[];for(let o of e){let i=await q({message:`Incluir "${o}" neste commit?`});if(F(i))break;i&&t.push(o)}return t}async function Y(e){if(e.length===0)return!1;R.info(`\u{1F4C4} Arquivos restantes: ${e.join(", ")}`);let t=await q({message:"Gerar commit para os arquivos restantes?"});return F(t)?!1:t}function G(){Ke("Opera\xE7\xE3o cancelada pelo usu\xE1rio")}var D=$(()=>{"use strict";p()});var $e={};O($e,{chooseSplitMode:()=>X,confirmGroupCommit:()=>Ze,showSmartSplitGroups:()=>Qe,showSmartSplitProgress:()=>Xe});import{select as be,confirm as Ye,log as ve,note as we,isCancel as Z}from"@clack/prompts";async function X(){let e=await be({message:"Como voc\xEA gostaria de organizar os commits?",options:[{value:"smart",label:"\u{1F9E0} Smart Split (Recomendado)",hint:"IA analisa contexto e agrupa automaticamente"},{value:"manual",label:"\u270B Split Manual",hint:"Voc\xEA escolhe arquivos manualmente"},{value:"cancel",label:"\u274C Cancelar",hint:"Voltar ao modo normal"}]});return Z(e)?{action:"cancel"}:e==="manual"?{action:"manual"}:e==="smart"?{action:"proceed"}:{action:"cancel"}}async function Qe(e){we(`Identificamos ${e.length} grupo(s) l\xF3gico(s) para seus commits:
|
|
36
36
|
|
|
37
37
|
`+e.map((o,i)=>`${i+1}. **${o.name}**
|
|
38
38
|
\u{1F4C4} ${o.files.join(", ")}
|
|
39
39
|
\u{1F4A1} ${o.description}
|
|
40
40
|
\u{1F3AF} Confian\xE7a: ${Math.round(o.confidence*100)}%`).join(`
|
|
41
41
|
|
|
42
|
-
`),"\u{1F9E0} An\xE1lise de Contexto");let t=await
|
|
42
|
+
`),"\u{1F9E0} An\xE1lise de Contexto");let t=await be({message:"O que voc\xEA gostaria de fazer?",options:[{value:"proceed",label:"\u2705 Prosseguir com esta organiza\xE7\xE3o",hint:"Usar os grupos como sugeridos pela IA"},{value:"manual",label:"\u270B Fazer split manual",hint:"Escolher arquivos manualmente"},{value:"cancel",label:"\u274C Cancelar",hint:"Voltar ao modo normal"}]});return Z(t)?{action:"cancel"}:t==="proceed"?{action:"proceed",groups:e}:{action:t}}async function Ze(e,t){we(`**Grupo:** ${e.name}
|
|
43
43
|
**Arquivos:** ${e.files.join(", ")}
|
|
44
|
-
**Mensagem:** "${t}"`,"\u{1F680} Confirmar Commit do Grupo");let o=await
|
|
44
|
+
**Mensagem:** "${t}"`,"\u{1F680} Confirmar Commit do Grupo");let o=await Ye({message:`Fazer commit para "${e.name}"?`});return Z(o)?!1:o}function Xe(e,t,o){let i=Math.round(e/t*100),n="\u2588".repeat(Math.floor(i/10))+"\u2591".repeat(10-Math.floor(i/10));ve.info(`\u{1F504} Progresso: [${n}] ${i}% (${e}/${t})`),ve.info(`\u{1F4CB} Processando: ${o}`)}var ee=$(()=>{"use strict";p()});import et from"crypto";function Ee(e){Ae=new te(e)}function Me(){return Ae}function ze(e,t){let o=Me();return o?o.get(e,t):{hit:!1}}function Re(e,t,o){let i=Me();i&&i.set(e,t,o)}var te,Ae,ie=$(()=>{"use strict";p();te=class{cache=new Map;config;constructor(t){this.config=t}generateHash(t,o){let i={files:t.sort(),diff:o.substring(0,1e3),model:this.config.openai.model,temperature:this.config.openai.temperature};return et.createHash("md5").update(JSON.stringify(i)).digest("hex")}get(t,o){if(!this.config.cache.enabled)return{hit:!1};let i=this.generateHash(t,o),n=this.cache.get(i);if(!n)return{hit:!1};let s=Date.now(),a=this.config.cache.ttl*60*1e3;return s-n.timestamp>a?(this.cache.delete(i),{hit:!1}):{hit:!0,groups:n.groups}}set(t,o,i){if(!this.config.cache.enabled||(this.cache.size>=this.config.cache.maxSize&&this.cleanup(),this.cache.size>=this.config.cache.maxSize))return;let n=this.generateHash(t,o),s={groups:i,timestamp:Date.now(),hash:n};this.cache.set(n,s)}cleanup(){let t=Date.now(),o=this.config.cache.ttl*60*1e3;for(let[i,n]of this.cache.entries())t-n.timestamp>o&&this.cache.delete(i);if(this.cache.size>=this.config.cache.maxSize){let n=Array.from(this.cache.entries()).sort((s,a)=>s[1].timestamp-a[1].timestamp).slice(0,Math.ceil(this.config.cache.maxSize*.5));for(let[s]of n)this.cache.delete(s)}}clear(){this.cache.clear()}getStats(){return{size:this.cache.size,maxSize:this.config.cache.maxSize,enabled:this.config.cache.enabled}}},Ae=null});import{log as f}from"@clack/prompts";function tt(e,t){let i=t.length>8e3?t.substring(0,8e3)+`
|
|
45
45
|
... (diff truncado)`:t,n=e.length,s=e.reduce((c,r)=>{let m=r.split(".").pop()||"sem-extensao";return c[m]=(c[m]||0)+1,c},{}),a=Object.entries(s).map(([c,r])=>`${c}: ${r}`).join(", ");return`Analise os arquivos modificados e agrupe em commits l\xF3gicos.
|
|
46
46
|
|
|
47
47
|
ARQUIVOS (${n}): ${e.join(", ")}
|
|
@@ -63,7 +63,7 @@ Agrupe arquivos relacionados. M\xE1ximo 5 grupos. Responda em JSON:
|
|
|
63
63
|
"confidence": 0.8
|
|
64
64
|
}
|
|
65
65
|
]
|
|
66
|
-
}`}function
|
|
66
|
+
}`}function it(e){let t=e.reduce((i,n)=>{let s=n.split("/").slice(0,-1).join("/")||"root";return i[s]||(i[s]=[]),i[s].push(n),i},{});return`Agrupe estes arquivos em commits l\xF3gicos baseado nos diret\xF3rios:
|
|
67
67
|
|
|
68
68
|
ARQUIVOS POR DIRET\xD3RIO:
|
|
69
69
|
${Object.entries(t).map(([i,n])=>`${i}: ${n.length} arquivo(s)`).join(`
|
|
@@ -82,7 +82,7 @@ Agrupe por funcionalidade relacionada. M\xE1ximo 5 grupos. JSON:
|
|
|
82
82
|
"confidence": 0.7
|
|
83
83
|
}
|
|
84
84
|
]
|
|
85
|
-
}`}async function
|
|
85
|
+
}`}async function ot(e,t,o){try{if(!o.openai.apiKey)return{success:!1,error:"Chave da OpenAI n\xE3o encontrada"};let i=ze(e,t);if(i.hit&&i.groups)return{success:!0,groups:i.groups};let s=t.length>6e3,a=s?it(e):tt(e,t);s&&console.warn(`\u26A0\uFE0F Diff muito grande (${t.length} chars), usando an\xE1lise baseada em nomes de arquivos`);let c=await fetch("https://api.openai.com/v1/chat/completions",{method:"POST",headers:{Authorization:`Bearer ${o.openai.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({model:o.openai.model,messages:[{role:"user",content:a}],max_tokens:800,temperature:.3})});if(!c.ok){let d=await c.json().catch(()=>({}));return{success:!1,error:`Erro da OpenAI (${c.status}): ${d.error?.message||"Erro desconhecido"}`}}let m=(await c.json()).choices?.[0]?.message?.content?.trim();if(!m)return{success:!1,error:"OpenAI retornou resposta vazia"};let u=m.match(/\{[\s\S]*\}/);if(!u)return{success:!1,error:"Resposta da OpenAI n\xE3o cont\xE9m JSON v\xE1lido"};let g=JSON.parse(u[0]);if(!g.groups||!Array.isArray(g.groups))return{success:!1,error:"Formato de resposta inv\xE1lido da OpenAI"};let h=g.groups.flatMap(d=>d.files||[]),M=e.filter(d=>!h.includes(d));M.length>0&&(g.groups[0].files=[...g.groups[0].files||[],...M]);let y=g.groups.map(d=>({id:d.id||`group-${Math.random().toString(36).substr(2,9)}`,name:d.name||"Grupo sem nome",description:d.description||"Sem descri\xE7\xE3o",files:d.files||[],diff:"",confidence:d.confidence||.5}));return Re(e,t,y),{success:!0,groups:y}}catch(i){return{success:!1,error:`Erro ao analisar contexto: ${i instanceof Error?i.message:"Erro desconhecido"}`}}}async function st(e){let{getFileDiff:t}=await Promise.resolve().then(()=>(b(),E)),o=e.files.map(s=>{try{let a=t(s),c=4e3;return a.length>c?a.substring(0,c)+`
|
|
86
86
|
... (diff truncado)`:a}catch{return""}}).filter(s=>s.length>0);if(o.length===0&&e.files.length>0){let{execSync:s}=await import("child_process"),a=e.files.filter(r=>{try{return s(`test -f "${r}"`,{stdio:"ignore"}),s(`git status --porcelain -- "${r}"`,{encoding:"utf-8",stdio:"pipe"}).trim().startsWith("??")}catch{return!1}});if(a.length>0)return a.map(r=>{try{let m=s(`cat "${r}"`,{encoding:"utf-8",stdio:"pipe"}),u=2e3,g=m.length>u?m.substring(0,u)+`
|
|
87
87
|
... (conte\xFAdo truncado)`:m;return`diff --git a/${r} b/${r}
|
|
88
88
|
new file mode 100644
|
|
@@ -107,9 +107,9 @@ ${g.split(`
|
|
|
107
107
|
`)}`}catch{return""}}).filter(r=>r.length>0).join(`
|
|
108
108
|
`)}let i=o.join(`
|
|
109
109
|
`),n=8e3;return i.length>n?i.substring(0,n)+`
|
|
110
|
-
... (diff total truncado)`:i}async function oe(e,t,o){o.silent||f.info("\u{1F9E0} Modo Smart Split ativado - Agrupando arquivos por contexto"),o.silent||f.info("\u{1F916} Analisando contexto das mudan\xE7as...");let i=await
|
|
111
|
-
\u{1F504} Processando grupo ${n+1}/${i.groups.length}: ${s.name}`);let a=await
|
|
112
|
-
`);if(!a){o.silent||l.warn("\u26A0\uFE0F Nenhum diff encontrado para os arquivos selecionados"),i=i.filter(r=>!n.includes(r));continue}o.silent||l.info(`\u{1F916} Gerando commit para: ${n.join(", ")}`);let c=await
|
|
110
|
+
... (diff total truncado)`:i}async function oe(e,t,o){o.silent||f.info("\u{1F9E0} Modo Smart Split ativado - Agrupando arquivos por contexto"),o.silent||f.info("\u{1F916} Analisando contexto das mudan\xE7as...");let i=await ot(e.stagedFiles,e.diff,t);if(!i.success){o.silent||f.error(`\u274C Erro na an\xE1lise de contexto: ${i.error}`);return}if(!i.groups||i.groups.length===0){o.silent||f.error("\u274C Nenhum grupo foi criado pela an\xE1lise");return}if(o.silent||(f.success(`\u2705 ${i.groups.length} grupo(s) identificado(s):`),i.groups.forEach((n,s)=>{f.info(` ${s+1}. ${n.name} (${n.files.length} arquivo(s))`),f.info(` \u{1F4C4} ${n.files.join(", ")}`)})),!o.yes&&!o.silent){let{showSmartSplitGroups:n}=await Promise.resolve().then(()=>(ee(),$e)),s=await n(i.groups);if(s.action==="cancel"){o.silent||f.info("\u274C Opera\xE7\xE3o cancelada pelo usu\xE1rio");return}if(s.action==="manual"){let a={...o,split:!0,smartSplit:!1},{main:c}=await Promise.resolve().then(()=>(se(),Ge));await c(a);return}}for(let n=0;n<i.groups.length;n++){let s=i.groups[n];if(!s){o.silent||f.error(`\u274C Grupo ${n+1} \xE9 undefined`);continue}o.silent||f.info(`
|
|
111
|
+
\u{1F504} Processando grupo ${n+1}/${i.groups.length}: ${s.name}`);let a=await st(s);if(!a){o.silent||(f.warn(`\u26A0\uFE0F Nenhum diff encontrado para o grupo: ${s.name}`),f.info(` \u{1F4C4} Arquivos: ${s.files.join(", ")}`),f.info(" \u{1F4A1} Poss\xEDvel causa: arquivos novos, deletados/recriados, ou sem mudan\xE7as"));continue}o.silent||f.info(`\u{1F916} Gerando commit para: ${s.name}`);let{generateWithRetry:c}=await Promise.resolve().then(()=>(W(),Ce)),r=await c(a,t,s.files);if(!r.success){o.silent||f.error(`\u274C Erro ao gerar commit para ${s.name}: ${r.error}`);continue}if(!r.suggestion){o.silent||f.error(`\u274C Nenhuma sugest\xE3o gerada para ${s.name}`);continue}if(t.dryRun){o.silent||(f.info(`\u{1F50D} Dry Run - Grupo: ${s.name}`),f.info(`\u{1F4C4} Arquivos: ${s.files.join(", ")}`),f.info(`\u{1F4AD} Mensagem: "${r.suggestion.message}"`));continue}if(o.yes){let{executeFileCommit:m}=await Promise.resolve().then(()=>(b(),E)),u;if(s.files.length===1&&s.files[0])u=m(s.files[0],r.suggestion.message||"");else{let{execSync:g}=await import("child_process"),{escapeShellArg:h}=await Promise.resolve().then(()=>(b(),E));try{let M=s.files.map(x=>h(x)).join(" "),y=h(r.suggestion.message||"");g(`git commit ${M} -m ${y}`,{stdio:"pipe"}),u={success:!0,hash:g("git rev-parse HEAD",{encoding:"utf-8",stdio:"pipe"}).trim(),message:r.suggestion.message||""}}catch(M){u={success:!1,error:M instanceof Error?M.message:"Erro desconhecido ao executar commit"}}}S(u.success,u.hash,u.error)}else{let{showCommitPreview:m,editCommitMessage:u,copyToClipboard:g,showCancellation:h}=await Promise.resolve().then(()=>(D(),Q));switch((await m(r.suggestion)).action){case"commit":{let{executeFileCommit:y}=await Promise.resolve().then(()=>(b(),E)),d,x=r.suggestion.message||"Atualiza\xE7\xE3o de arquivos";if(s.files.length===1&&s.files[0])d=y(s.files[0],x);else{let{execSync:I}=await import("child_process"),{escapeShellArg:P}=await Promise.resolve().then(()=>(b(),E));try{let w=s.files.map(V=>P(V)).join(" "),_=P(x);I(`git commit ${w} -m ${_}`,{stdio:"pipe"}),d={success:!0,hash:I("git rev-parse HEAD",{encoding:"utf-8",stdio:"pipe"}).trim(),message:x}}catch(w){d={success:!1,error:w instanceof Error?w.message:"Erro desconhecido ao executar commit"}}}S(d.success,d.hash,d.error);break}case"edit":{let y=await u(r.suggestion.message);if(y.action==="commit"&&y.message){let{executeFileCommit:d}=await Promise.resolve().then(()=>(b(),E)),x;if(s.files.length===1&&s.files[0])x=d(s.files[0],y.message||"");else{let{execSync:I}=await import("child_process"),{escapeShellArg:P}=await Promise.resolve().then(()=>(b(),E));try{let w=s.files.map(V=>P(V)).join(" "),_=P(y.message||"");I(`git commit ${w} -m ${_}`,{stdio:"pipe"}),x={success:!0,hash:I("git rev-parse HEAD",{encoding:"utf-8",stdio:"pipe"}).trim(),message:y.message||""}}catch(w){x={success:!1,error:w instanceof Error?w.message:"Erro desconhecido ao executar commit"}}}S(x.success,x.hash,x.error)}break}case"copy":{await g(r.suggestion.message),o.silent||f.info("\u{1F3AF} Mensagem copiada para clipboard");break}case"cancel":{h();return}}}if(n<i.groups.length-1&&!o.yes){let{askContinueCommits:m}=await Promise.resolve().then(()=>(D(),Q)),u=i.groups.slice(n+1).filter(h=>h!==void 0).map(h=>h.name);if(!await m(u))break}}o.silent||f.success("\u2705 Smart Split conclu\xEDdo!")}var Fe=$(()=>{"use strict";p();ie();D()});var Ge={};O(Ge,{main:()=>ne});import{log as l}from"@clack/prompts";async function ne(e={silent:!1,yes:!1,auto:!1,split:!1,smartSplit:!1,dryRun:!1,help:!1,version:!1}){e.silent||l.info("\u{1F680} Commit Wizard iniciado!"),H()||(l.error("\u274C N\xE3o foi encontrado um reposit\xF3rio Git neste diret\xF3rio."),e.silent||l.info("\u{1F4A1} Execute o comando em um diret\xF3rio com reposit\xF3rio Git inicializado."),process.exit(1)),e.silent||l.info("\u2699\uFE0F Carregando configura\xE7\xE3o...");let t=ue();Ee(t),e.split&&(t.splitCommits=!0),e.dryRun&&(t.dryRun=!0);let o=pe(t);o.length>0&&(l.error("\u274C Erros na configura\xE7\xE3o:"),o.forEach(a=>l.error(` \u2022 ${a}`)),process.exit(1)),e.silent||l.success(`\u2705 Configura\xE7\xE3o carregada (modelo: ${t.openai.model}, idioma: ${t.language})`),e.silent||l.info("\u{1F4CB} Verificando arquivos staged...");let i=J();i.hasStaged||(l.warn("\u26A0\uFE0F Nenhum arquivo foi encontrado no stage."),e.silent||l.info("\u{1F4A1} Use `git add <arquivo>` para adicionar arquivos ao stage antes de gerar o commit."),process.exit(0));let n=K();if(e.silent||(l.success(`\u2705 Encontrados ${i.stagedFiles.length} arquivo(s) staged:`),i.stagedFiles.forEach(a=>l.info(` \u{1F4C4} ${a}`)),l.info(`\u{1F4CA} Estat\xEDsticas: +${n.added} -${n.removed} linhas`)),t.splitCommits||e.smartSplit){if(e.yes)return await oe(i,t,e);switch((await X()).action){case"proceed":return await oe(i,t,e);case"manual":return await nt(i,t,e);case"cancel":G();return}}e.silent||l.info("\u{1F916} Gerando mensagem de commit com IA...");let s=await T(i.diff,t,i.stagedFiles);if(s.success||(l.error(`\u274C Erro ao gerar commit: ${s.error}`),process.exit(1)),s.suggestion||(l.error("\u274C Nenhuma sugest\xE3o foi gerada"),process.exit(1)),e.silent||l.success("\u2728 Mensagem de commit gerada!"),t.dryRun){l.info("\u{1F50D} Modo Dry Run - Mensagem gerada:"),l.info(`"${s.suggestion.message}"`),l.info("\u{1F4A1} Execute sem --dry-run para fazer o commit");return}if(e.yes){let a=z(s.suggestion.message);S(a.success,a.hash,a.error);return}for(;;)switch((await N(s.suggestion)).action){case"commit":{let c=z(s.suggestion.message);S(c.success,c.hash,c.error);return}case"edit":{let c=await L(s.suggestion.message);if(c.action==="cancel"){G();return}if(c.action==="commit"&&c.message){let r=z(c.message);S(r.success,r.hash,r.error);return}break}case"copy":{await U(s.suggestion.message),e.silent||l.info('\u{1F3AF} Voc\xEA pode usar a mensagem copiada com: git commit -m "mensagem"');return}case"cancel":{G();return}}}async function nt(e,t,o){o.silent||l.info("\u{1F504} Modo Split ativado - Commits separados por arquivo");let i=[...e.stagedFiles];for(;i.length>0;){let n=o.yes?[i[0]]:await B(i);if(n.length===0){o.silent||l.info("\u274C Nenhum arquivo selecionado");break}let{getFileDiff:s}=await Promise.resolve().then(()=>(b(),E)),a=n.filter(r=>r!==void 0).map(r=>{try{return s(r)}catch(m){return l.error(`\u274C Erro ao obter diff do arquivo ${r}: ${m instanceof Error?m.message:"Erro desconhecido"}`),""}}).filter(r=>r.length>0).join(`
|
|
112
|
+
`);if(!a){o.silent||l.warn("\u26A0\uFE0F Nenhum diff encontrado para os arquivos selecionados"),i=i.filter(r=>!n.includes(r));continue}o.silent||l.info(`\u{1F916} Gerando commit para: ${n.join(", ")}`);let c=await T(a,t,n.filter(r=>r!==void 0));if(!c.success){l.error(`\u274C Erro ao gerar commit: ${c.error}`),i=i.filter(r=>!n.includes(r));continue}if(!c.suggestion){l.error("\u274C Nenhuma sugest\xE3o foi gerada"),i=i.filter(r=>!n.includes(r));continue}if(t.dryRun){l.info(`\u{1F50D} Dry Run - Mensagem para ${n.join(", ")}:`),l.info(`"${c.suggestion.message}"`),i=i.filter(r=>!n.includes(r));continue}if(o.yes){let r=n.length===1&&n[0]?await j(n[0],c.suggestion.message):await z(c.suggestion.message);S(r.success,r.hash,r.error)}else{let r=await N(c.suggestion);if(r.action==="commit"){let m=n.length===1&&n[0]?await j(n[0],c.suggestion.message):await z(c.suggestion.message);S(m.success,m.hash,m.error)}else if(r.action==="edit"){let m=await L(c.suggestion.message);if(m.action==="commit"&&m.message){let u=n.length===1&&n[0]?await j(n[0],m.message):await z(m.message);S(u.success,u.hash,u.error)}}else if(r.action==="copy")await U(c.suggestion.message),o.silent||l.info("\u{1F3AF} Mensagem copiada para clipboard");else if(r.action==="cancel"){G();return}}if(i=i.filter(r=>!n.includes(r)),i.length>0&&!o.yes&&!await Y(i))break}o.silent||l.success("\u2705 Modo Split conclu\xEDdo!")}var se=$(()=>{"use strict";p();de();b();W();D();ee();Fe();ie()});p();se();import{intro as at,outro as ct,log as mt}from"@clack/prompts";p();p();import{readFileSync as rt}from"fs";import{join as re}from"path";function Ie(){try{let e=[re(process.cwd(),"package.json"),re(process.cwd(),"..","package.json"),re(C,"..","..","package.json")];for(let t of e)try{let o=rt(t,"utf-8"),i=JSON.parse(o);if(i.name==="@gilbert_oliveira/commit-wizard")return i.version}catch{continue}throw new Error("Package.json n\xE3o encontrado")}catch{return console.warn("\u26A0\uFE0F N\xE3o foi poss\xEDvel ler a vers\xE3o do package.json, usando vers\xE3o padr\xE3o"),"0.0.0"}}function Pe(e){return{silent:e.includes("--silent")||e.includes("-s"),yes:e.includes("--yes")||e.includes("-y"),auto:e.includes("--auto")||e.includes("-a"),split:e.includes("--split"),smartSplit:e.includes("--smart-split"),dryRun:e.includes("--dry-run")||e.includes("-n"),help:e.includes("--help")||e.includes("-h"),version:e.includes("--version")||e.includes("-v")}}function Oe(){console.log(`
|
|
113
113
|
\u{1F9D9}\u200D\u2642\uFE0F Commit Wizard - Gerador inteligente de mensagens de commit
|
|
114
114
|
|
|
115
115
|
USAGE:
|
|
@@ -134,4 +134,4 @@ EXAMPLES:
|
|
|
134
134
|
commit-wizard --auto # Modo totalmente autom\xE1tico
|
|
135
135
|
|
|
136
136
|
Para mais informa\xE7\xF5es, visite: https://github.com/user/commit-wizard
|
|
137
|
-
`)}function
|
|
137
|
+
`)}function je(){let e=Ie();console.log(`commit-wizard v${e}`)}async function lt(){try{let e=Pe(process.argv.slice(2));e.help&&(Oe(),process.exit(0)),e.version&&(je(),process.exit(0)),e.auto&&(e.silent=!0,e.yes=!0),e.silent||at("\u{1F9D9}\u200D\u2642\uFE0F Commit Wizard"),await ne(e),e.silent||ct("At\xE9 logo! \u2728")}catch(e){mt.error(`Erro: ${e instanceof Error?e.message:"Erro desconhecido"}`),process.exit(1)}}lt();
|
package/package.json
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare module '@clack/prompts' {
|
|
2
|
+
export const intro: (message: string) => void;
|
|
3
|
+
export const outro: (message: string) => void;
|
|
4
|
+
export const log: {
|
|
5
|
+
error: (message: string) => void;
|
|
6
|
+
info: (message: string) => void;
|
|
7
|
+
success: (message: string) => void;
|
|
8
|
+
};
|
|
9
|
+
}
|
package/src/utils/args.ts
CHANGED
|
@@ -51,6 +51,9 @@ Para mais informações, visite: https://github.com/user/commit-wizard
|
|
|
51
51
|
`);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
import { getVersion } from './version';
|
|
55
|
+
|
|
54
56
|
export function showVersion(): void {
|
|
55
|
-
|
|
57
|
+
const version = getVersion();
|
|
58
|
+
console.log(`commit-wizard v${version}`);
|
|
56
59
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Lê a versão do package.json dinamicamente
|
|
6
|
+
*/
|
|
7
|
+
export function getVersion(): string {
|
|
8
|
+
try {
|
|
9
|
+
// Tentar diferentes caminhos para encontrar o package.json
|
|
10
|
+
const possiblePaths = [
|
|
11
|
+
// Caminho relativo ao arquivo atual (para desenvolvimento)
|
|
12
|
+
join(process.cwd(), 'package.json'),
|
|
13
|
+
// Caminho relativo ao binário compilado (para produção)
|
|
14
|
+
join(process.cwd(), '..', 'package.json'),
|
|
15
|
+
// Caminho absoluto baseado no __dirname
|
|
16
|
+
join(__dirname, '..', '..', 'package.json'),
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
for (const packagePath of possiblePaths) {
|
|
20
|
+
try {
|
|
21
|
+
const packageContent = readFileSync(packagePath, 'utf-8');
|
|
22
|
+
const packageJson = JSON.parse(packageContent);
|
|
23
|
+
|
|
24
|
+
// Verificar se é realmente o package.json do commit-wizard
|
|
25
|
+
if (packageJson.name === '@gilbert_oliveira/commit-wizard') {
|
|
26
|
+
return packageJson.version;
|
|
27
|
+
}
|
|
28
|
+
} catch {
|
|
29
|
+
// Continuar para o próximo caminho
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
throw new Error('Package.json não encontrado');
|
|
35
|
+
} catch {
|
|
36
|
+
// Fallback caso não consiga ler o package.json
|
|
37
|
+
console.warn('⚠️ Não foi possível ler a versão do package.json, usando versão padrão');
|
|
38
|
+
return '0.0.0';
|
|
39
|
+
}
|
|
40
|
+
}
|