fix(spawn): spawn the detected absolute CLI path, not the bare name (#104)#105
Merged
Conversation
…104) Detection (cli-detect) resolves a concrete absolute path (PATH lookup → fallback-dir scan → manual override), but headless spawns re-resolved by bare name against the daemon PATH. The two could disagree: - ENOENT: a CLI found only via the fallback-dir scan (its dir not on the spawn PATH) couldn't be launched by bare name. - shadowing: two same-named binaries (e.g. ~/.kimi/bin/kimi vs ~/.kimi-code/bin/kimi) — bare-name spawn could run a different build than detection (and the #101 transport decision) resolved. Add resolveCliBinaryPath(command): bare known CLI name → detection's verified absolute path, else passthrough (already-a-path, unknown name, or not-found → preserves the existing PATH/`where` fallback). - headless.ts:resolveBinaryPath calls it first — covers the 6 direct shims (claude/codex/gemini/kimi-cli/grok/agy) and Windows opencode. - opencode.ts + kimi.ts resolve opencode before wrapWithPty — the PTY wrapper embeds the binary in argv, so the spawn core only sees `script` and can't resolve it (covers the POSIX PTY path). No behaviour change when detection has no path: the bare name flows to the unchanged Unix-PATH / Windows-`where` resolution. Tests: resolver unit tests against real staged detection; headless spawn integration tests for the abs-path case (Linux + Windows) plus the detection-not-found fallback. Full suite 1033 passing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #104.
Problem
Detection (
cli-detect.ts:detectAllClis) resolves a concrete absolute path per CLI (PATH lookup → fallback-dir scan → manual override) and verifies it runs. But the daemon spawned reviewers by bare name (command: 'kimi'), re-resolving against the merged spawn PATH. The two resolutions could diverge:~/.kimi/bin/kimivs native~/.kimi-code/bin/kimi): bare-name spawn could run a different build than detection — and the fix(kimi): key transport on the resolved binary, not ~/.kimi-code existence #101 transport decision — resolved.Fix
resolveCliBinaryPath(command)(new export,cli-detect.ts): bare known-CLI name → detection's verified absolute path. Passthrough when the command already has a path separator, isn't a known CLI binary name (e.g. thescriptPTY wrapper), or detection currently can't find it → preserving the existing Unix-PATH / Windows-wherefallback. Reads cacheddetectAllClis(30s TTL).headless.ts:resolveBinaryPathcalls it first — covers the 6 direct bare-name spawns (claude/codex/gemini/kimi-cli/grok/agy) and Windows opencode. A resolved absolute path short-circuits the Windowswherelookup; bare names (detection-not-found) still flow throughwhereunchanged.opencode.ts+kimi.tsresolveopencodebeforewrapWithPty()— the PTY wrapper embeds the binary in argv (script -qfec '<bin> …'), so the spawn core only ever seesscriptand can't resolve it.No behaviour change when detection has no path — the bare name flows to the unchanged PATH/
whereresolution.Tests
tests/cli-detect-resolve.test.ts— resolver unit tests against real staged detection (prepended-PATH executables): bare→abs resolution, already-a-path / unknown-name / not-found passthrough, and a per-CLI mirror property.tests/headless-spawn-windows.test.ts— new spawn integration tests for the abs-path case (Linux + Windows, assertingwhereis skipped) plus the detection-not-found fallback; existing tests reconciled with an identitystubCliDetectso their bare-name/whereassertions remain under test.Full suite: 1033 passing, 1 skipped. typecheck + lint clean.
Review
chorus self-review (
review-only, 7 reviewers): approved, no changes requested.🤖 Generated with Claude Code