Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(cli): a PATH entry that is not absolute no longer holds every launch (#1206)

Deeea5236c46b13
diff --git a/cli/src/engines/kit/launchExecutable.spec.ts b/cli/src/engines/kit/launchExecutable.spec.ts
index fb30a8a34..897537981 100644
--- a/cli/src/engines/kit/launchExecutable.spec.ts
+++ b/cli/src/engines/kit/launchExecutable.spec.ts
@@ -32,6 +32,20 @@ it('distinguishes complete absence from inaccessible or ambiguous candidates', a
vi.stubEnv('PATH', 'relative')
expect(await captureLaunchExecutable('opencode', '')).toMatchObject({ state: 'held' })
})
+it('searches the absolute folders of a PATH that also lists what is not one', async () => {
+ // The login PATH of a Mac with the .NET SDK: `~/.dotnet/tools`, unexpanded. An empty entry and `.` are as common.
+ const { bin, captureLaunchExecutable } = await fixture()
+ vi.stubEnv('PATH', ['~/.dotnet/tools', '', '.', 'relative', bin].join(':'))
+ expect(await captureLaunchExecutable('opencode', '')).toMatchObject({ state: 'install' })
+ const file = join(bin, 'opencode'); writeFileSync(file, 'fixture', { mode: 0o700 })
+ const result = await captureLaunchExecutable('opencode', '')
+ expect(result).toMatchObject({ state: 'ready', executable: { command: file } })
+ // Nothing absolute to search, or more entries than a search is bounded to: still held.
+ vi.stubEnv('PATH', '~/.dotnet/tools::.')
+ expect(await captureLaunchExecutable('opencode', '')).toMatchObject({ state: 'held' })
+ vi.stubEnv('PATH', Array(257).fill(bin).join(':'))
+ expect(await captureLaunchExecutable('opencode', '')).toMatchObject({ state: 'held' })
+})
it('never installs over an explicitly configured missing executable', async () => {
await fixture()
vi.stubEnv('OPENCODE_PATH', join(root, 'absent'))
diff --git a/cli/src/engines/kit/launchExecutable.ts b/cli/src/engines/kit/launchExecutable.ts
index 4801b5d6e..f33dccf5e 100644
--- a/cli/src/engines/kit/launchExecutable.ts
+++ b/cli/src/engines/kit/launchExecutable.ts
@@ -60,10 +60,12 @@ export async function captureLaunchExecutable(engine: AgentEngine, shell?: strin
const environment = await launchEnvironment(shell)
if (!environment || !environment.HOME || !isAbsolute(environment.HOME)) return held('Waiting to read the engine’s launch environment.')
const command = engineBin(engine), override = enginePathOverride(engine)
- const entries = environment.PATH?.split(delimiter) ?? []
- if (entries.length === 0 || entries.length > 256 || entries.some(path => !isAbsolute(path) || path.length > 4096)) {
- return held('Waiting for a bounded, absolute engine search path.')
- }
+ // An entry that is not absolute names no fixed folder, so it is left out of the search, as an over-long
+ // one is. It is not a reason to hold: `~/.dotnet/tools` is on the login PATH of every Mac with the .NET SDK
+ // (its /etc/paths.d file says it that way), and 0.3.74 held every launch on such a computer for good.
+ const listed = environment.PATH?.split(delimiter) ?? []
+ const entries = listed.filter(path => isAbsolute(path) && path.length <= 4096)
+ if (entries.length === 0 || listed.length > 256) return held('Waiting for a bounded, absolute engine search path.')
const recipe = override ? undefined : engineInstallRecipe(engine)
const names = [...new Set([command, ...(recipe?.executable.names ?? [])])]
const candidates = command.includes('/') ? [resolve(command)] : names.flatMap(name => entries.map(path => join(path, name)))