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

TODO

Changed files
+280 -2
toru
+280 -2
toru/TODO.md
···
-
# Toru TODO: Missing Features vs Python Pooch
+
# Toru TODO: XDG-Eio Integration & Missing Features
+
+
This document tracks the XDG-Eio integration plan and features missing from the OCaml Toru implementation compared to the Python Pooch library.
+
+
## XDG-Eio Integration Plan
+
+
### Phase 1: Core Interface Updates
+
+
#### 1. Update Cache Module (`lib/cache.mli`)
+
- [ ] Change constructor to accept `Xdge.t` instead of explicit cache path
+
- [ ] Add `xdg` field accessor
+
- [ ] Keep version support for subdirectory organization
+
- [ ] Use `Xdge.cache_dir` as base path
+
- [ ] Follow XDG pretty-printing conventions
+
+
```ocaml
+
module Cache : sig
+
type t
+
+
val create : xdg:Xdge.t -> ?version:string -> unit -> t
+
+
(* Field accessors *)
+
val xdg : t -> Xdge.t
+
val base_path : t -> Eio.Fs.dir_ty Eio.Path.t
+
val version : t -> string option
+
+
(* Operations unchanged *)
+
val file_path : t -> string -> Eio.Fs.dir_ty Eio.Path.t
+
val exists : t -> string -> bool
+
val ensure_dir : t -> unit
+
val clear : t -> unit
+
val size_bytes : t -> int64
+
val list_files : t -> string list
+
+
(* XDG-compliant pretty printing *)
+
val pp : Format.formatter -> t -> unit
+
end
+
```
+
+
#### 2. Enhance Registry Module (`lib/registry.mli`)
+
- [ ] Add multi-source support (files, URLs, strings)
+
- [ ] Add registry merging capabilities (later sources override earlier)
+
- [ ] Add XDG integration for loading/saving registry files
+
- [ ] Support Pooch's multiple registry pattern
+
+
```ocaml
+
module Registry : sig
+
type t
+
type entry
+
type source =
+
| File of Eio.Fs.dir_ty Eio.Path.t
+
| Url of string
+
| String of string
+
| Xdg_file of Xdge.t * string (* Search in XDG config dirs *)
+
+
(* Entry operations unchanged *)
+
val create_entry : filename:string -> hash:Hash.t -> ?custom_url:string -> unit -> entry
+
val filename : entry -> string
+
val hash : entry -> Hash.t
+
val custom_url : entry -> string option
+
+
(* Multi-source registry support *)
+
val empty : t
+
val create : source list -> t
+
val load_sources : source list -> t
+
val add_source : t -> source -> t
+
val sources : t -> source list
+
val merge : t list -> t
+
+
(* XDG integration *)
+
val load_from_xdg : Xdge.t -> ?filename:string -> (t, string) result
+
val save_to_xdg : Xdge.t -> ?filename:string -> t -> (unit, string) result
+
val find_registry_file : Xdge.t -> string -> Eio.Fs.dir_ty Eio.Path.t option
+
+
(* Legacy single-file operations *)
+
val load : Eio.Fs.dir_ty Eio.Path.t -> t
+
val load_from_url : string -> t
+
val save : Eio.Fs.dir_ty Eio.Path.t -> t -> unit
+
val of_string : string -> t
+
val to_string : t -> string
+
+
(* Query operations unchanged *)
+
val find : string -> t -> entry option
+
val exists : string -> t -> bool
+
val add : entry -> t -> t
+
val remove : string -> t -> t
+
val entries : t -> entry list
+
val size : t -> int
+
+
(* XDG-compliant pretty printing *)
+
val pp : Format.formatter -> t -> unit
+
val pp_sources : Format.formatter -> source list -> unit
+
end
+
```
+
+
#### 3. Update Toru Main Interface (`lib/toru.mli`)
+
- [ ] Accept `Xdge.t` as primary parameter
+
- [ ] Remove `cache_path` parameter (use xdg cache directory)
+
- [ ] Accept `Registry.t` instead of registry file path
+
- [ ] Get app name from xdg context
+
- [ ] Add XDG-compliant pretty printing
-
This document tracks features missing from the OCaml Toru implementation compared to the Python Pooch library.
+
```ocaml
+
module Toru : sig
+
type t
+
+
val create :
+
xdg:Xdge.t ->
+
base_url:string ->
+
registry:Registry.t ->
+
?version:string ->
+
?downloader:(module DOWNLOADER) ->
+
unit -> t
+
+
(* Field accessors *)
+
val xdg : t -> Xdge.t
+
val app_name : t -> string (* derived from xdg *)
+
val base_url : t -> string
+
val cache : t -> Cache.t
+
val registry : t -> Registry.t
+
+
(* Operations unchanged *)
+
val fetch :
+
t ->
+
filename:string ->
+
?processor:(Eio.Fs.dir_ty Eio.Path.t -> Eio.Fs.dir_ty Eio.Path.t) ->
+
unit -> (Eio.Fs.dir_ty Eio.Path.t, string) result
+
+
val fetch_all :
+
t ->
+
?concurrency:int ->
+
unit -> (unit, string) result
+
+
val load_registry : t -> Registry.t -> t
+
val add_registry_entry : t -> Registry.entry -> t
+
val update_base_url : t -> string -> t
+
+
(* Static functions - add xdg parameter *)
+
val retrieve :
+
xdg:Xdge.t ->
+
url:string ->
+
?hash:Hash.t ->
+
?version:string ->
+
?downloader:(module DOWNLOADER) ->
+
unit -> (Eio.Fs.dir_ty Eio.Path.t, string) result
+
+
(* XDG-compliant pretty printing *)
+
val pp : Format.formatter -> t -> unit
+
val pp_brief : Format.formatter -> t -> unit
+
end
+
```
+
+
### Phase 2: XDG Directory Usage
+
+
#### 4. Add Configuration Support (`lib/config.mli`)
+
- [ ] Create new Config module for application settings
+
- [ ] Use `Xdge.config_dir` for storing configuration files
+
- [ ] Support TOML configuration format
+
- [ ] Use `Xdge.find_config_file` for config discovery
+
+
```ocaml
+
module Config : sig
+
type t = {
+
base_urls : string list;
+
default_downloader : string option;
+
timeout : float option;
+
concurrency : int option;
+
registry_sources : Registry.source list;
+
}
+
+
val default : t
+
val load : Xdge.t -> (t, string) result
+
val save : Xdge.t -> t -> (unit, string) result
+
val find_config_file : Xdge.t -> (Eio.Fs.dir_ty Eio.Path.t, string) result
+
+
(* XDG-compliant pretty printing *)
+
val pp : Format.formatter -> t -> unit
+
end
+
```
+
+
#### 5. Add State Management (`lib/state.mli`)
+
- [ ] Create State module for download history and logs
+
- [ ] Use `Xdge.state_dir` for persistent state
+
- [ ] Track download statistics and failures
+
- [ ] Implement download resume capability
+
+
```ocaml
+
module State : sig
+
type t
+
type download_entry = {
+
filename : string;
+
url : string;
+
hash : Hash.t option;
+
downloaded_at : Ptime.t;
+
success : bool;
+
error_msg : string option;
+
}
+
+
val create : Xdge.t -> t
+
val load : Xdge.t -> (t, string) result
+
val save : Xdge.t -> t -> (unit, string) result
+
+
val add_download : t -> download_entry -> t
+
val recent_downloads : t -> int -> download_entry list
+
val failed_downloads : t -> download_entry list
+
val download_count : t -> int
+
val success_rate : t -> float
+
+
(* XDG-compliant pretty printing *)
+
val pp : Format.formatter -> t -> unit
+
val pp_recent : Format.formatter -> t -> unit
+
end
+
```
+
+
#### 6. Add Data Directory Usage
+
- [ ] Use `Xdge.data_dir` for user-installed registries
+
- [ ] Store custom download processors in data directory
+
- [ ] Support user plugin/extension discovery
+
+
### Phase 3: Toru-Specific XDG Extensions
+
+
#### 7. Create Toru XDG Extensions (`lib/toru_xdg.mli`)
+
- [ ] Keep Toru-specific XDG functionality separate from xdg-eio
+
- [ ] Add archive extraction support using temp directories
+
- [ ] Add download lock file management
+
- [ ] Add cache size management utilities
+
+
```ocaml
+
module Toru_xdg : sig
+
(* Temporary directory management *)
+
val temp_dir : Xdge.t -> Eio.Fs.dir_ty Eio.Path.t
+
val with_temp_dir : Xdge.t -> (Eio.Fs.dir_ty Eio.Path.t -> 'a) -> 'a
+
+
(* Download locking *)
+
val with_download_lock : Xdge.t -> string -> (unit -> 'a) -> ('a, string) result
+
+
(* Cache management *)
+
val cache_disk_usage : Xdge.t -> int64
+
val cache_cleanup : Xdge.t -> ?max_size:int64 -> ?max_age:Ptime.Span.t -> unit -> int
+
val validate_cache_writable : Xdge.t -> (unit, string) result
+
+
(* Archive extraction *)
+
val extract_to_cache : Xdge.t ->
+
archive_path:Eio.Fs.dir_ty Eio.Path.t ->
+
extract_subdir:string ->
+
(Eio.Fs.dir_ty Eio.Path.t, string) result
+
end
+
```
+
+
### Phase 4: Examples and Documentation Updates
+
+
#### 8. Update Examples
+
- [ ] Update example code to use `Xdge.t`
+
- [ ] Show registry multi-source patterns
+
- [ ] Demonstrate configuration file usage
+
- [ ] Show state/logging integration
+
+
#### 9. Add Cmdliner Integration Example
+
- [ ] Create example showing `Xdge.Cmd.term` integration
+
- [ ] Demonstrate automatic XDG directory CLI flags
+
- [ ] Show environment variable precedence
+
+
### Phase 5: Testing and Migration
+
+
#### 10. Update Tests
+
- [ ] Test XDG directory creation and permissions
+
- [ ] Test multi-source registry loading
+
- [ ] Test configuration file discovery
+
- [ ] Test state persistence
+
- [ ] Add integration tests with real xdg-eio
+
+
#### 11. Migration Guide
+
- [ ] Document migration from explicit cache paths to XDG
+
- [ ] Provide migration utility for existing cache directories
+
- [ ] Document breaking changes in API
+
+
### Dependencies to Add
+
- [ ] Add `xdge` dependency to dune-project
+
- [ ] Add `ptime` for timestamp handling in state management
+
- [ ] Add `toml` library for configuration files (optional)
+
- [ ] Update OCaml-EIO-README.md reference if needed
## Major Missing Features in Toru