My agentic slop goes here. Not intended for anyone else!

more

Changed files
+67 -17
stack
zulip
examples
lib
+3 -11
stack/zulip/examples/echo_bot.ml
···
Send me a direct message or mention me in a channel."
let handle_message ~config:_ ~storage ~identity ~message ~env:_ =
-
Log.debug (fun m -> m "Received message for processing");
(* Use the new Message type for cleaner handling *)
match message with
| Message.Private { common; display_recipient = _ } ->
-
Log.info (fun m -> m "Processing private message from %s (ID: %d)"
-
common.sender_email common.id);
(* Check if this is our own message to avoid loops *)
let bot_email = Bot_handler.Identity.email identity in
···
) else
(* Process the message content *)
let sender_name = common.sender_full_name in
-
let sender_id = common.sender_id in
-
let msg = common.content in
-
-
Log.info (fun m -> m "Processing message from %s (ID: %d): %s" sender_name sender_id msg);
(* Remove bot mention using Message utility *)
let bot_email = Bot_handler.Identity.email identity in
···
Log.info (fun m -> m "Sending private reply");
Ok (Bot_handler.Response.Reply response_content)
-
| Message.Stream { common; display_recipient; subject; _ } ->
-
Log.info (fun m -> m "Processing stream message from %s in %s/%s"
-
common.sender_email display_recipient subject);
-
(* Check if this is our own message to avoid loops *)
let bot_email = Bot_handler.Identity.email identity in
if common.sender_email = bot_email then (
···
Send me a direct message or mention me in a channel."
let handle_message ~config:_ ~storage ~identity ~message ~env:_ =
+
(* Log the message with colorful formatting *)
+
Log.debug (fun m -> m "@[<h>Received: %a@]" (Message.pp_ansi ~show_json:false) message);
(* Use the new Message type for cleaner handling *)
match message with
| Message.Private { common; display_recipient = _ } ->
(* Check if this is our own message to avoid loops *)
let bot_email = Bot_handler.Identity.email identity in
···
) else
(* Process the message content *)
let sender_name = common.sender_full_name in
(* Remove bot mention using Message utility *)
let bot_email = Bot_handler.Identity.email identity in
···
Log.info (fun m -> m "Sending private reply");
Ok (Bot_handler.Response.Reply response_content)
+
| Message.Stream { common; display_recipient = _; subject = _; _ } ->
(* Check if this is our own message to avoid loops *)
let bot_email = Bot_handler.Identity.email identity in
if common.sender_email = bot_email then (
+6 -1
stack/zulip/lib/zulip_bot/lib/bot_runner.ml
···
(match Message.of_json (convert_json message_json) with
| Error err ->
Log.err (fun m -> m "Failed to parse message JSON: %s" err);
| Ok message ->
(* Get bot identity for checking mentions *)
let bot_email = Bot_handler.Identity.email (Bot_handler.identity t.handler) in
···
let is_from_self = Message.is_from_email message ~email:bot_email in
(* Log what we found *)
-
Log.info (fun m -> m "Message check: mentioned=%b, private=%b, from_self=%b"
is_mentioned is_private is_from_self);
(* Only process if bot was mentioned or it's a private message, and not from self *)
···
(match Message.of_json (convert_json message_json) with
| Error err ->
Log.err (fun m -> m "Failed to parse message JSON: %s" err);
+
(* Show raw JSON for debugging *)
+
Log.debug (fun m -> m "@[%a@]" Message.pp_json_debug (convert_json message_json));
| Ok message ->
+
(* Log the parsed message with colors *)
+
Log.info (fun m -> m "@[<h>%a@]" (Message.pp_ansi ~show_json:false) message);
+
(* Get bot identity for checking mentions *)
let bot_email = Bot_handler.Identity.email (Bot_handler.identity t.handler) in
···
let is_from_self = Message.is_from_email message ~email:bot_email in
(* Log what we found *)
+
Log.debug (fun m -> m "Message check: mentioned=%b, private=%b, from_self=%b"
is_mentioned is_private is_from_self);
(* Only process if bot was mentioned or it's a private message, and not from self *)
+1 -1
stack/zulip/lib/zulip_bot/lib/dune
···
(library
(public_name zulip_bot)
(name zulip_bot)
-
(libraries zulip unix eio logs mirage-crypto-rng)
(flags (:standard -warn-error -3)))
···
(library
(public_name zulip_bot)
(name zulip_bot)
+
(libraries zulip unix eio logs mirage-crypto-rng fmt)
(flags (:standard -warn-error -3)))
+50 -3
stack/zulip/lib/zulip_bot/lib/message.ml
···
in
let username_mention = "@**" ^ username ^ "**" in
-
let rec contains text pattern =
if String.length pattern = 0 || String.length pattern > String.length text then
false
else
···
in
search_from 0
in
-
contains content_text email_mention || contains content_text username_mention
let strip_mention msg ~user_email =
···
| Unknown { common; _ } ->
Format.fprintf fmt "Unknown { id=%d; sender=%s; content=%S }"
-
common.id common.sender_email common.content
···
in
let username_mention = "@**" ^ username ^ "**" in
+
let contains text pattern =
if String.length pattern = 0 || String.length pattern > String.length text then
false
else
···
in
search_from 0
in
contains content_text email_mention || contains content_text username_mention
let strip_mention msg ~user_email =
···
| Unknown { common; _ } ->
Format.fprintf fmt "Unknown { id=%d; sender=%s; content=%S }"
+
common.id common.sender_email common.content
+
+
(** ANSI colored pretty printing for debugging *)
+
let pp_ansi ?(show_json=false) ppf msg =
+
let open Fmt in
+
let blue = styled `Blue string in
+
let green = styled `Green string in
+
let yellow = styled `Yellow string in
+
let magenta = styled `Magenta string in
+
let cyan = styled `Cyan string in
+
let dim = styled (`Fg `Black) string in
+
+
match msg with
+
| Private { common; display_recipient } ->
+
pf ppf "%a %a %a %a %a"
+
(styled `Bold blue) "DM"
+
dim (Printf.sprintf "[#%d]" common.id)
+
(styled `Cyan string) common.sender_email
+
dim "→"
+
green (Printf.sprintf "%S" common.content);
+
if show_json then
+
pf ppf "@. %a %a" dim "Recipients:"
+
(list ~sep:(const string ", ") (fun fmt u -> cyan fmt (User.email u)))
+
display_recipient
+
+
| Stream { common; display_recipient; subject; _ } ->
+
pf ppf "%a %a %a%a%a %a %a"
+
(styled `Bold yellow) "STREAM"
+
dim (Printf.sprintf "[#%d]" common.id)
+
magenta display_recipient
+
dim "/"
+
cyan subject
+
(styled `Cyan string) common.sender_email
+
green (Printf.sprintf "%S" common.content)
+
+
| Unknown { common; _ } ->
+
pf ppf "%a %a %a %a"
+
(styled `Bold (styled (`Fg `Red) string)) "UNKNOWN"
+
dim (Printf.sprintf "[#%d]" common.id)
+
(styled `Cyan string) common.sender_email
+
(styled (`Fg `Red) string) (Printf.sprintf "%S" common.content)
+
+
(** Pretty print JSON for debugging *)
+
let pp_json_debug ppf json =
+
let open Fmt in
+
let json_str = Yojson.Safe.pretty_to_string json in
+
pf ppf "@[<v>%a@.%a@]"
+
(styled `Bold (styled (`Fg `Blue) string)) "Raw JSON:"
+
(styled (`Fg `Black) string) json_str
+7 -1
stack/zulip/lib/zulip_bot/lib/message.mli
···
val of_json : Yojson.Safe.t -> (t, string) result
(** Pretty printing *)
-
val pp : Format.formatter -> t -> unit
···
val of_json : Yojson.Safe.t -> (t, string) result
(** Pretty printing *)
+
val pp : Format.formatter -> t -> unit
+
+
(** ANSI colored pretty printing for debugging *)
+
val pp_ansi : ?show_json:bool -> Format.formatter -> t -> unit
+
+
(** Pretty print JSON for debugging *)
+
val pp_json_debug : Format.formatter -> Yojson.Safe.t -> unit