Repository navigation
fix: ignore an empty or relative XDG_*_HOME across every XDG base-directory read - #4104
Conversation
… tea's config An exported-but-empty $XDG_CONFIG_HOME was taken at face value, so read_tea_config looked for a relative tea/config.yml — resolved against whatever directory wt was invoked from — instead of falling through to ~/.config/tea/config.yml. With no logins found, is_authed_for and has_any_login report no Gitea login, so wt list --full drops the CI column and wt switch pr:<n> picks GitHub for a self-hosted host. The XDG base directory spec says an unset or empty value means the $HOME/.config default and a relative one is invalid; legacy_nushell_autoload_dirs already applies that rule to the same variable.
worktrunk-bot
left a comment
There was a problem hiding this comment.
The behavior change is right, but the precedent this cites doesn't exist on main.
legacy_nushell_autoload_dirs in src/shell/paths.rs still pushes PathBuf::from(xdg_config).join("nushell") straight from std::env::var("XDG_CONFIG_HOME") with no is_absolute() filter — the absolute-only guard is added by #4085, which is still open. So both the new doc comment ("applies the same absolute-only rule to the same variable") and the CHANGELOG's "as the Nushell wrapper search already did" are true only if #4085 merges first; merged in the other order, the comment points a reader at a function that does the opposite of what it claims, and nothing re-checks it later.
The guard that holds today regardless of merge order is nushell_data_dir_fallback in the same file, which applies the absolute-only rule to $XDG_DATA_HOME (if let Ok(xdg) = std::env::var("XDG_DATA_HOME") { … if path.is_absolute()). Citing that one makes the claim independent of #4085 — suggestions inline.
Separately, this makes three copies of "XDG base directory from the environment", each with a different strictness: xdg_config_base here is absolute-only, opencode_plugins_dir in src/commands/config/opencode.rs filters only the empty string (so XDG_CONFIG_HOME=cfg still resolves the plugin path relative to the invocation directory), and legacy_nushell_autoload_dirs filters neither. Not this PR's to fix given it is deliberately scoped to one site, but the divergence is the thing a shared helper would remove.
The new doc comment and the changelog entry pointed at legacy_nushell_autoload_dirs as already applying the absolute-only rule to XDG_CONFIG_HOME. It doesn't — that guard is added by #4085, which is still open, so the claim held only if that PR merged first. nushell_data_dir_fallback in the same file applies the rule to XDG_DATA_HOME today, independent of merge order; cite that instead.
| /// without mutating the process environment. | ||
| /// | ||
| /// [XDG base directory spec]: https://specifications.freedesktop.org/basedir-spec/latest/ | ||
| fn xdg_config_base(raw: Option<std::ffi::OsString>) -> Option<std::path::PathBuf> { |
There was a problem hiding this comment.
why is this specific to gitea?
There was a problem hiding this comment.
It shouldn't be — fixed in 1b68fdd. The rule now lives in path::xdg_base_dir(var) and all four XDG_*_HOME reads call it:
| Site | Variable | Before |
|---|---|---|
read_tea_config (gitea) |
XDG_CONFIG_HOME |
face value |
opencode_plugins_dir |
XDG_CONFIG_HOME |
empty filtered, relative not |
legacy_nushell_autoload_dirs |
XDG_CONFIG_HOME |
face value |
nushell_data_dir_fallback |
XDG_DATA_HOME |
absolute-only, written inline |
Three of the four picked their target by cwd under XDG_CONFIG_HOME=cfg, so this also fixes wt config plugins opencode install writing the plugin under the invocation directory (the empty case was #4084; the relative case wasn't) and the Nushell uninstall searching a relative nushell/vendor/autoload for stranded wrappers.
It returns Option<PathBuf> rather than resolving the fallback, because the $HOME-relative default really does differ per site — OpenCode reads ~/.config even on macOS, Nushell's data dir goes through dirs::data_dir(), worktrunk's own config follows etcetera. None means "apply yours", which is what each caller already did when the variable was unset.
This supersedes #4085's legacy_nushell_autoload_dirs hunk; its ZDOTDIR change is independent, so that PR just drops the shell/paths.rs hunk on rebase.
…read The absolute-only rule was written per site at four different strictnesses. Move it to path::xdg_base_dir and use it from tea's config lookup, OpenCode's plugins dir, and both Nushell fallbacks.
|
and why do we need this? if seome has an incorrect env var value, why are we adjusting it? |
worktrunk-bot
left a comment
There was a problem hiding this comment.
Self-review. The guard itself is right, and the four call sites are the complete set of direct XDG_*_HOME reads — the fifth, indirect one (worktrunk's own config via etcetera::choose_base_strategy) already applies the identical rule, so this converges on it rather than adding a fifth strictness.
One concern, in the testing rationale rather than the code:
A test driving
read_tea_configend-to-end would have to setXDG_CONFIG_HOMEin the process environment, which races every other test in the binary.
That holds for read_tea_config, but not for the OpenCode install site — and that is the target where the bug actually writes a file rather than failing to read one. tests/integration_tests/config_show.rs spawns wt as a child process, so cmd.env("XDG_CONFIG_HOME", …) sets the child's environment and races nothing. The pattern is already in that file: test_opencode_install_treats_empty_config_dir_as_unset, added by #4084 for the neighbouring OPENCODE_CONFIG_DIR case, sets the child's cwd with cmd.current_dir(&run_dir) and asserts the plugin is not written relative to it. The relative-$XDG_CONFIG_HOME case this PR fixes is the same shape one rung down the precedence, and is left to a unit test on the rule alone.
Pushing the missing guard as a sibling of that test. It fails against the pre-fix resolution (Plugin should fall through to $HOME/.config, but not found at: …/.config/opencode/plugins/worktrunk.ts) and passes with the shared guard, so it pins the behavior rather than restating it.
Not raised as blockers, for the record: read_tea_config dropping .clone() is safe (xdg is consumed once), the var() → var_os() move only widens each site to non-UTF-8 values, and narrowing legacy_nushell_autoload_dirs shrinks what the Nushell uninstall scan can reach, which is the safe direction.
…o-end
The rule was unit-tested in `path.rs`, but the target where a relative
`$XDG_CONFIG_HOME` actually writes a file — `wt config plugins opencode
install` — was not. The integration tests spawn `wt` as a child process,
so `cmd.env("XDG_CONFIG_HOME", …)` sets the child's environment and races
nothing in the binary; this is a sibling of
`test_opencode_install_treats_empty_config_dir_as_unset`, which #4084
added for the same shape one rung up the precedence.
Fails against the pre-fix resolution, passes with the shared guard.
|
Fair question, and the honest framing is that we're not adjusting the value — we're declining to use one that can't mean what it says. The failure isn't "wt looked in a slightly wrong directory". The spec makes both calls itself, which is why "ignore" rather than "use as-is" is the defined handling rather than our invention:
Empty is the shape that actually shows up: And as the self-review above notes, worktrunk already does this for its own config — so the argument for the change is consistency rather than a new policy. Provenance, since it bears on how much this is worth: no user reported it. It came out of the sweep of path-shaped environment reads that produced #4084 and #4085, so the evidence is the mechanism, not a field report. Alternative I didn't take: warn instead of ignoring. It would fire for other tools' lookups and stay silent for wt's own config, which resolves the same value through etcetera — inconsistent in the direction that's harder to explain. If the behavior change isn't worth it, the cut-down version is the empty-string case only, dropping the relative-path rule; that's the unambiguous half and it's where the real-world shape is. Happy to trim to that, or to close this — the consolidation in fb63418 stands on its own either way, since it removes three divergent copies of the rule regardless of which strictness we settle on. |
but then surely we should just use etcetra for all of these?? and delegate to that? |
The shared `path::xdg_base_dir` guard reimplemented what etcetera's XDG strategy already does — read the variable, ignore a non-absolute value, fall back to `$HOME/.config` — for the three sites that mean "the XDG config directory". They now call `Xdg::config_dir()` directly, which also removes each caller's own `~/.config` fallback. `Xdg` rather than `choose_base_strategy`: tea and OpenCode read `~/.config` on every platform, where the chosen strategy picks `%APPDATA%` on Windows. `nushell_data_dir_fallback` keeps a spelled-out read, because it mirrors Nushell's rule rather than the spec's: `XDG_DATA_HOME` wins when absolute, otherwise the platform-native data dir. etcetera's `Xdg::data_dir()` falls back to `~/.local/share` everywhere, and the native strategies that get macOS and Windows right ignore the variable.
|
Agreed — done in 0278375.
One site doesn't delegate, and it's the one that isn't reading the XDG rule in the first place. The unit test on the old helper went with it; etcetera's XDG strategy carries doctests asserting exactly the empty/relative behavior, and the end-to-end pin ( |
worktrunk-bot
left a comment
There was a problem hiding this comment.
Self-review. One claim in the new prose is wrong, and it conceals a real gap.
read_tea_config's comment gives as the reason for picking Xdg that "tea reads ~/.config on every platform". tea resolves its config path through xdg.ConfigFile("tea/config.yml") from github.com/adrg/xdg (GetConfigPath in modules/config/config.go), and that library's configHome default is ~/Library/Application Support on macOS and %LOCALAPPDATA% on Windows — baseDirs.configHome = pathutil.EnvPath(envConfigHome, homeAppSupport) in paths_darwin.go, pathutil.EnvPath(envConfigHome, kf.localAppData) in paths_windows.go. Only the Linux default is ~/.config, and the only fallback past it is ~/.tea/tea.yml.
So on macOS with $XDG_CONFIG_HOME unset — the default — wt reads ~/.config/tea/config.yml while tea's logins are in ~/Library/Application Support/tea/config.yml. That is the same symptom the CHANGELOG entry above describes: no Gitea CI column in wt list --full, and wt switch pr:<n> falling through to GitHub for a self-hosted host tea is logged in to. It is unchanged from main, so this PR doesn't cause it — but the comment now asserts the gap doesn't exist, which is what would stop it being found later.
The rejected alternative isn't the fix either: choose_base_strategy gives ~/Library/Preferences on macOS (etcetera's Apple::config_dir) and %APPDATA% on Windows, matching tea on neither. Xdg stays the right call, because it honors $XDG_CONFIG_HOME on every platform and so does tea. So this is a comment correction plus a separate decision, for whoever owns the scope: whether read_tea_config should also try tea's native macOS/Windows defaults. That is a behavior change past what this PR set out to do, so it isn't folded in here.
Second, smaller. The comment on the new Xdg::new() in legacy_nushell_autoload_dirs says ~/.config stays listed separately "for the case where no home directory can be determined from the environment". Both callers take home from home_dir_required() and bail when it's absent (config_paths in shell/paths.rs, scan_for_uninstall in commands/configure_shell.rs), so that case can't reach the function. The reachable reason is an absolute $XDG_CONFIG_HOME: xdg.config_dir() is then that directory, and ~/.config/nushell is still a location older worktrunk wrote to. As written, a later reader can drop the line as dead and quietly narrow what the Nushell uninstall scan reaches.
Both are comment-only; pushing them as a commit after this.
Not raised as blockers: the etcetera delegation itself is right, the deletion surface narrows rather than widens (legacy_nushell_autoload_dirs no longer contributes a cwd-relative directory, and nushell_autoload_candidates dedupes the ~/.config overlap), and the resolve_xdg_base citation in nushell_data_dir_fallback checks out against nushell's crates/nu-config/src/resolve.rs.
…XDG strategy `read_tea_config` claimed tea reads `~/.config` on every platform. tea resolves its config path through `github.com/adrg/xdg`, whose `configHome` defaults to `~/Library/Application Support` on macOS and `%LOCALAPPDATA%` on Windows; only the Linux default is `~/.config`. `Xdg` is still the right strategy — it honors $XDG_CONFIG_HOME on every platform, and so does tea — but the platform defaults diverge and the comment now says so. `legacy_nushell_autoload_dirs` justified its separate `~/.config` entry by a home-less environment, which neither caller can produce (both take `home` from `home_dir_required()` and bail without it). The reachable reason is an absolute $XDG_CONFIG_HOME, which makes `xdg.config_dir()` that directory and leaves `~/.config/nushell` a distinct stranded-wrapper location.
| /// platform, otherwise `dirs::data_dir()` (`~/Library/Application Support` on | ||
| /// macOS, `%APPDATA%` on Windows, `~/.local/share` on Linux). Nushell appends | ||
| /// `nushell`. | ||
| /// Mirrors Nushell's own `resolve_xdg_base` (`crates/nu-config/src/resolve.rs`): |
There was a problem hiding this comment.
and we can't ask nushell where to get its config?
I really want to move as much of this stuff out of worktrunk, we shouldn't have this sort of custom logic if we can possibly avoid it
have a subagent look for anything else like this in the repo and open an issue: i.e. anything that were maintaining that we can delegate to other libraries, especially brittle things like where they keep their configs
There was a problem hiding this comment.
We do ask it — nu_dirs(), ~40 lines above this one, spawns nu -c 'print ($nu.vendor-autoload-dirs | last); print $nu.default-config-dir' once per process, and that's the answer worktrunk installs against. This function is only what happens when nu isn't on PATH, which is the case asking can't cover: the uninstall scan still has to find a wrapper an older worktrunk stranded, on a machine where Nushell has since been removed.
But you're right that it shouldn't be restating Nushell's rules, and it no longer does. Nushell publishes that resolution as nu-config — resolve_paths returns the same $nu.vendor-autoload-dirs list the query above asks for, so 27aa9a8 delegates to it and the hand-written XDG_DATA_HOME branch is gone. That's a correctness gain too, not just less code: the fallback now picks up $XDG_DATA_DIRS, $NU_VENDOR_AUTOLOAD_DIR and macOS's /Library/Application Support, all of which the hand-written version missed, and completion_path's Nushell arm goes through the same pair instead of reconstructing the path a third time. test_uninstall_nushell_finds_wrapper_under_xdg_data_home pins the delegation end-to-end and still passes.
The cost, so it's easy to reject: 8 new transitive crates (nu-config, nu-path, darling ×3, derive_setters, omnipath, pwd), and nu-config's version is a Nushell release number — 0.115 today — so Dependabot will propose a bump roughly monthly. Its MSRV is 1.95 against our 1.97, but that's Nushell's floor to move, not ours. And it answers for the pinned release rather than the installed nu, which is the other reason the query stays preferred rather than being replaced by it. If the dependency isn't worth it, reverting that one commit leaves the rest of the PR intact.
The wider survey is #4106. Short version: the repo has mostly done this pass already, and the residue is 9 items — the ones I'd act on first are is_retriable_error classifying gh/glab failures by substring-matching English prose (the repo's own structured-output rule, inverted, while the Gitea backend beside it reads the HTTP status), tea's config.yml being matched by scanning lines for a url: prefix rather than parsing logins[].url, and fish's wrapper and completion resolving fish's config dir by two different rules in the same process. Four more are smaller, two are already in flight here and in #4085, and five things I checked are better left alone — the survey says which and why.
There was a problem hiding this comment.
Correcting my own reply above, since it oversold the change and that's the part your decision turns on.
vendor_autoload_dirs.last() is one directory, and nu-config appends the $XDG_DATA_DIRS and macOS /Library/Application Support entries before the data-home one — so the resolved path is byte-identical to the rule this deleted, on every platform. The uninstall scan reaches nothing it couldn't reach before. The only behavior the delegation adds is honoring $NU_VENDOR_AUTOLOAD_DIR. What it buys is that the rule is upstream's and can't go stale, not extra coverage — a much narrower claim than the one I made, and the PR body now says so.
One thing I'll correct in the other direction, from the self-review below: nu-config requiring dirs 6 does not put a second dirs major in the tree next to #4102's bump to 7. shellexpand requires dirs = ">=4, <7", so it's pinned to 6 either way — that's why #4102's own lockfile diff already carries dirs 6.0.0 beside dirs 7.0.0. nu-config joins the 6 side; it doesn't create the split.
So the trade is ~15 lines of copied Nushell rule against eight Cargo.lock entries and a dependency whose version is a Nushell release number. That's your call rather than mine — 27aa9a8 is a standalone commit, and dropping it leaves the etcetera consolidation you asked for intact.
`wt config shell install nu` already asks `nu` where its vendor-autoload directory is; the hand-written fallback for when `nu` isn't on PATH restated Nushell's `$XDG_DATA_HOME` rule and stopped there. Nushell publishes that resolution as `nu-config`. `resolve_paths` returns the same `$nu.vendor-autoload-dirs` list `nu_dirs` queries for, so the fallback now answers the identical expression — and picks up `$XDG_DATA_DIRS`, `$NU_VENDOR_AUTOLOAD_DIR` and macOS's `/Library/Application Support`, which the hand-written version missed. No Nushell layout rule is left restated in worktrunk. `completion_path`'s Nushell arm goes through the same pair rather than reconstructing the path a third time.
worktrunk-bot
left a comment
There was a problem hiding this comment.
Self-review of the two commits since the last pass. The comment corrections in 2a20fff are what the previous review asked for. 27aa9a8 is the substantive one, and it claims more than it delivers.
The nu-config delegation adds one behavior, not three. nushell_vendor_autoload_fallback returns dirs.vendor_autoload_dirs.last() — a single directory. In nu-config's resolve_vendor_autoload_dirs, the $XDG_DATA_DIRS entries and macOS's /Library/Application Support are appended before the data-home entry, and the data-home entry is resolve_xdg_base(env, "XDG_DATA_HOME", |e| e.data_dir()) — the same $XDG_DATA_HOME-when-absolute-else-dirs::data_dir() rule the deleted nushell_data_dir_fallback computed, with the same nushell/vendor/autoload suffix. So .last() is byte-identical to the old fallback on every platform, and the only entry that can displace it is the runtime $NU_VENDOR_AUTOLOAD_DIR, which nu-config appends last. The CHANGELOG's "looks everywhere Nushell itself would, including $XDG_DATA_DIRS and $NU_VENDOR_AUTOLOAD_DIR" and the commit message's "picks up $XDG_DATA_DIRS, $NU_VENDOR_AUTOLOAD_DIR and macOS's /Library/Application Support" are both wrong: nothing but the last entry ever reaches the scan. Fixing the CHANGELOG.
That reframes the cost, which is the decision here. The honest argument for the dependency is drift-proofing — the rule is upstream's, so it can't go stale — not coverage. Against it: eight new Cargo.lock entries (nu-config, nu-path, omnipath, pwd, derive_setters, darling, darling_core, darling_macro; the darling proc-macro chain comes in for nu-config's TestEnv, which is always compiled), on a crate first published 2026-08-15 with two releases to date, version-locked to a Nushell release so it answers for the pinned version rather than the installed one. And nu-config and nu-path both require dirs = "^6.0", while #4102 proposes bumping worktrunk to dirs 7.0 — merge both and the tree carries two dirs majors instead of one. Trading ~15 lines for that is a judgment call I don't think a bot should make unilaterally; happy to drop 27aa9a8 and keep the etcetera commit, which is what you actually asked for, if the trade doesn't look worth it.
codecov/patch is failing at 85.18% (4 misses / 27 lines): the io::Error construction inside completion_path's new ok_or_else, and the panic! arm of the new unit test. Both are fixable rather than unavoidable — pushing a commit that pulls the write-target resolution into a small pure function a unit test can drive into both arms, and rebuilds the test on nu-config's TestEnv.
The new error text names a variable that is already set. completion_path calls home_dir_required()? before the Nushell arm, so by the time ok_or_else fires, $HOME/$USERPROFILE resolved fine — the remedy it prints can't be the remedy. The reachable cause is resolve_paths returning ConfigError::ConfigDirNotFound, which the doc comment's "None only when no home directory is discoverable" also misses.
The unit test resolves from the ambient process environment. nushell_vendor_autoload_fallback hardcodes nu_config::SystemEnv, so test_nushell_vendor_autoload_fallback_is_a_vendor_autoload_dir asserts a suffix against whatever the runner exports; with $NU_VENDOR_AUTOLOAD_DIR set to a directory nu-config appends verbatim, it fails. running-tend is explicit that a test relying on inherited env vars should set up its own, and nu-config ships TestEnv for exactly this.
One thing I'm reporting rather than fixing, because the fix is a contract change. nushell_autoload_candidates used to start from nushell_vendor_autoload_dir, which returned a PathBuf — the first entry was a data-dir path by construction. It now extends two Options, so when both are absent the first entry is a legacy <config-dir>/nushell/vendor/autoload, and scan_and_configure's wrapper-based branch writes to paths.first() — the never-autoloaded location whose comment there says it "must not become the write target" (issue #2878). Reaching it needs nu off PATH and resolve_paths erroring while home::home_dir() succeeds, which on Unix is unreachable (both key on $HOME) but on Windows is not: home::home_dir() falls back to %USERPROFILE%/%HOMEDRIVE%, dirs::config_dir() has no env fallback past the known-folder call. Restoring the invariant means either failing the whole install or splitting the write target out of the candidate list, and which of those you want isn't mine to pick.
…dded `completion_path`'s Nushell arm built its "no vendor-autoload directory" error in a closure and the new unit test used a `let`-`else` `panic!`. Neither can run: both callers reach the arm through `home_dir_required`, which already failed where `nu-config` has no home directory to resolve from, so `codecov/patch` counted four lines nothing could cover. The error value is cheap, so `ok_or` constructs it eagerly with the message hoisted to a module-level const, and the test asserts with `expect`. Same behavior, no dead lines.
Three corrections to the nu-config delegation. The CHANGELOG and the fallback's doc comment claimed the offline path now searches `$XDG_DATA_DIRS` and macOS's `/Library/Application Support`. It does not: `vendor_autoload_dirs.last()` is one directory, and nu-config appends those entries before the data-home one, so the value is the same `$XDG_DATA_HOME`-else-platform-data-dir path the deleted copy computed. `$NU_VENDOR_AUTOLOAD_DIR` is the one entry that displaces it, and the one behavior the delegation actually adds. `completion_path`'s new error told the user to set `$HOME`/`$USERPROFILE`, which `home_dir_required` has already accepted before that arm runs. The reachable cause is `ConfigError::ConfigDirNotFound` — Windows-only, where `home` falls back to `%USERPROFILE%` and `dirs::config_dir` has no fallback past the known-folder call. The message now names what failed, and the resolution moves into `nushell_write_target`, a pure function whose error arm a unit test can reach; both were uncovered patch lines. `nushell_vendor_autoload_fallback` takes nu-config's `EnvAccess` seam instead of reading the process environment, so its test pins an exact path through `TestEnv` rather than asserting a suffix against whatever the runner exports.
worktrunk-bot
left a comment
There was a problem hiding this comment.
Self-review of the two commits since the last pass. codecov/patch is green at this head, so the coverage gap the last review flagged is closed. What is left is in the error text and a test label rather than the resolution, which I re-checked against the nu-config 0.115.1 source and now agree with: vendor_autoload_dirs.last() is the data-home entry on Linux, macOS and Windows, displaced only by a runtime $NU_VENDOR_AUTOLOAD_DIR.
The new error message names a crate instead of an action. NO_NU_VENDOR_AUTOLOAD_DIR now ends "neither nu nor nu-config could resolve one". nu-config is a Cargo dependency, not anything a user running wt config shell install nu has a handle on, and dropping the old remedy left the message with no resolution at all — writing-user-outputs → Error Message Structure lists "How to resolve" as the fourth thing an error communicates, and home_dir_required at the top of the same file does exactly that.
The resolution that works is having nu on PATH: nu_dirs() answers from the running binary, and it is the only path that does not go through the resolve_paths call that just failed. $NU_VENDOR_AUTOLOAD_DIR is not a remedy to name — nu-config reads it in resolve_vendor_autoload_dirs, which the ConfigDirNotFound early return never reaches.
The test pinning the None arm does not exercise the case it is named for. test_nushell_vendor_autoload_fallback_without_a_home builds TestEnv::new(HashMap::new()), whose config_dir() is None, so resolve_config_home_with_source returns ConfigError::ConfigDirNotFound on nu-config's first step and the env.home_dir().ok_or(ConfigError::NoHomeDir)? five steps later is never reached. The coverage is the valuable half — ConfigDirNotFound is the Windows-reachable error the fallback's own doc comment distinguishes, where home falls back to %USERPROFILE% while dirs::config_dir has nothing past the known-folder call — so only the label is wrong. NoHomeDir staying untested is fine; it is the arm that is unreachable past home_dir_required.
Pushing both as a commit after this.
The message named `nu-config`, a Cargo dependency the user has no handle on, and gave no resolution at all. `nu` on PATH is the one remedy: it routes through `nu_dirs()`, which answers from the running binary rather than the `resolve_paths` call that just failed. `$NU_VENDOR_AUTOLOAD_DIR` would not help — nu-config reads it in `resolve_vendor_autoload_dirs`, past the `ConfigDirNotFound` early return that produced the `None`. The test pinning that `None` is renamed for the error it reaches: `TestEnv::new` leaves `config_dir()` unset, so `resolve_paths` stops at `ConfigDirNotFound` and never reaches the `NoHomeDir` lookup five steps later. That is the Windows-reachable half of the two errors the fallback documents, so only the label was wrong.
| # `$NU_VENDOR_AUTOLOAD_DIR`. Version-locked to a Nushell release, so it answers | ||
| # for the pinned version rather than the installed one; that is why the query | ||
| # stays preferred. | ||
| nu-config = "0.115" |
There was a problem hiding this comment.
how big is this dependency? if it's big, then we can instead shell out
There was a problem hiding this comment.
Two corrections to the size answer I posted a minute ago, both narrow.
The dirs collision isn't one. I said nu-config's dirs = "^6" collides with #4102's bump to 7.0. It doesn't: shellexpand 3.1.2 requires dirs = ">=4, <7", so dirs 6 is in the tree either way — #4102's own lockfile diff already carries shellexpand → dirs 6.0.0 beside worktrunk → dirs 7.0.0. nu-config joins the 6 side rather than creating the split. (I'd corrected this earlier in this thread and then repeated the original claim anyway.)
Linked binary size, which I'd left unmeasured: +19,040 bytes stripped, release with lto = "thin" — the delta between two probe binaries differing only in the resolve_paths call, both already linking dirs. So the runtime footprint is ~19 KB; the bulk of the 19k source lines is the darling chain, which is proc-macro and never reaches the binary.
That doesn't move the recommendation much — a third darling major, 11.2k lines of proc-macro compiled for one #[derive] on a test helper, and monthly Nushell-release bumps are still the case for dropping it, and none of those depended on the dirs claim. But one of the four reasons I gave was false, and it's the kind that reads as a hard blocker.
There was a problem hiding this comment.
Dropped in a1fe07cb8 — the measurement answered your conditional, so I acted on it rather than waiting on a word: eight lock entries and ~18.7k lines of source for a rule that resolves to the same directory the ~15 reverted lines compute on all three platforms. nushell_data_dir_fallback is back as it was, the etcetera consolidation this PR set out to deliver is untouched, and cargo clippy --all-targets plus the Nushell and OpenCode integration tests pass locally.
On wanting this stuff out of worktrunk: the delegation that does that is already here and unchanged. nu_dirs() asks the running nu for $nu.vendor-autoload-dirs | last, and that is what the install writes to whenever nu is on PATH — the reinstated lines only answer the case shelling out can't reach, which is the uninstall scan looking for a wrapper an older worktrunk stranded on a machine where Nushell has since been removed. There is no third source for that answer short of the dependency.
Say the word if you'd rather keep nu-config and I'll revert the revert.
worktrunk-bot
left a comment
There was a problem hiding this comment.
how big is this dependency? if it's big, then we can instead shell out
Size. Eight new Cargo.lock entries, ~18.7k lines of source, ~221 KB of .crate tarballs:
| crate | why it is here | src LOC | .crate |
|---|---|---|---|
nu-config 0.115.1 |
the one call — resolve_paths |
1,413 | 36 KB |
nu-path 0.115.1 |
nu-config hard dep | 4,606 | 29 KB |
omnipath 0.1.6 |
nu-path, Windows | 1,271 | 11 KB |
pwd 1.4.0 |
nu-path, Unix | 272 | 4 KB |
derive_setters 0.1.9 |
nu-config's TestEnv |
555 | 20 KB |
darling + _core + _macro 0.21.3 |
derive_setters | 10,597 | 118 KB |
Two things that table hides. Over half of it — the darling chain plus derive_setters, 11.2k lines — exists for one #[derive(derive_setters::Setters)] on nu-config's TestEnv in src/env_access.rs, a test helper that compiles into every build; nu-config's only feature is plugin, so there is no opting out. And darling 0.21 is a third major of darling in the lock (0.20.11 and 0.23.0 are already there), so it is fresh compilation rather than a shared unit. nu-path is likewise dead weight for our call: nu-config reaches it only from overrides.rs, to expand paths given in CliOverrides, and we pass CliOverrides::default().
Compile time is the small part. With the rest of the graph built, cargo build -p nu-path then -p nu-config is 4.2s + 3.5s debug and 4.1s + 3.6s release on this 4-core runner, the second command covering the whole proc-macro chain. I did not measure linked binary size.
On shelling out — we already do, and it already wins. nu_dirs() spawns nu -c 'print ($nu.vendor-autoload-dirs | last); print $nu.default-config-dir' once per process, and nushell_write_target is queried.or(fallback), so nu-config answers only when nu is not on PATH. That case is mostly the uninstall scan: finding a wrapper an older worktrunk stranded, on a machine where nu has since been removed. So the alternative to the dependency is not a subprocess — it is the ~15 hand-written lines 27aa9a8 deleted ($XDG_DATA_HOME when absolute, else dirs::data_dir(), plus nushell/vendor/autoload), which resolve byte-identically to nu-config's .last() on all three platforms. The dependency buys drift-proofing against a future Nushell layout change, not coverage today.
So: drop it. 19k lines, a third darling major, and a dirs = "^6" requirement that collides with #4102's bump to 7.0 are out of proportion to 15 lines that are correct today — and being version-locked to a Nushell release, nu-config answers for the pinned version rather than the installed nu, in exactly the case where there is no installed nu to check it against. Say the word and I'll push a revert of 27aa9a8 and keep the etcetera commit, which is what the PR set out to deliver.
# Conflicts: # CHANGELOG.md
Reverts 27aa9a8, 6ac159b, 727fa1f and e569b08, restoring the hand-written `$XDG_DATA_HOME`-else-platform-data-dir rule in `nushell_data_dir_fallback`. The measurement asked for on #4104 came back big: eight new `Cargo.lock` entries and ~18.7k lines of source, over half of it the `darling` chain pulled in for one `#[derive(Setters)]` on nu-config's `TestEnv` test helper, which compiles into every build. Against that, the delegation bought no coverage — `vendor_autoload_dirs.last()` resolves to the same directory the ~15 reverted lines compute on all three platforms, with `$NU_VENDOR_AUTOLOAD_DIR` the only behavior it added, and nu-config is version-locked to a Nushell release so it answers for the pinned version rather than the installed one, in exactly the case where there is no installed `nu` to check against. The etcetera consolidation this PR set out to deliver is untouched.
worktrunk-bot
left a comment
There was a problem hiding this comment.
Self-review of a1fe07cb8. The revert is clean — src/shell/paths.rs is byte-identical to 2a20fff26, the last commit before the nu-config series, and all four reverted commits touched nothing outside that experiment. CI is green on all three platforms, including codecov/patch.
One consequence of the etcetera delegation hasn't been raised yet, and it needs a call rather than a fix from me.
Xdg::new() couples the XDG config read to a resolvable home directory. etcetera's Xdg captures the home directory at construction (home_dir: crate::home_dir()?) and config_dir() reads it off the struct, so Xdg::new() fails when no home can be resolved — even when $XDG_CONFIG_HOME is set and absolute. Both replaced sites used to need no home directory in that case: read_tea_config took std::env::var_os("XDG_CONFIG_HOME") first and only fell back to ~/.config, and opencode_plugins_dir reached home_dir() only on its last rung. So with an absolute $XDG_CONFIG_HOME and no resolvable home — no $HOME and no passwd entry for the uid, which is how a container run under an arbitrary uid looks — Gitea detection now silently finds no tea config where it previously read one, and wt config plugins opencode install errors with "Could not determine home directory" instead of writing under $XDG_CONFIG_HOME.
The OpenCode half fails loudly, which is the acceptable direction. The Gitea half is silent in the same way the bug this PR fixes was silent, which is why it's worth a decision rather than a shrug: keeping that case working means reading the variable by hand ahead of etcetera at both sites, and that is precisely the duplication you asked to delete. I don't think a bot should re-introduce it unilaterally, so it's flagged here and recorded in the description under What the delegation costs.
The description also described the nu-config delegation as present, including a "known gap" that only existed in the reverted nushell_autoload_candidates. Recomposed around the current diff.
…s where fish reads it (#4107) ## Problem `config_paths`'s fish arm resolved the wrapper directory as a hardcoded `~/.config/fish`, while `completion_path`'s fish arm two functions down used the XDG config directory. Same tool, same process, two rules — so a `$XDG_CONFIG_HOME` pointing anywhere but `~/.config` sent the two files to different directories. Fish reads `$__fish_config_dir`, which follows `$XDG_CONFIG_HOME`: it autoloaded the completion and never saw the wrapper. Nothing surfaced the split. `wt config shell install fish` printed `✓` for both files, and `wt config show` read its "configured" answer back from the same hardcoded path it had just written, so the report agreed. What the user saw was `wt switch` leaving the shell in the same directory, with completions working. ## Solution One `fish_config_dir()` helper resolves fish's config directory, and every path fish itself reads goes through it: the wrapper (`config_paths`), the completion (`completion_path`), the directories `wt config shell uninstall` scans, and the `functions/` entry in `scan_for_detection_details` that `wt config show` reports from. Install, uninstall and detection agree on one directory rather than three hardcodes and one lookup. The helper uses `etcetera`'s `Xdg` strategy rather than `choose_base_strategy`, which resolves `%APPDATA%` on Windows — fish has no `%APPDATA%` notion on any platform, and one resolver with no platform branch is the simpler code. On Unix the two are identical, so this is a no-op there. On Windows it moves the fish completion off `%APPDATA%\fish\completions` onto `%USERPROFILE%\.config\fish\completions`, where the wrapper already resolved — that is the two files agreeing, not a path fish can load: `Xdg::new` takes its home from `std::env::home_dir`, which returns `%USERPROFILE%` on Windows and stopped reading `HOME` there in Rust 1.85, so the POSIX `$HOME` a Cygwin or MSYS fish runs under is the one thing it won't see. The `%APPDATA%` completion an earlier install wrote is left in place, like the other pre-fix files. Uninstall does not chase the `~/.config/fish` directories a pre-fix install wrote to. Fish never loaded those files, so they are not integration to remove, and scanning a second directory per file kind costs more machinery than the case is worth. The same applies to the Windows completion this moves off `%APPDATA%`. Two things deliberately stay pinned to `~/.config/fish`: - `legacy_fish_conf_d_path`, which names a file worktrunk *wrote* rather than one fish reads. Install removes what it resolves to whole and unread, so resolving it through `$XDG_CONFIG_HOME` would both stop finding the stranded file and start deleting a `conf.d/{cmd}.fish` in the directory fish actually loads — one worktrunk never wrote. Install's deletion surface is therefore unchanged by this PR. - `scan_for_detection_details`'s `conf.d` entry, because `config/show.rs` decides `legacy_fish_has_integration` by comparing that result's path against `legacy_fish_conf_d_path`. Resolving the two by different rules would stop the "deprecated location" row from ever firing. ## Testing `test_configure_shell_fish_honors_xdg_config_home` installs with `$XDG_CONFIG_HOME` pointed at a directory other than `$HOME/.config`, asserts the wrapper and the completion both land under it, then uninstalls and asserts both are gone. It fails on [`3a6d9c623853befa4ac077442d3d26702d2b9411`](3a6d9c6) with the wrapper missing, and fails again on the uninstall assertion if only the install side is fixed — verified by reverting the uninstall hunk. The existing fish tests did not catch any of this because `set_temp_home_env` pins `XDG_CONFIG_HOME` to `$HOME/.config` — the one value that makes the hardcode and the XDG lookup agree. Nothing can catch the Windows difference for the same reason: that helper pins `APPDATA` to `$HOME/.config` too. `cargo test --test integration configure_shell` (63), `config_show` (196) and `shell` (101) pass locally, as does `cargo clippy --all-targets`. ## Scope This is item 3 of the survey in #4106, which asks not to be turned into a single PR. The other items are independent and untouched here. #4104 edits `src/shell/paths.rs` too (the Nushell paths and the `XDG_*_HOME` guards) without overlapping these hunks. The survey's fuller remedy for this item — asking fish itself via `fish -c 'echo $__fish_config_dir'`, the `nu_dirs()` shape — is still open and isn't verifiable from CI without fish installed. Refs #4106 — automated triage --------- Co-authored-by: worktrunk-bot <[email protected]>
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md
The shared `absolute_env_dir` helper also rewrote the two `XDG_*` reads in this module, which #4104 replaces with `etcetera::base_strategy::Xdg` — the same lines, a different mechanism, and whichever landed second would have decided silently. Those two reads go back to their form on main, the check inlines into `zsh_config_dir`, and the two PRs no longer share a hunk. Adds the absolute-`$ZDOTDIR` case the suite was missing: every other zsh test points the variable at `$HOME` or `/dev/null`, so ignoring it outright passed all 261 shell tests.
…s neighbour The base merge in bcdc987 consumed the blank line separating this PR's Fixed entry from the one below it, leaving the only glued pair in the section.
legacy_nushell_autoload_dirs still reads $XDG_CONFIG_HOME at face value; #4104 brings that one under etcetera's Xdg, so the exclusivity claim was true only for a revision this PR no longer carries.
Drop this PR's CHANGELOG.md entry. Changelog entries are written from the commits at release time (CLAUDE.md, Releases), so an open PR carrying an entry drops it rather than resolving a conflict on it.
this is totally fine; we're an order of magnitude too anxious here. if someone doesn't have a resolvable home dir, then honoring the xdg config in worktrunk is the least of their problems do any simplifications we can given this direction |
read_tea_config resolved the home directory twice — once inside Xdg::new() for the config path, once through path::home_dir() for ~/.tea/tea.yml. Take both from the same strategy and collapse the two if-let chains into one candidate list; the no-home case already read nothing, so behavior is unchanged. Trim the commentary at the other two sites to the rule, dropping the restatements of what an empty or relative value would do.
|
Taken as a precondition in c4089e3, and it simplified one more site than the delegation itself did.
fn read_tea_config() -> Option<String> {
let xdg = Xdg::new().ok()?;
[
xdg.config_dir().join("tea").join("config.yml"),
xdg.home_dir().join(".tea").join("tea.yml"),
]
.into_iter()
.find_map(|path| std::fs::read_to_string(path).ok())
}No behavior change: The other two sites keep their code and lose commentary — the paragraphs re-deriving what an empty or relative value would do at each one, which the
|
#4104 moved the OpenCode plugin path to etcetera's Xdg strategy, which uses $XDG_CONFIG_HOME only when it is absolute, but the help text still said install mirrors OpenCode's precedence. OpenCode reads a relative value as-is, so the two differ there; say that an empty $OPENCODE_CONFIG_DIR and an empty or relative $XDG_CONFIG_HOME are ignored. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…obable environments (#4137) Four times in the last 24 hours, `max-sixty` asked a bot PR for less code, and each time the ask was the same one in a different costume: stop encoding another tool's rules in `wt`, and stop defending environments that are already broken. Nothing in `CLAUDE.md` said either, so each PR re-learned it in review. The first extends **Code Quality → Use Existing Dependencies**, which already tells you to reach for a dependency before hand-rolling a utility; the second gets its own heading beside it, since defending an environment has nothing to do with dependencies. Both cases the delegation rule came from resolved *into* its exception rather than out of it — #4085 established that zsh has no "where should the config file go" to ask, and #4124 that MiniJinja exposes no binding list without `unstable_machinery`. The guidance names neither: cited as examples, they read as debt still to pay off, and the zsh decision already lives in `zsh_config_dir`'s docstring, which is where the rule says that reasoning belongs. The generalisation is the maintainer's, not an inference from the diffs — on #4085: *"can we try to remove as much as possible from our code that attempts to interpret the internals of other libraries?"*, prefaced with *"we hit this on some of the sibling issues"*. #4106 is the standing backlog that same instinct produced. **Second half, the anxiety one.** On #4104: *"this is totally fine; we're an order of magnitude too anxious here. if someone doesn't have a resolvable home dir, then honoring the xdg config in worktrunk is the least of their problems"* — the wording here is close to his deliberately. The earlier instance is #4107, where a bot self-review invented a scan of a stranded fish config directory and he cut it: *"if someone moves the config dir, then we'll miss the uninstall, that's fine"*. The **Data Safety** carve-out is explicit because that section rules the opposite way on purpose, and this paragraph must not be read as licensing a silent loss. **Why now rather than at the next instance.** The behaviour is stochastic, so it carries a 5-occurrence floor; the window took it to six (#4085, #4104, #4123, #4124 here, plus #4104's `nu-config` round and #4107 recorded on 2026-09-15 in #3980). The bot also has seven PRs open, over the self-initiated budget — this one is filed anyway because the cost class is a wrong outward action, not compute: #4124 shipped a hand-rolled MiniJinja binding scanner whose correctness gap the maintainer had to find himself. <details><summary>The four corrections, and what each one cost</summary> | PR | Correction | Outcome | |----|-----------|---------| | [#4085](#4085) | "can we just ask `zsh` for whether the config file should go?" | Bot showed the `zsh -f -c` probe relocates the rule rather than removing it, deleted the zsh-source docstring, and gave `zsh_config_dir` the absolute-only guard the module already applied to `$XDG_DATA_HOME`. The rule itself stays in `wt`. Merged. | | [#4104](#4104) | "we're an order of magnitude too anxious here" | Taken as a precondition in `c4089e3c`; `read_tea_config`'s two home-directory resolutions collapsed into one candidate list. Merged. | | [#4123](#4123) | "can't we just delegate all toml parsing to serde?" | Bot tested `serde_ignored` in a scratch crate and reported where `#[serde(flatten)]` blinds it, rather than answering from reasoning. Open. | | [#4124](#4124) | "the new binding scanner still misses parenthesized tuple targets that MiniJinja 2.24 accepts" | Fixed in `5fe64767` across `for`/`set`/`with`; deriving bindings from MiniJinja's parse needs `unstable_machinery`. Open. | Only the last is a correctness defect — the other three are complexity the maintainer declined to carry. The bot absorbed all four within hours, so the gap is not in how it responds but in it not knowing beforehand. Evidence for this run is appended to the `review-runs-tracking` issue [#3980](#3980); the prior two occurrences are under `Run 34943713746`. </details> `CLAUDE.md` is hand-edited, not generated, so no mirror regenerates from it and `test_docs_are_in_sync` is unaffected. --------- Co-authored-by: worktrunk-bot <[email protected]> Co-authored-by: worktrunk-bot <[email protected]> Co-authored-by: Maximilian Roos <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Version bump to 0.78.0 plus the changelog section for this release, a comment-preservation fix the release review turned up, a PTY test-filter fix, and merges of `main` (commits that landed during the review, including #4124, #4122, #4141, #4140 and #4145). **Bump level**: minor. `cargo semver-checks` reports 2 breaking library changes — a new `leftover_branch` field on the `GitError::WorktreeCreationFailed` struct variant, and `DEPRECATED_TEMPLATE_VARS` removed. Pre-1.0, so a breaking change takes a minor bump. ## Comment-preservation fix A config save — declining the commit-generation offer, say — dropped the trailing comment on every value it rewrote. That was already true in v0.77.0 for a line the save itself changed (`skip-commit-generation-prompt = false # note` → `true`, reproduced on the v0.77.0 binary). #4080 widened it to lines the command never touched: retired template variables now migrate on every load, so the next unrelated save rewrote any line naming one. #4080's own PR said this "needs a call before merge" and merged without one. - `replace_keeping_decor` keeps the value's decor (spacing after `=`, trailing comment) when `merge_tables` replaces a scalar. Comments *above* a line sit on the key and were never at risk. - `main`'s #4120 independently reworked the inline-table arm and moved a key's leading comment onto the rewritten header, but documented that a trailing comment after the closing brace "is still dropped". `replace_inline_with_table` now carries it after the header's `]`, so both of its callers keep it. - Tests: the existing comment-preservation test goes back to a retired name (the only fixture that exercises the replacement) and adds a comment on the mutated line; a new test snapshots and re-parses an inline `[projects]` entry. Each fails without its half of the fix. Not fixed, and identical on v0.77.0: a save deletes an explicitly written *default* value (e.g. `skip-commit-generation-prompt = false # note`) as a stale key, comment included. ## `--help` correction #4104 moved the OpenCode plugin path to etcetera's `Xdg` strategy, which uses `$XDG_CONFIG_HOME` only when absolute — a deliberate, documented choice — but `wt config plugins opencode --help` still said install mirrors OpenCode's precedence. OpenCode reads a relative value as-is, so the help now says an empty `$OPENCODE_CONFIG_DIR` and an empty or relative `$XDG_CONFIG_HOME` are ignored. ## Data-loss surface review Independent finders swept the full diff, including the five commits merged from `main`. Nothing holds the tag; candidates were adjudicated against v0.77.0 binaries: - **Fixed in this release, reproduced on v0.77.0**: #4104 stops `wt config shell install` (with Nushell) deleting a `nushell/vendor/autoload/wt.nu` under the current directory when `$XDG_CONFIG_HOME` is empty or relative; #4120 stops a save or migration from writing an inline section's comment inside `[commit]` brackets, which made the config unparseable, and from dropping unknown keys. - **`wt step prune --min-age` doesn't apply where no reflog exists** — pre-existing, proven by building the pre-#4077 binary. `git clone --bare` and `git fetch` into `refs/heads/*` write no reflog, so in the bare layout `tips-patterns.md` recommends every branch starts unprotected. Docstring corrected here; behavioral fix is follow-up. - **`wt config update --output <path>` replaces any named file whole**, no existence check or prompt — pre-existing, follow-up. - **`wt config shell install fish --yes` replaces a hand-written wrapper at the XDG path** — accepted ("ownership is the path", predates #3602), newly reachable only for users with `$XDG_CONFIG_HOME` set. The FAQ's delete inventory now cross-references it. - **`--var <retired-name>` binds a name nothing references** after #4080 — inert, no shipped usage; follow-up. - **#4135 migrates nothing**: an existing oh-my-pi hook stays put, `pi uninstall` points at `omp uninstall`. `PI_CODING_AGENT_DIR='~/x'` is used literally (Pi expands `~`) — creates a stray directory, deletes nothing; follow-up. ## Changelog 37 entries; each new or edited entry was re-verified against v0.77.0 until a pass came back clean (six passes in all). Passes caught, among others: the OpenCode `-x` recipe was wrong since 0.76.0, not 0.75.0; #4080's JSON reaches every hook, not just `pre-start`/`post-start`; a quoted git error string git never prints; a copy-button overlap that existed only inside this release; #4104's relative-`XDG_CONFIG_HOME` OpenCode change described as a fix when OpenCode reads that path as-is; and which commands a broken inline section stopped. **Fixed** leads with the data-loss entries. ## Open PRs checked against v0.77.0 - **#4124** fixed a bug new in this release, caused by #4080, and has landed and been merged in here. The hand-rolled template-variable scanner it extends is slated for removal; see its commit message. - **#4112** — no data-loss regression vs v0.77.0; two small non-safety regressions from #4111 (an uncapped auto-staging file list, a narrow `Nothing to commit` refusal under `status.showUntrackedFiles = no`). Not merged, by decision. - **#4122** (merged in) and **#4123** — pre-existing bugs, identical on v0.77.0. ## PTY filter fix `test (macos)` failed once on a shell's failed-`setpgid` diagnostic that landed straight after the capture's trailing `\x1b[0m`, with no newline between, so #4136's line-anchored filter missed it. The filter now also matches right after an SGR escape and keeps the escape; its test gains that shape and fails on the old pattern. ## Validation - `cargo run -- hook pre-merge --yes` — 4930 tests passed, 1 skipped; clippy, fmt, doc-sync, snapshot and lockfile checks green - Nightly on the original cut-from tip (https://github.com/max-sixty/worktrunk/actions/runs/35060617020): green across `full-tests` on linux/macos/windows, `feature-powerset`, all `release-target`s, `nix-flake`, `minimal-versions`, `link-check` > _This was written by Claude Code on behalf of max-sixty_ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
worktrunk 0.78.0 Created-by: HarmonybrewBot Commit-by: HarmonybrewBot Merged-by: HarmonybrewBot Description: Created by `brew bump` --- Created with `brew bump-formula-pr`.<details> <summary>release notes</summary> <pre>## Release Notes ### Improved - **Hook scripts read renamed context keys**: the JSON piped to every hook drops `worktree`, `repo_root`, `main_worktree`, and `main_worktree_path` in favour of `worktree_path`, `repo_path`, `repo`, and `primary_worktree_path`. Config templates migrate on load, so hooks written with the old names keep working; scripts reading the JSON, `--execute` templates, and `--var` overrides need updating. (Breaking.) ([#4080](max-sixty/worktrunk#4080)) - **`wt config plugins pi` installs for Pi; oh-my-pi moves to `wt config plugins omp`**: `pi install` wrote an oh-my-pi hook, which Pi never loads; Pi users re-run it to get a Pi extension. Existing oh-my-pi hooks keep working, listed as outdated until `wt config plugins omp install`. (Breaking: scripts that run `wt config plugins pi` for oh-my-pi need `omp`.) [Docs](https://worktrunk.dev/claude-code/#oh-my-pi) ([#4135](max-sixty/worktrunk#4135), thanks @ashebanow) - **Interactive prompts no longer open with a blank line**: `wt config shell install`, `wt config plugins claude install`, and the commit-message setup offer in `wt merge` began with one. ([#4059](max-sixty/worktrunk#4059)) - **`wt config show` gives a single `wt config shell install` hint**: an outdated wrapper, a fish wrapper at the deprecated `conf.d` path, and missing fish completions each printed their own hint. The zsh `compinit` snippet is now syntax-highlighted. ([#4059](max-sixty/worktrunk#4059)) - **`wt config update --output <path>` confirms the write**: it now prints `✓ Wrote user config migration @ ~/migrated.toml` where it printed nothing. `--output=-` stays silent. ([#4053](max-sixty/worktrunk#4053)) ### Fixed - **Removal no longer discards untracked files hidden by `status.showUntrackedFiles = no`**: under that setting, a worktree holding only untracked files looked clean, so `wt remove`, `wt merge`, and `wt step prune` removed it without `--force`. Safety checks now always count untracked files, and auto-staging warnings list every file they stage. ([#4111](max-sixty/worktrunk#4111), thanks @Duang777) - **`wt remove` and `wt merge` check the right worktree under an inherited `GIT_DIR`**: run from a `!wt` git alias or a git hook, which pass `GIT_DIR` down, `wt remove` could delete a dirty worktree without `--force`, and `wt merge` could refuse a clean merge. Both now check the worktree they act on. ([#4082](max-sixty/worktrunk#4082), thanks @Duang777) - **`wt merge` no longer deletes a worktree locked with `git worktree lock`**: the merge completes and prints `Worktree preserved (locked)`. Every Worktrunk removal refuses a locked worktree, even with `--force`; run `git worktree unlock <path>` first. ([#4073](max-sixty/worktrunk#4073), thanks @Duang777) - **`wt config update` no longer overwrites a config edited while its prompt is open**: it wrote the pre-prompt snapshot over the newer file and reported success. It now fails with the path and leaves the newer file; re-running previews the current contents. ([#4127](max-sixty/worktrunk#4127), thanks @zach-hammad-vs for reporting) - **`wt step prune` no longer deletes a branch created minutes ago from an older commit**: `--min-age` aged a branch without a worktree by its commit's date, so a new branch off a day-old commit was pruned on the next run. Age now comes from the branch's oldest reflog entry. ([#4077](max-sixty/worktrunk#4077)) - **A comment or blank line above an inline config section no longer breaks the config**: a save or migration that rewrote `commit = { … }` as `[commit]` put that line inside the brackets. `wt switch`, `wt merge`, `wt remove`, and several `wt step` commands then failed with `Failed to load config`; `wt list` warned and ran without the config. Saves also dropped unrecognized keys from inline sections. ([#4120](max-sixty/worktrunk#4120), thanks @zach-hammad-vs for reporting) - **Config saves keep the trailing comment on a value they rewrite**: a save such as answering the commit-generation offer dropped the comment after each value it rewrote, including one after an inline section's closing brace. ([#4138](max-sixty/worktrunk#4138)) - **Ignored project-config keys warn from every worktree**: an unknown key in `.config/wt.toml`, or one that belongs in user config such as `[merge]`, warned only in the main worktree, so `wt merge` from a linked worktree ignored it silently. ([#4145](max-sixty/worktrunk#4145), thanks @ee-prog for reporting) - **`wt merge` skips `post-commit` when it removes that hook's worktree**: before, the hook ran in the primary worktree when the removed one sat inside the repository, and otherwise didn't run. The merge now prints `▲ Skipped post-commit`; move work that must finish there to `pre-remove`. ([#4049](max-sixty/worktrunk#4049)) - **`wt switch` recovers from a removed worktree in a bare repository**: `wt switch` and the picker surfaced git's raw `fatal: Unable to read current working directory` instead, and the removed-directory message lacked `wt switch ^`. ([#4067](max-sixty/worktrunk#4067)) - **`wt config shell install fish` puts the wrapper where fish reads it under a custom `$XDG_CONFIG_HOME`**: the wrapper always went to `~/.config/fish/functions/`, so install reported success while `wt switch` changed no directory. On Windows, the fish completion moves from `%APPDATA%\fish\completions` to the wrapper's directory. ([#4107](max-sixty/worktrunk#4107)) - **`wt config shell install zsh` honours `$ZDOTDIR` only when it is absolute**: an empty or relative value resolved against the current directory, so install appended to a `.zshrc` under the current directory and reported success while the file zsh reads went untouched. A non-absolute value now falls back to `$HOME`. ([#4085](max-sixty/worktrunk#4085)) - **`wt config shell install` for Nushell no longer deletes a `wt.nu` under the current directory**: an empty or relative `$XDG_CONFIG_HOME` resolved against it, so install removed a `nushell/vendor/autoload/wt.nu` beneath it unread, as a stale wrapper. It now falls back to `~/.config`, which also fixes unread `tea` logins that let `wt switch pr:<n>` treat a Gitea host as GitHub. ([#4104](max-sixty/worktrunk#4104)) - **`wt switch --create` names the branch a failed worktree add leaves behind**: `git worktree add -b` writes the branch ref before populating the worktree, so a failure in between left the branch with no worktree, and the next attempt reported a name collision. The error now says how to delete or reuse it. ([#4109](max-sixty/worktrunk#4109), thanks @technicalpickles for reporting) - **`wt config shell install` no longer tells an already-wrapped shell to restart**: reinstalling from a shell with the wrapper loaded, such as after a version bump, printed `↳ Restart shell to activate shell integration`. ([#4059](max-sixty/worktrunk#4059)) - **`wt config shell install` migrates a deprecated `conf.d` fish wrapper when `~/.config/fish/functions` is missing**: before, only `wt config shell install fish` migrated it. `wt config show` now reports that wrapper even when fish isn't on `PATH`. ([#4059](max-sixty/worktrunk#4059)) - **Plugin status and uninstall checks ask the agent CLIs**: `wt config show` could list an installed Claude Code plugin or Gemini CLI extension as not installed, and `wt config plugins claude|codex uninstall` could report success over a marketplace still configured. A repeat Claude uninstall now runs both removals instead of stopping at `Plugin not installed`. ([#4048](max-sixty/worktrunk#4048), [#4054](max-sixty/worktrunk#4054)) - **`wt config plugins opencode install` no longer writes the plugin into the current directory**: with `OPENCODE_CONFIG_DIR` set but empty, it wrote `plugins/worktrunk.ts` there, typically inside a repository, reporting success though OpenCode never saw it. An empty value now counts as unset. ([#4084](max-sixty/worktrunk#4084)) - **The OpenCode plugin clears its activity marker when OpenCode 1 disposes it**: only explicit session deletion cleared it, so a finished session kept its `💬` and `wt list` showed it as active until `wt config state marker clear` was run by hand. ([#4129](max-sixty/worktrunk#4129), thanks @drewdas for reporting) - **`wt config update` migrates `[ci] platform` into a `[forge]` section that only sets `hostname`**: that config, common with GitHub Enterprise and self-hosted GitLab, kept the deprecated key with no deprecation warning. ([#4061](max-sixty/worktrunk#4061)) - **Deprecated keys in an inline `[projects]` entry now migrate**: `"example.com/org/repo" = { merge = { no-ff = true } }` skipped the migration the section form got, so the per-project setting was ignored. ([#4122](max-sixty/worktrunk#4122), thanks @zach-hammad-vs for reporting) - **A deprecated config section the migration can't rewrite now warns**: `select = "not a table"`, or a `[select]` whose `[switch.picker]` destination is already set, was ignored without a message. It now reports `unknown field select (will be ignored)`. ([#4121](max-sixty/worktrunk#4121), thanks @zach-hammad-vs for reporting) - **`wt config update` no longer changes what a template renders**: it could rename `{{ repo_root }}` inside a quoted s See merge request: Harmonybrew/homebrew-core!20435
wt's Gitea support readstea's config file directly to answer "is tea logged in to this host?" —is_authed_forfor thewt switch pr:<n>forge dispatcher,has_any_loginfor the CI-status backend.read_tea_configtook$XDG_CONFIG_HOMEat face value, so an exported-but-empty value turned the lookup into the relativetea/config.yml, resolved against whatever directorywtwas invoked from. The user's real~/.config/tea/config.ymlwas never read, and where the repository happened to contain atea/config.yml, that file was consulted instead.With no logins found, both callers report no Gitea login, and the effect is silent:
wt list --fullin a Gitea repository drops the CI column (ci_status/mod.rsgates the backend onhas_any_login()).wt switch pr:<n>against a self-hosted host thatteais logged in to falls through to the GitHub CLI (switch.rs, the forge dispatcher).The XDG base directory spec makes both exclusions: an unset or empty value means the
$HOME-relative default, and a relative path is invalid and must be ignored.Why this isn't gitea-specific
It isn't, and the first revision was wrong to scope it there. worktrunk read an
XDG_*_HOMEvariable at four sites, each joining a subpath onto it, and each had written the rule at a different strictness — soXDG_CONFIG_HOME=cfgpicked the target by cwd at three of them.The three that mean "the XDG config directory" now delegate to
etcetera::base_strategy::Xdg::config_dir()— the env read, the spec's absolute-only filter, and the~/.configfallback in one call, from the crate worktrunk already resolves its own config with. Each caller's hand-written~/.configfallback goes with it, so the fix is net −39 lines.read_tea_config(git::remote_ref::gitea)XDG_CONFIG_HOMEXdg::config_dir()opencode_plugins_dir(commands::config::opencode)XDG_CONFIG_HOMEXdg::config_dir()legacy_nushell_autoload_dirs(shell::paths)XDG_CONFIG_HOMEXdg::config_dir()nushell_data_dir_fallback(shell::paths)XDG_DATA_HOMEXdgrather thanchoose_base_strategy()at the first three: both tools honor$XDG_CONFIG_HOMEon every platform, whichXdgkeeps and the native strategies don't. Their defaults differ — OpenCode reads~/.configeverywhere (~/Library/Application Support/opencode/is its managed-settings path, which is whyopencode_plugins_diralready avoideddirs::config_dir()), while tea's default comes fromgithub.com/adrg/xdg:~/Library/Application Supporton macOS,%LOCALAPPDATA%on Windows. SoXdgmatches tea's default on Linux only;choose_base_strategy()would give~/Library/Preferencesand%APPDATA%, matching it on neither. worktrunk's own config keepschoose_base_strategy(), which is the right answer for a native CLI config dir.That leaves a pre-existing gap this PR doesn't close: on macOS with
$XDG_CONFIG_HOMEunset,wtlooks in~/.config/tea/config.ymlwhile tea's logins are in~/Library/Application Support/tea/config.yml— the same silent symptom described above. It is unchanged frommain, and whetherread_tea_configshould also try tea's native macOS and Windows defaults is a behavior change past this PR's scope.Beyond tea, this fixes two real targets:
wt config plugins opencode installwith a relative$XDG_CONFIG_HOMEwrote the plugin under the invocation directory (the empty case was fixed in #4084; the relative case was not), and the Nushell uninstall's search for wrappers stranded by older versions searched a relativenushell/vendor/autoload.The home directory is a precondition
etcetera'sXdgcaptures the home directory at construction, soXdg::new()fails when none can be resolved even where$XDG_CONFIG_HOMEis set and absolute — a container run under a uid with no passwd entry and no$HOME. Per review, that is accepted rather than worked around: a machine with no resolvable home has larger problems than worktrunk's XDG reads, and preserving the case means reading the variable by hand ahead of etcetera at every site, which is the duplication this PR deletes.Taking it as a precondition simplifies one more site than the delegation itself did.
read_tea_configresolved a home directory twice — insideXdg::new()for~/.config/tea/config.yml, then again throughpath::home_dir()for the legacy~/.tea/tea.yml. Both now come off the one strategy (xdg.home_dir()), and the twoif letchains collapse into one candidate list. The no-home case read neither file before, so nothing changes behaviorally.The fourth site stays spelled out
nushell_data_dir_fallbackis the one read that doesn't follow the XDG spec — it mirrors Nushell's ownresolve_xdg_base(XDG_DATA_HOMEwhen absolute, otherwisedirs::data_dir()), because etcetera'sXdg::data_dir()falls back to~/.local/shareeverywhere, which is the wrong directory on macOS and Windows, while theApple/Windowsstrategies that get those right ignoreXDG_DATA_HOME. It already applied the absolute-only rule, so it is unchanged here apart from moving tovar_osfor parity with the other sites.An intermediate revision delegated it to
nu-config, Nushell's own path-resolution crate, and that was dropped ina1fe07cb8after measuring it. The delegation bought drift-proofing, not coverage:resolve_paths(...).vendor_autoload_dirs.last()resolves to the same directory the ~15 hand-written lines compute on all three platforms, because nu-config appends the$XDG_DATA_DIRSand macOS/Library/Application Supportentries before the data-home one and only the last entry is the write target. Against that it cost eight newCargo.lockentries and ~18.7k lines of source — over half of it thedarlingchain, pulled in for one#[derive(Setters)]on nu-config's always-compiledTestEnv— and a version lock to a Nushell release, so it would answer for the pinned version rather than the installed one in exactly the case where there is no installednuto check against. Worktrunk already delegates the reachable half:nu_dirs()asks a runningnufor$nu.vendor-autoload-dirs | last, and that is what the install writes to whenevernuis on PATH. The reinstated lines answer only the case shelling out can't reach — the uninstall scan looking for a wrapper an older worktrunk stranded on a machine where Nushell has since been removed.Testing
The OpenCode install target — the one site where a bad value writes a file rather than failing to read one — is pinned end-to-end by
test_opencode_install_ignores_relative_xdg_config_homeintests/integration_tests/config_show.rs. Those tests spawnwtas a child process, socmd.env("XDG_CONFIG_HOME", …)sets the child's environment and races nothing; it is a sibling oftest_opencode_install_treats_empty_config_dir_as_unset, which #4084 added for the same shape one rung up the precedence. It fails against the pre-fix resolution and passes now.test_uninstall_nushell_finds_wrapper_under_xdg_data_homecovers the$XDG_DATA_HOMEcandidate end-to-end. The XDG config rule itself is not unit-tested here: etcetera's XDG strategy carries doctests asserting exactly the empty-and-relative behavior, so a local copy would be restating a dependency's contract.Overlap with #4085
That PR adds an absolute-only filter inline to
legacy_nushell_autoload_dirs. This supersedes that hunk — itsZDOTDIRchange is independent and unaffected, so on rebase #4085 should drop theshell/paths.rshunk and the CHANGELOG sentence about it.