Any plugin or script to relink close nodes automatically?

I have lines cut and want to close them again after some changes. Glyphs can relink nodes, but it’s not enough and sometimes it doesn’t work for unknown reason. For nodes which are very close, i want to relink them and keep the shape.
any plugin or script ?thanks
屏幕快照 2022-03-28 下午5.27.37

You can write it yourself in Macro window.

for layer in Font.selectedLayers:
    for path in layer.paths:
        path.closed = True

thanks, but don’t know how to do it.