@@ -269,7 +269,9 @@ export async function handleSessionCommands(params: {
269269 flags : action . flags ?? { } ,
270270 } ) ;
271271 if ( response . ok ) continue ;
272- if ( ! shouldUpdate ) return response ;
272+ if ( ! shouldUpdate ) {
273+ return withReplayFailureContext ( response , action , index , resolved ) ;
274+ }
273275 const nextAction = await healReplayAction ( {
274276 action,
275277 sessionName,
@@ -278,7 +280,7 @@ export async function handleSessionCommands(params: {
278280 dispatch,
279281 } ) ;
280282 if ( ! nextAction ) {
281- return response ;
283+ return withReplayFailureContext ( response , action , index , resolved ) ;
282284 }
283285 actions [ index ] = nextAction ;
284286 response = await invoke ( {
@@ -289,7 +291,7 @@ export async function handleSessionCommands(params: {
289291 flags : nextAction . flags ?? { } ,
290292 } ) ;
291293 if ( ! response . ok ) {
292- return response ;
294+ return withReplayFailureContext ( response , nextAction , index , resolved ) ;
293295 }
294296 healed += 1 ;
295297 }
@@ -334,6 +336,42 @@ export async function handleSessionCommands(params: {
334336 return null ;
335337}
336338
339+ function withReplayFailureContext (
340+ response : DaemonResponse ,
341+ action : SessionAction ,
342+ index : number ,
343+ replayPath : string ,
344+ ) : DaemonResponse {
345+ if ( response . ok ) return response ;
346+ const step = index + 1 ;
347+ const summary = formatReplayActionSummary ( action ) ;
348+ const details = {
349+ ...( response . error . details ?? { } ) ,
350+ replayPath,
351+ step,
352+ action : action . command ,
353+ positionals : action . positionals ?? [ ] ,
354+ } ;
355+ return {
356+ ok : false ,
357+ error : {
358+ code : response . error . code ,
359+ message : `Replay failed at step ${ step } (${ summary } ): ${ response . error . message } ` ,
360+ details,
361+ } ,
362+ } ;
363+ }
364+
365+ function formatReplayActionSummary ( action : SessionAction ) : string {
366+ const values = ( action . positionals ?? [ ] ) . map ( ( value ) => {
367+ const trimmed = value . trim ( ) ;
368+ if ( / ^ - ? \d + ( \. \d + ) ? $ / . test ( trimmed ) ) return trimmed ;
369+ if ( trimmed . startsWith ( '@' ) ) return trimmed ;
370+ return JSON . stringify ( trimmed ) ;
371+ } ) ;
372+ return [ action . command , ...values ] . join ( ' ' ) ;
373+ }
374+
337375async function healReplayAction ( params : {
338376 action : SessionAction ;
339377 sessionName : string ;
0 commit comments