go-dt Filepath Refactorer
Use this skill when the user asks to:
- •clean up path/file handling
- •remove stringly-typed
filepath.*/os.*usage in favor of go-dt types - •reduce casting churn between string and dt types
- •introduce dt types into APIs safely
Mandatory references (read in order)
- •
references/nonnegotiables.md - •
references/go-dt-paths.md - •
references/clearpath.md(production code only) - •
references/testing.md(only when in tests) - •
references/go-dt-package-notes.md(catalog notes)
Refactor strategy (default)
Prioritize mechanical, behavior-preserving refactors:
- •Identify externally-sourced strings (CLI args, env, config, JSON, flags).
- •Convert them at the boundary into dt types (e.g.,
dt.Filepath(...), parse helpers, or join helpers). - •Propagate dt types internally to avoid repeated casts.
- •Replace
filepath.Join/path/filepathcalls with dt join helpers (dt.FilepathJoin, etc.). - •Replace
os.ReadFile(string(fp))withfp.ReadFile()and similar dt methods when available. - •Ensure errors produced follow doterr usage if the calling code uses doterr.
Things to avoid
- •Don't introduce dt types in public API boundaries unless requested; prefer internal migration first.
- •Don't add conversions that increase casting churn.
- •Don't convert tests to ClearPath style; but dt types are still fine in tests.
Common rewrite patterns
- •
filepath.Join(a, b)→dt.FilepathJoin(dt.DirPath(a), dt.Filename(b))(or the most appropriate dt join helper) - •
os.Stat(p)→dt.Filepath(p).Stat()(if available) or a dt helper method - •
os.ReadFile(p)→dt.Filepath(p).ReadFile()
(Use the exact helpers/methods from the reference guide; do not invent APIs.)
Deliverables
- •Provide updated code for the touched files.
- •If many files: include a summary of “boundary conversions” (where you accepted strings and converted to dt).
- •Include a small “risk notes” section if any semantic edge cases exist (relative vs absolute, symlinks, Windows separators, etc.).