Skip to content

Detect an installed agent by its command on the path as well as its folder (refs #3748) - #3794

Merged
malibio merged 4 commits into
mainfrom
issue-3748-agent-detection
Oct 13, 2026
Merged

malibio merged 4 commits into
mainfrom
issue-3748-agent-detection

Conversation

@malibio

@malibio malibio commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

Refs #3748.

nodespace skill install with 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 of PATH counts as present as well. The desktop app asks the installer's own detect, 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 PATH to an empty folder so the machine's own agents are not theirs. bun run --cwd packages/skill test 284 pass, typecheck clean.

🤖 Generated with Claude Code

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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_agents and install_skill spawn 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 problem check_cli_on_path/augmented_cli_path() already documents and solves for the nodespace CLI. So for the onboarding wizard a never-started claude/codex/pi installed 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 as detect: the wizard's question and install agree with each other (both go through detectAgents), they just both miss. Suggested: give the installer subprocess .env("PATH", augmented_cli_path()) in both *_installer_command builders (the helper already exists in the same file and is tested), so detect/install see the same search path the daemon's agent_search_path() uses for launching. This also makes "detected" agree with packages/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 command table and the Rust catalog binary are now two sources of the same fact. A agents.test.ts assertion is not possible across languages cheaply, but a comment on AgentConfig.command pointing at agent_catalog/registry.rs (and vice versa) would stop silent drift.
  • [Improvement] packages/skill/src/tests/install.test.ts (describe('the lines the CLI prints'), run()). It spawns the real install.ts with the inherited env (only HOME is redirected), and run('install') / run('status') use no agent argument, so they go through detectAgents(). On a developer machine with claude, 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-sandboxing beforeEachs in installer.test.ts / harness-delivery.test.ts don't cover spawned children. The assertions use toContain so it passes today, but it is the same machine-dependence this PR set out to remove. Set PATH in that env to 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, as codex-hooks*.test.ts do with an explicit PATH). Worth a quick grep of mcp-installer.test.ts and codex-hooks*.test.ts for any no-argument install(); I found none besides the ones covered.

  • [Improvement] isOnPath test 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 by statSync following links - worth one assertion since ~/.local/bin/claude is typically a symlink), a broken symlink (throws, swallowed - correct), an empty PATH entry (skipped - correct), and the win32 PATHEXT branch (untested; it can't be exercised without stubbing process.platform, so either stub it via Object.defineProperty in 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: statSync follows, 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 which crate the Rust side uses behaves the same way for practical purposes. Fine.
  • Relative entries (., bin) resolve against cwd: matches shell semantics; fine.
  • Windows: PATHEXT is split without filtering empty strings, so a trailing ; yields an extra '' extension (harmless duplicate probe). The '' extension is probed first, so an extensionless file named claude/pi counts; npm creates exactly such an sh-shim next to claude.cmd, so this is fine in practice, but on Windows X_OK is just existence, so any extensionless stray file named pi is a positive. Nit: probe only PATHEXT entries on win32 (drop the leading '') to match cmd/which semantics. Also Nit: Windows PATH entries may be wrapped in double quotes; strip them before join.
  • 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 through detectAgents) agree with each other, and the desktop wizard delegates to them, so there is no new disagreement there. status is intentionally install-based (checkInstalled), and uninstall does not use detectAgents, so neither is affected.
  • packages/cli/src/commands/session.rs only mentions antigravity-cli in a negative test (ids that session launch must reject); it is not a detection rule and needs no change.
  • Remaining mismatch is the GUI PATH one above: pty/detection.rs uses the augmented path, the skill installer uses the raw one.
  • mcp-installer.ts detectMcpClients keeps 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.ts import list puts statSync after existsSync, out of the otherwise grouped order; trivial.
  • Nit: the isOnPath doc 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.

@malibio

malibio commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed (1f8051e)

