Skip to content

feat: link existing SDKs, add vfox doctor, aliases and path.mode - #736

Merged
linghengqian merged 14 commits into
version-fox:mainfrom
linghengqian:receipt-link-doctor-alias
Oct 22, 2026
Merged

linghengqian merged 14 commits into
version-fox:mainfrom
linghengqian:receipt-link-doctor-alias

Conversation

@linghengqian

@linghengqian linghengqian commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Why

vfox treats an installed SDK as a directory name, and assumes it is the only author of what is inside that directory and of PATH. A number of open reports are the same gap seen from different sides:

What vfox assumes What users run into
Nobody else writes to an installed SDK flutter upgrade / downgrade / channel rewrite the SDK in place, and vfox has no record of what it installed
The PATH vfox exports is the one that takes effect pnpm's node, a system JDK or Homebrew's node in front of vfox's directories (#337, #732)
Every SDK was installed by vfox A system JDK, an IDE download or a CI tool cache cannot be registered (#706, #669)
A version is named by its directory There are no short names for versions (#670, #359)

The core now owns the chain "record → check → tell", and plugins only supply facts. Unlike the shim proposal (#726), everything stays per version, vfox says what is actually in effect, and the user never has to run anything after a switch: receipts are written by install and link, the checks run after use, and activate records the PATH baseline.

What it adds

$ vfox link java@17-system /usr/lib/jvm/java-17-openjdk-amd64    # nothing is downloaded or copied
$ vfox list java
-> 17-system (linked → /usr/lib/jvm/java-17-openjdk-amd64)
$ vfox info --format "{{.Home}}" java@17-system                  # what JAVA_HOME wants
$ vfox uninstall java@17-system                                  # removes the link, never the JDK
$ vfox use -g [email protected]                                     # a pnpm `node` sits in front of vfox in PATH
Now using [email protected].
 WARNING  `node` runs ~/pnpm/bin/node instead of [email protected]: its directory comes before vfox in PATH.
  pnpm installed its own node. Run `pnpm remove -g node`. See https://example.com/pnpm
  That directory was added to PATH after `vfox activate` ran. Activate vfox after the line that adds it in your shell's startup file, or run `vfox config path.mode aggressive`.

(Output of a local run with a throw-away plugin; names and paths changed for readability.)

  • Receipts. Every installation leaves .vfox-receipt.json in its version directory: what was asked for, the sources (URLs without credentials and query, never request headers), the vfox and plugin versions, and who owns the files. It is written atomically after PostInstall and before the .installing marker is removed, and it is advisory: failing to write it never fails an installation, and a version without one is a legacy installation for which every check that needs a baseline stays silent.
  • vfox link <sdk>@<version> <path> registers an SDK that already exists. The version name is used as written, the plugin's own EnvKeys decides whether the directory looks like the SDK, and --force only re-points a link, never replaces a version vfox installed. A linked version works like any other (install is a no-op; use, env, info work); uninstall removes only the link and the receipt, runs no PreUninstall and works when the target is gone. vfox info gets {{.Home}} and --json.
  • vfox doctor [<sdk>[@<version>]] [--json] runs the checks with stable finding IDs and exits with 1 only for errors. The fast checks also run after vfox use and only print warnings; they never fail use. diagnostics.onUse and diagnostics.ignore (<id>[:<sdk>[@<version>]]) control them. path.shadowed compares the commands of the selected version with the executables in front of vfox's directories, in the order vfox env is going to export; plugins can add explanations with declarative PLUGIN.shadowHints. It looks at the version the shell uses, which is what vfox env exports, including its fallback to another installed version when the configured one is missing. A command that is the very file the SDK provides, such as a symlink to a linked SDK, is not a shadow.
  • Fingerprint hook (optional) returns facts that identify an installation. They are stored in the receipt and compared again by use and doctor (sdk.drift). vfox install --reinstall restores a version that changed in place, and vfox doctor --adopt writes the missing receipts of legacy installations.
  • path.mode (legacy | baseline | aggressive, plus path.preserve). vfox activate records the PATH it found in __VFOX_ORIG_PATH, so that the system directories macOS and Windows put in front of vfox's can be told apart from what was added later (pnpm, a virtualenv). The default stays legacy, which is today's behavior. Quick Start and the READMEs ask new installations to set baseline, and the docs announce that it becomes the default in a future release. Nushell cannot evaluate what activate prints, so the vfox.nu that activate nushell generates records the baseline itself. A change of path.mode or path.preserve applies at the next prompt.
  • Aliases (vfox alias set|list|unset) are resolved for what is typed on the command line only (use, uninstall, info, exec, doctor) and never written to or read from version files, so .vfox.toml stays portable. An installed version of the same name always wins. A leading v in a typed version (v20.1.0) is only dropped when no version or alias has the name as typed, so aliases and linked versions may start with a v. vfox alias edits only the aliases key of the user's config.yaml: the rest of the file stays as it is, and a section it does not declare keeps following the shared config.
  • Detect hook (optional) lists SDKs found on the machine; vfox link --detect <sdk> [-y] links them, e.g. on a CI runner.

Commits

The PR is meant to be read commit by commit. Each one builds and passes the tests on its own.

  1. fix: treat a runtime directory that is a link as installed — GetRuntimePackage used DirEntry.IsDir(), so a linked SDK was listed but not found by info/use; plus info's Home and --json.
  2. feat: record installation receipts and add vfox link
  3. feat: add vfox doctor and warn when a command is shadowed on PATH
  4. feat: notice SDKs that change in place with the Fingerprint hook
  5. feat: record the PATH at activation and add the path.mode setting — the only commit that changes how PATH is assembled, and only when the setting is changed.
  6. feat: add aliases for installed versions and the Detect hook
  7. docs: describe receipts, link, doctor, hooks, path.mode and aliases — English and Simplified Chinese, plus AGENTS.md.

Commits 8 to 14 answer the review of the first seven (six comments, one commit each) and one more problem found while testing. They are separate commits so that what changed since the review is easy to see.

  1. fix: take a version name as typed before dropping a leading v — alpha@v1 selected the prefix 1 instead of the alias v1, and a linked vendor became endor.
  2. fix: let vfox alias change only the aliases in the user config — it saved the whole default-filled config, which pinned path.mode and diagnostics over the shared config.
  3. fix: record the PATH baseline from vfox.nu in Nushell — Nushell cannot evaluate what activate prints, so it never had a baseline.
  4. fix: refresh the cached env output when path.preserve changes — the cache was only keyed by path.mode.
  5. fix: make vfox doctor check the PATH of the version env uses — doctor skipped the check when env fell back to another installed version.
  6. fix: do not report a link to the SDK's own command as a shadow — a symlink to a linked SDK's own command was reported as shadowing it.
  7. fix: do not declare path and diagnostics in a config file vfox creates — the first run wrote their defaults into the user's file, which then overrode a shared VFOX_HOME.

About 3.5k lines of production code, 7.1k lines of tests and 0.7k lines of docs (added lines). Happy to split it into several PRs if that is easier to review.

Compatibility

  • PATH assembly is unchanged unless path.mode is set.
  • Visible by default: the warning after vfox use when a command is shadowed (vfox config diagnostics.onUse false turns it off), and the __VFOX_ORIG_PATH variable that activate exports (in Nushell, the generated vfox.nu sets it).
  • Plugins only get optional additions: the Fingerprint and Detect hooks and the shadowHints metadata. Existing plugins work unchanged, and an older vfox does not load hook files it does not know.
  • The config.yaml that vfox creates on a first run is the one it created before, without the new diagnostics, path and aliases sections, so a shared VFOX_HOME can still decide them. A section the user's file declares replaces the shared one; one it does not declare follows it.
  • sdk.Sdk (internal) gains Installation, Link, Reinstall, Adopt, Diagnose, Detect and HasVersion.

Testing

  • Unit tests per layer, and end-to-end tests that run the commands in a subprocess against a fake plugin and fake SDK directories.
  • Every commit builds, passes go vet (linux, windows, darwin) and go test on Linux. The regression tests of commit 1 and of commits 8 to 14 fail without the fix.
  • On my fork, the last commit is green on Ubuntu, macOS and Windows: VersionFox CI (including the Windows regressions and Fish completion jobs) and vfox E2E Test (including MSIX).
  • CI has no Nushell, so its unit test checks the text of the generated vfox.nu. I also ran that script in Nushell 0.116.1: with path.mode: baseline, a directory that was in PATH at activation goes behind vfox's and one added afterwards stays in front, while without the line both stayed in front.
  • TestBashZshCompletionShellFormat fails in a CRLF checkout ([Feature]: Repo-wide line-ending policy via .gitattributes #727, chore: add repo-wide line-ending policy via .gitattributes #734); it is unrelated and passes in CI.

Feedback welcome on

  1. The names Fingerprint and .vfox-receipt.json.
  2. Whether the warning after vfox use may be on by default.
  3. Aliases that are never written to .vfox.toml. This differs from the second scenario in [Feature]: 支持为已安装的 SDK 版本添加别名/重命名功能 #670, where an alias is a team convention in the version file; a teammate without the alias would get an "is not installed" that vfox cannot explain.
  4. Asking new installations for path.mode baseline now and flipping the default later.
  5. Whether Detect belongs in the core or in the plugins.

Not in this PR

vfox config <key> <value> still saves the merged config into the user's file, as before, so every section counts as declared by the user after it. Making it write only what was set would be a separate change.

The plugin side follows in their repositories: vfox-flutter can drop its manifest-based drift detection for Fingerprint, vfox-nodejs its PATH scan for shadowHints, and vfox-java can add Detect.

Closes #706
Closes #669
Refs #670, #359, #337, #732

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.20685% with 111 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.05%. Comparing base (b67f56e) to head (6cca7a3).

Files with missing lines Patch % Lines
internal/sdk/link.go 83.69% 8 Missing and 7 partials ⚠️
internal/env/executables.go 75.51% 10 Missing and 2 partials ⚠️
internal/sdk/receipt.go 75.00% 8 Missing and 4 partials ⚠️
internal/env/pathpolicy.go 92.59% 8 Missing and 2 partials ⚠️
cmd/commands/link.go 88.60% 7 Missing and 2 partials ⚠️
cmd/commands/doctor.go 92.98% 4 Missing and 4 partials ⚠️
cmd/commands/alias.go 89.09% 3 Missing and 3 partials ⚠️
internal/config/alias_file.go 90.76% 3 Missing and 3 partials ⚠️
internal/manager_doctor.go 94.64% 3 Missing and 3 partials ⚠️
internal/env/shadow.go 88.37% 3 Missing and 2 partials ⚠️
... and 7 more
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #736       +/-   ##
===========================================
+ Coverage   34.99%   51.05%   +16.06%     
===========================================
  Files          95      111       +16     
  Lines        6704     8236     +1532     
===========================================
+ Hits         2346     4205     +1859     
+ Misses       4045     3609      -436     
- Partials      313      422      +109     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +205 to +223
### Let vfox's versions win over the system's

Run this once, after hooking `vfox` into your shell:

```shell
vfox config path.mode baseline
```

Without it, the system directories that macOS and Windows put in front of `vfox`'s can keep winning: `vfox use` says it
switched, but `node` or `java` is still the system's. With `baseline`, `vfox` puts its directories before everything
that was already in `PATH` when it was activated, and only what is added afterwards, such as a Python virtualenv you
activate later, stays in front of it. Open a new terminal afterwards. If you rely on a directory of your own being in
front of `vfox`'s, list it in `path.preserve`; see [PATH Order Settings](./configuration.md#path-order-settings).

::: info 📌 The default will change
`baseline` is going to become the default of `path.mode` in a future release. Until then the default is `legacy`, which
leaves `PATH` the way `vfox` 1.0.x did. Setting `baseline` now means that upgrading will not change anything for you.
:::

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CC @aooohan . What do you think of this plan? Could you help review it? I actually want to change the default value in another PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s a pretty big change! I’ll take a look.

`vfox list` and CheckRuntimeExist follow symlinks and junctions
(os.Stat), but GetRuntimePackage asked DirEntry.IsDir(), which is false
for them. An SDK linked into the install path by hand was therefore
listed as installed while `vfox info` printed "notfound" and
`vfox use` failed with "runtime not found" (version-fox#669).

Ask the file system about the target instead, so that every way of
asking whether a version is installed gives the same answer. A link
whose target is gone is still not installed, for all of them.

`vfox info <sdk>@<version>` also tells where the SDK lives:

- `{{.Home}}` in --format templates is the main runtime directory, the
  one to point JAVA_HOME and the like at (version-fox#706). `{{.Path}}` keeps
  meaning the version directory, so existing scripts are not affected.
- `--json` prints the version directory, the main runtime, the
  additional runtimes and what the plugin's EnvKeys puts in the
  environment. It works for `vfox info <sdk>` as well.
vfox treated an installed SDK as a directory name and nothing more: it
could not tell who owns the files, and it had no way to use an SDK that
is already on the machine.

Receipt. Every installation now leaves `.vfox-receipt.json` in its
version directory, next to the payload: what was asked for, the sources
(URLs without credentials and query, never request headers), the vfox
and plugin versions, and whether vfox owns the files. It is written
atomically after PostInstall and before the `.installing` marker is
removed. It only informs later checks: failing to write it never fails
the installation, and a version without one is a legacy installation,
for which every check that needs a baseline stays silent.

Link. `vfox link <sdk>@<version> <path>` registers an SDK that is
already there (a system JDK, an IDE download, a CI tool cache; version-fox#706,
version-fox#669). Nothing is downloaded or copied: the version directory holds a
link to <path>, and the version name is used as written, so
`java@17-system` stays `17-system`. No new hook is needed to validate
it: the directories the plugin's EnvKeys puts on PATH must hold
commands (env.ListExecutables, PATHEXT-aware on Windows), or the link is
refused. `--force` points an already linked version somewhere else; it
never replaces a version vfox installed.

A linked version is a version like any other (`install` is a no-op,
`use`, `env` and `info` work), except that vfox does not own its files:

- `uninstall` removes the link and the receipt, never the target, and
  does not run PreUninstall. A link whose target is gone can still be
  removed, and a link made by hand with `ln -s` counts as linked.
- `list` marks it: `17-system (linked -> /usr/lib/jvm/...)`.
- `info` reports the origin and the target, and `info --json` the
  receipt.
pnpm puts its own `node` in front of the one vfox exports, and
`vfox use` says nothing about it (version-fox#732, version-fox#337). Plugins work around this
in Lua, each with its own wording, and the user cannot ask for it.

The core now owns the whole chain; plugins only provide facts.

- `vfox doctor [<sdk>[@<version>]] [--json]` runs the checks. It exits
  with status 1 only when a finding of severity error is not ignored.
  `--json` prints {"ok": ..., "findings": [...]}.
- `vfox use` runs the fast checks for the version it just selected and
  prints the warnings. It never fails because of them.
- A finding has a stable ID, a severity, hints that explain it and
  commands that fix it. This commit has path.shadowed,
  path.not-activated, sdk.link-dangling, sdk.payload-empty,
  sdk.envkeys-failed, sdk.install-interrupted, sdk.plugin-missing and
  plugin.incompatible.
- path.shadowed compares the commands the version puts on PATH with the
  executables in front of vfox's directories, in the order `vfox env`
  is going to export, so it can speak before the shell has picked the
  version up. It names the executable that wins. An active virtualenv
  or conda environment shadows on purpose and is only a notice. Where
  any other directory comes from is not known yet.
- `diagnostics.onUse: false` in config.yaml turns the check after `use`
  off. `diagnostics.ignore` silences findings by
  `<id>[:<sdk>[@<version>]]`.
- A plugin can explain a shadowing executable with declarative
  metadata, `PLUGIN.shadowHints = {{match = "pnpm", message = "...",
  url = "..."}}`, matched against the path of the winner. Detection,
  display and exit codes stay in the core.

Refs version-fox#732, version-fox#337 (diagnosis only).
`flutter upgrade`, `downgrade` and `channel` rewrite an SDK inside the
directory vfox installed it into. vfox kept no record of what it had
installed, so there was nothing to compare with.

Plugins can implement the optional `Fingerprint` hook, which returns
facts that identify an installation (`return {facts = {head = "9584c67"}}`).
It must only read, quickly and without network access. vfox records the
facts in the receipt when it installs or links a version, and asks again
in `vfox use` and `vfox doctor`. When a recorded fact differs or cannot
be read any more, sdk.drift says what changed and how to get back: a
warning, or only a notice for a linked SDK, which is not vfox's to
repair. Facts the plugin learned since are ignored. A hook that fails
makes `doctor` report sdk.fingerprint-failed and leaves `use` silent.

- `vfox install --reinstall <sdk>@<version>` replaces an installed
  version with a fresh copy. The version has to be given exactly as it
  is installed, a linked version is refused, and it cannot be combined
  with --all. If the new installation fails the old one is gone, as with
  any failed installation.
- `vfox doctor --adopt [<sdk>[@<version>]]` writes the receipts of
  versions installed before receipts existed, taking their current state
  as the baseline. It is explicit because doing it by itself would take
  an SDK that has already drifted for the truth. Until then `doctor`
  only mentions the missing receipt (sdk.no-receipt).
- The plugin development commands can run the hook as well.
vfox keeps every PATH entry in front of its own directories in front, so
that a virtualenv activated later keeps winning. That cannot tell apart
entries that mean different things:

- directories the system put first: macOS path_helper, the Windows
  machine PATH (version-fox#337, version-fox#732),
- a directory added after `vfox activate`, such as `pnpm setup`'s,
- an environment the user activated later (version-fox#622).

`vfox activate` now records the PATH it found, without vfox's own
directories, in __VFOX_ORIG_PATH, once per shell session. A shell
started from another shell records its own, and an IDE resolving its
environment never gets it. `vfox env` only reads it, and a missing
baseline means the old behavior.

`path.mode` (config.yaml, or `vfox config path.mode <mode>`) decides
what stays in front of vfox's directories:

  legacy      everything, as in 1.0.x. This is the default.
  baseline    what was added after activation, plus active virtualenv
              and conda directories. What was already in PATH when vfox
              was activated goes behind vfox's directories.
  aggressive  only active virtualenv and conda directories and
              `path.preserve`.

`path.preserve` lists directories that always stay in front;
environment variables and a leading ~ are expanded. The output `vfox env`
caches is keyed by the mode, so a change shows at the next prompt.

The default stays `legacy`: nothing changes for anyone who does not set
it. Making `baseline` the default is a one line change of EmptyPath in
internal/config/path.go, for whoever decides it should be.

`vfox doctor` and `vfox use` can now say where a shadowing directory
comes from (inherited, added after activation, preserved) and which
setting or startup file change would help.

Refs version-fox#337, version-fox#732, version-fox#622.
Aliases (version-fox#670, version-fox#359). `vfox alias set <sdk> <alias> <version>`,
`alias list` and `alias unset` give an installed version a short name.
They are kept in the user's config.yaml (`aliases:`; the shared
config's are used too) and resolved for what is typed on the command
line only: `use`, `uninstall`, `info`, `exec` and `doctor`. They are
never resolved for, or written to, a version file, so .vfox.toml always
holds the real version and stays valid on other machines.

- An installed version of the same name always wins over an alias, and
  `alias set` refuses a name that is an installed version or that is not
  a usable version name.
- `list` shows the aliases, `uninstall` removes the ones that name the
  removed version, and `doctor` reports an alias whose version is gone
  (alias.dangling).

Detect. A plugin can implement the optional `Detect` hook to list SDKs
that are on the machine already (/usr/lib/jvm/*, $JAVA_HOME_*_X64, ...).
`vfox link --detect <sdk>` shows what was found and links it after
asking, or without asking with -y, which is required when not
interactive. Nothing is downloaded; what is installed or linked
already is skipped, with the reason.

Refs version-fox#706 (CI use), version-fox#670, version-fox#359.
English and Simplified Chinese:

- usage: `vfox link`, `vfox doctor`, `vfox alias`, `install
  --reinstall`, and `info`'s `{{.Home}}` and `--json`.
- configuration guide: `diagnostics`, `path.mode` / `path.preserve`
  and `aliases`.
- FAQ: `use` switched but the old command still runs, using an SDK that
  is already installed, and an SDK that changed after vfox installed it.
- plugin guides: the `Fingerprint` and `Detect` hooks and
  `shadowHints`, and how to test them.

Quick Start and the READMEs now ask new installations to run
`vfox config path.mode baseline` right after hooking vfox into the
shell, so that the system directories macOS and Windows put in front of
vfox's stop winning. `legacy` stays the default; the Quick Start and the
configuration guide announce that `baseline` becomes the default in a
future release, and say how to keep today's behavior (`vfox config
path.mode legacy`).

AGENTS.md describes the receipt and link semantics, the diagnostics and
the PATH policy, so that it keeps matching the implementation, and notes
that flipping the default is a deliberate change that updates those
announcements with it.
@linghengqian
linghengqian force-pushed the receipt-link-doctor-alias branch from 8d1afea to 6f56a98 Compare October 22, 2026 03:08

@aooohan aooohan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found six issues that I think we should fix before merging. The main ones are alias resolution picking the wrong installed version and alias updates changing unrelated settings. There are also a few gaps in the PATH handling and doctor checks, with repro details in the inline comments.

I reviewed 6f56a98 on macOS arm64 with Go 1.24.0. The build, go vet ./..., and CI=true go test ./... passed. Seven temporary regression cases using the PR's CLI fixtures reproduced the six issues below. For Nushell, I checked the generated activation script; I haven't run that case in a native Nushell session.

Comment thread cmd/commands/use.go Resolved
Comment thread internal/manager_alias.go Resolved
Comment thread cmd/commands/activate.go Resolved
Comment thread cmd/commands/env.go Resolved
Comment thread internal/manager_doctor.go Resolved
Comment thread internal/env/shadow.go Resolved
`use`, `exec`, `doctor` and `install` removed a leading `v` while parsing
`<sdk>@<version>`, before they knew which names exist. Linked versions and
aliases may start with a `v`, so:

- `vfox alias set alpha v1 2.0.0` followed by `vfox use alpha@v1` selected
  1.0.0, because `v1` had become the prefix `1`;
- a linked version called `vendor` could not be used, run or diagnosed:
  `alpha@endor is not installed`, and `vfox install alpha@vendor` even
  installed a version `endor`.

The commands now keep the version as typed. `Manager.ResolveVersionName`
checks the name as typed first (an installed version, then an alias) and only
then reads the `v` as the conventional prefix (`v20.1.0`), looking the name
without it up the same way. `install` has no aliases to resolve and uses
`sdk.StripVersionPrefix` directly.

A version that is only on disk, such as a link whose target is gone, also
counts as having that name, so `vfox doctor alpha@vendor` can report the
broken link. `Sdk.HasVersion` answers that; `CheckRuntimeExist` stays the
stricter "can be used".
`updateAliases` loaded the user config through `NewConfigWithPath`, which
fills every section the file does not declare with its defaults, and saved
the whole thing. Setting or removing an alias (and uninstalling a version
that had one) therefore wrote `path.mode: legacy`, `diagnostics.onUse: true`
and the other defaults into the user's file as if the user had chosen them.
They then overrode what the shared config said: with `path.mode: baseline` and
`diagnostics.onUse: false` there, the next process saw `legacy` and `true`.

`config.AliasFile` reads and writes the `aliases` key of the file as a YAML
document, so every other key and comment stays, and a section the file does
not declare is still not declared afterwards. The key goes when no alias is
left. A file that cannot be parsed, or whose aliases are malformed, is
refused and left as it is.
`vfox activate` records the PATH baseline for `path.mode` by exporting
`__VFOX_ORIG_PATH` in the script it prints. Nushell cannot evaluate that
output: it only gets a `source` line, and the generated `vfox.nu` did not set
the variable either. A Nushell session therefore never had a baseline, and
`vfox env` fell back to the `legacy` ordering even with `path.mode: baseline`.

The `export-env` block of `vfox.nu` now sets `__VFOX_ORIG_PATH` from the
session's PATH, before the first `vfox env` call. vfox's own directories are
left in; `env` skips them when it compares.

Checked with Nushell 0.116.1: with `path.mode: baseline`, a directory that
was in PATH at activation now goes behind vfox's and one added afterwards
stays in front, while without the line both stayed in front. The unit test
checks the generated script, since CI has no Nushell.
`vfox env` caches its output per shell session and recomputes it when a
version file, the project or the PATH changes. `path.mode` was added to what
invalidates it, but `path.preserve` was not, and `config.yaml` is not among the
files whose modification time is watched. Removing a directory from
`path.preserve` while keeping the mode therefore left the old ordering in
effect until something else invalidated the cache, and the same held for an
environment variable the setting names (`$PNPM_HOME`).

The state now records a PATH policy key instead of the mode: the mode, the
directories `path.preserve` expands to at that moment, and the directories of
an active virtualenv or conda environment, sorted and normalized so that
spelling and order do not matter.
`doctor` limits the shadowing check to the version in effect and took that
from `Sdk.Current`, which only looks at the highest-priority selection. When
that selection is not installed, `vfox env` falls back to the next installed
one, but `Current` returned nothing and `doctor` skipped the check: with
`[email protected]` installed globally and a project asking for the missing
`[email protected]`, an `alphatool` ahead of vfox in PATH went unreported.

`Manager.Diagnose` now takes a `VersionInEffect` from the command layer, which
answers with the same installed-version fallback `env` uses
(`resolveInstalledToolConfig`). Reading the version files, legacy ones
included, moves into `loadToolChain`, which `env` and `activate` use as well,
so that `doctor` cannot drift from them. `Current` is unchanged.
The shadowing check kept only the names of the SDK's commands, so any match in
a directory in front of vfox counted as a different SDK's command. After
linking a system or Homebrew installation as `alpha@sys`, a symlink to its own
`alphatool` in an earlier PATH directory was reported as running "instead of
alpha@sys", although it is the same file.

`findShadows` keeps each command's own path and compares the first match with
it through `os.SameFile`, which follows links. When they are the same file
nothing is reported. The first match still ends the search for that command,
since later ones never run.
…eates

A section that the user's config file declares replaces the shared config's,
and one it leaves out follows it. `NewConfigWithPath` creates a missing file
from `DefaultConfig`, which since the diagnostics, PATH and alias settings
were added includes `diagnostics`, `path` and `aliases`. The first run
therefore wrote their defaults into the file, and from the second run on they
overrode a shared VFOX_HOME: with `path.mode: baseline` and
`diagnostics.onUse: false` there, every later process saw `legacy` and `true`.

A new file now holds the sections it always had (what vfox 1.0.13 creates) and
leaves those three out; `setOnDemand` lists them, for the next section of that
kind. `vfox config` still saves the merged config into the user's file, which
declares every section from then on; that is not changed here.

@linghengqian linghengqian left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All done.

@aooohan aooohan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fixes. I went through the seven follow-up commits on 6cca7a3 and rechecked all six points from my first review. They're addressed now:

  • Names starting with v are resolved before trying the version-prefix fallback.
  • Alias edits leave unrelated settings and shared-config inheritance alone.
  • The generated Nushell script records the baseline before updating the environment.
  • The env cache now accounts for path.preserve and its expanded values.
  • Doctor checks the installed version that env actually falls back to.
  • A symlink or hard link to the SDK's own executable no longer triggers a shadow warning.

The extra fix for a freshly generated user config looks good too; it avoids pinning the new defaults over shared settings.

I ran the build, go vet ./..., and CI=true go test ./... with Go 1.24.0 on macOS arm64. All passed, including the new regression tests, and GitHub CI is green for this commit. I checked the Nushell code and generated-script test, but haven't rerun it in native Nushell locally.

I don't have any remaining blockers from this review. Looks good to me.

@linghengqian
linghengqian merged commit feb6092 into version-fox:main Oct 22, 2026
6 checks passed
@linghengqian
linghengqian deleted the receipt-link-doctor-alias branch October 22, 2026 06:12
@linghengqian linghengqian added this to the 1.0.14 milestone Oct 29, 2026
aooohan pushed a commit that referenced this pull request Nov 7, 2026
* feat(config): make baseline the default path.mode

`legacy` keeps every PATH entry in front of vfox's first directory in
front of it, so a system directory that macOS path_helper or the Windows
machine PATH put there keeps winning over the version `vfox use`
selected (#337, #732). `baseline` fixes that by moving what was already
in PATH when `vfox activate` ran behind vfox's directories, but everyone
had to opt in with `vfox config path.mode baseline`. It is the default
now; `vfox config path.mode legacy` brings back the behavior of 1.0.x.

- config.DefaultPathMode names the default in one place. EmptyPath, both
  fallbacks of Path.EffectiveMode and the starting mode of pathPolicy()
  use it.
- An empty or unknown mode is the default, as before, so a typo lands on
  baseline instead of failing `vfox env`, which runs at every prompt.
  EffectiveMode names `legacy` as a case of its own now, because it is
  no longer what the fallback returns.
- A shell without a recorded baseline still behaves like legacy in every
  mode, so upgrading does not reorder the PATH of a running shell.
- The path.shadowed hint for a directory that was already in PATH at
  activation can only come up in legacy mode now. It says so before it
  suggests `vfox config path.mode baseline`.

Tests: the eleven that asserted the old default are updated. Tests that
used `baseline` as the value that has to survive a merge, a save or a
shared config would have passed for the wrong reason once it became the
default, so they use `legacy`. New checks pin the default and its
fallbacks, and that an unconfigured vfox leaves the PATH of a shell
without a baseline alone.

Part of #737

* docs: baseline is the default path.mode

Quick Start and both READMEs no longer ask new installations to run
`vfox config path.mode baseline`, and the configuration guide, the FAQ
and AGENTS.md stop announcing that the default will change. Quick Start
and the READMEs read as they did before #736 added that step.

- Configuration guide (en, zh-hans): the section described what `legacy`
  does as the general behavior. It now says that `baseline` is the
  default, what `legacy` is, and how to keep the behavior of vfox 1.0.x:
  `vfox config path.mode legacy`, or `path.preserve` when only a few
  directories have to stay in front.
- FAQ (en, zh-hans): a system JDK or a Homebrew node in front of vfox's
  directories no longer wins by default. It lists what still can (pnpm
  and anything added after `vfox activate`) and what to check when
  `vfox doctor` still names a system directory: a shell that was started
  before the upgrade, `legacy`, or `path.preserve`.
- AGENTS.md: where the default is defined and what has to stay in step.

Part of #737

* docs: only baseline mode falls back to legacy without a baseline

AGENTS.md said that a shell without a recorded baseline behaves like
`legacy` in every mode. Only `baseline` does: pathPolicy.keepInFront
returns false for `aggressive` whether or not a baseline was recorded,
and `legacy` never looks at one. Say that, instead of changing the
policy: `aggressive` is an opt-in mode that this change does not touch.

TestEnvWithoutABaselineBehavesLikeLegacyInEveryMode had the same
overstatement in its name and only covered the default and `baseline`.
It is now TestEnvWithoutABaselineOnlyBaselineModeFallsBackToLegacy and
asserts the PATH of all four cases: the default, `baseline`, `legacy`
and `aggressive`. Making `aggressive` follow `legacy`, or `baseline`
stop doing so, fails it.

Review feedback on #738.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use pre-existing JDK installations [Feature] 支持导入 Ubuntu/Debian 上由 update-alternatives 管理的现有工具版本

2 participants