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.

refactor: prioritize user shell over managed build for tmux path resolution

0xken159b5b457fdac1
diff --git a/cli/src/lib/tmuxOnPath.spec.ts b/cli/src/lib/tmuxOnPath.spec.ts
index 2a0127f4d..3eb610732 100644
--- a/cli/src/lib/tmuxOnPath.spec.ts
+++ b/cli/src/lib/tmuxOnPath.spec.ts
@@ -106,7 +106,7 @@ PATH="${binDir}" exec /bin/sh -c "$@"
expect(env.PATH?.split(delimiter)[0]).toBe(binDir)
})
- it('adopts the managed tmux before asking any shell', async () => {
+ it('falls back to the managed tmux when no shell can resolve one', async () => {
const runtimeDir = scratch('tmux-onpath-runtime-')
const binDir = join(runtimeDir, 'tmux-9.9-darwin-arm64', 'bin')
mkdirSync(binDir, { recursive: true })
@@ -115,13 +115,29 @@ PATH="${binDir}" exec /bin/sh -c "$@"
writeFileSync(join(runtimeDir, 'current-tmux'), `${managed}\n`)
const env: NodeJS.ProcessEnv = { PATH: '/nonexistent' }
- // A shell that would answer is deliberately NOT given: the managed build needs none.
const outcome = await ensureTmuxOnPath(env, '/nonexistent/shell', runtimeDir)
expect(outcome).toEqual({ state: 'adopted', path: managed, from: 'managed runtime' })
expect(env.PATH!.split(delimiter)[0]).toBe(binDir)
})
+ it("prefers the tmux the user's shell resolves over the managed one", async () => {
+ // Both exist: the daemon must run what the terminal runs, or they talk to two servers.
+ const runtimeDir = scratch('tmux-onpath-runtime-both-')
+ const managedBin = join(runtimeDir, 'tmux-9.9-darwin-arm64', 'bin')
+ mkdirSync(managedBin, { recursive: true })
+ writeFileSync(join(managedBin, 'tmux'), '#!/bin/sh\nexit 0\n', { mode: 0o755 })
+ writeFileSync(join(runtimeDir, 'current-tmux'), `${join(managedBin, 'tmux')}\n`)
+ const usersBin = scratch('tmux-onpath-users-')
+ writeFileSync(join(usersBin, 'tmux'), '#!/bin/sh\nexit 0\n', { mode: 0o755 })
+ const env: NodeJS.ProcessEnv = { PATH: '/nonexistent' }
+
+ const outcome = await ensureTmuxOnPath(env, fakeShell(usersBin), runtimeDir)
+
+ expect(outcome).toEqual({ state: 'adopted', path: join(usersBin, 'tmux'), from: usersBin })
+ expect(env.PATH!.split(delimiter)[0]).toBe(usersBin)
+ })
+
it('ignores a current-tmux that points outside the runtime dir or cannot run', () => {
const runtimeDir = scratch('tmux-onpath-runtime-bad-')
const elsewhere = scratch('tmux-onpath-elsewhere-')
diff --git a/cli/src/lib/tmuxOnPath.ts b/cli/src/lib/tmuxOnPath.ts
index 689099d5a..d6db975ba 100644
--- a/cli/src/lib/tmuxOnPath.ts
+++ b/cli/src/lib/tmuxOnPath.ts
@@ -50,7 +50,7 @@ export function requireTmuxAvailable(outcome: TmuxPathOutcome): AvailableTmuxPat
* installer downloads our checksum-verified build there and links it as ~/.local/bin/tmux. Null on
* every other machine, and for a record that names something outside the runtime dir or not
* executable: only a path inside the directory we own is ever trusted, the same containment check
- * `managedNodePath` applies.
+ * `managedNodePath` applies. A fallback, not a preference — see `ensureTmuxOnPath` for the order.
*/
export function managedTmuxPath(runtimeDir: string = appEnv.ADAPTER_RUNTIME_DIR): string | null {
try {
@@ -126,25 +126,28 @@ export async function ensureTmuxOnPath(
runtimeDir: string = appEnv.ADAPTER_RUNTIME_DIR,
): Promise<TmuxPathOutcome> {
if (binaryOnPath('tmux', env)) return { state: 'present' }
- // The managed build comes before asking the shell: it is what the user's own shells resolve too
- // (~/.local/bin is put first on PATH by the installer), so the daemon and the terminal keep
- // talking to one server — and it needs no shell at all, which a launch-agent context may lack.
+ // The user's own shell is asked first and the managed build is the fallback, in that order on
+ // purpose: the point is that the daemon runs the SAME tmux the user's terminal runs, so they
+ // share one server. Whatever their shell resolves — Homebrew's, the managed symlink in
+ // ~/.local/bin, something they put on PATH themselves — is that truth. The managed build is
+ // consulted only when no shell can answer: a launch-agent context with no usable shell, or a
+ // Mac where the installer's rc edit has not reached the shell yet.
+ const resolved = await resolveViaLoginShell('tmux', shell)
+ if (resolved) {
+ const dir = dirname(resolved)
+ env.PATH = env.PATH ? `${dir}${delimiter}${env.PATH}` : dir
+ return { state: 'adopted', path: resolved, from: dir }
+ }
const managed = managedTmuxPath(runtimeDir)
if (managed) {
const dir = dirname(managed)
env.PATH = env.PATH ? `${dir}${delimiter}${env.PATH}` : dir
return { state: 'adopted', path: managed, from: 'managed runtime' }
}
- const resolved = await resolveViaLoginShell('tmux', shell)
- if (!resolved) {
- return {
- state: 'absent',
- reason: interactiveEngineShell(shell)
- ? 'the user\'s login shell does not resolve tmux either'
- : 'no usable login shell to ask, and tmux is not on the daemon PATH',
- }
+ return {
+ state: 'absent',
+ reason: interactiveEngineShell(shell)
+ ? 'the user\'s login shell does not resolve tmux either, and there is no managed tmux'
+ : 'no usable login shell to ask, tmux is not on the daemon PATH, and there is no managed tmux',
}
- const dir = dirname(resolved)
- env.PATH = env.PATH ? `${dir}${delimiter}${env.PATH}` : dir
- return { state: 'adopted', path: resolved, from: dir }
}
diff --git a/desktop/RELEASE.md b/desktop/RELEASE.md
index ad4d2bfef..ce42eeb07 100644
--- a/desktop/RELEASE.md
+++ b/desktop/RELEASE.md
@@ -90,7 +90,8 @@ manifest by the first `"<platform>"` key and Node's already has one — with the
`{version,url,sha256,size,archiveRoot}` entries. `install.sh` reads it on a Mac that has no tmux and
no Homebrew (Homebrew's tmux is used when Homebrew is already there): download into
`~/.harness/runtime/tmux-<ver>-<platform>`, verify, record the binary in `~/.harness/runtime/current-tmux`
-(which the daemon's `ensureTmuxOnPath` puts on its PATH, exactly like `current-node`) and link it as
+(which the daemon's `ensureTmuxOnPath` falls back to when neither its PATH nor the user's login shell
+resolves a tmux — the terminal's tmux always wins, so daemon and terminal share one server) and link it as
`~/.local/bin/tmux`. The desktop runs that same `install.sh --host` in-app, so on macOS first-run setup
never opens a Terminal window. Publish a new runtime **before** the `install.sh` that pins a newer
tmux level, and keep it level with what Homebrew ships.