Addressed

  • GUI PATH: the installer subprocess the app launches (installer_command, compiled_installer_command) is given augmented_cli_path(), as check_cli_on_path already does, so a never-started agent under Homebrew, ~/.local/bin and the like is found from a dock-launched app. The two Rust tests that matched the command's Debug text now read get_program() (a set environment variable changes that text) and assert PATH is set.
  • Spawned-CLI tests (install.test.ts) run with an empty PATH; bun is named in full because the child's own PATH would not find it.
  • isOnPath: Windows probes PATHEXT extensions only and strips quotes from an entry; the doc says what it checks; tests add a link to an executable, a broken link and an empty entry.
  • AgentConfig.command comment points at the app catalog that names the same binaries.

Not changed

  • Shared PATH-sandbox helper for two test files: wait for a third.
  • The win32 PATHEXT branch has no test; it needs a process.platform stub for one branch, and the logic is a filter on a split string.
  • Import order nit.

Not built locally: the Rust edit cannot compile in this fresh worktree (llama.cpp / OpenSSL header); it is rustfmt-clean and the merge gate builds and tests it. Skill tests 285 pass, typecheck clean.

Re-Review Decision

Decision: 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.

@malibio

malibio commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

Merge queue: #3794 was taken out of the queue — the merge gate failed on it, on top of main. Reproduce by merging or rebasing origin/main and running bun run test:changed, fix, push, and re-run bun run merge 3794.

test window_state::tests::missing_file_yields_no_saved_geometry ... ok
test window_state::tests::save_leaves_no_temp_file_behind ... ok
test window_state::tests::save_then_load_round_trips ... ok
test window_state::tests::saving_again_for_the_same_database_overwrites_its_entry ... ok
test startup_ordering_tests::another_products_daemon_that_survives_the_boot_out_keeps_the_hold_on ... ok
failures:
---- skill_setup::tests::detect_subcommand_reports_present_agents_before_anything_is_installed stdout ----
thread 'skill_setup::tests::detect_subcommand_reports_present_agents_before_anything_is_installed' (113759489) panicked at packages/desktop-app/app-lib/src/skill_setup.rs:1852:9:
assertion `left == right` failed: both present agents must be detected with nothing yet installed
  left: ["claude-code", "codex", "antigravity", "opencode", "pi"]
 right: ["claude-code", "antigravity"]
