Are there any good hooks into the replication status through cli?

I am trying to figure out where truenas scale is getting the information for the replication status from as seen in the GUI:
replication GUI

I would like the information such as last run (duration since last run) and the state (finished, running, failed).

I want to run a script that act on this information, and I seem not to be the only one. There is a thread from the old forum called:

In that thread they talk about the same issue and come up with various hacks to try and guestimate this information. Their attempt at determining this information relies on looking at /var/logs/zettarepl.log, but it is pretty clear that this is a hack approach that is not really reliable. And for something like replication tasks, you really want reliable otherwise you can be lured into a false sense of security.

I also see the thread named:
correct-way-to-script-zfs-replication-in-truenas-scale which is touching a similar topic but from a slightly different angle where they are basically replacing the GUI replication with a script, which I might end up doing as well, if I cannot get a nice hook into the status of the GUI replication. But I would rather use the GUI replication and do as little modification as possible to the way truenas scale is supposed to run as possible.

So surely there must be a better way of getting this information in truenas scale?
Maybe the middleware API allows some extraction of this information, or perhaps it is directly written into a file somewhere else which is how the gui gets the information?

Does anyone know of a good way to get this information?

I believe the API is the golden path for doing this. Running midclt call core.get_jobs will return a JSON list of jobs (these include replication jobs set up in the UI. Piping it through jq will format it nicely, and then you can slice and dice with grep, etc.