@@ -72,17 +72,27 @@ function shapeDesktopSurfaceSnapshot(
7272 options : Pick < SnapshotOptions , 'depth' | 'interactiveOnly' | 'scope' > ,
7373) : SnapshotResult {
7474 let nodes = data . nodes ?? [ ] ;
75- if ( options . scope ) nodes = scopeSnapshotNodes ( nodes , options . scope ) ;
75+ if ( options . scope ) {
76+ nodes = scopeSnapshotNodes ( nodes , options . scope , ( range ) =>
77+ options . interactiveOnly
78+ ? nodes . slice ( range . start , range . end ) . some ( isInteractiveSnapshotNode )
79+ : true ,
80+ ) ;
81+ }
7682 if ( options . interactiveOnly ) nodes = filterInteractiveSnapshotNodes ( nodes ) ;
7783 if ( typeof options . depth === 'number' ) nodes = filterSnapshotNodesByDepth ( nodes , options . depth ) ;
7884 return { ...data , nodes } ;
7985}
8086
8187/** The shared scope specification applied post-wire (`@agent-device/contracts/snapshot`). */
82- export function scopeSnapshotNodes ( nodes : RawSnapshotNode [ ] , scope : string ) : RawSnapshotNode [ ] {
88+ export function scopeSnapshotNodes (
89+ nodes : RawSnapshotNode [ ] ,
90+ scope : string ,
91+ subtreeContributes ?: ( range : { start : number ; end : number } ) => boolean ,
92+ ) : RawSnapshotNode [ ] {
8393 const normalizedScope = normalizeSnapshotScope ( scope ) ;
8494 if ( ! normalizedScope ) return reindexSnapshotNodes ( nodes ) ;
85- const range = findSnapshotScopeRange ( nodes , normalizedScope ) ;
95+ const range = findSnapshotScopeRange ( nodes , normalizedScope , subtreeContributes ) ;
8696 if ( ! range ) return [ ] ;
8797 const slice = nodes . slice ( range . start , range . end ) ;
8898 return reindexSnapshotNodes ( slice , slice [ 0 ] ?. depth ?? 0 ) ;
0 commit comments