Repository navigation
docs: rule step 54 — find home by ladder, XDG names rooted there - #418
Merged
Merged
Conversation
added 2 commits
August 14, 2026 17:37
Planning phase 3 of the native-Windows-permissions campaign (#405) corrected two claims the earlier outline made, and turned up a blocker that has to land before any of it starts. CORRECTION 1 -- "pkg/signing first" is not executable. DefaultSigner derives its key path from configHome() and has exactly one production caller, internal/cli/store.go:197. Under the invariant signing must RECEIVE a root, so internal/cli must own a config root before signing can be handed one. The CLI plumbing comes first; signing is the first consumer of it, not the first change. CORRECTION 2 -- the windows failures do NOT clear in phase 3, and cannot. Ruling 5 already says why: Mode().Perm() reports 0666 on Windows whatever the DACL says, and every one of those tests asserts mode bits. Enforcement makes the file genuinely private without moving a single assertion. Enumerated from the leg: 7 tests, 8 assertions, six of which clear in phase 5 when IsRestricted and Observe's restricted fact give them something true to assert. The seventh, TestWrite_WithPermOverridesPermission, asserts 0644 -- which grants other, so ruling 4 leaves it inheriting the parent DACL by design. It has no enforcement state to observe and becomes a Unix-scoped assertion: the one case where scoping is right rather than evasive. So the windows leg stays at 28 through phases 3 and 4. An unmoved 28 after phase 3 is not a failed migration. BLOCKER, chartered as step 54: internal/cli/xdg.go resolves every anchor from os.Getenv("HOME"), which Windows does not define, so with XDG_* unset StateHome() yields the RELATIVE .local\state and state lands under the process's working directory. Phase 3.1 would anchor writable roots there -- authority over an arbitrary directory while presenting as scoped, strictly worse than the os.WriteFile it replaces. pkg/signing/configHome() already resolves correctly via os.UserHomeDir(), and its doc claims a parity with internal/cli that does not hold, so the same logical location resolves to two different places on Windows. CI cannot see it: the scenario tests set HOME and USERPROFILE, and 65 t.Setenv("XDG_*") sites skip the fallback branch. The charter leaves the fix open -- the failure mode when home cannot resolve, and whether Windows should use XDG paths at all, are questions it states rather than settles. Phase 7 appended, and ruled final: move internal/cli into cmd/internal/cli. Enumeration of its importers found 38 files across four commands plus exactly two non-command importers, neither a library use -- internal/model calls cli.Note/cli.Error for interactive narration and internal/config takes one path anchor and one warning. The move makes that layering violation a compile error, since cmd/internal is importable only from cmd/... . Accepted residual of going last: phases 3-5 plumb internal/cli's roots at the old path and the move rewrites those imports afterward. Assisted-by: Claude Signed-off-by: David Noble <[email protected]>
Researched current practice before deciding, because the campaign is
fixing the platform in question and the convention had only ever been
asserted, never tested.
THE RULING, part one: we find home, by a four-rung ladder, because no
single source delivers "no failure".
1. XDG_<ROLE>_HOME, IF ABSOLUTE. A relative value is invalid and
ignored -- the one thing the specification does rule on -- so
resolution continues as though it were unset.
2. os.UserHomeDir(). The environment answer.
3. os/user.Current().HomeDir. The operating system's answer.
4. Nothing left: assert.
Rung 3 is not redundant, because os.UserHomeDir is a Getenv with a nicer
name (os/file.go:605): it reads HOME / USERPROFILE / home, special-cases
android and ios, and otherwise returns one bare errors.New("$HOME is not
defined") -- no sentinel, nothing errors.Is-able. It never asks the OS
anything, and USERPROFILE is not guaranteed for services, scheduled
tasks, or some CI contexts. os/user does ask: on Windows it reads the
process token's profile directory via GetUserProfileDirectory, and on
Unix with cgo it reads the passwd entry. On CGO_ENABLED=0 Unix -- which
is how this repository cross-compiles -- lookup_stubs.go falls back to
os.UserHomeDir itself, so rung 3 collapses into rung 2 there. It is
carried anyway: it is the rung that saves Windows, the platform this
step exists for.
Rung 4 asserts rather than errors. Reaching it needs no $HOME, no passwd
entry and no cgo at once -- an environment where no anchor can be
honored at all -- so threading an error upward would change every
accessor's signature to describe a state in which the program cannot
function.
THE RULING, part two: we default to the XDG standard directory names
rooted at home -- ~/.config/devlore, ~/.local/share/devlore,
~/.local/state/devlore, ~/.cache/devlore -- with XDG_* overriding on
every platform as it already does. The names are XDG's, the root is
home, and Windows gets no special case.
The evidence, recorded so this is not relitigated. Two live cohorts and
no migration momentum in either: home-rooted (git, Microsoft's own
OpenSSH port at %USERPROFILE%\.ssh, Docker CLI, kubectl, aws, cargo, and
Starship and WezTerm reading ~/.config on Windows explicitly for
cross-platform sameness) versus Known-Folder (Neovim at
%LOCALAPPDATA%\nvim, gh at %AppData%\GitHub CLI, and the three dominant
directory libraries: Go adrg/xdg, Python platformdirs, Rust
dirs/directories). Nothing in the Known-Folder cohort treats %APPDATA%
as a substitute for $HOME -- they map XDG ROLES onto native folders --
so choosing AppData would have replaced one home with four unrelated
destinations. Both migration debates, starship#896 and neovim#24009, sit
open and unimplemented.
Roaming is a question the ruling avoids: %APPDATA% syncs at logon in
domain environments and %LOCALAPPDATA% does not, so AppData would have
forced a roaming-vs-local answer per role. A dotdir under the profile
never raises it.
Residuals accepted: ~\.local\state looks alien on Windows and Explorer
does not hide dot-directories; config does not roam between machines;
and this picks the Starship/WezTerm shape over the Neovim/gh shape, both
of which are current.
Still open: whether any cwd-relative data already written needs
migrating, and the full enumeration of home resolutions repository-wide.
Assisted-by: Claude
Signed-off-by: David Noble <[email protected]>
added 2 commits
August 14, 2026 18:18
The conflicts are a squash-merge artifact, not disagreeing work. This branch was cut from plan-phase-3, whose content reached develop as the DIFFERENT squashed commit ae85c1c (#417), so git sees two independent edits to the same lines and cannot tell they are the same text. Resolved by taking this branch's version of all three files, verified before resolving rather than assumed: every line present only on develop is text this branch deliberately rewrote -- the pre-ruling charter wording, the superseded open-questions list, and the old step-54 ledger row. Nothing unique to develop exists in these files, so ours is develop's content plus the ruling. The merge is guarded: it aborts if any path outside those three conflicts, since that would mean the verification no longer covers the resolution. Signed-off-by: David Noble <[email protected]>
…tripled step 54
RULED: there is exactly one place to ask for an XDG location and exactly
one way to resolve home. No other package resolves home for itself. That
rules out internal/cli as the owner, because pkg/signing, pkg/sops,
pkg/gitignore, internal/credentials and internal/lorepackage all need it
-- pkg/* would be importing internal/cli -- and phase 7 moves that
package to cmd/internal/cli, where pkg/* could not import it at all. The
owner is a low-level package every layer may depend on. Its name is the
one thing still open.
RULED: rung 3 of the ladder is mandatory, not a nicety. When HOME, or
USERPROFILE on Windows, is undefined we ask the operating system's user
account, because that is the authoritative answer and the environment is
a hint someone can fail to set.
The charter said enumerate rather than sample. Doing so found 30 home
resolutions across 12 files, ~18 of them defective, and moved the
step's center of gravity off xdg.go entirely:
cmd/writ 10 bare os.Getenv("HOME")
internal/cli/xdg.go 4 bare os.Getenv("HOME")
internal/cli/selfinstall.go 3 UserHomeDir then a bare HOME fallback
cmd/lore/lore/builder.go 1 UserHomeDir then a bare HOME fallback
signing/sops/gitignore/… 9 UserHomeDir with error handling
The most severe site is not the run index. cmd/writ/writ/config.go sets
cfg.TargetRoot = os.Getenv("HOME") at four separate sites, and writ
deploys dotfiles INTO that root. On Windows without HOME, TargetRoot is
"" -- so a deploy targets the working directory. State landing in the
wrong place is a nuisance; unpacking someone's dotfiles into whatever
directory they happened to be standing in is not. commands.go and
adopt/batch.go implement ~ expansion off the same bare read, so a tilde
expands to nothing.
Exit criteria updated: all 30 sites route through the one package, and
writ's TargetRoot and ~ expansion are called out by name.
Assisted-by: Claude
Signed-off-by: David Noble <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Rules step 54,
which blocks phase 3.1 of the native-Windows-permissions campaign
(#405).
The ruling: we find home; we default to XDG standard directory names rooted at home
Finding home is a four-rung ladder, because no single source delivers "no failure":
XDG_<ROLE>_HOME, if absolute — a relative value is invalid and ignoredos.UserHomeDir()— the environment answeros/user.Current().HomeDir— the operating system's answerRung 3 is the one that matters, and it is not redundant.
os.UserHomeDiris aGetenvwith anicer name (
os/file.go:605): it readsHOME/USERPROFILE/home, special-cases android and ios,and otherwise returns a single bare
errors.New("$HOME is not defined")— no sentinel, nothingerrors.Is-able. It never asks the OS anything, and%USERPROFILE%is not guaranteed for servicesor scheduled tasks.
os/userdoes ask: the process token's profile directory viaGetUserProfileDirectoryon Windows, the passwd entry on Unix with cgo. OnCGO_ENABLED=0Unix —how this repository cross-compiles — it falls back to
os.UserHomeDiritself, so rung 3 collapsesinto rung 2 there. Carried anyway: it is the rung that saves Windows, the platform this step
exists for.
Rung 4 asserts rather than errors. Reaching it needs no
$HOME, no passwd entry, and no cgo atonce — an environment where no anchor can be honored at all.
Layout:
~/.config,~/.local/share,~/.local/state,~/.cacheon every platform,XDG_*overriding as it already does. Windows gets no special case.
Why, on evidence
Two live cohorts, no migration momentum in either:
%USERPROFILE%\.ssh), Docker CLI,kubectl, aws, cargo, and Starship + WezTerm reading
~/.configon Windows explicitly forcross-platform sameness.
%LOCALAPPDATA%\nvim), gh (%AppData%\GitHub CLI), and the threedominant directory libraries: Go
adrg/xdg, Pythonplatformdirs, Rustdirs/directories.Three findings decided it: nothing in the Known-Folder cohort treats
%APPDATA%as a substitutefor
$HOME— they map XDG roles onto native folders, so AppData would have replaced one homewith four unrelated destinations; Microsoft's own OpenSSH keeps private keys in
%USERPROFILE%\.ssh, the closest precedent to this repository's signing key; and both upstreammigration debates (starship#896,
neovim#24009) sit open and unimplemented.
Roaming is a question this avoids entirely:
%APPDATA%syncs at logon in domain environments,%LOCALAPPDATA%does not, so AppData forces a roaming-vs-local answer per role. A dotdir under theprofile never raises it.
Residuals accepted:
~\.local\statelooks alien on Windows and Explorer does not hidedot-directories; config does not roam; this picks the Starship/WezTerm shape over the Neovim/gh
shape, both current.
Still open: whether any cwd-relative data already written needs migrating, and the full
enumeration of home resolutions repository-wide.
Documentation only.
Assisted-by: Claude