---- skill_setup::tests::installer_command_invokes_bun_directly_not_npx_or_npm stdout ----
thread 'skill_setup::tests::installer_command_invokes_bun_directly_not_npx_or_npm' (113759528) panicked at packages/desktop-app/app-lib/src/skill_setup.rs:1449:9:
found npx/npm in the constructed command: PATH="/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/pkg/env/global/bin:/Library/Apple/usr/bin:/Users/malibio/nodespace/nodespace-core/.claude/worktrees/_gate/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/.claude/worktrees/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/.claude/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/node_modules/.bin:/Users/malibio/nodespace/node_modules/.bin:/Users/malibio/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/Users/malibio/.local/bin:/Users/malibio/.nodespace/bin:/Users/malibio/.antigravity/antigravity/bin:/Users/malibio/.surrealdb:/Users/malibio/.bun/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/malibio/.npm-global/bin:/Users/malibio/.cargo/bin:/opt/anaconda3/bin:/opt/anaconda3/condabin:/Users/malibio/bin:/Library/Frameworks/Python.framework/Versions/3.13/bin:/Applications/supacode.app/Contents/Resources/bin:/Applications/supacode.app/Contents/MacOS:/Users/malibio/.npm-global/bin:/Users/malibio/.local/bin:/Users/malibio/.cargo/bin:/Users/malibio/go/bin:/opt/homebrew/bin:/usr/local/bin:/Users/malibio/nodespace/nodespace-core/.claude/worktrees/_gate/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/.claude/worktrees/_gate/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/.claude/worktrees/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/.claude/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/node_modules/.bin:/Users/malibio/nodespace/node_modules/.bin:/Users/malibio/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/.claude/worktrees/_gate/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/.claude/worktrees/_gate/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/.claude/worktrees/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/.claude/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/node_modules/.bin:/Users/malibio/nodespace/node_modules/.bin:/Users/malibio/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/.claude/worktrees/_gate/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/.claude/worktrees/_gate/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/.claude/worktrees/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/.claude/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/node_modules/.bin:/Users/malibio/nodespace/node_modules/.bin:/Users/malibio/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/.claude/worktrees/_gate/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/.claude/worktrees/_gate/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/.claude/worktrees/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/.claude/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/node_modules/.bin:/Users/malibio/nodespace/node_modules/.bin:/Users/malibio/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/node_modules/.bin:/Users/malibio/nodespace/node_modules/.bin:/Users/malibio/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/node_modules/.bin:/Users/malibio/nodespace/nodespace-core/node_modules/.bin:/Users/malibio/nodespace/node_modules/.bin:/Users/malibio/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/Users/malibio/.local/bin:/Users/malibio/.nodespace/bin:/Users/malibio/.antigravity/antigravity/bin:/Users/malibio/.surrealdb:/Users/malibio/.local/bin:/Users/malibio/.bun/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/malibio/.npm-global/bin:/Users/malibio/.cargo/bin:/opt/anaconda3/bin:/opt/anaconda3/condabin:/Users/malibio/.local/bin:/Users/malibio/bin:/Users/malibio/.local/bin:/Library/Frameworks/Python.framework/Versions/3.13/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/pkg/env/global/bin:/Library/Apple/usr/bin:/Users/malibio/.cargo/bin:/Applications/supacode.app/Contents/Resources/bin:/Applications/supacode.app/Contents/MacOS" "bun" "/tmp/fake/install.js" "install"
---- skill_setup::tests::run_skill_installer_reports_agents_skipped_for_a_genuinely_incomplete_package stdout ----
thread 'skill_setup::tests::run_skill_installer_reports_agents_skipped_for_a_genuinely_incomplete_package' (113759882) panicked at packages/desktop-app/app-lib/src/skill_setup.rs:1695:9:
assertion `left == right` failed
  left: 5
 right: 1
---- skill_setup::tests::status_subcommand_stops_reporting_an_agent_whose_skill_dir_was_deleted_by_hand stdout ----
thread 'skill_setup::tests::status_subcommand_stops_reporting_an_agent_whose_skill_dir_was_deleted_by_hand' (113759933) panicked at packages/desktop-app/app-lib/src/skill_setup.rs:1798:9:
assertion `left == right` failed: both agents must actually be installed before this test deletes one by hand
  left: ["claude-code", "codex", "antigravity", "opencode", "pi"]
 right: ["claude-code", "antigravity"]
failures:
    skill_setup::tests::detect_subcommand_reports_present_agents_before_anything_is_installed
    skill_setup::tests::installer_command_invokes_bun_directly_not_npx_or_npm
    skill_setup::tests::run_skill_installer_reports_agents_skipped_for_a_genuinely_incomplete_package
    skill_setup::tests::status_subcommand_stops_reporting_an_agent_whose_skill_dir_was_deleted_by_hand
test result: FAILED. 369 passed; 4 failed; 0 ignored; 0 measured; 0 filtered out; finished in 9.57s
error: test failed, to rerun pass `-p nodespace-app-lib --lib`
error: script "rust:test:app-units" exited with code 101
error: script "rust:test" exited with code 101
[stage exited with code 101]

  full output: /var/folders/yj/_2dcl_l16cl6dr1bp7h1j6hw0000gn/T/nodespace-gate-logs/_gate-merge-2026-10-13T16-50-13-117Z/rust-test-rust-workspace-nextest.log

✗ rust:test (Rust workspace, nextest) failed — merge blocked.
  Fix the failure, push, and re-run: bun run merge <PR#>

