Repository navigation
Detect an installed agent by its command on the path as well as its folder (refs #3748) - #3794
Conversation
malibio
left a comment
There was a problem hiding this comment.
Code Review Summary
Small, cohesive, net-positive change: an agent that is installed but never started (no config folder yet) is now detected through its command on PATH. The code is simple, the five commands match the Rust catalog (packages/agent/src/agent_catalog/registry.rs: claude, codex, agy, pi, opencode), the plugin-managed Claude Code path is unaffected, and the three affected test files pass locally (133 tests). One real gap undermines the stated purpose for the primary audience (GUI-launched desktop app), and a couple of tests/edge cases are worth tightening.
Verdict: Approve with one Improvement to address (GUI PATH).
Findings
Critical Issues
None.
Suggested Improvements
-
[Improvement]
packages/desktop-app/app-lib/src/skill_setup.rs(compiled_installer_command/installer_command) - the new rule is blind in the GUI app, which is the caller that matters.detect_agentsandinstall_skillspawn the installer with the app's inherited environment (no.env("PATH", ...)). A Finder/Dock-launched macOS app gets the minimal LaunchServices PATH (no/opt/homebrew/bin,~/.local/bin,~/.npm-global/bin, nvm), exactly the problemcheck_cli_on_path/augmented_cli_path()already documents and solves for thenodespaceCLI. So for the onboarding wizard a never-startedclaude/codex/piinstalled under any of those locations still reports "not detected", and the fix only helps terminal-launched/CLI use. Note this is the same process model asdetect: the wizard's question andinstallagree with each other (both go throughdetectAgents), they just both miss. Suggested: give the installer subprocess.env("PATH", augmented_cli_path())in both*_installer_commandbuilders (the helper already exists in the same file and is tested), sodetect/installsee the same search path the daemon'sagent_search_path()uses for launching. This also makes "detected" agree withpackages/agent/src/pty/detection.rs, which resolves the same binaries on the augmented path - today the desktop's session launcher can say "agy found" while the skill wizard says "antigravity not detected". If you'd rather keep this PR TS-only, at least state the limitation in the PR description / #3748 and file the follow-up; but it is a few lines and belongs with this change (Pragmatic Quality: fix the adjacent finding in the same PR).- Related, lower priority: the TS
commandtable and the Rust catalogbinaryare now two sources of the same fact. Aagents.test.tsassertion is not possible across languages cheaply, but a comment onAgentConfig.commandpointing atagent_catalog/registry.rs(and vice versa) would stop silent drift.
- Related, lower priority: the TS
-
[Improvement]
packages/skill/src/tests/install.test.ts(describe('the lines the CLI prints'),run()). It spawns the realinstall.tswith the inherited env (only HOME is redirected), andrun('install')/run('status')use no agent argument, so they go throughdetectAgents(). On a developer machine withclaude,agy, etc. on PATH, those agents are now also targeted (into the temp HOME, so not destructive) and the test results depend on the machine. The two PATH-sandboxingbeforeEachs ininstaller.test.ts/harness-delivery.test.tsdon't cover spawned children. The assertions usetoContainso it passes today, but it is the same machine-dependence this PR set out to remove. SetPATHin thatenvto an empty/nonexistent folder (bun is spawned by absolute name via the parent's resolution?spawnSync('bun', ...)resolves in the parent's PATH, so pass the sandboxed PATH only to the child env, ascodex-hooks*.test.tsdo with an explicitPATH). Worth a quick grep ofmcp-installer.test.tsandcodex-hooks*.test.tsfor any no-argumentinstall(); I found none besides the ones covered. -
[Improvement]
isOnPathtest coverage vs. the edge cases the implementation claims. The new test covers: executable file hit, non-executable file miss, directory miss. Not covered: a symlink to an executable (works bystatSyncfollowing links - worth one assertion since~/.local/bin/claudeis typically a symlink), a broken symlink (throws, swallowed - correct), an emptyPATHentry (skipped - correct), and the win32PATHEXTbranch (untested; it can't be exercised without stubbingprocess.platform, so either stub it viaObject.definePropertyin one test or accept it as untested and say so). Low cost, and the PATHEXT branch is the one most likely to rot.
Correctness notes on isOnPath (no action unless you agree)
- Symlinks:
statSyncfollows, so a link to an executable counts and a dangling link does not. Correct. - Directories:
isFile()excludes them; test covers it. Correct. - Empty entries: skipped. POSIX treats an empty entry as the cwd, but skipping is the safer reading for a detector run from arbitrary cwd, and the
whichcrate the Rust side uses behaves the same way for practical purposes. Fine. - Relative entries (
.,bin) resolve against cwd: matches shell semantics; fine. - Windows:
PATHEXTis split without filtering empty strings, so a trailing;yields an extra''extension (harmless duplicate probe). The''extension is probed first, so an extensionless file namedclaude/picounts; npm creates exactly such an sh-shim next toclaude.cmd, so this is fine in practice, but on WindowsX_OKis just existence, so any extensionless stray file namedpiis a positive. Nit: probe only PATHEXT entries on win32 (drop the leading'') to matchcmd/whichsemantics. Also Nit: Windows PATH entries may be wrapped in double quotes; strip them beforejoin. accessSync(..., X_OK)runs as the current user, which is what you want; setuid/ACL oddities aside it matches what a launch will do.
Consistency: other things that decide "detected"
nodespace skill detect/install(both throughdetectAgents) agree with each other, and the desktop wizard delegates to them, so there is no new disagreement there.statusis intentionally install-based (checkInstalled), anduninstalldoes not usedetectAgents, so neither is affected.packages/cli/src/commands/session.rsonly mentionsantigravity-cliin a negative test (ids thatsession launchmust reject); it is not a detection rule and needs no change.- Remaining mismatch is the GUI PATH one above:
pty/detection.rsuses the augmented path, the skill installer uses the raw one. mcp-installer.tsdetectMcpClientskeeps folder-only detection; that is for GUI clients (Claude Desktop) with no command, so correctly untouched.
Plugin-managed Claude Code
Still behaves. A never-started claude is now "detected", claudeCodePluginManagedSkillExists reads plugins/installed_plugins.json, finds nothing, and fails open to a normal install, so a marketplace-installed copy is still the only thing that triggers plugin-managed, and the existing reconciliation tests (installer.test.ts ~1393, ~1576) still pass. One behavioral consequence worth knowing, not a bug: for a command-only agent install now creates the detection/config folder (e.g. ~/.claude, ~/.codex, ~/.pi/agent) as a side effect of writing skills, which is the intent of the change.
Nitpicks
- Nit:
installer.tsimport list putsstatSyncafterexistsSync, out of the otherwise grouped order; trivial. - Nit: the
isOnPathdoc says "executable file"; on win32 it is "file with a PATHEXT extension or none". One clause would be more honest. - Nit:
process.env.PATH = join(TMP, 'no-commands')is duplicated in two test files; fine at this size, a shared helper only if a third appears.
Test isolation
installer.test.ts and harness-delivery.test.ts sandbox PATH in beforeEach and restore it in afterEach (restored even if a test throws, since it is in afterEach). Vitest runs files in separate workers/processes by default, so mutating process.env.PATH does not leak across files. The new detection test sets PATH = bin and relies on afterEach to restore. The vi.doMock('node:fs') tests that re-import the installer still get statSync/accessSync from the mock factory only if the factory spreads the real module - they passed, so it does. Gap: spawned-child tests in install.test.ts (above).
Not merged; no files created in the repo.
Review addressed (1f8051e)Addressed
Not changed
Not built locally: the Rust edit cannot compile in this fresh worktree (llama.cpp / OpenSSL header); it is Re-Review DecisionDecision: NO RE-REVIEW NEEDED Rationale: The one real finding is applied as suggested, in two lines of the command builders; the rest are test and edge-case tightening. If the gate's Rust build fails, the PR is ejected and the failure is a compile error, not a behaviour question. |
|
Merge queue: #3794 was taken out of the queue — the merge gate failed on it, on top of main. Reproduce by merging or rebasing |
|
Merge queue: #3794 was taken out of the queue — the merge gate failed on it, on top of main. Reproduce by merging or rebasing |
…older (refs #3748) A harness installed and never started has made no configuration folder, so nodespace skill install with no agent named reported Pi and Antigravity as not detected and skipped them. Each agent now names its command, and one found as an executable file in a folder of PATH counts as present. The tests keep the machine's own commands out of the path. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…d tests (refs #3748) - The desktop app launches the installer with its own environment, which a dock-launched app has a minimal PATH in: it now gets the augmented one the CLI check already uses, so a never-started agent is found there too. - The spawned-CLI tests run with an empty PATH; bun is named in full. - isOnPath: Windows probes PATHEXT extensions only, strips quotes from an entry; a link to an executable and a broken link are tested. - The command table says where the app's catalog names the same binaries. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… its command is built (refs #3748) The tests build the same commands for an isolated home; a builder that set PATH made them see the machine's own agents and put its text under the npx/npm check. The launches of the installer itself set it. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…3748) The tests that run the real installer in an isolated home now get a PATH holding bun alone: an agent is also found by its command, and the gate machine has several. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
fd5032f to
936a3ef
Compare
Refs #3748.
nodespace skill installwith no agent named decided what was present by each agent's configuration folder alone. A harness installed and never started has made none, so Pi and Antigravity were reported "not detected" and skipped; naming them installed correctly.Each agent now names its command (
claude,codex,agy,opencode,pi), and an executable file of that name in a folder ofPATHcounts as present as well. The desktop app asks the installer's owndetect, so it follows.Tests: a command on the path is detected, a non-executable file and a folder of that name are not; the installer and delivery tests set
PATHto an empty folder so the machine's own agents are not theirs.bun run --cwd packages/skill test284 pass, typecheck clean.🤖 Generated with Claude Code