@@ -132,9 +132,12 @@ function createDaemonMaestroRuntimeParts(options: CreateDaemonMaestroRuntimeOper
132132 } ,
133133
134134 tapOn : async ( input , context ) =>
135- await tapTargetWithOutcome ( options , snapshots , input . target , context , {
136- count : input . repeat ,
137- intervalMs : input . delay ,
135+ await tapTargetAndSettle ( options , snapshots , input . target , context , {
136+ click : {
137+ count : input . repeat ,
138+ intervalMs : input . delay ,
139+ } ,
140+ retryIfNoChange : input . retryTapIfNoChange === true ,
138141 } ) ,
139142 doubleTapOn : async ( input ) => {
140143 snapshots . invalidate ( ) ;
@@ -387,31 +390,42 @@ function createSnapshotSource(
387390 } ;
388391}
389392
390- async function tapTargetWithOutcome (
393+ async function tapTargetAndSettle (
391394 options : CreateDaemonMaestroRuntimeOperationsOptions ,
392395 snapshots : MaestroSnapshotSource ,
393396 target : Parameters < MaestroRuntimeOperations [ 'tapOn' ] > [ 0 ] [ 'target' ] ,
394397 context : MaestroRuntimeOperationContext ,
395- flags : MaestroClickOptions ,
398+ policy : { click : MaestroClickOptions ; retryIfNoChange : boolean } ,
396399) : Promise < void > {
400+ const dispatch = async ( ) =>
401+ await dispatchTapTarget ( options , snapshots , target , context , policy . click ) ;
402+ if ( ! policy . retryIfNoChange ) {
403+ await dispatch ( ) ;
404+ snapshots . requireStability ( ) ;
405+ return ;
406+ }
407+
397408 const baselineSignature =
398409 target . resolution ?. surfaceSignature ??
399410 maestroSnapshotSignature ( await snapshots . capture ( context ) ) ;
400- const dispatch = async ( ) => await dispatchTapTarget ( options , snapshots , target , context , flags ) ;
411+ const settle = async ( ) =>
412+ await waitForTypedSnapshotStability ( {
413+ timeoutMs : MAESTRO_DEFAULT_SETTLE_TIMEOUT_MS ,
414+ context,
415+ snapshot : snapshots . capture ,
416+ dependencies : options . dependencies ,
417+ } ) ;
401418
402419 await dispatch ( ) ;
403-
404- await options . dependencies . sleep ( MAESTRO_OBSERVATION_POLL_MS , context . signal ) ;
405- let observed = await snapshots . capture ( context ) ;
420+ let observed = await settle ( ) ;
406421 let attempts = 1 ;
407422 while (
408423 maestroSnapshotSignature ( observed ) === baselineSignature &&
409- attempts < MAESTRO_COMPATIBILITY_PRESETS . command . tapMaxAttempts
424+ attempts < MAESTRO_COMPATIBILITY_PRESETS . command . retryTapMaxAttempts
410425 ) {
411426 await dispatch ( ) ;
412427 attempts += 1 ;
413- await options . dependencies . sleep ( MAESTRO_OBSERVATION_POLL_MS , context . signal ) ;
414- observed = await snapshots . capture ( context ) ;
428+ observed = await settle ( ) ;
415429 }
416430 snapshots . prime ( context . generation + 1 , observed ) ;
417431}
0 commit comments