@@ -18,6 +18,9 @@ import type {
1818} from "../types/workflow.types" ;
1919import { appendCodexUsage } from "../usage/usage-state" ;
2020
21+ const NO_STAGED_CHANGES_ERROR =
22+ "No staged changes found after implement step; cannot create PR" ;
23+
2124export function fixedBugsForImplementationComment (
2225 hasExistingPr : boolean ,
2326 bugs : RunState [ "bugs" ] ,
@@ -100,12 +103,22 @@ export async function handleImplementingStage(
100103 url : "https://example.invalid/dry-run" ,
101104 } ;
102105 } else {
103- state . pullRequest = await runtime . createDraftPrFromWorktree (
104- config ,
105- state . issue . key ,
106- state . issue . title ,
107- state . issue . branchName ,
108- ) ;
106+ state . pullRequest = await runtime
107+ . createDraftPrFromWorktree (
108+ config ,
109+ state . issue . key ,
110+ state . issue . title ,
111+ state . issue . branchName ,
112+ )
113+ . catch ( ( error ) => {
114+ if ( ! isNoStagedChangesError ( error ) ) {
115+ throw error ;
116+ }
117+ throw noImplementationChangesError (
118+ state . implementationSummary ,
119+ error ,
120+ ) ;
121+ } ) ;
109122 }
110123 } else if ( ! config . dryRun ) {
111124 if ( ! state . pullRequest ?. branch ) {
@@ -148,6 +161,27 @@ export async function handleImplementingStage(
148161 ) ;
149162}
150163
164+ function isNoStagedChangesError ( error : unknown ) : boolean {
165+ return (
166+ error instanceof Error && error . message . includes ( NO_STAGED_CHANGES_ERROR )
167+ ) ;
168+ }
169+
170+ function noImplementationChangesError (
171+ implementationSummary : string | undefined ,
172+ cause : unknown ,
173+ ) : Error {
174+ const summary = implementationSummary ?. trim ( ) || "No agent output recorded." ;
175+ const error = new Error (
176+ [
177+ "Implementation completed without file changes; no draft PR was created." ,
178+ `Agent output: ${ summary } ` ,
179+ ] . join ( "\n\n" ) ,
180+ ) ;
181+ Object . assign ( error , { cause } ) ;
182+ return error ;
183+ }
184+
151185export async function prepareImplementationBranchForStage (
152186 config : ResolvedProjectConfig ,
153187 state : RunState ,
0 commit comments