@@ -689,6 +689,46 @@ Generated by PostHog Agent`;
689689 stopReason : result . stopReason ,
690690 } ) ;
691691
692+ const branchName = await this . gitManager . getCurrentBranch ( ) ;
693+ const hasChanges = await this . gitManager . hasChanges ( ) ;
694+ const shouldCreatePR = options . createPR ?? false ;
695+
696+ if ( hasChanges ) {
697+ this . logger . info ( "Committing uncommitted changes" , { taskId : task . id } ) ;
698+ await this . gitManager . commitImplementation (
699+ task . id ,
700+ task . title ,
701+ task . description ?? undefined ,
702+ ) ;
703+ }
704+
705+ const defaultBranch = await this . gitManager . getDefaultBranch ( ) ;
706+ if ( branchName !== defaultBranch ) {
707+ this . logger . info ( "Pushing branch" , { branchName, taskId : task . id } ) ;
708+ await this . gitManager . pushBranch ( branchName ) ;
709+
710+ if ( shouldCreatePR ) {
711+ this . logger . info ( "Creating PR" , { branchName, taskId : task . id } ) ;
712+
713+ const prUrl = await this . createPullRequest (
714+ task . id ,
715+ branchName ,
716+ task . title ,
717+ task . description ?? "" ,
718+ ) ;
719+
720+ this . logger . info ( "PR created" , { prUrl, taskId : task . id } ) ;
721+
722+ try {
723+ await this . attachPullRequestToTask ( task . id , prUrl , branchName ) ;
724+ } catch ( err ) {
725+ this . logger . warn ( "Could not attach PR to task" , {
726+ error : err instanceof Error ? err . message : String ( err ) ,
727+ } ) ;
728+ }
729+ }
730+ }
731+
692732 await this . sessionStore . complete ( taskRunId ) ;
693733 } catch ( error ) {
694734 const errorMessage =
0 commit comments