this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

more

+237 -710
+1 -1
claudeio/lib/client.ml
··· 159 159 (* Extract session ID from system messages *) 160 160 (match msg with 161 161 | Message.System sys -> 162 - (match Message.System.Data.session_id (Message.System.data sys) with 162 + (match Message.System.session_id sys with 163 163 | Some session_id -> 164 164 t.session_id <- Some session_id; 165 165 Log.debug (fun m -> m "Stored session ID: %s" session_id)
+1 -29
claudeio/lib/content_block.ml
··· 3 3 4 4 5 5 module Text = struct 6 - module Unknown = struct 7 - type t = Jsont.json 8 - let empty = Jsont.Object ([], Jsont.Meta.none) 9 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 10 - let jsont = Jsont.json 11 - end 12 - 13 6 type t = { 14 7 text : string; 15 8 unknown : Unknown.t; ··· 85 78 let of_json json = json 86 79 end 87 80 88 - module Unknown = struct 89 - type t = Jsont.json 90 - let empty = Jsont.Object ([], Jsont.Meta.none) 91 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 92 - let jsont = Jsont.json 93 - end 94 - 95 81 type t = { 96 82 id : string; 97 83 name : string; ··· 136 122 end 137 123 138 124 module Tool_result = struct 139 - module Unknown = struct 140 - type t = Jsont.json 141 - let empty = Jsont.Object ([], Jsont.Meta.none) 142 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 143 - let jsont = Jsont.json 144 - end 145 - 146 125 type t = { 147 126 tool_use_id : string; 148 127 content : string option; ··· 196 175 end 197 176 198 177 module Thinking = struct 199 - module Unknown = struct 200 - type t = Jsont.json 201 - let empty = Jsont.Object ([], Jsont.Meta.none) 202 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 203 - let jsont = Jsont.json 204 - end 205 - 206 178 type t = { 207 179 thinking : string; 208 180 signature : string; ··· 301 273 Log.debug (fun m -> m "Received content block: %a" pp t) 302 274 303 275 let log_sending t = 304 - Log.debug (fun m -> m "Sending content block: %a" pp t) 276 + Log.debug (fun m -> m "Sending content block: %a" pp t)
+13 -29
claudeio/lib/content_block.mli
··· 11 11 module Text : sig 12 12 (** Plain text content blocks. *) 13 13 14 - module Unknown : sig 15 - type t = Jsont.json 16 - val empty : t 17 - val is_empty : t -> bool 18 - val jsont : t Jsont.t 19 - end 20 - 21 14 type t 22 15 (** The type of text blocks. *) 23 16 ··· 26 19 27 20 val text : t -> string 28 21 (** [text t] returns the text content of the block. *) 22 + 23 + val unknown : t -> Unknown.t 24 + (** [unknown t] returns any unknown fields from JSON parsing. *) 29 25 30 26 val jsont : t Jsont.t 31 27 (** [jsont] is the Jsont codec for text blocks. *) ··· 83 79 (** [of_json json] parses from JSON. Internal use only. *) 84 80 end 85 81 86 - module Unknown : sig 87 - type t = Jsont.json 88 - val empty : t 89 - val is_empty : t -> bool 90 - val jsont : t Jsont.t 91 - end 92 - 93 82 type t 94 83 (** The type of tool use blocks. *) 95 84 ··· 107 96 108 97 val input : t -> Input.t 109 98 (** [input t] returns the input parameters for the tool. *) 99 + 100 + val unknown : t -> Unknown.t 101 + (** [unknown t] returns any unknown fields from JSON parsing. *) 110 102 111 103 val jsont : t Jsont.t 112 104 (** [jsont] is the Jsont codec for tool use blocks. *) ··· 127 119 module Tool_result : sig 128 120 (** Results from tool invocations. *) 129 121 130 - module Unknown : sig 131 - type t = Jsont.json 132 - val empty : t 133 - val is_empty : t -> bool 134 - val jsont : t Jsont.t 135 - end 136 - 137 122 type t 138 123 (** The type of tool result blocks. *) 139 124 ··· 152 137 val is_error : t -> bool option 153 138 (** [is_error t] returns whether this result represents an error. *) 154 139 140 + val unknown : t -> Unknown.t 141 + (** [unknown t] returns any unknown fields from JSON parsing. *) 142 + 155 143 val jsont : t Jsont.t 156 144 (** [jsont] is the Jsont codec for tool result blocks. *) 157 145 ··· 171 159 module Thinking : sig 172 160 (** Assistant's internal reasoning blocks. *) 173 161 174 - module Unknown : sig 175 - type t = Jsont.json 176 - val empty : t 177 - val is_empty : t -> bool 178 - val jsont : t Jsont.t 179 - end 180 - 181 162 type t 182 163 (** The type of thinking blocks. *) 183 164 ··· 191 172 192 173 val signature : t -> string 193 174 (** [signature t] returns the cryptographic signature. *) 175 + 176 + val unknown : t -> Unknown.t 177 + (** [unknown t] returns any unknown fields from JSON parsing. *) 194 178 195 179 val jsont : t Jsont.t 196 180 (** [jsont] is the Jsont codec for thinking blocks. *) ··· 246 230 (** [log_received t] logs that a content block was received. *) 247 231 248 232 val log_sending : t -> unit 249 - (** [log_sending t] logs that a content block is being sent. *) 233 + (** [log_sending t] logs that a content block is being sent. *)
-7
claudeio/lib/control.ml
··· 9 9 in 10 10 Fmt.string fmt s 11 11 12 - module Unknown = struct 13 - type t = Jsont.json 14 - let empty = Jsont.Object ([], Jsont.Meta.none) 15 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 16 - let jsont = Jsont.json 17 - end 18 - 19 12 type t = { 20 13 request_id : string; 21 14 subtype : string;
-8
claudeio/lib/control.mli
··· 7 7 (** The log source for control message operations *) 8 8 val src : Logs.Src.t 9 9 10 - (** Unknown field preservation *) 11 - module Unknown : sig 12 - type t = Jsont.json 13 - val empty : t 14 - val is_empty : t -> bool 15 - val jsont : t Jsont.t 16 - end 17 - 18 10 type t 19 11 (** The type of control messages. *) 20 12
+22 -99
claudeio/lib/hooks.ml
··· 39 39 40 40 (** Context provided to hook callbacks *) 41 41 module Context = struct 42 - module Unknown = struct 43 - type t = Jsont.json 44 - let empty = Jsont.Object ([], Jsont.Meta.none) 45 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 46 - let jsont = Jsont.json 47 - end 48 - 49 42 type t = { 50 43 signal: unit option; (* Future: abort signal support *) 51 44 unknown : Unknown.t; ··· 75 68 ] 76 69 77 70 (** Generic hook result *) 78 - module Result_unknown = struct 79 - type t = Jsont.json 80 - let empty = Jsont.Object ([], Jsont.Meta.none) 81 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 82 - let jsont = Jsont.json 83 - end 84 - 85 71 type result = { 86 72 decision: decision option; 87 73 system_message: string option; 88 74 hook_specific_output: Jsont.json option; 89 - unknown : Result_unknown.t; 75 + unknown : Unknown.t; 90 76 } 91 77 92 78 let result_jsont : result Jsont.t = ··· 102 88 103 89 (** {1 PreToolUse Hook} *) 104 90 module PreToolUse = struct 105 - module Input_unknown = struct 106 - type t = Jsont.json 107 - let empty = Jsont.Object ([], Jsont.Meta.none) 108 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 109 - let jsont = Jsont.json 110 - end 111 - 112 91 type input = { 113 92 session_id: string; 114 93 transcript_path: string; 115 94 tool_name: string; 116 95 tool_input: Jsont.json; 117 - unknown : Input_unknown.t; 96 + unknown : Unknown.t; 118 97 } 119 98 120 99 type t = input ··· 151 130 "ask", `Ask; 152 131 ] 153 132 154 - module Output_unknown = struct 155 - type t = Jsont.json 156 - let empty = Jsont.Object ([], Jsont.Meta.none) 157 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 158 - let jsont = Jsont.json 159 - end 160 - 161 133 type output = { 162 134 permission_decision: permission_decision option; 163 135 permission_decision_reason: string option; 164 136 updated_input: Jsont.json option; 165 - unknown : Output_unknown.t; 137 + unknown : Unknown.t; 166 138 } 167 139 168 140 let output_jsont : output Jsont.t = ··· 181 153 | Ok json -> json 182 154 | Error msg -> failwith ("PreToolUse.output_to_json: " ^ msg) 183 155 184 - let allow ?reason ?updated_input ?(unknown = Output_unknown.empty) () = 156 + let allow ?reason ?updated_input ?(unknown = Unknown.empty) () = 185 157 { permission_decision = Some `Allow; permission_decision_reason = reason; 186 158 updated_input; unknown } 187 159 188 - let deny ?reason ?(unknown = Output_unknown.empty) () = 160 + let deny ?reason ?(unknown = Unknown.empty) () = 189 161 { permission_decision = Some `Deny; permission_decision_reason = reason; 190 162 updated_input = None; unknown } 191 163 192 - let ask ?reason ?(unknown = Output_unknown.empty) () = 164 + let ask ?reason ?(unknown = Unknown.empty) () = 193 165 { permission_decision = Some `Ask; permission_decision_reason = reason; 194 166 updated_input = None; unknown } 195 167 196 - let continue ?(unknown = Output_unknown.empty) () = 168 + let continue ?(unknown = Unknown.empty) () = 197 169 { permission_decision = None; permission_decision_reason = None; 198 170 updated_input = None; unknown } 199 171 end 200 172 201 173 (** {1 PostToolUse Hook} *) 202 174 module PostToolUse = struct 203 - module Input_unknown = struct 204 - type t = Jsont.json 205 - let empty = Jsont.Object ([], Jsont.Meta.none) 206 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 207 - let jsont = Jsont.json 208 - end 209 - 210 175 type input = { 211 176 session_id: string; 212 177 transcript_path: string; 213 178 tool_name: string; 214 179 tool_input: Jsont.json; 215 180 tool_response: Jsont.json; 216 - unknown : Input_unknown.t; 181 + unknown : Unknown.t; 217 182 } 218 183 219 184 type t = input ··· 243 208 | Ok v -> v 244 209 | Error msg -> raise (Invalid_argument ("PostToolUse: " ^ msg)) 245 210 246 - module Output_unknown = struct 247 - type t = Jsont.json 248 - let empty = Jsont.Object ([], Jsont.Meta.none) 249 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 250 - let jsont = Jsont.json 251 - end 252 - 253 211 type output = { 254 212 decision: decision option; 255 213 reason: string option; 256 214 additional_context: string option; 257 - unknown : Output_unknown.t; 215 + unknown : Unknown.t; 258 216 } 259 217 260 218 let output_jsont : output Jsont.t = ··· 273 231 | Ok json -> json 274 232 | Error msg -> failwith ("PostToolUse.output_to_json: " ^ msg) 275 233 276 - let continue ?additional_context ?(unknown = Output_unknown.empty) () = 234 + let continue ?additional_context ?(unknown = Unknown.empty) () = 277 235 { decision = None; reason = None; additional_context; unknown } 278 236 279 - let block ?reason ?additional_context ?(unknown = Output_unknown.empty) () = 237 + let block ?reason ?additional_context ?(unknown = Unknown.empty) () = 280 238 { decision = Some Block; reason; additional_context; unknown } 281 239 end 282 240 283 241 (** {1 UserPromptSubmit Hook} *) 284 242 module UserPromptSubmit = struct 285 - module Input_unknown = struct 286 - type t = Jsont.json 287 - let empty = Jsont.Object ([], Jsont.Meta.none) 288 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 289 - let jsont = Jsont.json 290 - end 291 - 292 243 type input = { 293 244 session_id: string; 294 245 transcript_path: string; 295 246 prompt: string; 296 - unknown : Input_unknown.t; 247 + unknown : Unknown.t; 297 248 } 298 249 299 250 type t = input ··· 319 270 | Ok v -> v 320 271 | Error msg -> raise (Invalid_argument ("UserPromptSubmit: " ^ msg)) 321 272 322 - module Output_unknown = struct 323 - type t = Jsont.json 324 - let empty = Jsont.Object ([], Jsont.Meta.none) 325 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 326 - let jsont = Jsont.json 327 - end 328 - 329 273 type output = { 330 274 decision: decision option; 331 275 reason: string option; 332 276 additional_context: string option; 333 - unknown : Output_unknown.t; 277 + unknown : Unknown.t; 334 278 } 335 279 336 280 let output_jsont : output Jsont.t = ··· 349 293 | Ok json -> json 350 294 | Error msg -> failwith ("UserPromptSubmit.output_to_json: " ^ msg) 351 295 352 - let continue ?additional_context ?(unknown = Output_unknown.empty) () = 296 + let continue ?additional_context ?(unknown = Unknown.empty) () = 353 297 { decision = None; reason = None; additional_context; unknown } 354 298 355 - let block ?reason ?(unknown = Output_unknown.empty) () = 299 + let block ?reason ?(unknown = Unknown.empty) () = 356 300 { decision = Some Block; reason; additional_context = None; unknown } 357 301 end 358 302 359 303 (** {1 Stop Hook} *) 360 304 module Stop = struct 361 - module Input_unknown = struct 362 - type t = Jsont.json 363 - let empty = Jsont.Object ([], Jsont.Meta.none) 364 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 365 - let jsont = Jsont.json 366 - end 367 - 368 305 type input = { 369 306 session_id: string; 370 307 transcript_path: string; 371 308 stop_hook_active: bool; 372 - unknown : Input_unknown.t; 309 + unknown : Unknown.t; 373 310 } 374 311 375 312 type t = input ··· 395 332 | Ok v -> v 396 333 | Error msg -> raise (Invalid_argument ("Stop: " ^ msg)) 397 334 398 - module Output_unknown = struct 399 - type t = Jsont.json 400 - let empty = Jsont.Object ([], Jsont.Meta.none) 401 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 402 - let jsont = Jsont.json 403 - end 404 - 405 335 type output = { 406 336 decision: decision option; 407 337 reason: string option; 408 - unknown : Output_unknown.t; 338 + unknown : Unknown.t; 409 339 } 410 340 411 341 let output_jsont : output Jsont.t = ··· 423 353 | Ok json -> json 424 354 | Error msg -> failwith ("Stop.output_to_json: " ^ msg) 425 355 426 - let continue ?(unknown = Output_unknown.empty) () = { decision = None; reason = None; unknown } 427 - let block ?reason ?(unknown = Output_unknown.empty) () = { decision = Some Block; reason; unknown } 356 + let continue ?(unknown = Unknown.empty) () = { decision = None; reason = None; unknown } 357 + let block ?reason ?(unknown = Unknown.empty) () = { decision = Some Block; reason; unknown } 428 358 end 429 359 430 360 (** {1 SubagentStop Hook} - Same structure as Stop *) ··· 434 364 435 365 (** {1 PreCompact Hook} *) 436 366 module PreCompact = struct 437 - module Input_unknown = struct 438 - type t = Jsont.json 439 - let empty = Jsont.Object ([], Jsont.Meta.none) 440 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 441 - let jsont = Jsont.json 442 - end 443 - 444 367 type input = { 445 368 session_id: string; 446 369 transcript_path: string; 447 - unknown : Input_unknown.t; 370 + unknown : Unknown.t; 448 371 } 449 372 450 373 type t = input ··· 491 414 type config = (event * matcher list) list 492 415 493 416 (** {1 Result Builders} *) 494 - let continue ?system_message ?hook_specific_output ?(unknown = Result_unknown.empty) () = 417 + let continue ?system_message ?hook_specific_output ?(unknown = Unknown.empty) () = 495 418 { decision = None; system_message; hook_specific_output; unknown } 496 419 497 - let block ?system_message ?hook_specific_output ?(unknown = Result_unknown.empty) () = 420 + let block ?system_message ?hook_specific_output ?(unknown = Unknown.empty) () = 498 421 { decision = Some Block; system_message; hook_specific_output; unknown } 499 422 500 423 (** {1 Matcher Builders} *)
+27 -104
claudeio/lib/hooks.mli
··· 73 73 (** {1 Context} *) 74 74 75 75 module Context : sig 76 - module Unknown : sig 77 - type t = Jsont.json 78 - val empty : t 79 - val is_empty : t -> bool 80 - val jsont : t Jsont.t 81 - end 82 - 83 76 type t = { 84 77 signal: unit option; 85 78 unknown : Unknown.t; ··· 101 94 102 95 (** {1 Generic Hook Result} *) 103 96 104 - module Result_unknown : sig 105 - type t = Jsont.json 106 - val empty : t 107 - val is_empty : t -> bool 108 - val jsont : t Jsont.t 109 - end 110 - 111 97 (** Generic result structure for hooks *) 112 98 type result = { 113 99 decision: decision option; 114 100 system_message: string option; 115 101 hook_specific_output: Jsont.json option; 116 - unknown: Result_unknown.t; 102 + unknown: Unknown.t; 117 103 } 118 104 119 105 val result_jsont : result Jsont.t ··· 122 108 123 109 (** PreToolUse hook - fires before tool execution *) 124 110 module PreToolUse : sig 125 - module Input_unknown : sig 126 - type t = Jsont.json 127 - val empty : t 128 - val is_empty : t -> bool 129 - val jsont : t Jsont.t 130 - end 131 - 132 111 (** Typed input for PreToolUse hooks *) 133 112 type input = { 134 113 session_id: string; 135 114 transcript_path: string; 136 115 tool_name: string; 137 116 tool_input: Jsont.json; 138 - unknown: Input_unknown.t; 117 + unknown: Unknown.t; 139 118 } 140 119 141 120 type t = input ··· 148 127 val transcript_path : t -> string 149 128 val tool_name : t -> string 150 129 val tool_input : t -> Jsont.json 151 - val unknown : t -> Input_unknown.t 130 + val unknown : t -> Unknown.t 152 131 153 132 val input_jsont : input Jsont.t 154 133 ··· 157 136 158 137 val permission_decision_jsont : permission_decision Jsont.t 159 138 160 - module Output_unknown : sig 161 - type t = Jsont.json 162 - val empty : t 163 - val is_empty : t -> bool 164 - val jsont : t Jsont.t 165 - end 166 - 167 139 (** Typed output for PreToolUse hooks *) 168 140 type output = { 169 141 permission_decision: permission_decision option; 170 142 permission_decision_reason: string option; 171 143 updated_input: Jsont.json option; 172 - unknown: Output_unknown.t; 144 + unknown: Unknown.t; 173 145 } 174 146 175 147 val output_jsont : output Jsont.t 176 148 177 149 (** {2 Response Builders} *) 178 - val allow : ?reason:string -> ?updated_input:Jsont.json -> ?unknown:Output_unknown.t -> unit -> output 179 - val deny : ?reason:string -> ?unknown:Output_unknown.t -> unit -> output 180 - val ask : ?reason:string -> ?unknown:Output_unknown.t -> unit -> output 181 - val continue : ?unknown:Output_unknown.t -> unit -> output 150 + val allow : ?reason:string -> ?updated_input:Jsont.json -> ?unknown:Unknown.t -> unit -> output 151 + val deny : ?reason:string -> ?unknown:Unknown.t -> unit -> output 152 + val ask : ?reason:string -> ?unknown:Unknown.t -> unit -> output 153 + val continue : ?unknown:Unknown.t -> unit -> output 182 154 183 155 (** Convert output to JSON for hook_specific_output *) 184 156 val output_to_json : output -> Jsont.json ··· 186 158 187 159 (** PostToolUse hook - fires after tool execution *) 188 160 module PostToolUse : sig 189 - module Input_unknown : sig 190 - type t = Jsont.json 191 - val empty : t 192 - val is_empty : t -> bool 193 - val jsont : t Jsont.t 194 - end 195 - 196 161 type input = { 197 162 session_id: string; 198 163 transcript_path: string; 199 164 tool_name: string; 200 165 tool_input: Jsont.json; 201 166 tool_response: Jsont.json; 202 - unknown: Input_unknown.t; 167 + unknown: Unknown.t; 203 168 } 204 169 205 170 type t = input ··· 211 176 val tool_name : t -> string 212 177 val tool_input : t -> Jsont.json 213 178 val tool_response : t -> Jsont.json 214 - val unknown : t -> Input_unknown.t 179 + val unknown : t -> Unknown.t 215 180 216 181 val input_jsont : input Jsont.t 217 182 218 - module Output_unknown : sig 219 - type t = Jsont.json 220 - val empty : t 221 - val is_empty : t -> bool 222 - val jsont : t Jsont.t 223 - end 224 - 225 183 type output = { 226 184 decision: decision option; 227 185 reason: string option; 228 186 additional_context: string option; 229 - unknown: Output_unknown.t; 187 + unknown: Unknown.t; 230 188 } 231 189 232 190 val output_jsont : output Jsont.t 233 191 234 - val continue : ?additional_context:string -> ?unknown:Output_unknown.t -> unit -> output 235 - val block : ?reason:string -> ?additional_context:string -> ?unknown:Output_unknown.t -> unit -> output 192 + val continue : ?additional_context:string -> ?unknown:Unknown.t -> unit -> output 193 + val block : ?reason:string -> ?additional_context:string -> ?unknown:Unknown.t -> unit -> output 236 194 val output_to_json : output -> Jsont.json 237 195 end 238 196 239 197 (** UserPromptSubmit hook - fires when user submits a prompt *) 240 198 module UserPromptSubmit : sig 241 - module Input_unknown : sig 242 - type t = Jsont.json 243 - val empty : t 244 - val is_empty : t -> bool 245 - val jsont : t Jsont.t 246 - end 247 - 248 199 type input = { 249 200 session_id: string; 250 201 transcript_path: string; 251 202 prompt: string; 252 - unknown: Input_unknown.t; 203 + unknown: Unknown.t; 253 204 } 254 205 255 206 type t = input ··· 259 210 val session_id : t -> string 260 211 val transcript_path : t -> string 261 212 val prompt : t -> string 262 - val unknown : t -> Input_unknown.t 213 + val unknown : t -> Unknown.t 263 214 264 215 val input_jsont : input Jsont.t 265 216 266 - module Output_unknown : sig 267 - type t = Jsont.json 268 - val empty : t 269 - val is_empty : t -> bool 270 - val jsont : t Jsont.t 271 - end 272 - 273 217 type output = { 274 218 decision: decision option; 275 219 reason: string option; 276 220 additional_context: string option; 277 - unknown: Output_unknown.t; 221 + unknown: Unknown.t; 278 222 } 279 223 280 224 val output_jsont : output Jsont.t 281 225 282 - val continue : ?additional_context:string -> ?unknown:Output_unknown.t -> unit -> output 283 - val block : ?reason:string -> ?unknown:Output_unknown.t -> unit -> output 226 + val continue : ?additional_context:string -> ?unknown:Unknown.t -> unit -> output 227 + val block : ?reason:string -> ?unknown:Unknown.t -> unit -> output 284 228 val output_to_json : output -> Jsont.json 285 229 end 286 230 287 231 (** Stop hook - fires when conversation stops *) 288 232 module Stop : sig 289 - module Input_unknown : sig 290 - type t = Jsont.json 291 - val empty : t 292 - val is_empty : t -> bool 293 - val jsont : t Jsont.t 294 - end 295 - 296 233 type input = { 297 234 session_id: string; 298 235 transcript_path: string; 299 236 stop_hook_active: bool; 300 - unknown: Input_unknown.t; 237 + unknown: Unknown.t; 301 238 } 302 239 303 240 type t = input ··· 307 244 val session_id : t -> string 308 245 val transcript_path : t -> string 309 246 val stop_hook_active : t -> bool 310 - val unknown : t -> Input_unknown.t 247 + val unknown : t -> Unknown.t 311 248 312 249 val input_jsont : input Jsont.t 313 250 314 - module Output_unknown : sig 315 - type t = Jsont.json 316 - val empty : t 317 - val is_empty : t -> bool 318 - val jsont : t Jsont.t 319 - end 320 - 321 251 type output = { 322 252 decision: decision option; 323 253 reason: string option; 324 - unknown: Output_unknown.t; 254 + unknown: Unknown.t; 325 255 } 326 256 327 257 val output_jsont : output Jsont.t 328 258 329 - val continue : ?unknown:Output_unknown.t -> unit -> output 330 - val block : ?reason:string -> ?unknown:Output_unknown.t -> unit -> output 259 + val continue : ?unknown:Unknown.t -> unit -> output 260 + val block : ?reason:string -> ?unknown:Unknown.t -> unit -> output 331 261 val output_to_json : output -> Jsont.json 332 262 end 333 263 ··· 339 269 340 270 (** PreCompact hook - fires before message compaction *) 341 271 module PreCompact : sig 342 - module Input_unknown : sig 343 - type t = Jsont.json 344 - val empty : t 345 - val is_empty : t -> bool 346 - val jsont : t Jsont.t 347 - end 348 - 349 272 type input = { 350 273 session_id: string; 351 274 transcript_path: string; 352 - unknown: Input_unknown.t; 275 + unknown: Unknown.t; 353 276 } 354 277 355 278 type t = input ··· 360 283 361 284 val session_id : t -> string 362 285 val transcript_path : t -> string 363 - val unknown : t -> Input_unknown.t 286 + val unknown : t -> Unknown.t 364 287 365 288 val input_jsont : input Jsont.t 366 289 ··· 399 322 (** {1 Generic Result Builders} *) 400 323 401 324 (** [continue ?system_message ?hook_specific_output ?unknown ()] creates a continue result *) 402 - val continue : ?system_message:string -> ?hook_specific_output:Jsont.json -> ?unknown:Result_unknown.t -> unit -> result 325 + val continue : ?system_message:string -> ?hook_specific_output:Jsont.json -> ?unknown:Unknown.t -> unit -> result 403 326 404 327 (** [block ?system_message ?hook_specific_output ?unknown ()] creates a block result *) 405 - val block : ?system_message:string -> ?hook_specific_output:Jsont.json -> ?unknown:Result_unknown.t -> unit -> result 328 + val block : ?system_message:string -> ?hook_specific_output:Jsont.json -> ?unknown:Unknown.t -> unit -> result 406 329 407 330 (** {1 Configuration Builders} *) 408 331
+82 -199
claudeio/lib/message.ml
··· 7 7 | String of string 8 8 | Blocks of Content_block.t list 9 9 10 - module Unknown = struct 11 - type t = Jsont.json 12 - let empty = Jsont.Object ([], Jsont.Meta.none) 13 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 14 - let jsont = Jsont.json 15 - end 16 - 17 10 type t = { 18 11 content : content; 19 12 unknown : Unknown.t; ··· 173 166 ("unknown", `Unknown); 174 167 ] 175 168 176 - module Unknown = struct 177 - type t = Jsont.json 178 - let empty = Jsont.Object ([], Jsont.Meta.none) 179 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 180 - let jsont = Jsont.json 181 - end 182 - 183 169 type t = { 184 170 content : Content_block.t list; 185 171 model : string; ··· 287 273 end 288 274 289 275 module System = struct 290 - (** Typed data for system init messages *) 291 - module Init = struct 292 - module Unknown = struct 293 - type t = Jsont.json 294 - let empty = Jsont.Object ([], Jsont.Meta.none) 295 - let _jsont = Jsont.json 296 - end 276 + (** System messages as a discriminated union on "subtype" field *) 297 277 298 - type t = { 299 - session_id : string option; 300 - model : string option; 301 - cwd : string option; 302 - unknown : Unknown.t; 303 - } 278 + type init = { 279 + session_id : string option; 280 + model : string option; 281 + cwd : string option; 282 + unknown : Unknown.t; 283 + } 304 284 305 - let make session_id model cwd unknown = { session_id; model; cwd; unknown } 306 - 307 - let create ?session_id ?model ?cwd () = 308 - { session_id; model; cwd; unknown = Unknown.empty } 309 - 310 - let session_id t = t.session_id 311 - let model t = t.model 312 - let cwd t = t.cwd 313 - let unknown t = t.unknown 285 + type error = { 286 + error : string; 287 + unknown : Unknown.t; 288 + } 314 289 315 - let jsont : t Jsont.t = 316 - Jsont.Object.map ~kind:"SystemInit" make 317 - |> Jsont.Object.opt_mem "session_id" Jsont.string ~enc:session_id 318 - |> Jsont.Object.opt_mem "model" Jsont.string ~enc:model 319 - |> Jsont.Object.opt_mem "cwd" Jsont.string ~enc:cwd 320 - |> Jsont.Object.keep_unknown Jsont.json_mems ~enc:unknown 321 - |> Jsont.Object.finish 322 - end 323 - 324 - (** Typed data for system error messages *) 325 - module Error = struct 326 - module Unknown = struct 327 - type t = Jsont.json 328 - let empty = Jsont.Object ([], Jsont.Meta.none) 329 - let _jsont = Jsont.json 330 - end 331 - 332 - type t = { 333 - error : string; 334 - unknown : Unknown.t; 335 - } 336 - 337 - let make error unknown = { error; unknown } 338 - 339 - let create ~error = { error; unknown = Unknown.empty } 340 - 341 - let error t = t.error 342 - let unknown t = t.unknown 343 - 344 - let jsont : t Jsont.t = 345 - Jsont.Object.map ~kind:"SystemError" make 346 - |> Jsont.Object.mem "error" Jsont.string ~enc:error 347 - |> Jsont.Object.keep_unknown Jsont.json_mems ~enc:unknown 348 - |> Jsont.Object.finish 349 - end 350 - 351 - (** Sum type for system message data *) 352 - module Data = struct 353 - type t = 354 - | Init of Init.t 355 - | Error of Error.t 356 - | Other of Jsont.json (** Unknown subtypes preserve raw JSON *) 357 - 358 - let init ?session_id ?model ?cwd () = Init (Init.create ?session_id ?model ?cwd ()) 359 - let error ~error = Error (Error.create ~error) 360 - let other json = Other json 361 - 362 - let session_id = function 363 - | Init i -> Init.session_id i 364 - | _ -> None 365 - 366 - let model = function 367 - | Init i -> Init.model i 368 - | _ -> None 369 - 370 - let cwd = function 371 - | Init i -> Init.cwd i 372 - | _ -> None 373 - 374 - let error_msg = function 375 - | Error e -> Some (Error.error e) 376 - | _ -> None 377 - 378 - let to_json = function 379 - | Init i -> 380 - (match Jsont.Json.encode Init.jsont i with 381 - | Ok json -> json 382 - | Error msg -> failwith ("Init.to_json: " ^ msg)) 383 - | Error e -> 384 - (match Jsont.Json.encode Error.jsont e with 385 - | Ok json -> json 386 - | Error msg -> failwith ("Error.to_json: " ^ msg)) 387 - | Other json -> json 388 - 389 - let of_json ~subtype json = 390 - match subtype with 391 - | "init" -> 392 - (match Jsont.Json.decode Init.jsont json with 393 - | Ok i -> Init i 394 - | Error _ -> Other json) 395 - | "error" -> 396 - (match Jsont.Json.decode Error.jsont json with 397 - | Ok e -> Error e 398 - | Error _ -> Other json) 399 - | _ -> Other json 400 - end 401 - 402 - module Unknown = struct 403 - type t = Jsont.json 404 - let empty = Jsont.Object ([], Jsont.Meta.none) 405 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 406 - let jsont = Jsont.json 407 - end 408 - 409 - type t = { 290 + type other = { 410 291 subtype : string; 411 - data : Data.t; 412 292 unknown : Unknown.t; 413 293 } 414 294 415 - let create ~subtype ~data = { subtype; data; unknown = Unknown.empty } 416 - let subtype t = t.subtype 417 - let data t = t.data 418 - let unknown t = t.unknown 295 + type t = 296 + | Init of init 297 + | Error of error 298 + | Other of other 299 + 300 + (* Accessors *) 301 + let session_id = function Init i -> i.session_id | _ -> None 302 + let model = function Init i -> i.model | _ -> None 303 + let cwd = function Init i -> i.cwd | _ -> None 304 + let error_msg = function Error e -> Some e.error | _ -> None 305 + let subtype = function Init _ -> "init" | Error _ -> "error" | Other o -> o.subtype 306 + let unknown = function 307 + | Init i -> i.unknown 308 + | Error e -> e.unknown 309 + | Other o -> o.unknown 419 310 420 - (** Create a system init message *) 311 + (* Constructors *) 421 312 let init ?session_id ?model ?cwd () = 422 - { subtype = "init"; 423 - data = Data.init ?session_id ?model ?cwd (); 424 - unknown = Unknown.empty } 313 + Init { session_id; model; cwd; unknown = Unknown.empty } 425 314 426 - (** Create a system error message *) 427 315 let error ~error = 428 - { subtype = "error"; 429 - data = Data.error ~error; 430 - unknown = Unknown.empty } 316 + Error { error; unknown = Unknown.empty } 431 317 432 - (* Custom jsont that handles both formats: 433 - - Old format: {"type":"system","subtype":"init","data":{...}} 434 - - New format: {"type":"system","subtype":"init","cwd":"...","session_id":"...",...} 435 - When data field is not present, we use the entire object as data *) 318 + let other ~subtype = 319 + Other { subtype; unknown = Unknown.empty } 320 + 321 + (* Individual record codecs *) 322 + let init_jsont : init Jsont.t = 323 + let make session_id model cwd unknown : init = { session_id; model; cwd; unknown } in 324 + Jsont.Object.map ~kind:"SystemInit" make 325 + |> Jsont.Object.opt_mem "session_id" Jsont.string ~enc:(fun (r : init) -> r.session_id) 326 + |> Jsont.Object.opt_mem "model" Jsont.string ~enc:(fun (r : init) -> r.model) 327 + |> Jsont.Object.opt_mem "cwd" Jsont.string ~enc:(fun (r : init) -> r.cwd) 328 + |> Jsont.Object.keep_unknown Jsont.json_mems ~enc:(fun (r : init) -> r.unknown) 329 + |> Jsont.Object.finish 330 + 331 + let error_jsont : error Jsont.t = 332 + let make err unknown : error = { error = err; unknown } in 333 + Jsont.Object.map ~kind:"SystemError" make 334 + |> Jsont.Object.mem "error" Jsont.string ~enc:(fun (r : error) -> r.error) 335 + |> Jsont.Object.keep_unknown Jsont.json_mems ~enc:(fun (r : error) -> r.unknown) 336 + |> Jsont.Object.finish 337 + 338 + (* Main codec using case_mem for "subtype" discriminator *) 436 339 let jsont : t Jsont.t = 437 - let dec json = 438 - (* First decode just the subtype *) 439 - let subtype_codec = Jsont.Object.map ~kind:"SystemSubtype" Fun.id 440 - |> Jsont.Object.mem "subtype" Jsont.string ~enc:Fun.id 340 + let case_init = Jsont.Object.Case.map "init" init_jsont ~dec:(fun v -> Init v) in 341 + let case_error = Jsont.Object.Case.map "error" error_jsont ~dec:(fun v -> Error v) in 342 + let case_other tag = 343 + (* For unknown subtypes, create Other with the tag as subtype *) 344 + let other_codec : other Jsont.t = 345 + let make unknown : other = { subtype = tag; unknown } in 346 + Jsont.Object.map ~kind:"SystemOther" make 347 + |> Jsont.Object.keep_unknown Jsont.json_mems ~enc:(fun (r : other) -> r.unknown) 441 348 |> Jsont.Object.finish 442 349 in 443 - match Jsont.Json.decode subtype_codec json with 444 - | Error msg -> failwith ("System.jsont: " ^ msg) 445 - | Ok subtype -> 446 - (* Try to get data field, otherwise use full object *) 447 - let data_codec = Jsont.Object.map ~kind:"SystemDataField" Fun.id 448 - |> Jsont.Object.opt_mem "data" Jsont.json ~enc:Fun.id 449 - |> Jsont.Object.finish 450 - in 451 - let data_json = match Jsont.Json.decode data_codec json with 452 - | Ok (Some d) -> d 453 - | _ -> json 454 - in 455 - let data = Data.of_json ~subtype data_json in 456 - { subtype; data; unknown = Unknown.empty } 350 + Jsont.Object.Case.map tag other_codec ~dec:(fun v -> Other v) 457 351 in 458 - let enc t = 459 - Jsont.Json.object' [ 460 - Jsont.Json.mem (Jsont.Json.name "type") (Jsont.Json.string "system"); 461 - Jsont.Json.mem (Jsont.Json.name "subtype") (Jsont.Json.string t.subtype); 462 - Jsont.Json.mem (Jsont.Json.name "data") (Data.to_json t.data); 463 - ] 352 + let enc_case = function 353 + | Init v -> Jsont.Object.Case.value case_init v 354 + | Error v -> Jsont.Object.Case.value case_error v 355 + | Other v -> Jsont.Object.Case.value (case_other v.subtype) v 464 356 in 465 - Jsont.map ~kind:"System" ~dec ~enc Jsont.json 357 + let cases = Jsont.Object.Case.[ 358 + make case_init; 359 + make case_error; 360 + ] in 361 + Jsont.Object.map ~kind:"System" Fun.id 362 + |> Jsont.Object.case_mem "subtype" Jsont.string ~enc:Fun.id ~enc_case cases 363 + ~tag_to_string:Fun.id ~tag_compare:String.compare 364 + |> Jsont.Object.finish 466 365 467 366 let to_json t = 468 367 match Jsont.Json.encode jsont t with ··· 474 373 | Ok v -> v 475 374 | Error msg -> raise (Invalid_argument ("System.of_json: " ^ msg)) 476 375 477 - let pp fmt t = 478 - match t.data with 479 - | Data.Init i -> 376 + let pp fmt = function 377 + | Init i -> 480 378 Fmt.pf fmt "@[<2>System.init@ { session_id = %a;@ model = %a;@ cwd = %a }@]" 481 - Fmt.(option string) (Init.session_id i) 482 - Fmt.(option string) (Init.model i) 483 - Fmt.(option string) (Init.cwd i) 484 - | Data.Error e -> 485 - Fmt.pf fmt "@[<2>System.error@ { error = %s }@]" (Error.error e) 486 - | Data.Other _ -> 487 - Fmt.pf fmt "@[<2>System.%s@ { ... }@]" t.subtype 379 + Fmt.(option string) i.session_id 380 + Fmt.(option string) i.model 381 + Fmt.(option string) i.cwd 382 + | Error e -> 383 + Fmt.pf fmt "@[<2>System.error@ { error = %s }@]" e.error 384 + | Other o -> 385 + Fmt.pf fmt "@[<2>System.%s@ { ... }@]" o.subtype 488 386 end 489 387 490 388 module Result = struct 491 389 module Usage = struct 492 - module Unknown = struct 493 - type t = Jsont.json 494 - let empty = Jsont.Object ([], Jsont.Meta.none) 495 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 496 - let jsont = Jsont.json 497 - end 498 - 499 390 type t = { 500 391 input_tokens : int option; 501 392 output_tokens : int option; ··· 568 459 | Error msg -> raise (Invalid_argument ("Usage.of_json: " ^ msg)) 569 460 end 570 461 571 - module Unknown = struct 572 - type t = Jsont.json 573 - let empty = Jsont.Object ([], Jsont.Meta.none) 574 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 575 - let jsont = Jsont.json 576 - end 577 - 578 462 type t = { 579 463 subtype : string; 580 464 duration_ms : int; ··· 700 584 let assistant_text ~text ~model ?error () = 701 585 Assistant (Assistant.create ~content:[Content_block.text text] ~model ?error ()) 702 586 703 - let system ~subtype ~data = System (System.create ~subtype ~data) 704 587 let system_init ~session_id = 705 588 System (System.init ~session_id ()) 706 589 let system_error ~error = ··· 775 658 | _ -> [] 776 659 777 660 let get_session_id = function 778 - | System s -> System.Data.session_id (System.data s) 661 + | System s -> System.session_id s 779 662 | Result r -> Some (Result.session_id r) 780 663 | _ -> None 781 664
+53 -122
claudeio/lib/message.mli
··· 17 17 | Blocks of Content_block.t list (** Complex message with multiple content blocks *) 18 18 (** The content of a user message. *) 19 19 20 - module Unknown : sig 21 - type t = Jsont.json 22 - val empty : t 23 - val is_empty : t -> bool 24 - val jsont : t Jsont.t 25 - end 26 - 27 20 type t 28 21 (** The type of user messages. *) 29 22 ··· 92 85 val error_of_string : string -> error 93 86 (** [error_of_string s] parses an error string. Unknown strings become [`Unknown]. *) 94 87 95 - module Unknown : sig 96 - type t = Jsont.json 97 - val empty : t 98 - val is_empty : t -> bool 99 - val jsont : t Jsont.t 100 - end 101 - 102 88 type t 103 89 (** The type of assistant messages. *) 104 90 ··· 152 138 (** {1 System Messages} *) 153 139 154 140 module System : sig 155 - (** System control and status messages. *) 141 + (** System control and status messages. 156 142 157 - (** Typed data for system init messages *) 158 - module Init : sig 159 - type t 160 - (** Type of init message data. *) 143 + System messages use a discriminated union on the "subtype" field: 144 + - "init": Session initialization with session_id, model, cwd 145 + - "error": Error messages with error string 146 + - Other subtypes are preserved as [Other] *) 161 147 162 - val create : ?session_id:string -> ?model:string -> ?cwd:string -> unit -> t 163 - (** [create ?session_id ?model ?cwd ()] creates init data. *) 148 + type init = { 149 + session_id : string option; 150 + model : string option; 151 + cwd : string option; 152 + unknown : Unknown.t; 153 + } 154 + (** Init message fields. *) 164 155 165 - val session_id : t -> string option 166 - (** [session_id t] returns the session ID if present. *) 156 + type error = { 157 + error : string; 158 + unknown : Unknown.t; 159 + } 160 + (** Error message fields. *) 167 161 168 - val model : t -> string option 169 - (** [model t] returns the model name if present. *) 162 + type other = { 163 + subtype : string; 164 + unknown : Unknown.t; 165 + } 166 + (** Unknown subtype fields. *) 170 167 171 - val cwd : t -> string option 172 - (** [cwd t] returns the current working directory if present. *) 168 + type t = 169 + | Init of init 170 + | Error of error 171 + | Other of other 172 + (** The type of system messages. *) 173 173 174 - val jsont : t Jsont.t 175 - (** [jsont] is the Jsont codec for init data. *) 176 - end 174 + val jsont : t Jsont.t 175 + (** [jsont] is the Jsont codec for system messages. *) 177 176 178 - (** Typed data for system error messages *) 179 - module Error : sig 180 - type t 181 - (** Type of error message data. *) 177 + (** {2 Constructors} *) 182 178 183 - val create : error:string -> t 184 - (** [create ~error] creates error data. *) 179 + val init : ?session_id:string -> ?model:string -> ?cwd:string -> unit -> t 180 + (** [init ?session_id ?model ?cwd ()] creates an init message. *) 185 181 186 - val error : t -> string 187 - (** [error t] returns the error message. *) 182 + val error : error:string -> t 183 + (** [error ~error] creates an error message. *) 188 184 189 - val jsont : t Jsont.t 190 - (** [jsont] is the Jsont codec for error data. *) 191 - end 185 + val other : subtype:string -> t 186 + (** [other ~subtype] creates a message with unknown subtype. *) 192 187 193 - (** System message data variants *) 194 - module Data : sig 195 - type t = 196 - | Init of Init.t (** Init message data *) 197 - | Error of Error.t (** Error message data *) 198 - | Other of Jsont.json (** Unknown subtype data *) 199 - (** Variant type for system message data. *) 188 + (** {2 Accessors} *) 200 189 201 - val init : ?session_id:string -> ?model:string -> ?cwd:string -> unit -> t 202 - (** [init ?session_id ?model ?cwd ()] creates init data. *) 203 - 204 - val error : error:string -> t 205 - (** [error ~error] creates error data. *) 206 - 207 - val other : Jsont.json -> t 208 - (** [other json] creates data for unknown subtypes. *) 209 - 210 - val session_id : t -> string option 211 - (** [session_id t] extracts session_id from Init data, None otherwise. *) 212 - 213 - val model : t -> string option 214 - (** [model t] extracts model from Init data, None otherwise. *) 215 - 216 - val cwd : t -> string option 217 - (** [cwd t] extracts cwd from Init data, None otherwise. *) 218 - 219 - val error_msg : t -> string option 220 - (** [error_msg t] extracts error from Error data, None otherwise. *) 221 - 222 - val to_json : t -> Jsont.json 223 - (** [to_json t] converts to JSON representation. *) 190 + val session_id : t -> string option 191 + (** [session_id t] returns session_id from Init, None otherwise. *) 224 192 225 - val of_json : subtype:string -> Jsont.json -> t 226 - (** [of_json ~subtype json] parses data based on subtype. *) 227 - end 228 - 229 - module Unknown : sig 230 - type t = Jsont.json 231 - val empty : t 232 - val is_empty : t -> bool 233 - val jsont : t Jsont.t 234 - end 193 + val model : t -> string option 194 + (** [model t] returns model from Init, None otherwise. *) 235 195 236 - type t 237 - (** The type of system messages. *) 196 + val cwd : t -> string option 197 + (** [cwd t] returns cwd from Init, None otherwise. *) 238 198 239 - val jsont : t Jsont.t 240 - (** [jsont] is the Jsont codec for system messages. *) 241 - 242 - val create : subtype:string -> data:Data.t -> t 243 - (** [create ~subtype ~data] creates a system message. 244 - @param subtype The subtype of the system message 245 - @param data Additional data for the message *) 246 - 247 - val init : ?session_id:string -> ?model:string -> ?cwd:string -> unit -> t 248 - (** [init ?session_id ?model ?cwd ()] creates a system init message. *) 249 - 250 - val error : error:string -> t 251 - (** [error ~error] creates a system error message. *) 199 + val error_msg : t -> string option 200 + (** [error_msg t] returns error from Error, None otherwise. *) 252 201 253 202 val subtype : t -> string 254 - (** [subtype t] returns the subtype of the system message. *) 255 - 256 - val data : t -> Data.t 257 - (** [data t] returns the additional data of the system message. *) 203 + (** [subtype t] returns the subtype string. *) 258 204 259 205 val unknown : t -> Unknown.t 260 - (** [unknown t] returns the unknown fields preserved from JSON. *) 206 + (** [unknown t] returns the unknown fields. *) 207 + 208 + (** {2 Conversion} *) 261 209 262 210 val to_json : t -> Jsont.json 263 - (** [to_json t] converts the system message to its JSON representation. *) 211 + (** [to_json t] converts to JSON representation. *) 264 212 265 213 val of_json : Jsont.json -> t 266 - (** [of_json json] parses a system message from JSON. 267 - @raise Invalid_argument if the JSON is not a valid system message. *) 214 + (** [of_json json] parses from JSON. 215 + @raise Invalid_argument if invalid. *) 268 216 269 217 val pp : Format.formatter -> t -> unit 270 - (** [pp fmt t] pretty-prints the system message. *) 218 + (** [pp fmt t] pretty-prints the message. *) 271 219 end 272 220 273 221 (** {1 Result Messages} *) ··· 277 225 278 226 module Usage : sig 279 227 (** Usage statistics for API calls. *) 280 - 281 - module Unknown : sig 282 - type t = Jsont.json 283 - val empty : t 284 - val is_empty : t -> bool 285 - val jsont : t Jsont.t 286 - end 287 228 288 229 type t 289 230 (** Type for usage statistics. *) ··· 334 275 335 276 val of_json : Jsont.json -> t 336 277 (** [of_json json] parses from JSON. Internal use only. *) 337 - end 338 - 339 - module Unknown : sig 340 - type t = Jsont.json 341 - val empty : t 342 - val is_empty : t -> bool 343 - val jsont : t Jsont.t 344 278 end 345 279 346 280 type t ··· 445 379 446 380 val assistant_text : text:string -> model:string -> ?error:Assistant.error -> unit -> t 447 381 (** [assistant_text ~text ~model ?error ()] creates an assistant message with only text content. *) 448 - 449 - val system : subtype:string -> data:System.Data.t -> t 450 - (** [system ~subtype ~data] creates a system message. *) 451 382 452 383 val system_init : session_id:string -> t 453 384 (** [system_init ~session_id] creates a system init message. *)
-28
claudeio/lib/permissions.ml
··· 68 68 69 69 (** Permission rules *) 70 70 module Rule = struct 71 - module Unknown = struct 72 - type t = Jsont.json 73 - let empty = Jsont.Object ([], Jsont.Meta.none) 74 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 75 - let jsont = Jsont.json 76 - end 77 - 78 71 type t = { 79 72 tool_name : string; 80 73 rule_content : string option; ··· 163 156 "addDirectories", Add_directories; 164 157 "removeDirectories", Remove_directories; 165 158 ] 166 - 167 - module Unknown = struct 168 - type t = Jsont.json 169 - let empty = Jsont.Object ([], Jsont.Meta.none) 170 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 171 - let jsont = Jsont.json 172 - end 173 159 174 160 type t = { 175 161 update_type : update_type; ··· 219 205 220 206 (** Permission context for callbacks *) 221 207 module Context = struct 222 - module Unknown = struct 223 - type t = Jsont.json 224 - let empty = Jsont.Object ([], Jsont.Meta.none) 225 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 226 - let jsont = Jsont.json 227 - end 228 - 229 208 type t = { 230 209 suggestions : Update.t list; 231 210 unknown : Unknown.t; ··· 249 228 250 229 (** Permission results *) 251 230 module Result = struct 252 - module Unknown = struct 253 - type t = Jsont.json 254 - let empty = Jsont.Object ([], Jsont.Meta.none) 255 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 256 - let jsont = Jsont.json 257 - end 258 - 259 231 type t = 260 232 | Allow of { 261 233 updated_input : Jsont.json option;
-28
claudeio/lib/permissions.mli
··· 63 63 module Rule : sig 64 64 (** Rules define specific permissions for tools. *) 65 65 66 - module Unknown : sig 67 - type t = Jsont.json 68 - val empty : t 69 - val is_empty : t -> bool 70 - val jsont : t Jsont.t 71 - end 72 - 73 66 type t = { 74 67 tool_name : string; (** Name of the tool *) 75 68 rule_content : string option; (** Optional rule specification *) ··· 119 112 | Add_directories (** Add allowed directories *) 120 113 | Remove_directories (** Remove allowed directories *) 121 114 (** The type of permission update. *) 122 - 123 - module Unknown : sig 124 - type t = Jsont.json 125 - val empty : t 126 - val is_empty : t -> bool 127 - val jsont : t Jsont.t 128 - end 129 115 130 116 type t 131 117 (** The type of permission updates. *) ··· 182 168 module Context : sig 183 169 (** Context provided to permission callbacks. *) 184 170 185 - module Unknown : sig 186 - type t = Jsont.json 187 - val empty : t 188 - val is_empty : t -> bool 189 - val jsont : t Jsont.t 190 - end 191 - 192 171 type t = { 193 172 suggestions : Update.t list; (** Suggested permission updates *) 194 173 unknown : Unknown.t; (** Unknown fields *) ··· 217 196 218 197 module Result : sig 219 198 (** Results of permission checks. *) 220 - 221 - module Unknown : sig 222 - type t = Jsont.json 223 - val empty : t 224 - val is_empty : t -> bool 225 - val jsont : t Jsont.t 226 - end 227 199 228 200 type t = 229 201 | Allow of {
-28
claudeio/lib/sdk_control.ml
··· 54 54 end 55 55 56 56 module Request = struct 57 - module Unknown = struct 58 - type t = Jsont.json 59 - let empty = Jsont.Object ([], Jsont.Meta.none) 60 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 61 - let jsont = Jsont.json 62 - end 63 - 64 57 type interrupt = { 65 58 subtype : [`Interrupt]; 66 59 unknown : Unknown.t; ··· 280 273 end 281 274 282 275 module Response = struct 283 - module Unknown = struct 284 - type t = Jsont.json 285 - let empty = Jsont.Object ([], Jsont.Meta.none) 286 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 287 - let jsont = Jsont.json 288 - end 289 - 290 276 type success = { 291 277 subtype : [`Success]; 292 278 request_id : string; ··· 371 357 e.request_id e.error 372 358 end 373 359 374 - module Unknown = struct 375 - type t = Jsont.json 376 - let empty = Jsont.Object ([], Jsont.Meta.none) 377 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 378 - let jsont = Jsont.json 379 - end 380 - 381 360 type control_request = { 382 361 type_ : [`Control_request]; 383 362 request_id : string; ··· 466 445 467 446 (** Server information *) 468 447 module Server_info = struct 469 - module Unknown = struct 470 - type t = Jsont.json 471 - let empty = Jsont.Object ([], Jsont.Meta.none) 472 - let is_empty = function Jsont.Object ([], _) -> true | _ -> false 473 - let jsont = Jsont.json 474 - end 475 - 476 448 type t = { 477 449 version : string; 478 450 capabilities : string list;
-28
claudeio/lib/sdk_control.mli
··· 131 131 module Request : sig 132 132 (** SDK control request types. *) 133 133 134 - module Unknown : sig 135 - type t = Jsont.json 136 - val empty : t 137 - val is_empty : t -> bool 138 - val jsont : t Jsont.t 139 - end 140 - 141 134 type interrupt = { 142 135 subtype : [`Interrupt]; 143 136 unknown : Unknown.t; ··· 248 241 249 242 module Response : sig 250 243 (** SDK control response types. *) 251 - 252 - module Unknown : sig 253 - type t = Jsont.json 254 - val empty : t 255 - val is_empty : t -> bool 256 - val jsont : t Jsont.t 257 - end 258 244 259 245 type success = { 260 246 subtype : [`Success]; ··· 292 278 293 279 (** {1 Control Messages} *) 294 280 295 - module Unknown : sig 296 - type t = Jsont.json 297 - val empty : t 298 - val is_empty : t -> bool 299 - val jsont : t Jsont.t 300 - end 301 - 302 281 type control_request = { 303 282 type_ : [`Control_request]; 304 283 request_id : string; ··· 369 348 370 349 module Server_info : sig 371 350 (** Server information and capabilities. *) 372 - 373 - module Unknown : sig 374 - type t = Jsont.json 375 - val empty : t 376 - val is_empty : t -> bool 377 - val jsont : t Jsont.t 378 - end 379 351 380 352 type t = { 381 353 version : string;
+20
claudeio/lib/unknown.ml
··· 1 + (** Unknown fields for capturing extra JSON object members. 2 + 3 + This module provides a type and utilities for preserving unknown/extra 4 + fields when parsing JSON objects with jsont. Use with 5 + [Jsont.Object.keep_unknown] to capture fields not explicitly defined 6 + in your codec. *) 7 + 8 + type t = Jsont.json 9 + (** The type of unknown fields - stored as raw JSON. *) 10 + 11 + let empty = Jsont.Object ([], Jsont.Meta.none) 12 + (** An empty unknown fields value (empty JSON object). *) 13 + 14 + let is_empty = function 15 + | Jsont.Object ([], _) -> true 16 + | _ -> false 17 + (** [is_empty t] returns [true] if there are no unknown fields. *) 18 + 19 + let jsont = Jsont.json 20 + (** Codec for unknown fields. *)
+18
claudeio/lib/unknown.mli
··· 1 + (** Unknown fields for capturing extra JSON object members. 2 + 3 + This module provides a type and utilities for preserving unknown/extra 4 + fields when parsing JSON objects with jsont. Use with 5 + [Jsont.Object.keep_unknown] to capture fields not explicitly defined 6 + in your codec. *) 7 + 8 + type t = Jsont.json 9 + (** The type of unknown fields - stored as raw JSON. *) 10 + 11 + val empty : t 12 + (** An empty unknown fields value (empty JSON object). *) 13 + 14 + val is_empty : t -> bool 15 + (** [is_empty t] returns [true] if there are no unknown fields. *) 16 + 17 + val jsont : t Jsont.t 18 + (** Codec for unknown fields. *)