AI could have free access to all public source codes on GitHub without respecting their licenses.
IANAL, but aren't their licenses are being respected up until they are put into a codebase? At least insomuch as Google is allowed to display code snippets in the preview when you look up a file in a GitHub repo, or you are allowed to copy a snippet to a StackOverflow discussion or ticket comment.
I do agree regulation is a very good idea, in more ways than just citation given the potential economic impacts that we seem clearly unprepared for.