Solved.
I submitted the problem to Copilot, Gemini, and Stack Overflow AI, and none of them were able to find the problem and fix it.
All I had to do was change the first two rules in onEnterRules to this:
...
{
"beforeText": "^((?!\\/\\/).)*\\s*\\$[a-zA-Z0-9_]+\\([a-zA-Z0-9%_]+,$",
"action": { "indent": "indent" }
},
{
"beforeText": "^((?!\\/\\/).)*\\s*.*,$",
"action": { "indent": "none" }
},
...
Basically, I added the end-of-line character $ to beforeText, and everything started working as expected again.