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.

feat: implement engine installation recipes with automatic binary validation and status reporting

0xken15123824e43b31
diff --git a/cli/src/backendSocket.ts b/cli/src/backendSocket.ts
index cea7a3c4b..7e5589f82 100644
--- a/cli/src/backendSocket.ts
+++ b/cli/src/backendSocket.ts
@@ -1364,7 +1364,7 @@ export class BackendSocket {
installed: entry.installed,
command: entry.command,
installable: entry.installable,
- installCommand: entry.installable ? engineInstallRecipe(entry.engine)?.command ?? null : null,
+ installCommand: entry.installable ? engineInstallRecipe(entry.engine).command : null,
})),
}))
.catch(() => reply(type, requestId, { error: 'ENGINE_PROBE_FAILED' }))
diff --git a/cli/src/cli.ts b/cli/src/cli.ts
index f6d7cc0b3..b3a11dccb 100644
--- a/cli/src/cli.ts
+++ b/cli/src/cli.ts
@@ -44,7 +44,7 @@ import { AuthSessionError, AuthSessionManager, clearAuthSession, readAuthSession
import { handOffToGrid } from './lib/gridHandoff.js'
import { passThroughToGridLogout } from './lib/gridLogout.js'
import { warnIfGridSignInRemains } from './lib/gridCredentials.js'
-import { ENGINE_CLI_COMMANDS, ENGINES, engineBin } from './lib/engineBin.js'
+import { ENGINE_CLI_COMMANDS, ENGINES, engineBin, enginePathOverride } from './lib/engineBin.js'
import type { AgentEngine } from './engines/types.js'
import { engineInstallRecipe } from './lib/engineInstall.js'
import { buildEngineCommandArgv, buildEngineLaunchArgv, commandAvailableInInteractiveShell } from './lib/engineLaunch.js'
@@ -3111,7 +3111,7 @@ async function runForeground(session: AuthSession): Promise<void> {
// Do not start a second interactive login shell merely to ask whether the engine is installed.
// The pane's own shell performs the same check before exec, and installs only when necessary.
// This removes ~1s of shell startup from the click-to-terminal critical path.
- const installIfMissing = engineInstallRecipe(engine)?.command
+ const installIfMissing = enginePathOverride(engine) ? undefined : engineInstallRecipe(engine)
// Clearing the vendor credentials this launch does NOT set is part of pointing an agent at a
// grid, not an extra. An engine chooses its provider from whatever it can see, and an inherited
// key wins on its own terms — OpenCode picked Anthropic over a grid it had been handed, and said
@@ -3181,7 +3181,7 @@ async function runForeground(session: AuthSession): Promise<void> {
return
}
if (paneState.dead) {
- const installed = await commandAvailableInInteractiveShell(command[0])
+ const installed = await commandAvailableInInteractiveShell(command[0], undefined, installIfMissing)
const error = installed ? 'ENGINE_DID_NOT_START' : 'ENGINE_NOT_INSTALLED'
const detail = installed
? `${engine} exited before its engine process became ready. See the terminal output for details.`
diff --git a/cli/src/lib/engineBin.spec.ts b/cli/src/lib/engineBin.spec.ts
index b619ad019..2b8949bf9 100644
--- a/cli/src/lib/engineBin.spec.ts
+++ b/cli/src/lib/engineBin.spec.ts
@@ -26,7 +26,7 @@ describe('canonical engine CLI commands', () => {
expect(ENGINES.map((engine) => [engine, ENGINE_CLI_COMMANDS[engine]])).toEqual([
['claude', 'claude'],
['codex', 'codex'],
- ['cursor', 'agent'],
+ ['cursor', 'cursor-agent'],
['opencode', 'opencode'],
['pi', 'pi'],
['hermes', 'hermes'],
diff --git a/cli/src/lib/engineBin.ts b/cli/src/lib/engineBin.ts
index 03db357d3..3a38ab823 100644
--- a/cli/src/lib/engineBin.ts
+++ b/cli/src/lib/engineBin.ts
@@ -20,7 +20,9 @@ export { ENGINES }
export const ENGINE_CLI_COMMANDS: Readonly<Record<AgentEngine, string>> = {
claude: 'claude',
codex: 'codex',
- cursor: 'agent',
+ // Cursor and Grok both publish `agent`; Cursor's documented, unambiguous command is
+ // `cursor-agent`, so creation must use that and keep `agent` for discovery only.
+ cursor: 'cursor-agent',
opencode: 'opencode',
pi: 'pi',
hermes: 'hermes',
@@ -179,7 +181,8 @@ function vendorFallbackCommands(engine: AgentEngine): string[] {
const home = homedir()
switch (engine) {
case 'claude': return [join(home, '.local', 'bin', 'claude')]
- case 'cursor': return [join(home, '.local', 'bin', 'agent'), join(home, '.local', 'bin', 'cursor-agent')]
+ case 'codex': return [join(home, '.local', 'bin', 'codex')]
+ case 'cursor': return [join(home, '.local', 'bin', 'cursor-agent'), join(home, '.local', 'bin', 'agent')]
case 'opencode': return [join(home, '.opencode', 'bin', 'opencode')]
case 'hermes': return [join(home, '.local', 'bin', 'hermes')]
case 'devin': return [join(home, '.local', 'bin', 'devin')]
@@ -412,7 +415,8 @@ export function engineBin(engine: AgentEngine): string {
switch (engine) {
case 'claude': return env.CLAUDE_PATH || ENGINE_CLI_COMMANDS.claude
case 'codex': return process.env.CODEX_PATH || ENGINE_CLI_COMMANDS.codex
- // Cursor's CLI is installed as `agent`, not `cursor`.
+ // `cursor-agent` is the vendor-documented command; `agent` remains a discovery alias only
+ // because Grok publishes the same basename.
case 'cursor': return env.CURSOR_PATH || ENGINE_CLI_COMMANDS.cursor
case 'opencode': return env.OPENCODE_PATH || ENGINE_CLI_COMMANDS.opencode
case 'pi': return env.PI_PATH || ENGINE_CLI_COMMANDS.pi
diff --git a/cli/src/lib/engineInstall.spec.ts b/cli/src/lib/engineInstall.spec.ts
new file mode 100644
index 000000000..af9356d16
--- /dev/null
+++ b/cli/src/lib/engineInstall.spec.ts
@@ -0,0 +1,52 @@
+import { describe, expect, it } from 'vitest'
+import { execFileSync } from 'node:child_process'
+import { ENGINES } from '../engines/types.js'
+import { ENGINE_INSTALL } from './engineInstall.js'
+import { buildEngineLaunchArgv } from './engineLaunch.js'
+
+const OFFICIAL_COMMANDS = {
+ claude: 'npm install -g @anthropic-ai/claude-code',
+ codex: 'npm install -g @openai/codex',
+ cursor: 'curl https://cursor.com/install -fsS | bash',
+ opencode: 'npm install -g opencode-ai',
+ pi: 'npm install -g --ignore-scripts @earendil-works/pi-coding-agent',
+ hermes: 'curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash',
+ commandcode: 'npm i -g command-code',
+ devin: 'curl -fsSL https://cli.devin.ai/install.sh | bash',
+ muse: 'curl -fsSL https://dev.meta.ai/install.sh | bash',
+ amp: 'curl -fsSL https://ampcode.com/install.sh | bash',
+ kilo: 'npm install -g @kilocode/cli',
+ grok: 'curl -fsSL https://x.ai/cli/install.sh | bash',
+ agy: 'curl -fsSL https://antigravity.google/cli/install.sh | bash',
+ copilot: 'npm install -g @github/copilot',
+} as const
+
+describe('ENGINE_INSTALL', () => {
+ it('has one first-party recipe for every supported engine', () => {
+ expect(Object.keys(ENGINE_INSTALL)).toEqual(ENGINES)
+ expect(Object.fromEntries(
+ Object.entries(ENGINE_INSTALL).map(([engine, recipe]) => [engine, recipe.command]),
+ )).toEqual(OFFICIAL_COMMANDS)
+ for (const recipe of Object.values(ENGINE_INSTALL)) {
+ expect(recipe.source).toMatch(/^https:\/\//)
+ expect(recipe.executable.names.length).toBeGreaterThan(0)
+ }
+ })
+
+ it('uses Cursor’s unambiguous documented command and OpenCode stable', () => {
+ expect(ENGINE_INSTALL.cursor.executable.names[0]).toBe('cursor-agent')
+ expect(ENGINE_INSTALL.opencode.command).not.toContain('opencode2')
+ expect(ENGINE_INSTALL.opencode.command).not.toContain('@beta')
+ })
+
+ it('generates valid POSIX pane scripts for every recipe', () => {
+ for (const engine of ENGINES) {
+ const script = buildEngineLaunchArgv(
+ engine,
+ { installIfMissing: ENGINE_INSTALL[engine] },
+ '/bin/sh',
+ )[2]
+ expect(() => execFileSync('/bin/sh', ['-n', '-c', script])).not.toThrow()
+ }
+ })
+})
diff --git a/cli/src/lib/engineInstall.ts b/cli/src/lib/engineInstall.ts
index 2ead2f065..116d4ccb7 100644
--- a/cli/src/lib/engineInstall.ts
+++ b/cli/src/lib/engineInstall.ts
@@ -1,115 +1,127 @@
/**
- * Installing an engine that is not on the target machine yet.
+ * Official install recipes for every engine Harness can launch.
*
- * The New Agent dialog lists every engine Harness supports, not every engine the machine HAS — and
- * until now the difference only surfaced as a failed create: tmux ran a command that did not exist,
- * the pane said `command not found`, and the daemon reported `ENGINE_NOT_INSTALLED` after the fact
- * (see the probe in `engineLaunch.ts` and its caller in `cli.ts`). This module is the other half:
- * what to RUN so that the engine exists, so the dialog can offer the install instead of the failure.
- *
- * ## Every entry is the vendor's own published install line
- *
- * Nothing here is derived, and nothing is a plausible-looking package name. An engine whose install
- * could not be verified against the vendor's own registry entry or documentation gets **no entry**,
- * and the dialog then says the engine is missing without offering to fix it. A missing entry is a
- * smaller lie than a wrong one.
- *
- * Verify against the VENDOR, not against a plausible package name. The unscoped `pi-coding-agent`
- * on npm is "Placeholder package name reservation" with no bin, while pi.dev publishes
- * `@earendil-works/pi-coding-agent` — installing the first would leave a machine with no `pi` and
- * no error, having just reported success.
- *
- * ## Why the command is a string, and why it runs in the user's own shell
- *
- * These are the lines a person would paste. They are run through the SAME interactive shell that
- * launches an agent (`interactiveEngineShell`), for the reason that shell exists at all: a detached
- * daemon does not have the user's PATH, and `npm`, `node` and `curl` frequently arrive through
- * `.zshrc`/`.bashrc` (nvm, asdf, vendor installers). Installing with the daemon's PATH would either
- * fail to find npm or install into a prefix the agent's own shell cannot then see — the worst
- * outcome, because it looks like success and leaves the engine still missing.
- *
- * ## What this module deliberately does NOT do
- *
- * It does not sudo, does not choose a package manager on the user's behalf beyond what the vendor
- * publishes, and does not retry. An install that fails leaves its output in the pane and says so;
- * the person reads the reason and fixes it. A privileged retry is how a tool ends up owning a
- * machine's global prefix without ever being asked.
+ * The command is shown in Desktop before Create is pressed, then runs inside the tmux pane on the
+ * target machine. Keep every line tied to first-party documentation: a plausible package name that
+ * installs successfully but does not provide the expected executable is worse than no recipe.
*/
import type { AgentEngine } from '../engines/types.js'
-/** One engine's published install line. */
+/** How to find the executable after the installer returns. */
+export interface EngineInstallExecutable {
+ /** Executable names published by the vendor, in preference order. */
+ readonly names: readonly string[]
+ /** Paths relative to the target user's home, used before a freshly edited PATH can be reloaded. */
+ readonly homeRelativePaths?: readonly string[]
+ /** Fixed system paths used by a vendor installer in a special mode, such as a root install. */
+ readonly absolutePaths?: readonly string[]
+ /** Resolve each name below `npm prefix -g` when the install method is npm. */
+ readonly npmGlobal?: boolean
+}
+
export interface EngineInstallRecipe {
- /**
- * The shell command, exactly as the vendor publishes it.
- *
- * Runs in the user's interactive shell on the TARGET machine — which is not necessarily the
- * machine the person is sitting at, so it must not assume anything about the operating system
- * beyond a POSIX shell.
- */
+ /** The first-party line a person would paste into a POSIX shell. */
readonly command: string
- /**
- * Where the line above was read from. Kept in the code rather than a commit message because the
- * next person to touch this needs to re-verify it, and a URL in a diff is not findable later.
- */
+ /** First-party documentation used to verify the command. */
readonly source: string
+ /** Ordered, source-owned ways to locate the binary after installation. */
+ readonly executable: EngineInstallExecutable
}
/**
- * The engines Harness can install, and how.
- *
- * `Partial` on purpose — an absent key is the honest answer for an engine whose install we cannot
- * cite, and [engineInstallRecipe] returns null for it rather than guessing.
+ * Exhaustive on purpose. Adding an engine without deciding how it is installed must fail typecheck
+ * rather than silently creating another unsupported row in Desktop.
*/
-export const ENGINE_INSTALL: Partial<Record<AgentEngine, EngineInstallRecipe>> = {
+export const ENGINE_INSTALL: Readonly<Record<AgentEngine, EngineInstallRecipe>> = {
claude: {
command: 'npm install -g @anthropic-ai/claude-code',
- source: 'npm: @anthropic-ai/claude-code — the same package the remote-machine rig installs',
+ source: 'https://docs.anthropic.com/en/docs/claude-code/getting-started',
+ executable: { names: ['claude'], npmGlobal: true, homeRelativePaths: ['.local/bin/claude'] },
},
codex: {
command: 'npm install -g @openai/codex',
- source: 'npm: @openai/codex — matches the `@openai/codex/bin/codex.js` runtime evidence in engines/README.md',
+ source: 'https://github.com/openai/codex',
+ executable: { names: ['codex'], npmGlobal: true, homeRelativePaths: ['.local/bin/codex'] },
},
- copilot: {
- command: 'npm install -g @github/copilot',
- source: 'npm: @github/copilot — matches the `@github/copilot` npm loader in engines/README.md',
+ cursor: {
+ command: 'curl https://cursor.com/install -fsS | bash',
+ source: 'https://docs.cursor.com/en/cli/installation',
+ // `cursor-agent` is deliberately the canonical name. Grok also installs `agent`; using that
+ // shared alias here could turn a requested Cursor pane into a Grok pane.
+ executable: { names: ['cursor-agent'], homeRelativePaths: ['.local/bin/cursor-agent'] },
},
opencode: {
command: 'npm install -g opencode-ai',
- source: 'npm: opencode-ai — matches the `opencode-ai/bin/opencode.exe` runtime evidence in engines/README.md',
+ source: 'https://opencode.ai/docs',
+ executable: { names: ['opencode'], npmGlobal: true, homeRelativePaths: ['.opencode/bin/opencode'] },
+ },
+ pi: {
+ // pi.dev publishes the scoped package with --ignore-scripts. The unscoped package is unrelated
+ // and does not provide the `pi` executable.
+ command: 'npm install -g --ignore-scripts @earendil-works/pi-coding-agent',
+ source: 'https://pi.dev/',
+ executable: { names: ['pi'], npmGlobal: true },
},
hermes: {
- // Not npm. Hermes is a Python agent whose installer builds a venv and links an entrypoint, which
- // is why a broken checkout shows up as a DANGLING SYMLINK on ~/.local/bin/hermes rather than a
- // missing file — and why the availability probe tests `-f` and `-x`, not just `command -v`.
command: 'curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash',
- source: 'NousResearch/hermes-agent README — "Quick Install", Linux/macOS/WSL2/Termux',
+ source: 'https://github.com/NousResearch/hermes-agent/blob/main/website/docs/getting-started/quickstart.md',
+ executable: {
+ names: ['hermes'],
+ homeRelativePaths: ['.local/bin/hermes'],
+ absolutePaths: ['/usr/local/bin/hermes'],
+ },
},
- pi: {
- // `--ignore-scripts` is the vendor's own line, not a hardening we added — pi.dev publishes it
- // that way, and dropping it is not ours to decide.
- //
- // The package is SCOPED, and the unscoped `pi-coding-agent` is a different thing entirely:
- // "Placeholder package name reservation", version 0.0.1, no bin. Installing that one leaves a
- // machine with no `pi` and no error, which is the exact failure this comment exists to prevent
- // the next person from re-introducing by "simplifying" the name.
- command: 'npm install -g --ignore-scripts @earendil-works/pi-coding-agent',
- source: 'pi.dev — its published install line; npm @earendil-works/pi-coding-agent ships bin `pi`',
+ commandcode: {
+ command: 'npm i -g command-code',
+ source: 'https://commandcode.ai/docs',
+ executable: { names: ['cmd', 'command-code'], npmGlobal: true },
+ },
+ devin: {
+ command: 'curl -fsSL https://cli.devin.ai/install.sh | bash',
+ source: 'https://cli.devin.ai/reference/commands',
+ executable: { names: ['devin'], homeRelativePaths: ['.local/bin/devin'] },
+ },
+ muse: {
+ command: 'curl -fsSL https://dev.meta.ai/install.sh | bash',
+ source: 'https://ai.meta.com/llama/',
+ executable: { names: ['muse'], homeRelativePaths: ['.local/bin/muse'] },
+ },
+ amp: {
+ command: 'curl -fsSL https://ampcode.com/install.sh | bash',
+ source: 'https://ampcode.com/docs/cli',
+ executable: { names: ['amp'], homeRelativePaths: ['.local/bin/amp', '.amp/bin/amp'] },
+ },
+ kilo: {
+ command: 'npm install -g @kilocode/cli',
+ source: 'https://kilo.ai/docs/code-with-ai/platforms/cli',
+ executable: {
+ names: ['kilo', 'kilocode'],
+ npmGlobal: true,
+ homeRelativePaths: ['.kilo/bin/kilo', '.local/bin/kilo'],
+ },
+ },
+ grok: {
+ command: 'curl -fsSL https://x.ai/cli/install.sh | bash',
+ source: 'https://docs.x.ai/build/overview',
+ executable: { names: ['grok'], homeRelativePaths: ['.grok/bin/grok', '.local/bin/grok'] },
+ },
+ agy: {
+ command: 'curl -fsSL https://antigravity.google/cli/install.sh | bash',
+ source: 'https://antigravity.google/docs/cli/install/',
+ executable: { names: ['agy'], homeRelativePaths: ['.local/bin/agy'] },
+ },
+ copilot: {
+ command: 'npm install -g @github/copilot',
+ source: 'https://docs.github.com/en/copilot/get-started/cli-quickstart',
+ executable: { names: ['copilot'], npmGlobal: true, homeRelativePaths: ['.local/bin/copilot'] },
},
}
-/** The install line for an engine, or null when Harness has none it can cite. */
-export function engineInstallRecipe(engine: AgentEngine): EngineInstallRecipe | null {
- return ENGINE_INSTALL[engine] ?? null
+export function engineInstallRecipe(engine: AgentEngine): EngineInstallRecipe {
+ return ENGINE_INSTALL[engine]
}
-/**
- * The engines an install can be offered for.
- *
- * Mirrored by `kInstallableEngines` in the desktop app so the dialog can label a row before it has
- * asked the machine anything — the same arrangement `kGridCapableEngines` has with `gridLaunch.ts`.
- * Keep the two in sync.
- */
export const INSTALLABLE_ENGINES: ReadonlySet<AgentEngine> = new Set(
Object.keys(ENGINE_INSTALL) as AgentEngine[],
)
diff --git a/cli/src/lib/engineLaunch.spec.ts b/cli/src/lib/engineLaunch.spec.ts
index 51689e5d3..ee4c19bf5 100644
--- a/cli/src/lib/engineLaunch.spec.ts
+++ b/cli/src/lib/engineLaunch.spec.ts
@@ -11,6 +11,7 @@ import {
} from './engineLaunch.js'
import { ENGINES } from '../engines/types.js'
import { engineBin } from './engineBin.js'
+import type { EngineInstallRecipe } from './engineInstall.js'
describe('buildEngineLaunchArgv', () => {
it('wraps zsh in its interactive login form and execs the resolved binary', () => {
@@ -129,6 +130,22 @@ describe('commandAvailableInInteractiveShell', () => {
await expect(commandAvailableInInteractiveShell('kilo', bashProbeShell())).resolves.toBe(true)
await expect(commandAvailableInInteractiveShell('missing-engine', bashProbeShell())).resolves.toBe(false)
})
+
+ it('recognizes an installed vendor path before the shell profile has it on PATH', async () => {
+ const binDir = mkdtempSync(join(tmpdir(), 'harness-engine-vendor-bin-'))
+ dirs.push(binDir)
+ const installed = executable(binDir, 'cursor-agent')
+ process.env.HARNESS_ENGINE_TEST_PATH = '/usr/bin:/bin'
+ const recipe: EngineInstallRecipe = {
+ command: 'false',
+ source: 'test fixture',
+ executable: { names: ['cursor-agent'], absolutePaths: [installed] },
+ }
+
+ await expect(
+ commandAvailableInInteractiveShell('cursor-agent', bashProbeShell(), recipe),
+ ).resolves.toBe(true)
+ })
})
describe('buildEngineLaunchArgv with installFirst', () => {
@@ -184,19 +201,44 @@ describe('buildEngineLaunchArgv with installFirst', () => {
})
describe('buildEngineLaunchArgv with installIfMissing', () => {
- const script = (install: string): string =>
+ const recipe = (
+ command: string,
+ executable: EngineInstallRecipe['executable'] = { names: ['harness-no-such-engine'] },
+ ): EngineInstallRecipe => ({ command, source: 'test fixture', executable })
+ const script = (install: EngineInstallRecipe): string =>
buildEngineLaunchArgv('opencode', { installIfMissing: install }, '/bin/zsh')[2]
it('execs an installed engine without running the installer', async () => {
- await expect(runPaneScript(script('false'))).resolves.toMatchObject({ code: 0, ranEngine: true })
+ await expect(runPaneScript(script(recipe('false')))).resolves.toMatchObject({ code: 0, ranEngine: true })
})
it('runs the installer inside the pane when the engine is absent', async () => {
- const result = await runPaneScript(script('false'), 'harness-no-such-engine')
+ const result = await runPaneScript(script(recipe('false')), 'harness-no-such-engine')
expect(result.ranEngine).toBe(false)
expect(result.code).toBe(1)
expect(result.stdout).toContain('engine is missing')
})
+
+ it('execs a vendor path after install even when the current PATH did not reload', async () => {
+ const dir = mkdtempSync(join(tmpdir(), 'harness-engine-installed-'))
+ dirs.push(dir)
+ const source = join(dir, 'source-engine')
+ const installed = join(dir, 'new-engine')
+ writeFileSync(source, '#!/bin/sh\n/usr/bin/printf "%s" "$1"\n')
+ chmodSync(source, 0o700)
+ const install = `cp ${JSON.stringify(source)} ${JSON.stringify(installed)}`
+ const result = await runPaneScript(
+ script(recipe(install, { names: ['harness-no-such-engine'], absolutePaths: [installed] })),
+ 'harness-no-such-engine',
+ )
+ expect(result).toMatchObject({ code: 0, ranEngine: true })
+ })
+
+ it('reports a successful install that did not provide an executable', async () => {
+ const result = await runPaneScript(script(recipe('true')), 'harness-no-such-engine')
+ expect(result).toMatchObject({ code: 1, ranEngine: false })
+ expect(result.stdout).toContain('install completed, but its executable could not be found')
+ })
})
/** Run one generated pane script under /bin/sh and report what it did. */
diff --git a/cli/src/lib/engineLaunch.ts b/cli/src/lib/engineLaunch.ts
index 99c61b2e7..8c0abec1b 100644
--- a/cli/src/lib/engineLaunch.ts
+++ b/cli/src/lib/engineLaunch.ts
@@ -1,9 +1,10 @@
import { execFile } from 'node:child_process'
-import { userInfo } from 'node:os'
-import { isAbsolute, basename } from 'node:path'
+import { homedir, userInfo } from 'node:os'
+import { isAbsolute, basename, join } from 'node:path'
import type { AgentEngine } from '../engines/types.js'
import { binaryOnPath } from './binaryOnPath.js'
import { engineBin } from './engineBin.js'
+import type { EngineInstallRecipe } from './engineInstall.js'
/**
* Best-effort "skip permission prompts" flag per engine, confirmed against each vendor's own docs.
@@ -56,7 +57,7 @@ export interface LaunchCommandOptions {
*/
installFirst?: string
/** Install only when command[0] is absent, checked inside the pane's already-started shell. */
- installIfMissing?: string
+ installIfMissing?: EngineInstallRecipe
/**
* Environment variables to clear in the pane before the engine starts — the vendor credentials a
* grid launch must not leave lying around. See `gridConflictingEnvToClear` in `gridLaunch.ts`,
@@ -232,19 +233,95 @@ function installThenExecScript(install: string): string {
].join('\n')
}
-function installIfMissingThenExecScript(install: string): string {
+function shellSingleQuote(value: string): string {
+ return `'${value.replace(/'/g, `'"'"'`)}'`
+}
+
+function installedPathCandidates(recipe: EngineInstallRecipe): string[] {
+ return [
+ ...(recipe.executable.homeRelativePaths ?? []).map((path) => join(homedir(), path)),
+ ...(recipe.executable.absolutePaths ?? []),
+ ]
+}
+
+/**
+ * Install-if-missing has to resolve twice: before installing, and again after it returns.
+ *
+ * A `curl | bash` installer cannot export PATH back into its parent shell. Several supported
+ * vendors correctly put their binary under ~/.local/bin and update a profile for the NEXT shell,
+ * which previously made this very pane print `command not found` after a successful install. The
+ * source-owned candidate paths below bridge that one-shell gap without sourcing arbitrary profile
+ * files a second time. npm installs also get their active global prefix as a fallback.
+ */
+function installIfMissingThenExecScript(recipe: EngineInstallRecipe): string {
+ const install = recipe.command
+ const names = recipe.executable.names.map(shellSingleQuote).join(' ')
+ const paths = installedPathCandidates(recipe).map(shellSingleQuote).join(' ')
+ const candidates = [names, paths].filter(Boolean).join(' ')
+ const tryCandidates = candidates
+ ? `for candidate in ${candidates}; do try_engine "$candidate" "$@" || true; done`
+ : ''
+ const tryNpmGlobal = recipe.executable.npmGlobal
+ ? [
+ 'npm_prefix="$(npm prefix -g 2>/dev/null)" || true',
+ `if [ -n "$npm_prefix" ]; then for bin in ${names}; do try_engine "$npm_prefix/bin/$bin" "$@" || true; done; fi`,
+ ].join('\n')
+ : ''
return [
- 'resolved="$(command -v "$1" 2>/dev/null)" || true',
- 'if [ -n "$resolved" ] && [ -f "$resolved" ] && [ -x "$resolved" ]; then exec "$@"; fi',
+ 'resolve_engine() {',
+ ' candidate="$1"',
+ ' resolved=""',
+ ' case "$candidate" in',
+ ' */*) resolved="$candidate" ;;',
+ ' *) resolved="$(command -v "$candidate" 2>/dev/null)" || true ;;',
+ ' esac',
+ ' [ -n "$resolved" ] && [ -f "$resolved" ] && [ -x "$resolved" ]',
+ '}',
+ 'try_engine() {',
+ ' candidate="$1"',
+ ' shift',
+ ' if ! resolve_engine "$candidate"; then return 1; fi',
+ ' shift',
+ ' exec "$resolved" "$@"',
+ '}',
+ 'try_engine "$1" "$@" || true',
+ tryCandidates,
+ tryNpmGlobal,
`printf '%s\\n' 'harness: engine is missing — installing it in this terminal' 'harness: $ ${install.replace(/'/g, "'\\''")}' ''`,
- `if eval ${JSON.stringify(install)}; then exec "$@"; fi`,
+ `if eval ${JSON.stringify(install)}; then`,
+ ' hash -r 2>/dev/null || true',
+ ' try_engine "$1" "$@" || true',
+ ` ${tryCandidates}`,
+ tryNpmGlobal.split('\n').map((line) => ` ${line}`).join('\n'),
+ ` printf '\\n%s\\n' 'harness: the install completed, but its executable could not be found. Check the installer output and PATH above.'`,
+ ' exit 1',
+ 'fi',
`printf '\\n%s\\n' 'harness: the install failed, so the agent was not started. The command is above; fix it and create the agent again.'`,
'exit 1',
- ].join('\n')
+ ].filter(Boolean).join('\n')
}
-const AVAILABILITY_SCRIPT = 'resolved="$(command -v "$1" 2>/dev/null)" || exit 1\n'
- + '[ -n "$resolved" ] && [ -f "$resolved" ] && [ -x "$resolved" ]'
+function availabilityScript(recipe: EngineInstallRecipe | undefined): string {
+ const names = recipe?.executable.names.map(shellSingleQuote).join(' ') ?? ''
+ const paths = recipe ? installedPathCandidates(recipe).map(shellSingleQuote).join(' ') : ''
+ const candidates = [names, paths].filter(Boolean).join(' ')
+ return [
+ `for candidate in "$@" ${candidates}; do`,
+ ' case "$candidate" in',
+ ' */*) resolved="$candidate" ;;',
+ ' *) resolved="$(command -v "$candidate" 2>/dev/null)" || true ;;',
+ ' esac',
+ ' if [ -n "$resolved" ] && [ -f "$resolved" ] && [ -x "$resolved" ]; then exit 0; fi',
+ 'done',
+ ...(recipe?.executable.npmGlobal ? [
+ 'npm_prefix="$(npm prefix -g 2>/dev/null)" || true',
+ 'if [ -n "$npm_prefix" ]; then',
+ ` for bin in ${names}; do [ -f "$npm_prefix/bin/$bin" ] && [ -x "$npm_prefix/bin/$bin" ] && exit 0; done`,
+ 'fi',
+ ] : []),
+ 'exit 1',
+ ].join('\n')
+}
/**
* Does the same interactive shell that launches a new agent resolve this CLI?
@@ -255,13 +332,17 @@ const AVAILABILITY_SCRIPT = 'resolved="$(command -v "$1" 2>/dev/null)" || exit 1
export async function commandAvailableInInteractiveShell(
command: string,
shell: string | undefined = undefined,
+ recipe: EngineInstallRecipe | undefined = undefined,
): Promise<boolean> {
const interactive = interactiveEngineShell(shell)
- if (!interactive) return binaryOnPath(command)
+ if (!interactive) {
+ return binaryOnPath(command)
+ || (recipe ? installedPathCandidates(recipe).some((candidate) => binaryOnPath(candidate)) : false)
+ }
return await new Promise((resolve) => {
execFile(
interactive.path,
- [...interactive.args, AVAILABILITY_SCRIPT, 'harness-engine-probe', command],
+ [...interactive.args, availabilityScript(recipe), 'harness-engine-probe', command],
{ timeout: 5_000 },
(error) => resolve(!error),
)
diff --git a/cli/src/lib/engineProbe.ts b/cli/src/lib/engineProbe.ts
index c869a0a5f..1643712e5 100644
--- a/cli/src/lib/engineProbe.ts
+++ b/cli/src/lib/engineProbe.ts
@@ -31,7 +31,7 @@
*/
import { ENGINES, type AgentEngine } from '../engines/types.js'
-import { engineBin } from './engineBin.js'
+import { engineBin, enginePathOverride } from './engineBin.js'
import { commandAvailableInInteractiveShell } from './engineLaunch.js'
import { engineInstallRecipe } from './engineInstall.js'
@@ -42,7 +42,7 @@ export interface EngineAvailability {
readonly installed: boolean
/** The command that was probed — `command[0]` of a launch. Null when the engine has no binary. */
readonly command: string | null
- /** Whether Harness has a citable install line for it (see `engineInstall.ts`). */
+ /** Whether Harness can apply the official recipe without overriding a custom launch path. */
readonly installable: boolean
}
@@ -90,10 +90,14 @@ export async function probeEngines(
if (index >= engines.length) return
const engine = engines[index]
const command = launchCommand(engine)
+ // An explicit path is a user-owned launch contract. A vendor installer creates its own
+ // default binary; it cannot repair that path, so do not offer an install that would silently
+ // ignore the override.
+ const recipe = enginePathOverride(engine) ? undefined : engineInstallRecipe(engine)
let installed = false
if (command) {
try {
- installed = await commandAvailableInInteractiveShell(command)
+ installed = await commandAvailableInInteractiveShell(command, undefined, recipe)
} catch {
// The probe has its own 5s timeout and resolves false rather than rejecting; this catch is
// for the spawn itself failing. Unknown reads as not installed, which is the safe way
@@ -106,7 +110,7 @@ export async function probeEngines(
engine,
installed,
command,
- installable: !installed && command !== null && engineInstallRecipe(engine) !== null,
+ installable: !installed && command !== null && recipe !== undefined,
}
}
}