The best way is to create a custom toplevel and map the replies.
"val x : int = 3" is printed using [Toploop.print_out_phrase] which is
a reference, so you can replace by a function adding markers around
the text.
This won't catch error/warning messages. If you also want to
distinguish these, you can redirect the standard formatters. The
toplevel prints replies and error messages on the formatter passed to
[Toploop.loop], which is [Format.std_formatter] by default. So you can
either:
(1) override [Format.std_formatter] callbacks
(2) call [Toploop.loop] with a custom formatter
You can do (1) with [Format.pp_set_all_formatter_output_functions] and
(2) by setting the startup hook:
Toploop.toplevel_startup_hook := (fun () -> Toploop.loop my_formatter; exit 0)
Warnings are always printed on [Format.err_formatter] so you'll need
to override its callbacks.
If you can't create a custom toplevel, I guess you can also send the
code to the toplevel at the beginning of the session.