Developer on the Language Interoperability Team at InterSystems.
The PackageDefinition class contains only packages where we need to keep metadata about a package. Most packages do not have any extra metadata.
The SQL solution is the correct solution IMO. If I were a developer on the Object team I would advocate for a method in $system.OBJ - PackageExists(<package_name>) perhaps. :)
I was tempted to criticize the Mixtral response. I did implement the original versions of both of these items so I know them both well. The Mixtral code example for %SQL.Statement is incorrect in a few ways but I'm surprised that it was as close as it is.
Once that temptation was put aside, I realized that Mixtral can only analyze what it finds. If it can't find the solution then perhaps our class documentation is not going to provide the answer to a user. Hmmm...
Basically the same as Enrico's:
LATEST:USER>set result = $system.SQL.Execute("select * from %SYS.Namespace_List()")
LATEST:USER>do result.%Display()
Nsp Status Remote
%SYS 1 0
B360 1 0
USER 1 0
3 Rows(s) Affected