Repositories / agent-snapshot.git

agent-snapshot.git

Clone (read-only): git clone http://git.guha-anderson.com/git/agent-snapshot.git

Branch

Add fpath and route path helpers through Fpath

Co-authored-by: Cursor <cursoragent@cursor.com>
Author
Arjun Guha <a.guha@northeastern.edu>
Date
2026-05-03 03:46:17 -0400
Commit
4e805389e13aa92b21f252c1aeb574be9907f488
dune-project
index fb4eb04..70d57d2 100644
--- a/dune-project
+++ b/dune-project
@@ -9,4 +9,5 @@
   dune
   yojson
   camomile
-  ocaml-git))
+  ocaml-git
+  fpath))
src/ocaml/agent_snapshot.ml
index fe72b98..5f075e1 100644
--- a/src/ocaml/agent_snapshot.ml
+++ b/src/ocaml/agent_snapshot.ml
@@ -123,34 +123,20 @@ let blob_dir : string ref = ref ""
 let tracer_uid : int = Unix.getuid ()
 let tracer_gid : int = Unix.getgid ()
 
-let path_sep = '/'
-
 let split_path (path : string) : string list =
-  path |> String.split_on_char path_sep |> List.filter (fun part -> part <> "" && part <> ".")
+  if path = "" then []
+  else Fpath.segs (Fpath.normalize (Fpath.v path)) |> List.filter (fun seg -> seg <> "")
 
 let normalize_path (path : string) : string =
-  let absolute = String.length path > 0 && path.[0] = path_sep in
-  let parts =
-    List.fold_left
-      (fun acc part ->
-        if part = ".." then match acc with [] -> acc | _ :: rest -> rest else part :: acc)
-      [] (split_path path)
-    |> List.rev
-  in
-  let body = String.concat "/" parts in
-  if absolute then if body = "" then "/" else "/" ^ body else if body = "" then "." else body
+  if path = "" then "." else Fpath.to_string (Fpath.normalize (Fpath.v path))
 
 let concat_path (base : string) (path : string) : string =
   if path = "" then base
-  else if String.length path > 0 && path.[0] = '/' then normalize_path path
-  else normalize_path (base ^ "/" ^ path)
+  else Fpath.to_string (Fpath.normalize (Fpath.append (Fpath.v base) (Fpath.v path)))
 
 let dirname (path : string) : string =
-  let path = normalize_path path in
-  match String.rindex_opt path '/' with
-  | None -> "."
-  | Some 0 -> "/"
-  | Some i -> String.sub path 0 i
+  if path = "" then "."
+  else Fpath.to_string (Fpath.parent (Fpath.normalize (Fpath.v path)))
 
 let rec mkdir_p (path : string) : unit =
   if path = "" || path = "/" || Sys.file_exists path then ()
@@ -158,7 +144,7 @@ let rec mkdir_p (path : string) : unit =
     mkdir_p (dirname path);
     try Unix.mkdir path 0o777 with Unix.Unix_error (Unix.EEXIST, _, _) -> ())
 
-let is_absolute (path : string) : bool = String.length path > 0 && path.[0] = '/'
+let is_absolute (path : string) : bool = path <> "" && Fpath.is_abs (Fpath.v path)
 
 let realpath_opt (path : string) : string option = try Some (Unix.realpath path) with Unix.Unix_error _ -> None
 
src/ocaml/dune
index 7254f07..a1286d8 100644
--- a/src/ocaml/dune
+++ b/src/ocaml/dune
@@ -4,4 +4,4 @@
  (foreign_stubs
   (language c)
   (names ptrace_stubs))
- (libraries unix yojson camomile ocaml-git))
+ (libraries unix yojson camomile ocaml-git fpath))