@malibio

malibio commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

Merge queue: #3794 was taken out of the queue — the merge gate failed on it, on top of main. Reproduce by merging or rebasing origin/main and running bun run test:changed, fix, push, and re-run bun run merge 3794.

test window_state::tests::a_transient_non_missing_read_failure_refuses_to_save_rather_than_wiping_the_file ... ok
test window_state::tests::concurrent_saves_for_different_databases_all_survive ... ok
test window_state::tests::different_databases_do_not_clobber_each_other ... ok
test window_state::tests::is_plausible_rejects_degenerate_dimensions_but_allows_negative_position ... ok
test window_state::tests::missing_file_yields_no_saved_geometry ... ok
test window_state::tests::save_leaves_no_temp_file_behind ... ok
test window_state::tests::save_then_load_round_trips ... ok
test window_state::tests::saving_again_for_the_same_database_overwrites_its_entry ... ok
test startup_ordering_tests::another_products_daemon_that_survives_the_boot_out_keeps_the_hold_on ... ok
failures:
---- skill_setup::tests::detect_subcommand_reports_present_agents_before_anything_is_installed stdout ----
thread 'skill_setup::tests::detect_subcommand_reports_present_agents_before_anything_is_installed' (113823608) panicked at packages/desktop-app/app-lib/src/skill_setup.rs:1847:9:
assertion `left == right` failed: both present agents must be detected with nothing yet installed
  left: ["claude-code", "codex", "antigravity", "opencode", "pi"]
 right: ["claude-code", "antigravity"]
---- skill_setup::tests::run_skill_installer_reports_agents_skipped_for_a_genuinely_incomplete_package stdout ----
thread 'skill_setup::tests::run_skill_installer_reports_agents_skipped_for_a_genuinely_incomplete_package' (113824059) panicked at packages/desktop-app/app-lib/src/skill_setup.rs:1690:9:
assertion `left == right` failed
  left: 5
 right: 1
---- skill_setup::tests::status_subcommand_stops_reporting_an_agent_whose_skill_dir_was_deleted_by_hand stdout ----
thread 'skill_setup::tests::status_subcommand_stops_reporting_an_agent_whose_skill_dir_was_deleted_by_hand' (113824137) panicked at packages/desktop-app/app-lib/src/skill_setup.rs:1793:9:
assertion `left == right` failed: both agents must actually be installed before this test deletes one by hand
  left: ["claude-code", "codex", "antigravity", "opencode", "pi"]
 right: ["claude-code", "antigravity"]
failures:
    skill_setup::tests::detect_subcommand_reports_present_agents_before_anything_is_installed
    skill_setup::tests::run_skill_installer_reports_agents_skipped_for_a_genuinely_incomplete_package
    skill_setup::tests::status_subcommand_stops_reporting_an_agent_whose_skill_dir_was_deleted_by_hand
test result: FAILED. 370 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out; finished in 9.44s
error: test failed, to rerun pass `-p nodespace-app-lib --lib`
error: script "rust:test:app-units" exited with code 101
error: script "rust:test" exited with code 101
[stage exited with code 101]

  full output: /var/folders/yj/_2dcl_l16cl6dr1bp7h1j6hw0000gn/T/nodespace-gate-logs/_gate-merge-2026-10-13T16-54-44-345Z/rust-test-rust-workspace-nextest.log

✗ rust:test (Rust workspace, nextest) failed — merge blocked.
  Fix the failure, push, and re-run: bun run merge <PR#>

malibio and others added 4 commits October 13, 2026 19:09
…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]>
@malibio
malibio force-pushed the issue-3748-agent-detection branch from fd5032f to 936a3ef Compare October 13, 2026 17:09
@malibio
malibio merged commit 411be9d into main Oct 13, 2026
@malibio
malibio deleted the issue-3748-agent-detection branch October 13, 2026 17:09
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