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: add requireTmuxAvailable utility to enforce tmux presence before daemon startup

0xken1520365b900f76
diff --git a/cli/src/cli.ts b/cli/src/cli.ts
index bae9d1383..7b695bb36 100644
--- a/cli/src/cli.ts
+++ b/cli/src/cli.ts
@@ -38,7 +38,7 @@ import { DeviceFleet } from './device/deviceFleet.js'
import { registry, projectDisplayName, type RegisteredSession } from './lib/registry.js'
import { installAmpPlugin, installCodexHooks, installCommandCodeHooks, installCursorHooks, installDevinHooks, installGrokHooks, installAgyHooks, installCopilotHooks, installHermesHooks, installKiloPlugin, installOpencodePlugin, installPiExtension, installSessionHooks } from './lib/hooks.js'
import { PID_FILE, daemonPort, isAlive, readPid } from './lib/daemonState.js'
-import { ensureTmuxOnPath } from './lib/tmuxOnPath.js'
+import { ensureTmuxOnPath, requireTmuxAvailable } from './lib/tmuxOnPath.js'
import { flashCommand } from './lib/flash.js'
import { readOrMintComputerId } from './lib/computerIdentity.js'
import { renderLoginSuccessHtml } from './lib/loginPage.js'
@@ -985,11 +985,9 @@ async function runForeground(session: AuthSession): Promise<void> {
const tmuxPathPromise = terminalConfig.backends.includes('tmux') ? ensureTmuxOnPath() : null
const loginShellEnvPromise = warmLoginShellEnvironment()
if (tmuxPathPromise) {
- const tmuxPath = await tmuxPathPromise
+ const tmuxPath = requireTmuxAvailable(await tmuxPathPromise)
if (tmuxPath.state === 'adopted') {
console.log(`[tmux] not on the daemon PATH · adopted ${tmuxPath.from} from the user's login shell`)
- } else if (tmuxPath.state === 'absent') {
- console.warn(`[tmux] unavailable · ${tmuxPath.reason} · new agents cannot be created`)
}
}
const tmuxBackend = terminalConfig.backends.includes('tmux') ? new TmuxBackend() : null
diff --git a/cli/src/lib/tmuxOnPath.spec.ts b/cli/src/lib/tmuxOnPath.spec.ts
index c78a46661..560e99e26 100644
--- a/cli/src/lib/tmuxOnPath.spec.ts
+++ b/cli/src/lib/tmuxOnPath.spec.ts
@@ -3,7 +3,7 @@ import { tmpdir } from 'node:os'
import { delimiter, join } from 'node:path'
import { afterEach, describe, expect, it } from 'vitest'
import { TmuxBackend } from './tmuxBackend.js'
-import { ensureTmuxOnPath, resolveViaLoginShell } from './tmuxOnPath.js'
+import { ensureTmuxOnPath, requireTmuxAvailable, resolveViaLoginShell } from './tmuxOnPath.js'
const dirs: string[] = []
const originalPath = process.env.PATH
@@ -124,6 +124,13 @@ PATH="${binDir}" exec /bin/sh -c "$@"
expect(env.PATH).toBe('/nonexistent-for-this-test')
})
+ it('fails before daemon startup when tmux is unavailable', () => {
+ expect(() => requireTmuxAvailable({
+ state: 'absent',
+ reason: 'the user\'s login shell does not resolve tmux either',
+ })).toThrow('tmux is required but unavailable')
+ })
+
it('does not consult a shell it cannot trust', async () => {
// A relative SHELL is not something to hand a command to.
expect(await resolveViaLoginShell('tmux', 'sh')).toBeNull()
diff --git a/cli/src/lib/tmuxOnPath.ts b/cli/src/lib/tmuxOnPath.ts
index 8f435429f..12caddd24 100644
--- a/cli/src/lib/tmuxOnPath.ts
+++ b/cli/src/lib/tmuxOnPath.ts
@@ -29,6 +29,19 @@ export type TmuxPathOutcome =
/** Not resolvable either way — tmux is genuinely absent, or there is no usable login shell. */
| { state: 'absent'; reason: string }
+export type AvailableTmuxPathOutcome = Exclude<TmuxPathOutcome, { state: 'absent' }>
+
+/** Refuse to start a daemon that cannot create terminals. */
+export function requireTmuxAvailable(outcome: TmuxPathOutcome): AvailableTmuxPathOutcome {
+ if (outcome.state === 'absent') {
+ throw new Error(
+ `tmux is required but unavailable: ${outcome.reason}. `
+ + 'Install tmux, verify `tmux -V`, then run `harness start` again.',
+ )
+ }
+ return outcome
+}
+
/** Where the user's own interactive shell finds a command, which is not where the daemon looks. */
export async function resolveViaLoginShell(
command: string,