Thanks, Robert. It is available in 2017, but I was not able to set it up yet. Something is still wrong the way I run it, please see below. I start debugging, stop at a breakpoint and input the $J value.

%SYS>D DIR^TRACE()
 
%SYS>D ^TRACE
 
TRACE utility for Cache. You can signal a process to write a record of all
procedure, function, or subroutine calls to a file. Then use this utility to
interpret and display the trace. The trace file is named: CacheTrace_'pid'.txt
 
Use $$DIR^TRACE(dir) to set the directory where the file(s) should be written
(process must have create/write access to the directory). $$DIR^TRACE() returns
the current directory for trace files.
 
Use $$ON^TRACE(pid) to start the trace and $$OFF^TRACE(pid) to end the
recording. Then just run ^TRACE to see the results.
 
Process ID for trace file: 5352
Output to: <0> TestAG.txt
 
Processing file ...
 
-1,Unable to open file CacheTrace_5352.txt
%SYS>

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.