pathcanon

package
v0.17.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 3 Imported by: 0

README

pkg/pathcanon

Canonicalizes filesystem directory paths so two spellings of the same directory compare equal. Stdlib-only leaf — both pkg/config and pkg/provider depend on it without an import cycle.

Files

File Role
pathcanon.go CanonicalDir(dir) — tilde-expand → AbsCleanEvalSymlinks (falling back to the lexical form when the path can't be resolved). Returns "" unchanged (callers use "" for "the default dir", which has no filesystem identity).

Why

This is the matching contract behind per-(provider, config dir) backend bindings (kata hpec). confab setup --config-dir <dir> stores a binding under CanonicalDir(configDir), and at runtime a Claude hook derives its config dir from the transcript path and looks the binding up under CanonicalDir(derivedDir). Because both sides pass through this same function on the same logical directory (which exists at both times), relative form, ./..///, trailing slash, tilde, and symlinked components all converge to one string — the lookup matches by construction.

Invariants / limits

  • Strength depends on the path existing at call time (symlink resolution needs it); a non-existent path degrades to Abs+Clean (no symlink resolution).
  • Does not unify non-symlink aliases (bind mounts, multiple mounts of one FS) or case/Unicode-equivalent names on case-insensitive volumes — those are filesystem identity, not string identity. Callers handle the residual by making a binding miss loud and leak-free rather than silently wrong.

Documentation

Overview

Package pathcanon canonicalizes filesystem directory paths so that two different spellings of the same directory compare equal. It is a stdlib-only leaf so both pkg/config and pkg/provider can depend on it without creating an import cycle.

Canonicalization is the matching contract behind per-(provider, dir) backend bindings (kata hpec): `setup` stores a binding under CanonicalDir(configDir), and at runtime the hook derives the config dir from the transcript path and looks it up under CanonicalDir(derivedDir). Because both sides pass through this same function on the same logical directory (which exists at both times), relative form, "."/".."/"//", trailing slash, tilde, and symlinked components all converge.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanonicalDir

func CanonicalDir(dir string) string

CanonicalDir returns a canonical form of dir: tilde-expanded, made absolute, lexically cleaned, and with symlinks resolved when the path exists (falling back to the lexical form when it cannot be resolved). Two paths that name the same directory return the same string.

An empty input is returned unchanged (callers use "" to mean "the default dir", which has no filesystem identity to canonicalize).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL