My agentic slop goes here. Not intended for anyone else!
1open Ezjsonm
2
3let src = Logs.Src.create "claude.control" ~doc:"Claude control messages"
4module Log = (val Logs.src_log src : Logs.LOG)
5
6(* Helper for pretty-printing JSON *)
7let pp_json fmt json =
8 Fmt.string fmt (value_to_string json)
9
10type t = {
11 request_id : string;
12 subtype : string;
13 data : value;
14}
15
16let create ~request_id ~subtype ~data = { request_id; subtype; data }
17
18let request_id t = t.request_id
19let subtype t = t.subtype
20let data t = t.data
21
22let to_json t =
23 `O [
24 ("type", `String "control");
25 ("request_id", `String t.request_id);
26 ("subtype", `String t.subtype);
27 ("data", t.data);
28 ]
29
30let of_json = function
31 | `O fields ->
32 let request_id = get_string (List.assoc "request_id" fields) in
33 let subtype = get_string (List.assoc "subtype" fields) in
34 let data = List.assoc "data" fields in
35 { request_id; subtype; data }
36 | _ -> raise (Invalid_argument "Control.of_json: expected object")
37
38let pp fmt t =
39 Fmt.pf fmt "@[<2>Control@ { request_id = %S;@ subtype = %S;@ data = %a }@]"
40 t.request_id t.subtype pp_json t.data
41
42let log_received t =
43 Log.debug (fun m -> m "Received control message: %a" pp t)
44
45let log_sending t =
46 Log.debug (fun m -> m "Sending control message: %a" pp t)