@@ -93,10 +93,10 @@ export interface AISummarizeResult extends AIResult {
9393
9494export interface AIRebaseResult extends AIResult {
9595 readonly diff : string ;
96- readonly explanation : string ;
9796 readonly hunkMap : { index : number ; hunkHeader : string } [ ] ;
9897 readonly commits : {
9998 readonly message : string ;
99+ readonly explanation : string ;
100100 readonly hunks : { hunk : number } [ ] ;
101101 } [ ] ;
102102}
@@ -871,82 +871,57 @@ export class AIProviderService implements Disposable {
871871 commits : [ ] ,
872872 } as unknown as AIRebaseResult ;
873873
874- const lazyDiff = lazy ( ( ) => repo . git . diff . getDiff ?.( headRef , baseRef , { notation : '...' } ) ) ;
875-
876- const conversation : AIChatMessage [ ] = [ ] ;
877-
878- const req1 = await this . sendRequest (
874+ const rq = await this . sendRequest (
879875 'generate-rebase' ,
880876 async ( model , reporting , cancellation , maxInputTokens , retries ) => {
881- const diff = await lazyDiff . value ;
882- if ( ! diff ?. contents ) {
883- throw new AINoRequestDataError ( 'No changes found to generate a rebase from.' ) ;
884- }
885- if ( cancellation . isCancellationRequested ) throw new CancellationError ( ) ;
877+ const [ diffResult , logResult ] = await Promise . allSettled ( [
878+ repo . git . diff . getDiff ?.( headRef , baseRef , { notation : '...' } ) ,
879+ repo . git . commits . getLog ( `${ baseRef } ..${ headRef } ` ) ,
880+ ] ) ;
886881
887- result . diff = diff . contents ;
882+ const diff = getSettledValue ( diffResult ) ;
883+ const log = getSettledValue ( logResult ) ;
888884
889- const { prompt } = await this . getPrompt (
890- 'generate-rebase-explanation' ,
891- model ,
892- {
893- diff : diff . contents ,
894- context : options ?. context ,
895- // instructions: configuration.get('ai.generateRebase.customInstructions'),
896- } ,
897- maxInputTokens ,
898- retries ,
899- reporting ,
900- ) ;
901- if ( cancellation . isCancellationRequested ) throw new CancellationError ( ) ;
902-
903- const messages : AIChatMessage [ ] = [ { role : 'user' , content : prompt } ] ;
904-
905- conversation . push ( ...messages ) ;
906- return messages ;
907- } ,
908- m => `Generating rebase (examining changes) with ${ m . name } ...` ,
909- source ,
910- m => ( {
911- key : 'ai/generate' ,
912- data : {
913- type : 'rebase' ,
914- 'model.id' : m . id ,
915- 'model.provider.id' : m . provider . id ,
916- 'model.provider.name' : m . provider . name ,
917- 'retry.count' : 0 ,
918- } ,
919- } ) ,
920- options ,
921- ) ;
922-
923- conversation . push ( {
924- role : 'assistant' ,
925- content : req1 ! . content ,
926- } ) ;
927- result . explanation = req1 ! . content ;
928-
929- const req2 = await this . sendRequest (
930- 'generate-rebase' ,
931- async ( model , reporting , cancellation , maxInputTokens , retries ) => {
932- const diff = await lazyDiff . value ;
933- if ( ! diff ?. contents ) {
885+ if ( ! diff ?. contents || ! log ?. commits ?. size ) {
934886 throw new AINoRequestDataError ( 'No changes found to generate a rebase from.' ) ;
935887 }
936888 if ( cancellation . isCancellationRequested ) throw new CancellationError ( ) ;
937889
890+ result . diff = diff . contents ;
891+
938892 const hunkMap : { index : number ; hunkHeader : string } [ ] = [ ] ;
939893 let counter = 0 ;
894+ //const filesDiffs = await repo.git.diff().getDiffFiles!(diff.contents)!;
895+ //for (const f of filesDiffs!.files)
896+ //for (const hunk of parsedDiff.hunks) {
897+ // hunkMap.push({ index: ++counter, hunkHeader: hunk.contents.split('\n', 1)[0] });
898+ //}
899+
900+ // let hunksByNumber= '';
901+
940902 for ( const hunkHeader of diff . contents . matchAll ( / @ @ - \d + , \d + \+ \d + , \d + @ @ ( .* ) $ / gm) ) {
941903 hunkMap . push ( { index : ++ counter , hunkHeader : hunkHeader [ 0 ] } ) ;
942904 }
943905
944906 result . hunkMap = hunkMap ;
907+ // const hunkNumber = `hunk-${counter++}`;
908+ // hunksByNumber += `${hunkNumber}: ${hunk[0]}\n`;
909+ // }
910+
911+ // const commits: { diff: string; message: string }[] = [];
912+ // for (const commit of [...log.commits.values()].sort((a, b) => a.date.getTime() - b.date.getTime())) {
913+ // const diff = await repo.git.diff().getDiff?.(commit.ref);
914+ // commits.push({ message: commit.message ?? commit.summary, diff: diff?.contents ?? '' });
915+
916+ // if (cancellation.isCancellationRequested) throw new CancellationError();
917+ // }
945918
946919 const { prompt } = await this . getPrompt (
947- 'generate-rebase-commits ' ,
920+ 'generate-rebase' ,
948921 model ,
949922 {
923+ diff : diff . contents ,
924+ // commits: JSON.stringify(commits),
950925 data : JSON . stringify ( hunkMap ) ,
951926 context : options ?. context ,
952927 // instructions: configuration.get('ai.generateRebase.customInstructions'),
@@ -958,7 +933,7 @@ export class AIProviderService implements Disposable {
958933 if ( cancellation . isCancellationRequested ) throw new CancellationError ( ) ;
959934
960935 const messages : AIChatMessage [ ] = [ { role : 'user' , content : prompt } ] ;
961- return [ ... conversation , ... messages ] ;
936+ return messages ;
962937 } ,
963938 m => `Generating rebase with ${ m . name } ...` ,
964939 source ,
@@ -972,21 +947,23 @@ export class AIProviderService implements Disposable {
972947 'retry.count' : 0 ,
973948 } ,
974949 } ) ,
975- { ... options , modelOptions : { temperature : 0.2 } } ,
950+ options ,
976951 ) ;
977952
978- // if it is wrapped in markdown, we need to strip it
979- const content = req2 ! . content . replace ( / ^ \s * ` ` ` j s o n \s * / , '' ) . replace ( / \s * ` ` ` $ / , '' ) ;
980-
981953 try {
954+ // if it is wrapped in markdown, we need to strip it
955+ const content = rq ! . content . replace ( / ^ \s * ` ` ` j s o n \s * / , '' ) . replace ( / \s * ` ` ` $ / , '' ) ;
982956 // Parse the JSON content from the result
983957 result . commits = JSON . parse ( content ) as AIRebaseResult [ 'commits' ] ;
984958 } catch {
985959 debugger ;
986960 throw new Error ( 'Unable to parse rebase result' ) ;
987961 }
988962
989- return result ;
963+ return {
964+ ...rq ,
965+ ...result ,
966+ } ;
990967 }
991968
992969 private async sendRequest < T extends AIActionType > (
0 commit comments