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.

cli: a harness agent's own shell finds Harness's Node when the machine has none

dee04b8f58019e4
diff --git a/cli/src/cli.ts b/cli/src/cli.ts
index 435cd7260..01022c122 100644
--- a/cli/src/cli.ts
+++ b/cli/src/cli.ts
@@ -3592,6 +3592,7 @@ async function runForeground(session: AuthSession): Promise<void> {
...(entry.cwd ? { cwd: entry.cwd } : {}),
...(extraArgs.length ? { extraArgs } : {}),
...(clearEnv.length ? { clearEnv } : {}),
+ ...(launchEnv.HARNESS_DSH ? { harnessNode: true } : {}),
})
return { argv, ...(Object.keys(launchEnv).length ? { env: launchEnv } : {}) }
},
@@ -3867,7 +3868,7 @@ async function runForeground(session: AuthSession): Promise<void> {
// is supposed to use exactly these variables.
const clearEnv = gridLaunch ? gridConflictingEnvToClear(gridLaunch) : undefined
const extraArgs = [...(gridLaunch?.args ?? []), ...dshArgs]
- const launchOptions = { bypassPermission, extraArgs: extraArgs.length ? extraArgs : undefined, installIfMissing, clearEnv, cwd }
+ const launchOptions = { bypassPermission, extraArgs: extraArgs.length ? extraArgs : undefined, installIfMissing, clearEnv, cwd, harnessNode: dsh ? true : undefined }
const command = buildEngineCommandArgv(engine, launchOptions)
const argv = buildEngineLaunchArgv(engine, launchOptions)
// A tmux route is enough to stream its screen. Register it before looking for a process so both
@@ -4019,6 +4020,7 @@ async function runForeground(session: AuthSession): Promise<void> {
// a swap that sets no grid — back to the engine's own login, or a Codex profile's CODEX_HOME —
// clears nothing. There the user's own variables are the point.
...(launch.clearEnv?.length ? { clearEnv: launch.clearEnv } : {}),
+ ...(launch.env?.HARNESS_DSH ? { harnessNode: true } : {}),
}),
log: (message) => console.log(message),
})
diff --git a/cli/src/dsh/shell.ts b/cli/src/dsh/shell.ts
index 915be7631..fcbe82d9e 100644
--- a/cli/src/dsh/shell.ts
+++ b/cli/src/dsh/shell.ts
@@ -5,8 +5,7 @@
* same shell selection) `engineLaunch.ts` uses to exec an engine in a pane.
*/
import { spawn, type ChildProcess } from 'node:child_process'
-import { dirname } from 'node:path'
-import { interactiveEngineShell, shellSingleQuote } from '../lib/engineLaunch.js'
+import { harnessNodePrelude, interactiveEngineShell } from '../lib/engineLaunch.js'
import { managedNodePath } from '../lib/nodeRuntime.js'
export interface DshCommandOptions {
@@ -64,8 +63,7 @@ export function dshShellArgv(script: string): { path: string; args: string[] } {
* files, so a profile that assigns PATH outright cannot drop it.
*/
export function dshNodeFallback(): string {
- const bin = shellSingleQuote(dirname(managedNodePath()))
- return `if ! command -v node >/dev/null 2>&1; then PATH="\${PATH:+$PATH:}"${bin}; export PATH; fi`
+ return harnessNodePrelude(managedNodePath()).trimEnd()
}
export function spawnDshCommand(script: string, opts: { cwd: string; env?: Record<string, string> }): ChildProcess {
diff --git a/cli/src/lib/engineLaunch.spec.ts b/cli/src/lib/engineLaunch.spec.ts
index 2d49fd6eb..ebd7a07dd 100644
--- a/cli/src/lib/engineLaunch.spec.ts
+++ b/cli/src/lib/engineLaunch.spec.ts
@@ -1,5 +1,6 @@
import { afterEach, describe, expect, it } from 'vitest'
-import { chmodSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
+import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
+import { execFileSync } from 'node:child_process'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import {
@@ -8,6 +9,7 @@ import {
buildEngineCommandArgv,
buildEngineLaunchArgv,
commandAvailableInInteractiveShell,
+ harnessNodePrelude,
} from './engineLaunch.js'
import { ENGINES } from '../engines/types.js'
import { engineBin } from './engineBin.js'
@@ -35,6 +37,37 @@ describe('buildEngineLaunchArgv', () => {
])
})
+ it('a DSH agent gets Harness\'s Node at the end of a PATH that has none; a plain launch is unchanged', () => {
+ const argv = buildEngineLaunchArgv('claude', { harnessNode: true }, '/bin/zsh', '/opt/harness runtime/bin/node')
+ expect(argv[2]).toBe(`${harnessNodePrelude('/opt/harness runtime/bin/node')}exec "$@"`)
+ expect(harnessNodePrelude('/opt/harness runtime/bin/node')).toBe(
+ 'if ! command -v node >/dev/null 2>&1; then PATH="${PATH:+$PATH:}"\'/opt/harness runtime/bin\'; export PATH; fi\n')
+ expect(buildEngineLaunchArgv('claude', { harnessNode: false }, '/bin/zsh')[2]).toBe('exec "$@"')
+ })
+
+ it('the DSH prelude, run by a real shell, reaches the engine\'s PATH only when node is missing', () => {
+ const home = mkdtempSync(join(tmpdir(), 'harness-node-prelude-'))
+ try {
+ const runtimeBin = join(home, 'runtime', 'bin')
+ mkdirSync(runtimeBin, { recursive: true })
+ writeFileSync(join(runtimeBin, 'node'), '#!/bin/sh\n', { mode: 0o755 })
+ const run = (path: string) => {
+ const argv = buildEngineLaunchArgv('claude', { harnessNode: true }, '/bin/sh', join(runtimeBin, 'node'))
+ const script = argv[2]
+ return execFileSync('/bin/sh', ['-c', script, 'harness-engine', '/bin/sh', '-c', 'echo "$PATH"; command -v node'], {
+ env: { HOME: home, PATH: path }, encoding: 'utf8',
+ }).trim().split('\n')
+ }
+ expect(run('/usr/bin:/bin')).toEqual([`/usr/bin:/bin:${runtimeBin}`, join(runtimeBin, 'node')])
+ const own = join(home, 'own')
+ mkdirSync(own)
+ writeFileSync(join(own, 'node'), '#!/bin/sh\n', { mode: 0o755 })
+ expect(run(`${own}:/usr/bin:/bin`)).toEqual([`${own}:/usr/bin:/bin`, join(own, 'node')])
+ } finally {
+ rmSync(home, { recursive: true, force: true })
+ }
+ })
+
it('falls back to direct execution when no absolute shell is available', () => {
expect(buildEngineLaunchArgv('claude', {}, '')).toEqual([engineBin('claude')])
expect(buildEngineLaunchArgv('claude', {}, 'zsh')).toEqual([engineBin('claude')])
diff --git a/cli/src/lib/engineLaunch.ts b/cli/src/lib/engineLaunch.ts
index bda91903e..0dd71b916 100644
--- a/cli/src/lib/engineLaunch.ts
+++ b/cli/src/lib/engineLaunch.ts
@@ -72,6 +72,14 @@ export interface LaunchCommandOptions {
* machine keeps everything it had.
*/
clearEnv?: readonly string[]
+ /**
+ * A DSH agent: when the pane's shell, rc files and all, has no `node`, the Node this daemon runs on
+ * joins the END of its PATH before the engine starts, so the agent's own tool calls can run what the
+ * harness's skills tell them to (`node "$MARP_TOOLCHAIN/check.mjs"`, a package's tscircuit CLI). A
+ * machine with no node on PATH is the normal case since the runtime went private; a plain engine
+ * launch is left exactly as it was.
+ */
+ harnessNode?: boolean
/** Workspace entered after interactive-shell startup, not before it. */
cwd?: string
}
@@ -188,7 +196,7 @@ export function buildEngineLaunchArgv(
// of this shell and inherits what it inherits: `npm` is not going to spend someone's Anthropic key,
// but an install script that probes for credentials to configure itself would, and the whole point
// of this launch is that the agent's environment is the one the user asked for.
- const prelude = clearEnvPrelude(opts.clearEnv)
+ const prelude = clearEnvPrelude(opts.clearEnv) + (opts.harnessNode ? harnessNodePrelude(runtimeNode) : '')
// rc files (notably nvm) call getcwd() before running this command. Start the shell in a safe
// directory and enter the selected workspace only after those files have loaded: an IDE can replace
// a workspace inode between the desktop picker resolving it and tmux spawning the pane.
@@ -203,6 +211,11 @@ export function buildEngineLaunchArgv(
return [interactive.path, ...interactive.args, prelude + cwdPrelude + body, 'harness-engine', ...(opts.cwd ? [opts.cwd] : []), ...command]
}
+/** Harness's Node at the end of PATH when the shell found none — see `LaunchCommandOptions.harnessNode`. */
+export function harnessNodePrelude(runtimeNode: string = managedNodePath()): string {
+ return `if ! command -v node >/dev/null 2>&1; then PATH="\${PATH:+$PATH:}"${shellSingleQuote(dirname(runtimeNode))}; export PATH; fi\n`
+}
+
/**
* `unset` for the variables a grid launch must not let through, or nothing at all.
*