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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
The daemon asks the account's shell when it was given no SHELL (#1228)
Deeb5bf34a3d913
diff --git a/cli/e2e/enginehomes.e2e.ts b/cli/e2e/enginehomes.e2e.tsindex 7117dd4fa..2f43ed4f3 100644--- a/cli/e2e/enginehomes.e2e.ts+++ b/cli/e2e/enginehomes.e2e.ts@@ -7,10 +7,10 @@* without the profile. An agent must still bind, take turns and come back after a restart.*/import { createHash } from 'node:crypto'-import { tmpdir } from 'node:os'+import { tmpdir, userInfo } from 'node:os'import { execFileSync } from 'node:child_process'import { appendFileSync, existsSync, mkdtempSync, rmSync, mkdirSync, readFileSync, readdirSync, renameSync, writeFileSync } from 'node:fs'-import { join } from 'node:path'+import { basename, join } from 'node:path'import { pathToFileURL } from 'node:url'import { afterEach, describe, expect, it, onTestFailed } from 'vitest'import { LocalClient, type Frame } from './harness/client.js'@@ -20,6 +20,9 @@ import { sharedCodex } from './harness/sharedCodex.js'type Engine = 'claude' | 'codex'type Row = Record<string, any>+/** The shell of the account running the tests, by name: what a daemon given no SHELL asks (lib/userShell.ts). */+const accountShell = (() => { try { return basename(userInfo().shell ?? '') } catch { return '' } })()+const rows = async (client: LocalClient): Promise<Row[]> =>(await client.request<{ agents: Row[] }>('agents_list', { includeStopped: true }, 30_000)).agentsconst row = async (client: LocalClient, agentId: string) => (await rows(client)).find((agent) => agent.id === agentId)@@ -128,7 +131,14 @@ describe('the person\'s engines keeping their data elsewhere', () => {await d.start()await until('the core to read the login shell', () => /\[env\] read \d+ variables/.test(d.log()))const client = await LocalClient.connect(d)- const created = await client.request('agent_create', { engine, cwd: d.projectsDir, bypassPermission: true }, 90_000)+ // A launch in the daemon's first seconds may be held while the moved home's hooks are confirmed: the base install+ // and the home's adoption were both writing, one lost its turn, and a create with no creation id is answered+ // NATIVE_LAUNCH_HELD at once (1 run in 4 on a 16-core Intel Mac, 2026-10-12). A hold is a wait, so it asks again,+ // as the apps do by creation id.+ const created = await until('the launch, once the hooks are confirmed', async () => {+ const reply = await client.request('agent_create', { engine, cwd: d.projectsDir, bypassPermission: true }, 90_000)+ return reply.error === 'NATIVE_LAUNCH_HELD' ? null : reply+ }, 60_000, 1_000)expect(created.error, JSON.stringify(created)).toBeUndefined()const agent = await until('the model-picker agent to bind', async () => {const now = await row(client, created.agent.id); return now?.sessionId ? now : null@@ -142,6 +152,22 @@ describe('the person\'s engines keeping their data elsewhere', () => {client.close()})+ // zsh reads the first file and bash, as a login shell, the second: whichever the account running the tests has.+ it.runIf(accountShell === 'zsh' || accountShell === 'bash')('reads the profile of the account\'s shell when the daemon is given no SHELL', async () => {+ // As from `docker exec`, a CI step or a bare service: a shell hands SHELL on only when it was handed it. The+ // daemon then read no profile at all, and a moved home named there never got its hooks.+ const d = await IsolatedDaemon.create(); daemon = d+ onTestFailed(() => console.log(`---- daemon log\n${d.log().split('\n').slice(-150).join('\n')}`))+ delete d.env.SHELL+ const home = join(d.root, 'codex-no-shell')+ mkdirSync(home, { mode: 0o700 })+ for (const profile of ['.zshrc', '.bash_profile']) writeFileSync(join(d.env.HOME!, profile), `export CODEX_HOME=${JSON.stringify(home)}\n`)+ await d.start()+ await until('the core to read the login shell', () => /\[env\] read \d+ variables/.test(d.log()))+ expect(d.log()).not.toContain('could not read a login shell environment')+ await until('the moved home to receive hooks', () => existsSync(join(home, 'hooks.json')), 30_000)+ })+it.each(['activity', 'resources', 'close'] as const)('a moved shared Codex server supplies %s when process environment discovery is unavailable', async operation => {const d = await IsolatedDaemon.create(); daemon = dd.env.NODE_OPTIONS = `--import=${pathToFileURL(join(CLI_ROOT, 'e2e/harness/hiddenProcessEnv.mjs')).href}`diff --git a/cli/src/lib/engineBin.ts b/cli/src/lib/engineBin.tsindex ce050cd0f..fff8a148e 100644--- a/cli/src/lib/engineBin.ts+++ b/cli/src/lib/engineBin.ts@@ -12,6 +12,7 @@ import { basename, delimiter, isAbsolute, join, normalize, sep } from 'node:pathimport { env } from '../config/env.js'import { ENGINES, PROCESS_ENGINES, type AgentEngine } from '../engines/types.js'import { engineInstallPaths, engineInstallRecipe } from './engineInstall.js'+import { currentUserShell } from './userShell.js'// Keep this historical import surface for callers, but never duplicate the// catalog here. `engines/types.ts` is the one iterable source of truth.@@ -97,8 +98,8 @@ let interactivePathCache: { shell: string; daemonPath: string; value: string[] }*/function interactivePathEntries(): string[] {if (process.env.NODE_ENV === 'test') return []- const shell = process.env.SHELL- if (!shell || !isAbsolute(shell)) return []+ const shell = currentUserShell()+ if (!shell) return []const daemonPath = process.env.PATH ?? ''if (interactivePathCache?.shell === shell && interactivePathCache.daemonPath === daemonPath) {return interactivePathCache.value@@ -380,14 +381,14 @@ export function opencodeBin(): string {export async function opencodeBinAsync(): Promise<string> {const configured = env.OPENCODE_PATHif (configured) return configured- const ownPath = processPathEntries(), shell = process.env.SHELL, daemonPath = process.env.PATH ?? ''+ const ownPath = processPathEntries(), shell = currentUserShell(), daemonPath = process.env.PATH ?? ''const installed = join(homedir(), '.opencode', 'bin', 'opencode')for (const entry of ownPath) {const file = join(entry, 'opencode')try { accessSync(file, constants.X_OK); return file } catch { /* next candidate */ }}let extra: string[] = []- if (process.env.NODE_ENV !== 'test' && shell && isAbsolute(shell)) {+ if (process.env.NODE_ENV !== 'test' && shell) {if (interactivePathCache?.shell === shell && interactivePathCache.daemonPath === daemonPath && interactivePathCache.value.length) {extra = interactivePathCache.value} else {diff --git a/cli/src/lib/engineLaunch.ts b/cli/src/lib/engineLaunch.tsindex 09b27b5a2..79536ef8c 100644--- a/cli/src/lib/engineLaunch.ts+++ b/cli/src/lib/engineLaunch.ts@@ -5,7 +5,7 @@ import { nativePaneHold, NATIVE_LAUNCH_MARKER } from './nativePaneHold.js'import { execFile } from 'node:child_process'import { randomUUID } from 'node:crypto'import { existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from 'node:fs'-import { homedir, userInfo } from 'node:os'+import { homedir } from 'node:os'import { isAbsolute, basename, dirname, join } from 'node:path'import { baseNode } from '../harnessd/baseNode.js'import { env } from '../config/env.js'@@ -23,6 +23,7 @@ import { managedNodePath } from './nodeRuntime.js'import { RAISE_OPEN_FILES_SH } from './openFiles.js'import { ENGINE_EXIT_PANE_OPTION } from './engineExitOption.js'import { shellSingleQuote } from './shellQuote.js'+import { currentUserShell } from './userShell.js'import { harnessPaneOwner } from './harnessSessionLabel.js'export { shellSingleQuote }@@ -386,16 +387,6 @@ export interface InteractiveEngineShell {* nvm/asdf and vendor PATH edits in .bashrc, so it must be interactive but not* login. Other POSIX-like shells get the portable interactive form.*/-function currentUserShell(): string | undefined {- if (process.env.SHELL && isAbsolute(process.env.SHELL)) return process.env.SHELL- try {- const shell = userInfo().shell- return shell && isAbsolute(shell) ? shell : undefined- } catch {- return undefined- }-}-/*** The shells that speak the POSIX shell language every launch script here is written in. Any other* login shell (fish, tcsh, csh, nushell, xonsh) cannot run one: handed the script with `-c`, it failsdiff --git a/cli/src/lib/loginShellEnv.spec.ts b/cli/src/lib/loginShellEnv.spec.tsindex a918f59a2..cfb472f80 100644--- a/cli/src/lib/loginShellEnv.spec.ts+++ b/cli/src/lib/loginShellEnv.spec.ts@@ -1,4 +1,12 @@-import { afterEach, describe, expect, it } from 'vitest'+import { chmodSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'+import { tmpdir } from 'node:os'+import { join } from 'node:path'+import { afterEach, describe, expect, it, vi } from 'vitest'++// The account's shell, as the passwd entry gives it: none unless a test names one, never that of whoever runs the tests.+const account = vi.hoisted(() => ({ shell: null as string | null }))+vi.mock('node:os', async (original) => ({ ...await original<typeof import('node:os')>(), userInfo: () => ({ shell: account.shell }) }))+import {loginShellEnvironment,oneShotParentEnv,@@ -12,6 +20,7 @@ afterEach(() => {if (realShell === undefined) delete process.env.SHELLelse process.env.SHELL = realShelldelete process.env.HARNESS_LOGIN_SHELL_PROBE+ account.shell = nullresetLoginShellEnvironmentCache()})@@ -50,6 +59,23 @@ describe('loginShellEnvironment', () => {expect(await warmLoginShellEnvironment()).toEqual({})})+ it.skipIf(process.platform === 'win32')('asks the account\'s shell when the daemon was given no SHELL', async () => {+ // As from `docker exec` or a bare service: bash keeps SHELL to itself and zsh never sets it, so the daemon has+ // none. It then read nothing of the person's profile, and logged that it could not.+ const dir = mkdtempSync(join(tmpdir(), 'account-shell-'))+ try {+ const shell = join(dir, 'fake-shell')+ // Takes `-lic <script>` as a shell does, with one variable only a profile would have exported.+ writeFileSync(shell, '#!/bin/sh\nexport HARNESS_LOGIN_SHELL_PROBE=from-the-profile\nexec /bin/sh -c "$2"\n')+ chmodSync(shell, 0o755)+ account.shell = shell+ delete process.env.SHELL+ resetLoginShellEnvironmentCache()+ expect((await warmLoginShellEnvironment()).HARNESS_LOGIN_SHELL_PROBE).toBe('from-the-profile')+ expect(oneShotParentEnv().HARNESS_LOGIN_SHELL_PROBE).toBe('from-the-profile')+ } finally { rmSync(dir, { recursive: true, force: true }) }+ })+it('caches, so a recap never pays for the probe twice', async () => {resetLoginShellEnvironmentCache()// Two overlapping callers join the same in-flight capture rather than each spawning their owndiff --git a/cli/src/lib/loginShellEnv.ts b/cli/src/lib/loginShellEnv.tsindex f9cd25b6d..759586dd2 100644--- a/cli/src/lib/loginShellEnv.ts+++ b/cli/src/lib/loginShellEnv.ts@@ -17,6 +17,7 @@* All it does is let the recap run where the agent it summarises runs.*/import { spawn } from 'node:child_process'+import { currentUserShell } from './userShell.js'/** Printed before the dump so anything a chatty rc file writes to stdout is skipped, not parsed. */const SENTINEL = '__HARNESS_ENV_BEGIN__'@@ -81,8 +82,10 @@ export function warmLoginShellEnvironment(): Promise<NodeJS.ProcessEnv> {if (cached) return Promise.resolve(cached)inFlight = (async (): Promise<NodeJS.ProcessEnv> => {if (process.platform === 'win32') return (cached = {})- const shell = process.env.SHELL- if (!shell || !shell.startsWith('/')) return (cached = {})+ // The account's shell when the daemon was given no `SHELL` (userShell.ts): read only from the environment, a+ // daemon started from `docker exec` or a bare service captured nothing, and said so in its log.+ const shell = currentUserShell()+ if (!shell) return (cached = {})return (cached = await capture(shell))})().finally(() => {inFlight = nulldiff --git a/cli/src/lib/userShell.spec.ts b/cli/src/lib/userShell.spec.tsnew file mode 100644index 000000000..cd51f3fdd--- /dev/null+++ b/cli/src/lib/userShell.spec.ts@@ -0,0 +1,42 @@+import { afterEach, describe, expect, it, vi } from 'vitest'++// The account, as the passwd entry gives it: a fixture, never the shell of whoever runs the tests.+const account = vi.hoisted(() => ({ shell: (): string | null => null }))+vi.mock('node:os', async (original) => ({ ...await original<typeof import('node:os')>(), userInfo: () => ({ shell: account.shell() }) }))++import { currentUserShell } from './userShell.js'++const given = process.env.SHELL++afterEach(() => {+ if (given === undefined) delete process.env.SHELL+ else process.env.SHELL = given+ account.shell = () => null+})++describe('the person\'s shell', () => {+ it('is SHELL when the daemon was given one', () => {+ process.env.SHELL = '/bin/zsh'+ account.shell = () => '/bin/bash'+ expect(currentUserShell()).toBe('/bin/zsh')+ })++ it('is the account\'s own when the daemon was given none, or one that is no path', () => {+ // `docker exec`, a CI step, a bare service: no shell handed SHELL on, and the account still has one.+ account.shell = () => '/bin/bash'+ delete process.env.SHELL+ expect(currentUserShell()).toBe('/bin/bash')+ process.env.SHELL = 'zsh'+ expect(currentUserShell()).toBe('/bin/bash')+ })++ it('is none when the account has no usable shell either', () => {+ delete process.env.SHELL+ expect(currentUserShell()).toBeUndefined()+ account.shell = () => 'sh'+ expect(currentUserShell()).toBeUndefined()+ // No passwd entry for this user id (a container run as an arbitrary uid): Node throws.+ account.shell = () => { throw new Error('ENOENT: no such file or directory, uv_os_get_passwd') }+ expect(currentUserShell()).toBeUndefined()+ })+})diff --git a/cli/src/lib/userShell.ts b/cli/src/lib/userShell.tsnew file mode 100644index 000000000..1560cb1dc--- /dev/null+++ b/cli/src/lib/userShell.ts@@ -0,0 +1,23 @@+import { userInfo } from 'node:os'+import { isAbsolute } from 'node:path'++/**+ * The person's shell: `SHELL` when the daemon was given one, else the account's own (its passwd entry).+ *+ * A shell hands `SHELL` on only when it was handed it: bash sets it for itself without exporting it, zsh and sh do+ * not set it at all (measured with `env -i` on macOS 15, 2026-10-12). So a daemon started from `docker exec`, a CI+ * step or a bare service has none, while the account still has a shell. The launch path asked the account from the+ * start (engineLaunch.ts, measured in a Linux container). The login-shell environment and the engine lookups read+ * only `SHELL`, and there found no shell at all: the daemon logged "could not read a login shell environment", and+ * nothing the person's profile exports reached it (a moved CODEX_HOME, an API key, nvm's PATH). Found when+ * e2e/enginehomes.e2e.ts failed whole under `env -i`, which is that daemon.+ */+export function currentUserShell(): string | undefined {+ if (process.env.SHELL && isAbsolute(process.env.SHELL)) return process.env.SHELL+ try {+ const shell = userInfo().shell+ return shell && isAbsolute(shell) ? shell : undefined+ } catch {+ return undefined+ }+}