···11-# Toru TODO: Missing Features vs Python Pooch
11+# Toru TODO: XDG-Eio Integration & Missing Features
22+33+This document tracks the XDG-Eio integration plan and features missing from the OCaml Toru implementation compared to the Python Pooch library.
44+55+## XDG-Eio Integration Plan
66+77+### Phase 1: Core Interface Updates
88+99+#### 1. Update Cache Module (`lib/cache.mli`)
1010+- [ ] Change constructor to accept `Xdge.t` instead of explicit cache path
1111+- [ ] Add `xdg` field accessor
1212+- [ ] Keep version support for subdirectory organization
1313+- [ ] Use `Xdge.cache_dir` as base path
1414+- [ ] Follow XDG pretty-printing conventions
1515+1616+```ocaml
1717+module Cache : sig
1818+ type t
1919+2020+ val create : xdg:Xdge.t -> ?version:string -> unit -> t
2121+2222+ (* Field accessors *)
2323+ val xdg : t -> Xdge.t
2424+ val base_path : t -> Eio.Fs.dir_ty Eio.Path.t
2525+ val version : t -> string option
2626+2727+ (* Operations unchanged *)
2828+ val file_path : t -> string -> Eio.Fs.dir_ty Eio.Path.t
2929+ val exists : t -> string -> bool
3030+ val ensure_dir : t -> unit
3131+ val clear : t -> unit
3232+ val size_bytes : t -> int64
3333+ val list_files : t -> string list
3434+3535+ (* XDG-compliant pretty printing *)
3636+ val pp : Format.formatter -> t -> unit
3737+end
3838+```
3939+4040+#### 2. Enhance Registry Module (`lib/registry.mli`)
4141+- [ ] Add multi-source support (files, URLs, strings)
4242+- [ ] Add registry merging capabilities (later sources override earlier)
4343+- [ ] Add XDG integration for loading/saving registry files
4444+- [ ] Support Pooch's multiple registry pattern
4545+4646+```ocaml
4747+module Registry : sig
4848+ type t
4949+ type entry
5050+ type source =
5151+ | File of Eio.Fs.dir_ty Eio.Path.t
5252+ | Url of string
5353+ | String of string
5454+ | Xdg_file of Xdge.t * string (* Search in XDG config dirs *)
5555+5656+ (* Entry operations unchanged *)
5757+ val create_entry : filename:string -> hash:Hash.t -> ?custom_url:string -> unit -> entry
5858+ val filename : entry -> string
5959+ val hash : entry -> Hash.t
6060+ val custom_url : entry -> string option
6161+6262+ (* Multi-source registry support *)
6363+ val empty : t
6464+ val create : source list -> t
6565+ val load_sources : source list -> t
6666+ val add_source : t -> source -> t
6767+ val sources : t -> source list
6868+ val merge : t list -> t
6969+7070+ (* XDG integration *)
7171+ val load_from_xdg : Xdge.t -> ?filename:string -> (t, string) result
7272+ val save_to_xdg : Xdge.t -> ?filename:string -> t -> (unit, string) result
7373+ val find_registry_file : Xdge.t -> string -> Eio.Fs.dir_ty Eio.Path.t option
7474+7575+ (* Legacy single-file operations *)
7676+ val load : Eio.Fs.dir_ty Eio.Path.t -> t
7777+ val load_from_url : string -> t
7878+ val save : Eio.Fs.dir_ty Eio.Path.t -> t -> unit
7979+ val of_string : string -> t
8080+ val to_string : t -> string
8181+8282+ (* Query operations unchanged *)
8383+ val find : string -> t -> entry option
8484+ val exists : string -> t -> bool
8585+ val add : entry -> t -> t
8686+ val remove : string -> t -> t
8787+ val entries : t -> entry list
8888+ val size : t -> int
8989+9090+ (* XDG-compliant pretty printing *)
9191+ val pp : Format.formatter -> t -> unit
9292+ val pp_sources : Format.formatter -> source list -> unit
9393+end
9494+```
9595+9696+#### 3. Update Toru Main Interface (`lib/toru.mli`)
9797+- [ ] Accept `Xdge.t` as primary parameter
9898+- [ ] Remove `cache_path` parameter (use xdg cache directory)
9999+- [ ] Accept `Registry.t` instead of registry file path
100100+- [ ] Get app name from xdg context
101101+- [ ] Add XDG-compliant pretty printing
210233-This document tracks features missing from the OCaml Toru implementation compared to the Python Pooch library.
103103+```ocaml
104104+module Toru : sig
105105+ type t
106106+107107+ val create :
108108+ xdg:Xdge.t ->
109109+ base_url:string ->
110110+ registry:Registry.t ->
111111+ ?version:string ->
112112+ ?downloader:(module DOWNLOADER) ->
113113+ unit -> t
114114+115115+ (* Field accessors *)
116116+ val xdg : t -> Xdge.t
117117+ val app_name : t -> string (* derived from xdg *)
118118+ val base_url : t -> string
119119+ val cache : t -> Cache.t
120120+ val registry : t -> Registry.t
121121+122122+ (* Operations unchanged *)
123123+ val fetch :
124124+ t ->
125125+ filename:string ->
126126+ ?processor:(Eio.Fs.dir_ty Eio.Path.t -> Eio.Fs.dir_ty Eio.Path.t) ->
127127+ unit -> (Eio.Fs.dir_ty Eio.Path.t, string) result
128128+129129+ val fetch_all :
130130+ t ->
131131+ ?concurrency:int ->
132132+ unit -> (unit, string) result
133133+134134+ val load_registry : t -> Registry.t -> t
135135+ val add_registry_entry : t -> Registry.entry -> t
136136+ val update_base_url : t -> string -> t
137137+138138+ (* Static functions - add xdg parameter *)
139139+ val retrieve :
140140+ xdg:Xdge.t ->
141141+ url:string ->
142142+ ?hash:Hash.t ->
143143+ ?version:string ->
144144+ ?downloader:(module DOWNLOADER) ->
145145+ unit -> (Eio.Fs.dir_ty Eio.Path.t, string) result
146146+147147+ (* XDG-compliant pretty printing *)
148148+ val pp : Format.formatter -> t -> unit
149149+ val pp_brief : Format.formatter -> t -> unit
150150+end
151151+```
152152+153153+### Phase 2: XDG Directory Usage
154154+155155+#### 4. Add Configuration Support (`lib/config.mli`)
156156+- [ ] Create new Config module for application settings
157157+- [ ] Use `Xdge.config_dir` for storing configuration files
158158+- [ ] Support TOML configuration format
159159+- [ ] Use `Xdge.find_config_file` for config discovery
160160+161161+```ocaml
162162+module Config : sig
163163+ type t = {
164164+ base_urls : string list;
165165+ default_downloader : string option;
166166+ timeout : float option;
167167+ concurrency : int option;
168168+ registry_sources : Registry.source list;
169169+ }
170170+171171+ val default : t
172172+ val load : Xdge.t -> (t, string) result
173173+ val save : Xdge.t -> t -> (unit, string) result
174174+ val find_config_file : Xdge.t -> (Eio.Fs.dir_ty Eio.Path.t, string) result
175175+176176+ (* XDG-compliant pretty printing *)
177177+ val pp : Format.formatter -> t -> unit
178178+end
179179+```
180180+181181+#### 5. Add State Management (`lib/state.mli`)
182182+- [ ] Create State module for download history and logs
183183+- [ ] Use `Xdge.state_dir` for persistent state
184184+- [ ] Track download statistics and failures
185185+- [ ] Implement download resume capability
186186+187187+```ocaml
188188+module State : sig
189189+ type t
190190+ type download_entry = {
191191+ filename : string;
192192+ url : string;
193193+ hash : Hash.t option;
194194+ downloaded_at : Ptime.t;
195195+ success : bool;
196196+ error_msg : string option;
197197+ }
198198+199199+ val create : Xdge.t -> t
200200+ val load : Xdge.t -> (t, string) result
201201+ val save : Xdge.t -> t -> (unit, string) result
202202+203203+ val add_download : t -> download_entry -> t
204204+ val recent_downloads : t -> int -> download_entry list
205205+ val failed_downloads : t -> download_entry list
206206+ val download_count : t -> int
207207+ val success_rate : t -> float
208208+209209+ (* XDG-compliant pretty printing *)
210210+ val pp : Format.formatter -> t -> unit
211211+ val pp_recent : Format.formatter -> t -> unit
212212+end
213213+```
214214+215215+#### 6. Add Data Directory Usage
216216+- [ ] Use `Xdge.data_dir` for user-installed registries
217217+- [ ] Store custom download processors in data directory
218218+- [ ] Support user plugin/extension discovery
219219+220220+### Phase 3: Toru-Specific XDG Extensions
221221+222222+#### 7. Create Toru XDG Extensions (`lib/toru_xdg.mli`)
223223+- [ ] Keep Toru-specific XDG functionality separate from xdg-eio
224224+- [ ] Add archive extraction support using temp directories
225225+- [ ] Add download lock file management
226226+- [ ] Add cache size management utilities
227227+228228+```ocaml
229229+module Toru_xdg : sig
230230+ (* Temporary directory management *)
231231+ val temp_dir : Xdge.t -> Eio.Fs.dir_ty Eio.Path.t
232232+ val with_temp_dir : Xdge.t -> (Eio.Fs.dir_ty Eio.Path.t -> 'a) -> 'a
233233+234234+ (* Download locking *)
235235+ val with_download_lock : Xdge.t -> string -> (unit -> 'a) -> ('a, string) result
236236+237237+ (* Cache management *)
238238+ val cache_disk_usage : Xdge.t -> int64
239239+ val cache_cleanup : Xdge.t -> ?max_size:int64 -> ?max_age:Ptime.Span.t -> unit -> int
240240+ val validate_cache_writable : Xdge.t -> (unit, string) result
241241+242242+ (* Archive extraction *)
243243+ val extract_to_cache : Xdge.t ->
244244+ archive_path:Eio.Fs.dir_ty Eio.Path.t ->
245245+ extract_subdir:string ->
246246+ (Eio.Fs.dir_ty Eio.Path.t, string) result
247247+end
248248+```
249249+250250+### Phase 4: Examples and Documentation Updates
251251+252252+#### 8. Update Examples
253253+- [ ] Update example code to use `Xdge.t`
254254+- [ ] Show registry multi-source patterns
255255+- [ ] Demonstrate configuration file usage
256256+- [ ] Show state/logging integration
257257+258258+#### 9. Add Cmdliner Integration Example
259259+- [ ] Create example showing `Xdge.Cmd.term` integration
260260+- [ ] Demonstrate automatic XDG directory CLI flags
261261+- [ ] Show environment variable precedence
262262+263263+### Phase 5: Testing and Migration
264264+265265+#### 10. Update Tests
266266+- [ ] Test XDG directory creation and permissions
267267+- [ ] Test multi-source registry loading
268268+- [ ] Test configuration file discovery
269269+- [ ] Test state persistence
270270+- [ ] Add integration tests with real xdg-eio
271271+272272+#### 11. Migration Guide
273273+- [ ] Document migration from explicit cache paths to XDG
274274+- [ ] Provide migration utility for existing cache directories
275275+- [ ] Document breaking changes in API
276276+277277+### Dependencies to Add
278278+- [ ] Add `xdge` dependency to dune-project
279279+- [ ] Add `ptime` for timestamp handling in state management
280280+- [ ] Add `toml` library for configuration files (optional)
281281+- [ ] Update OCaml-EIO-README.md reference if needed
42825283## Major Missing Features in Toru
6284