Skip to content

fix(worker): find agent CLIs from any package manager - #146

Merged
nixuuu merged 1 commit into
devfrom
fix/cli-discovery-managers
Nov 5, 2026
Merged

nixuuu merged 1 commit into
devfrom
fix/cli-discovery-managers

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 5, 2026

Copy link
Copy Markdown
Member

On a Mac, Codex installed with bun was reported three different ways: "Not installed" in the updates center, "Codex" with no version under Agents, and "Homebrew · /opt/homebrew/bin/codex · version unknown · Up to date" under CLI tools.

Causes

  1. The desktop worker doesn't get the user's shell PATH, so ~/.bun/bin, ~/.volta/bin, nvm/fnm shims and npm prefixes are missing.
  2. Discovery took the first match, even a broken one, and only looked in known places when nothing was on PATH.
  3. Any path under /opt/homebrew/ counted as Homebrew, including npm packages installed with Homebrew's node.
  4. The reason --version failed was discarded; JS shims without node on PATH fail there.
  5. The three views read the empty version differently.

Fixes

  • Login-shell environment: the worker resolves the user's login shell once per start ($SHELL -l -i -c, through the process governor, 8 s limit, output between random markers). It takes PATH plus a fixed list of package-manager variables (BUN_INSTALL, VOLTA_HOME, PNPM_HOME, NVM_DIR, …). Provider or secret variables are never imported, and secret-looking variables are kept out of the shell. If PATH has no node, one from a known place is added. "Check for updates" refreshes it, at most once a minute. It can be turned off with CANOPY_LOGIN_SHELL_ENV=0.

  • Search order:

    1. the configured path
    2. the merged PATH
    3. ~/.local/bin and vendor folders
    4. Bun
    5. Volta
    6. pnpm
    7. npm prefixes (.npmrc read as a file)
    8. Yarn
    9. nvm and fnm
    10. mise and asdf
    11. Homebrew

    Windows adds npm, Volta and scoop.

  • Choosing a copy: the first copy that answers --version wins, so a working copy beats a stale or broken one. Other copies are listed in details.

  • Manager detection uses the real path, the shim type and the package path, and gives the right update command: volta install, pnpm add -g, bun add -g, npm, brew upgrade, and so on. New install methods: Volta, pnpm, Yarn.

  • One source of truth: the Agents list uses the same discovery and probe as the CLI report.

    • An unknown version shows "Version unknown" (never "Not installed", never "Up to date").
    • The probe error is shown: "Couldn't run codex --version: …".
  • Contract: additive proto: CliTool.version_error, CliTool.alternatives, and install methods VOLTA, PNPM and YARN.

Tests: tests/integration/cli-discovery.test.ts covers bun, Volta, an npm prefix from .npmrc, npm under the Homebrew prefix, pnpm, a stale Homebrew copy versus a working bun copy, a JS shim that needs node, a broken symlink, and noisy, slow and missing login shells. The full suite passed locally with provider variables unset.

Still needs a real macOS check: zsh/fish profiles started from the GUI, and real Volta and pnpm shim layouts.

Copy audit (docs/copy.md §8):

  • Wrong "Not installed" → "Version unknown".
  • No badge when the version is unknown.
  • New error text: what happened, then what to do.
  • "{n} other copies on this computer" uses correct plurals and "computer" per the glossary.

A worker started from the desktop app, launchd or systemd missed the
user's shell PATH, so a CLI installed with bun, Volta, nvm or pnpm was
not found. Discovery took the first match on PATH even when it did not
run, classified npm packages under Homebrew's prefix as Homebrew, and
dropped the reason a version probe failed. The updates center then
showed "Not installed", the Agents list no version and the CLI tools
section "Up to date" for the same CLI.

- Resolve the login-shell env once per start ($SHELL -l -i -c through
  the process governor, 8 s limit, NUL-separated output between
  markers) and merge PATH and package-manager variables into the
  worker env; append a known node when PATH has none.
- Search PATH, then Bun, Volta, pnpm, npm prefixes (~/.npmrc), Yarn,
  nvm, fnm, mise, asdf and Homebrew; use the first copy that answers
  --version and report the others as alternatives.
- Detect Volta, pnpm and Yarn from real paths and shims; add Volta and
  pnpm recipes; npm under Homebrew's prefix updates with npm.
- Report version_error; never show "Up to date" for an unknown version.
- The CLI report, ConfigApplied and harness lookups share one choice.
@nixuuu
nixuuu merged commit e3c937d into dev Nov 5, 2026
15 of 17 checks passed
@nixuuu
nixuuu deleted the fix/cli-discovery-managers branch November 5, 2026 08:10
nixuuu added a commit that referenced this pull request Nov 5, 2026
`computer-relay.test.ts` ("explicit reciprocal sharing … without a
routing loop") failed on CI in #146 and #147 (attempt 1), on line 258.
After the reciprocal share was turned off, W's mirror state existed
again as `{ cursor: "", overview: null }`.

**Cause:** a race on P2.
1. P1 revokes the grant and cancels the relayed `WatchThreadMirror`
stream before the new catalog reaches P2.
2. P2 still has W as `both`, so the next emit starts a new mirror task.
3. The new catalog then deletes W's `both` row, with its mirror, and
inserts W as `origin`.
4. The late `INSERT INTO computer_mirror_state` lands after that. The
new `origin` row satisfies the foreign key, so the empty state comes
back.

Before #36, a removed peer stayed removed and the late insert failed on
the foreign key.

**Fix**
- `mirror.ts` creates mirror state only for a direct peer or a relay
`home`/`both`. The check runs in the same statement, with the peer row
locked. Otherwise `consume` ends as superseded.
- `bot-mirror.ts` checkpoints use the same role check.
- The test adds a check that does not depend on timing: a late `consume`
for the revoked home is rejected and leaves no state. No assertion is
changed; no sleeps, retries or longer timeouts.

**Evidence**
- The new check fails on the old code (1/1) and passes with the fix:
15/15 runs under load.
- The other mirror suites pass: `thread-mirrors.test.ts` and
`linked-agents.test.ts`, 32/32.

Fixes: #36
nixuuu added a commit that referenced this pull request Nov 27, 2026
## Summary

- Read the worker snapshot once more when the accepted report changes
during local skill preview on the same connection. Validate the original
revision and copy token against the new snapshot before contacting the
worker.
- Add an integration test that accepts an identical report during the
read and checks the previewed bytes. Update the agent environment
documentation.

Push CI
[#146](https://github.com/itsoltech/canopy/actions/runs/45864889405/job/140065136848)
and
[#147](https://github.com/itsoltech/canopy/actions/runs/45870599390/job/140084790023)
reported the same `FAILED_PRECONDITION`. The controlled regression
reproduces that error. The original CI logs do not identify which
validation condition rejected those requests.

## Verification

- The new integration test failed with `FAILED_PRECONDITION` before the
fix and passed afterwards.
- Four focused integration cases passed via `check:tmp`, including
rejection of an on-disk change and preview through a linked computer.
- Lint and formatting passed for the two edited TypeScript files. `git
diff --check` passed.
- The remaining repository checks run in GitHub CI.

Fixes: #1303
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant