I did not try it myself, but I talked to other people and searched more, and it seems that using VS Code (as opposed to Iris/Cache Studio) combined with Copilot is currently the best available way of incorporating AI into ObjectScript/MUMPS coding: Coding InterSystems ObjectScript with AI Copilot. @Evgeny Shvarov, would you agree? Would you like to add anything on the discussion subject?
 

Excellent, just excellent. It did find correctly all globals in a routine (no indirection). I populated in = ##class(%Stream.TmpCharacter).%New() with this code:
NumLines=^ROUTINE(routineName,0,0)   ; Omit extension
n=0:1:NumLines {
    S line=$T(@routineName+n^@routineName)
    D in.Write(line),in.Write($c(13,10))
}
in.Rewind()

I also added this after your Write:
                Set line=$G(^ROUTINE(rtnName,0,lineNum+1))
                Write $C(9),$E(line,token.p+1,token.p+token.c),!

I did not try finding globals in classes, but I assume this would be very similar. Is there any online documentation that shows that token value for globals is 18? Would be curious about other token values.

I rebuild ^rINDEX using, as recommended, D ##class(%Library.RoutineIndex).RebuildIndex($NAMESPACE). That reduced the number of ^rINDEX entries with an empty Date Modified, the cause of the $RO error. However, this function is partially based on ^ROUTINE which in its turn had bogus entries, all of the type ^ROUTINE("ABC",0,"SIZE")=<some integer>. That’s all these routines contain. I killed these ^ROUTINE nodes and rebuilt ^rINDEX. No empty Date Modified.