PSDs are a hairy format - even people exporting things isn’t always straightforward, and a machine can’t reason the way a person does.
This idea was a pie-in-the-sky goal for a project I worked on ~ 10 years ago, and it was abandoned as too complex to do it reliably, within a reasonable timeframe.
Given that psd’s are just layers of raster graphics (but plausibly just a single layer) I doubt even adobe could make the tool as described, and they have the benefit of ~25 years of knowledge about photoshop and PSDs.
I believe this was posted on HN a while back.
The way I approach this is to use the slice tool. 10 years ago I would have cut boxes ajd change the background to the imagine and set width or height to 100%. The important part was picking a repeatable image when scaled 100%