Aider very much does pull in the right files to create context for itself. It also uses treesitter to build a repo-map and then uses that as an initial reference for everything, asking you to add the files it thinks it needs for the context. As of quite recently it also supports adding files for context in explicit read-only mode. It works extremely well.
This is a good read: https://aider.chat/2023/10/22/repomap.html