@@ -17,7 +17,7 @@ import {
1717 showInfo ,
1818 confirmCommit ,
1919} from '../utils/ui.js' ;
20- import { getAuthMode } from '../utils/config-manager.js' ;
20+ import { getAuthMode , getConvention } from '../utils/config-manager.js' ;
2121
2222/**
2323 * Main commit command logic
@@ -137,37 +137,47 @@ export async function processFilesInteractively(aiProvider, options = {}) {
137137 continue ;
138138 }
139139
140- // Generate commit message
141- try {
142- const message = await aiProvider . generateCommitMessage (
143- diff ,
144- file ,
145- options ,
146- ) ;
140+ let currentConvention = options . convention || getConvention ( ) ;
141+ let fileProcessed = false ;
147142
148- // Confirm and commit
149- const result = await confirmCommit ( message , file ) ;
143+ while ( ! fileProcessed ) {
144+ try {
145+ const message = await aiProvider . generateCommitMessage (
146+ diff ,
147+ file ,
148+ { ...options , convention : currentConvention } ,
149+ ) ;
150150
151- if ( result . action === 'accept' ) {
152- const success = await commit ( result . message ) ;
153- if ( success ) {
154- showSuccess ( `Committed: ${ file } ` ) ;
155- console . log ( `📝 ${ result . message } ` ) ;
156- committed ++ ;
157- } else {
158- showError ( `Failed to commit ${ file } ` ) ;
151+ const result = await confirmCommit ( message , file , currentConvention ) ;
152+
153+ if ( result . action === 'accept' ) {
154+ const success = await commit ( result . message ) ;
155+ if ( success ) {
156+ showSuccess ( `Committed: ${ file } ` ) ;
157+ console . log ( `📝 ${ result . message } ` ) ;
158+ committed ++ ;
159+ } else {
160+ showError ( `Failed to commit ${ file } ` ) ;
161+ await unstageFile ( file ) ;
162+ skipped ++ ;
163+ }
164+
165+ fileProcessed = true ;
166+ } else if ( result . action === 'regenerate' ) {
167+ currentConvention = result . convention ;
168+ // Loop continues to regenerate
169+ } else if ( result . action === 'skip' ) {
170+ showInfo ( `Skipped: ${ file } ` ) ;
159171 await unstageFile ( file ) ;
160172 skipped ++ ;
173+ fileProcessed = true ;
161174 }
162- } else if ( result . action === 'skip' ) {
163- showInfo ( `Skipped: ${ file } `) ;
175+ } catch ( error ) {
176+ showError ( `Error processing ${ file } : ${ error . message } `) ;
164177 await unstageFile ( file ) ;
165178 skipped ++ ;
179+ fileProcessed = true ;
166180 }
167- } catch ( error ) {
168- showError ( `Error processing ${ file } : ${ error . message } ` ) ;
169- await unstageFile ( file ) ;
170- skipped ++ ;
171181 }
172182 }
173183
@@ -199,27 +209,52 @@ export async function processFile(filePath, aiProvider, options = {}) {
199209 return ;
200210 }
201211
202- // Generate commit message
203- showInfo ( 'Generating commit message...' ) ;
204- const message = await aiProvider . generateCommitMessage (
205- diff ,
206- filePath ,
207- options ,
208- ) ;
212+ let currentConvention = options . convention || getConvention ( ) ;
213+ let attempts = 0 ;
214+ const maxAttempts = 5 ;
209215
210- // Confirm and commit
211- const result = await confirmCommit ( message , filePath ) ;
216+ while ( attempts < maxAttempts ) {
217+ showInfo ( 'Generating commit message...' ) ;
212218
213- if ( result . action === 'accept' ) {
214- const success = await commit ( result . message ) ;
215- if ( success ) {
216- showSuccess ( 'Changes committed successfully!' ) ;
217- console . log ( `📝 ${ result . message } ` ) ;
218- } else {
219- showError ( 'Failed to commit changes.' ) ;
219+ try {
220+ const message = await aiProvider . generateCommitMessage (
221+ diff ,
222+ filePath ,
223+ { ...options , convention : currentConvention } ,
224+ ) ;
225+
226+ const result = await confirmCommit ( message , filePath , currentConvention ) ;
227+
228+ if ( result . action === 'accept' ) {
229+ const success = await commit ( result . message ) ;
230+ if ( success ) {
231+ showSuccess ( 'Changes committed successfully!' ) ;
232+ console . log ( `📝 ${ result . message } ` ) ;
233+ } else {
234+ showError ( 'Failed to commit changes.' ) ;
235+ }
236+
237+ return ;
238+ }
239+
240+ if ( result . action === 'regenerate' ) {
241+ currentConvention = result . convention ;
242+ attempts ++ ;
243+ continue ;
244+ }
245+
246+ if ( result . action === 'skip' ) {
247+ showInfo ( 'Commit cancelled.' ) ;
248+ await unstageFile ( filePath ) ;
249+ return ;
250+ }
251+ } catch ( error ) {
252+ showError ( `Error: ${ error . message } ` ) ;
253+ await unstageFile ( filePath ) ;
254+ return ;
220255 }
221- } else if ( result . action === 'skip' ) {
222- showInfo ( 'Commit cancelled.' ) ;
223- await unstageFile ( filePath ) ;
224256 }
257+
258+ showWarning ( 'Maximum regeneration attempts reached.' ) ;
259+ await unstageFile ( filePath ) ;
225260}
0 commit comments