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: the pane runs the grid the daemon resolved, and no grid this daemon runs is told to update itself

Kelvin2f4fcac59205
diff --git a/cli/src/lib/engineLaunch.spec.ts b/cli/src/lib/engineLaunch.spec.ts
index 0b5177d2c..0af33b51d 100644
--- a/cli/src/lib/engineLaunch.spec.ts
+++ b/cli/src/lib/engineLaunch.spec.ts
@@ -1,5 +1,5 @@
-import { afterEach, describe, expect, it } from 'vitest'
-import { chmodSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
+import { afterAll, afterEach, beforeEach, describe, expect, it } from 'vitest'
+import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import {
@@ -14,6 +14,7 @@ import {
buildEngineLaunchArgv,
commandAvailableInInteractiveShell,
firstPromptArgs,
+ gridPanePrelude,
namedAgentArgs,
supportsFirstPrompt,
supportsNamedAgent,
@@ -24,16 +25,27 @@ import { engineBin } from './engineBin.js'
import type { EngineInstallRecipe } from './engineInstall.js'
import { MIN_OPEN_FILES, RAISE_OPEN_FILES_SH } from './openFiles.js'
+// The launch script names the `grid` the daemon resolved, and a developer's own HARNESS_GRID_BIN
+// would resolve to THEIR grid. The suite's runtime dir is already a throwaway (vitest.setup.ts), so
+// with the override gone every case below resolves to the bare name.
+const developersOwnGridBin = process.env.HARNESS_GRID_BIN
+beforeEach(() => { delete process.env.HARNESS_GRID_BIN })
+afterAll(() => { if (developersOwnGridBin !== undefined) process.env.HARNESS_GRID_BIN = developersOwnGridBin })
+
+/** The prelude every case below gets by default: no managed grid on this machine, so PATH is left
+ * alone and only grid's update check is turned off. */
+const GRID_PRELUDE = gridPanePrelude('grid')
+
describe('buildEngineLaunchArgv', () => {
it('wraps zsh in its interactive login form and execs the resolved binary', () => {
expect(buildEngineLaunchArgv('claude', {}, '/bin/zsh')).toEqual([
- '/bin/zsh', '-lic', `${RAISE_OPEN_FILES_SH}exec "$@"`, 'harness-engine', engineBin('claude'),
+ '/bin/zsh', '-lic', `${RAISE_OPEN_FILES_SH}${GRID_PRELUDE}exec "$@"`, 'harness-engine', engineBin('claude'),
])
})
it('uses Ubuntu bash interactive startup files without making it a login shell', () => {
expect(buildEngineLaunchArgv('claude', {}, '/bin/bash')).toEqual([
- '/bin/bash', '-ic', `${RAISE_OPEN_FILES_SH}exec "$@"`, 'harness-engine', engineBin('claude'),
+ '/bin/bash', '-ic', `${RAISE_OPEN_FILES_SH}${GRID_PRELUDE}exec "$@"`, 'harness-engine', engineBin('claude'),
])
})
@@ -41,7 +53,7 @@ describe('buildEngineLaunchArgv', () => {
const argv = buildEngineLaunchArgv('claude', { cwd: '/work/project' }, '/bin/zsh')
expect(argv).toEqual([
'/bin/zsh', '-lic',
- `${RAISE_OPEN_FILES_SH}if ! cd -- "$1"; then printf '%s\\n' 'harness: the selected working directory is unavailable.' >&2; exit 1; fi\n${unreadableCwdGuard(process.platform)}shift\nexec "$@"`,
+ `${RAISE_OPEN_FILES_SH}${GRID_PRELUDE}if ! cd -- "$1"; then printf '%s\\n' 'harness: the selected working directory is unavailable.' >&2; exit 1; fi\n${unreadableCwdGuard(process.platform)}shift\nexec "$@"`,
'harness-engine', '/work/project', engineBin('claude'),
])
})
@@ -375,6 +387,70 @@ describe('commandAvailableInInteractiveShell', () => {
})
})
+describe('buildEngineLaunchArgv — the grid the pane finds', () => {
+ /** A runnable `grid` at `dir/grid`. Which one the pane's shell resolves is the assertion. */
+ function gridAt(dir: string): string {
+ mkdirSync(dir, { recursive: true })
+ return executable(dir, 'grid')
+ }
+
+ it('puts the resolved grid first on PATH and turns its update check off, before the engine', () => {
+ const managed = '/opt/harness/runtime/grid-0.3.47-darwin-arm64/grid'
+ const script = buildEngineLaunchArgv('claude', {}, '/bin/zsh', undefined, managed)[2]
+
+ expect(script).toContain(`PATH='/opt/harness/runtime/grid-0.3.47-darwin-arm64'"\${PATH:+:$PATH}"\nexport PATH\n`)
+ expect(script).toContain('GRID_NO_UPDATE_CHECK=1\nexport GRID_NO_UPDATE_CHECK\n')
+ expect(script.indexOf('export GRID_NO_UPDATE_CHECK')).toBeLessThan(script.indexOf('exec "$@"'))
+ })
+
+ it('leaves PATH alone when grid is only a name on it, but still turns the update check off', () => {
+ const script = buildEngineLaunchArgv('claude', {}, '/bin/zsh', undefined, 'grid')[2]
+
+ expect(script).not.toContain('export PATH')
+ expect(script).toContain('GRID_NO_UPDATE_CHECK=1')
+ })
+
+ /** What the engine's own `command -v grid` answers, and what it sees in GRID_NO_UPDATE_CHECK.
+ *
+ * The pane is the user's login shell, and a `.zshrc` that puts `~/.local/bin` first is ordinary —
+ * which is where grid's own installer (uv, on a Mac) leaves a `grid`. The prelude runs AFTER the
+ * startup files, so that one cannot get ahead of the grid the daemon resolved. `bashProbeShell()`
+ * plays the startup file: it resets PATH to HARNESS_ENGINE_TEST_PATH before the script runs. */
+ async function gridSeenByEngine(gridBinary: string): Promise<{ which: string; updateCheck: string }> {
+ const [shell, flag, script] = buildEngineLaunchArgv('claude', {}, bashProbeShell(), undefined, gridBinary)
+ const { execFile } = await import('node:child_process')
+ const out = await new Promise<string>((resolve, reject) => {
+ execFile(
+ shell,
+ [flag, script, 'harness-engine', '/bin/sh', '-c', 'command -v grid; printf "%s" "$GRID_NO_UPDATE_CHECK"'],
+ { timeout: 10_000 },
+ (error, stdout, stderr) => (error ? reject(new Error(`${error.message}\n${stderr}`)) : resolve(stdout)),
+ )
+ })
+ const [which, updateCheck] = out.split('\n')
+ return { which, updateCheck }
+ }
+
+ it('wins over a grid the shell\'s own startup files put first on PATH', async () => {
+ const root = mkdtempSync(join(tmpdir(), 'harness-pane-grid-'))
+ dirs.push(root)
+ gridAt(join(root, 'users-own'))
+ const managed = gridAt(join(root, 'runtime', 'grid-0.3.47-darwin-arm64'))
+ process.env.HARNESS_ENGINE_TEST_PATH = `${join(root, 'users-own')}:/usr/bin:/bin`
+
+ await expect(gridSeenByEngine(managed)).resolves.toEqual({ which: managed, updateCheck: '1' })
+ })
+
+ it('leaves the user\'s own grid in charge when the daemon resolved nothing better', async () => {
+ const root = mkdtempSync(join(tmpdir(), 'harness-pane-grid-'))
+ dirs.push(root)
+ const own = gridAt(join(root, 'users-own'))
+ process.env.HARNESS_ENGINE_TEST_PATH = `${join(root, 'users-own')}:/usr/bin:/bin`
+
+ await expect(gridSeenByEngine('grid')).resolves.toEqual({ which: own, updateCheck: '1' })
+ })
+})
+
describe('buildEngineLaunchArgv with installFirst', () => {
// Everything here is about ONE rule: the engine must not be exec'd after an install that failed.
// Doing so reproduces the `command not found` this feature exists to replace, with a screenful of
@@ -383,7 +459,7 @@ describe('buildEngineLaunchArgv with installFirst', () => {
buildEngineLaunchArgv('opencode', { installFirst: install }, '/bin/zsh')[2]
it('leaves the plain launch alone when nothing has to be installed', () => {
- expect(buildEngineLaunchArgv('opencode', {}, '/bin/zsh')[2]).toBe(`${RAISE_OPEN_FILES_SH}exec "$@"`)
+ expect(buildEngineLaunchArgv('opencode', {}, '/bin/zsh')[2]).toBe(`${RAISE_OPEN_FILES_SH}${GRID_PRELUDE}exec "$@"`)
})
it('keeps the engine argv positional, so the shell never re-parses a path or a flag', () => {
diff --git a/cli/src/lib/engineLaunch.ts b/cli/src/lib/engineLaunch.ts
index dc5323eab..6c45a661b 100644
--- a/cli/src/lib/engineLaunch.ts
+++ b/cli/src/lib/engineLaunch.ts
@@ -5,6 +5,7 @@ import type { AgentEngine } from '../engines/types.js'
import { binaryOnPath } from './binaryOnPath.js'
import { engineBin } from './engineBin.js'
import type { EngineInstallRecipe } from './engineInstall.js'
+import { GRID_NO_UPDATE_CHECK_VAR, gridBinaryPath } from './gridExec.js'
import { managedNodePath } from './nodeRuntime.js'
import { RAISE_OPEN_FILES_SH } from './openFiles.js'
@@ -303,6 +304,7 @@ export function buildEngineLaunchArgv(
opts: LaunchCommandOptions = {},
shell: string | undefined = undefined,
runtimeNode: string = managedNodePath(),
+ gridBinary: string = gridBinaryPath(),
): string[] {
const command = buildEngineCommandArgv(engine, opts)
const interactive = interactiveEngineShell(shell)
@@ -311,7 +313,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) + gridPanePrelude(gridBinary)
// 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.
@@ -448,6 +450,31 @@ function npmRuntimePrelude(recipe: EngineInstallRecipe, runtimeNode: string, req
].join('\n')
}
+/**
+ * The `grid` this pane's agent gets is the one the daemon resolved — and stays it.
+ *
+ * `grid` is not only the daemon's subprocess: the Harness Compute skill has the AGENT run it, in
+ * this pane, by name. A managed grid under `~/.harness/runtime` is invisible to a shell's PATH, and
+ * a login file that puts `~/.local/bin` first is ordinary — which is where grid's own installer
+ * (uv, on a Mac) leaves a `grid` of some other version. So the prepend is made HERE, after those
+ * files have run, the way [npmRuntimePrelude] does for the managed Node — never by a symlink in
+ * `~/.local/bin`, which would fight the installer for one file. Two versions of `grid` writing one
+ * `~/.grid` is the outcome this exists to prevent.
+ *
+ * Without an absolute path to prepend — the bare name of the PATH fallback, or an override that is
+ * not one — PATH is left alone. Either way grid's update check is off for the pane —
+ * [GRID_NO_UPDATE_CHECK_VAR]: the agent is the process most likely to read "run `grid update`" and
+ * do it, and under a managed runtime that overwrites the pin.
+ *
+ * Interactive shells only, like the npm prelude: a direct launch has no script to carry this.
+ */
+export function gridPanePrelude(binary: string): string {
+ const onPath = isAbsolute(binary)
+ ? [`PATH=${shellSingleQuote(dirname(binary))}"\${PATH:+:$PATH}"`, 'export PATH', 'hash -r 2>/dev/null || true']
+ : []
+ return [...onPath, `${GRID_NO_UPDATE_CHECK_VAR}=1`, `export ${GRID_NO_UPDATE_CHECK_VAR}`, ''].join('\n')
+}
+
/**
* Install-if-missing has to resolve twice: before installing, and again after it returns.
*
diff --git a/cli/src/lib/gridExec.spec.ts b/cli/src/lib/gridExec.spec.ts
new file mode 100644
index 000000000..36b80ee70
--- /dev/null
+++ b/cli/src/lib/gridExec.spec.ts
@@ -0,0 +1,141 @@
+/**
+ * Which `grid` this daemon runs, and what every child of it inherits.
+ *
+ * `gridBinaryPath()` is the one resolver behind every grid call — the daemon's own (`gridExec`), the
+ * sign-in hand-off and the sign-out, and the PATH the agent's pane gets (`engineLaunch.ts`). The
+ * order is the contract: the developer override, then the managed runtime's pointer, then PATH —
+ * with the pointer trusted only when it names something runnable INSIDE the runtime dir.
+ */
+import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import { join } from 'node:path'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+
+let root = ''
+let runtimeDir = ''
+const saved = { PATH: process.env.PATH, HARNESS_GRID_BIN: process.env.HARNESS_GRID_BIN, ADAPTER_RUNTIME_DIR: process.env.ADAPTER_RUNTIME_DIR }
+
+/** `gridExec.ts` reads `env.ADAPTER_RUNTIME_DIR` at import time, so the module is loaded fresh per case. */
+async function load() {
+ vi.resetModules()
+ process.env.ADAPTER_RUNTIME_DIR = runtimeDir
+ return import('./gridExec.js')
+}
+
+/** A `grid` that prints what it was given: its argv, then GRID_NO_UPDATE_CHECK. A shell script with
+ * builtins only, so an empty PATH cannot fail it for a reason that is not the one under test. */
+function fakeGrid(dir: string): string {
+ mkdirSync(dir, { recursive: true })
+ const bin = join(dir, 'grid')
+ writeFileSync(bin, '#!/bin/sh\nprintf \'%s\\n\' "$@" "update-check=${GRID_NO_UPDATE_CHECK-unset}"\nexit 0\n', { mode: 0o755 })
+ return bin
+}
+
+beforeEach(() => {
+ root = mkdtempSync(join(tmpdir(), 'grid-exec-'))
+ runtimeDir = join(root, 'runtime')
+ mkdirSync(runtimeDir)
+ mkdirSync(join(root, 'empty-bin'))
+ process.env.PATH = join(root, 'empty-bin')
+ delete process.env.HARNESS_GRID_BIN
+})
+
+afterEach(() => {
+ for (const [key, value] of Object.entries(saved)) {
+ if (value === undefined) delete process.env[key]
+ else process.env[key] = value
+ }
+ rmSync(root, { recursive: true, force: true })
+})
+
+describe('gridBinaryPath', () => {
+ it('is the developer override when there is one, whatever else exists', async () => {
+ const managed = fakeGrid(join(runtimeDir, 'grid-0.3.47-darwin-arm64'))
+ writeFileSync(join(runtimeDir, 'current-grid'), `${managed}\n`)
+ const { gridBinaryPath } = await load()
+
+ expect(gridBinaryPath({ HARNESS_GRID_BIN: '/elsewhere/grid' })).toBe('/elsewhere/grid')
+ })
+
+ it('is the managed runtime when its pointer names a runnable grid inside the runtime dir', async () => {
+ const managed = fakeGrid(join(runtimeDir, 'grid-0.3.47-darwin-arm64'))
+ writeFileSync(join(runtimeDir, 'current-grid'), `${managed}\n`)
+ const { gridBinaryPath } = await load()
+
+ expect(gridBinaryPath({})).toBe(managed)
+ })
+
+ it('falls through to PATH when the pointer names something outside the runtime dir', async () => {
+ writeFileSync(join(runtimeDir, 'current-grid'), '/bin/sh\n')
+ const { gridBinaryPath } = await load()
+
+ expect(gridBinaryPath({})).toBe('grid')
+ })
+
+ it('falls through to PATH when the pointer names something that is not there, or not runnable', async () => {
+ const { gridBinaryPath } = await load()
+
+ writeFileSync(join(runtimeDir, 'current-grid'), `${join(runtimeDir, 'grid-gone', 'grid')}\n`)
+ expect(gridBinaryPath({})).toBe('grid')
+
+ const unrunnable = fakeGrid(join(runtimeDir, 'grid-0.3.47-darwin-arm64'))
+ chmodSync(unrunnable, 0o644)
+ writeFileSync(join(runtimeDir, 'current-grid'), `${unrunnable}\n`)
+ expect(gridBinaryPath({})).toBe('grid')
+ })
+})
+
+describe('gridCliPresence', () => {
+ it('is `managed` when the resolved grid is the runtime this daemon owns', async () => {
+ const managed = fakeGrid(join(runtimeDir, 'grid-0.3.47-darwin-arm64'))
+ writeFileSync(join(runtimeDir, 'current-grid'), `${managed}\n`)
+ const { gridCliPresence } = await load()
+
+ expect(gridCliPresence()).toBe('managed')
+ })
+
+ it('is `path` for a grid found on PATH, and for a developer override — neither is the pin', async () => {
+ fakeGrid(join(root, 'path-bin'))
+ process.env.PATH = join(root, 'path-bin')
+ const { gridCliPresence } = await load()
+ expect(gridCliPresence()).toBe('path')
+
+ process.env.HARNESS_GRID_BIN = fakeGrid(join(root, 'elsewhere'))
+ expect(gridCliPresence()).toBe('path')
+ })
+
+ it('is `missing` when there is nothing to run at all', async () => {
+ const { gridCliPresence } = await load()
+
+ expect(gridCliPresence()).toBe('missing')
+ })
+})
+
+describe('gridChildEnv', () => {
+ it('turns grid\'s own update check off on top of the environment it is given', async () => {
+ const { gridChildEnv } = await load()
+
+ expect(gridChildEnv({ GRID_HOME: '/x/.grid', PATH: '/bin' })).toEqual({ GRID_HOME: '/x/.grid', PATH: '/bin', GRID_NO_UPDATE_CHECK: '1' })
+ })
+})
+
+describe('gridExec', () => {
+ it('runs the resolved grid with its update check off, and hands back what it said', async () => {
+ process.env.HARNESS_GRID_BIN = fakeGrid(join(root, 'elsewhere'))
+ const { gridExec } = await load()
+
+ const result = await gridExec(['--version'])
+
+ expect(result.code).toBe('OK')
+ expect(result.stdout).toBe('--version\nupdate-check=1\n')
+ })
+
+ it('answers GRID_CLI_MISSING, without spawning, when there is nothing to run', async () => {
+ const { gridExec } = await load()
+
+ const result = await gridExec(['--version'])
+
+ expect(result).toMatchObject({ code: 'GRID_CLI_MISSING', exitCode: 1 })
+ expect(result.message).toContain('grid')
+ })
+})
diff --git a/cli/src/lib/gridExec.ts b/cli/src/lib/gridExec.ts
index eb5b37f8d..9dbceeeb9 100644
--- a/cli/src/lib/gridExec.ts
+++ b/cli/src/lib/gridExec.ts
@@ -47,6 +47,24 @@ const MAX_CAPTURED_CHARS = 64 * 1024
* sign-in path, where a hung child would otherwise hang the command that spawned it. */
const DEFAULT_TIMEOUT_MS = 30_000
+/**
+ * grid's own update check, and the one switch that turns it off.
+ *
+ * A `grid` with a terminal on stderr looks for a newer release and, finding one, prints "run
+ * `grid update`" — and `grid update` replaces the binary IN PLACE, wherever `which grid` found it
+ * (autonomous-grid `cli/update.py`). Under a managed runtime that file is the pin, and the process
+ * most likely to read that line and obey it is an agent in a pane. So the check is off for every
+ * child this daemon spawns ([gridChildEnv]) and in every pane it launches (`engineLaunch.ts`), by
+ * the variable grid honours for it. The daemon's own spawns pipe stderr and would be spared anyway;
+ * saying it explicitly is what makes the pane and the daemon one rule.
+ */
+export const GRID_NO_UPDATE_CHECK_VAR = 'GRID_NO_UPDATE_CHECK'
+
+/** The environment a `grid` child gets: the caller's own, with the update check off. */
+export function gridChildEnv(processEnv: NodeJS.ProcessEnv = process.env): NodeJS.ProcessEnv {
+ return { ...processEnv, [GRID_NO_UPDATE_CHECK_VAR]: '1' }
+}
+
export type GridCode = 'OK' | 'GRID_CLI_MISSING' | 'GRID_CLI_OUTDATED' | 'GRID_FAILED'
export interface GridResult {
@@ -104,6 +122,22 @@ export function gridAvailable(processEnv: NodeJS.ProcessEnv = process.env): bool
return binaryOnPath(gridBinaryPath(processEnv), processEnv)
}
+/**
+ * Which `grid` this machine would run, for a desktop that has to say so.
+ *
+ * `managed` is the runtime this daemon owns — the pin. `path` is one the user installed themselves,
+ * or a developer's override: runnable, but not the pin, and not ours to keep current. `missing` is
+ * nothing to run at all, which the picker and the Local model dialog need to know BEFORE they offer
+ * to start an agent whose second step is `grid`.
+ */
+export type GridCliPresence = 'managed' | 'path' | 'missing'
+
+export function gridCliPresence(processEnv: NodeJS.ProcessEnv = process.env): GridCliPresence {
+ const binary = gridBinaryPath(processEnv)
+ if (!binaryOnPath(binary, processEnv)) return 'missing'
+ return binary.startsWith(env.ADAPTER_RUNTIME_DIR + sep) ? 'managed' : 'path'
+}
+
export interface GridExecOptions {
/** Written to the child's stdin, which is then closed. For the token hand-off and nothing else. */
stdin?: string
@@ -125,7 +159,7 @@ export async function gridExec(args: readonly string[], opts: GridExecOptions =
return { code: 'GRID_CLI_MISSING', exitCode: 1, stdout: '', stderr: '', message: MISSING_MESSAGE }
}
return await new Promise<GridResult>((resolve) => {
- const child = spawn(binary, [...args], { stdio: ['pipe', 'pipe', 'pipe'] })
+ const child = spawn(binary, [...args], { stdio: ['pipe', 'pipe', 'pipe'], env: gridChildEnv(processEnv) })
let stdout = ''
let stderr = ''
let settled = false
diff --git a/cli/src/lib/gridHandoff.spec.ts b/cli/src/lib/gridHandoff.spec.ts
index 588ffa7b4..3a3c9e4b9 100644
--- a/cli/src/lib/gridHandoff.spec.ts
+++ b/cli/src/lib/gridHandoff.spec.ts
@@ -33,6 +33,7 @@ function fakeGrid(dir: string, label: string): string {
writeFileSync(bin, [
'#!/bin/sh',
`printf '%s\\n' "$@" > "${join(root, `${label}.args`)}"`,
+ `printf '%s' "\${GRID_NO_UPDATE_CHECK-unset}" > "${join(root, `${label}.update-check`)}"`,
`[ "$1" = login ] && /bin/cat > "${join(root, `${label}.stdin`)}"`,
'exit 0',
'',
@@ -42,6 +43,7 @@ function fakeGrid(dir: string, label: string): string {
function ran(label: string): boolean { return existsSync(join(root, `${label}.args`)) }
function argsOf(label: string): string[] { return readFileSync(join(root, `${label}.args`), 'utf8').trim().split('\n') }
+function updateCheckSeenBy(label: string): string { return readFileSync(join(root, `${label}.update-check`), 'utf8') }
beforeEach(() => {
root = mkdtempSync(join(tmpdir(), 'grid-handoff-'))
@@ -72,6 +74,9 @@ describe('handOffToGrid — which grid it runs', () => {
expect(result.code).toBe('OK')
expect(argsOf('override')).toEqual(['login', '--harness', '--json'])
expect(readFileSync(join(root, 'override.stdin'), 'utf8')).toBe('tok_1\n')
+ // grid's own "a newer version is out — run `grid update`" must never reach a binary the
+ // harness pins: `update` would overwrite it in place. Off for every child this daemon spawns.
+ expect(updateCheckSeenBy('override')).toBe('1')
})
it('prefers the managed runtime over a grid on PATH', async () => {
diff --git a/cli/src/lib/gridHandoff.ts b/cli/src/lib/gridHandoff.ts
index e552d5c51..e6764613f 100644
--- a/cli/src/lib/gridHandoff.ts
+++ b/cli/src/lib/gridHandoff.ts
@@ -13,7 +13,7 @@
*/
import { spawn } from 'node:child_process'
import { binaryOnPath } from './binaryOnPath.js'
-import { gridBinaryPath } from './gridExec.js'
+import { gridBinaryPath, gridChildEnv } from './gridExec.js'
/** The flag on `grid login` that means "read the token off stdin" (autonomous-grid's `cli/parser.py`).
* WHICH `grid` is not decided here: `gridBinaryPath()` (lib/gridExec.ts) answers that for every grid
@@ -94,6 +94,9 @@ export async function handOffToGrid(
return await new Promise<GridHandoffResult>((resolve) => {
const child = spawn(binary, args, {
stdio: ['pipe', opts.json ? 'pipe' : 'inherit', opts.json ? 'pipe' : 'inherit'],
+ // The human path inherits stderr, which is a terminal — exactly where grid would offer
+ // `grid update` for a binary the harness pins. See GRID_NO_UPDATE_CHECK_VAR in gridExec.ts.
+ env: gridChildEnv(),
})
let stdout = ''
let stderr = ''
diff --git a/cli/src/lib/gridLogout.spec.ts b/cli/src/lib/gridLogout.spec.ts
index cef1698b6..a1252556a 100644
--- a/cli/src/lib/gridLogout.spec.ts
+++ b/cli/src/lib/gridLogout.spec.ts
@@ -23,12 +23,19 @@ async function load() {
function fakeGrid(dir: string, label: string): string {
mkdirSync(dir, { recursive: true })
const bin = join(dir, 'grid')
- writeFileSync(bin, `#!/bin/sh\nprintf '%s\\n' "$@" > "${join(root, `${label}.args`)}"\nexit 0\n`, { mode: 0o755 })
+ writeFileSync(bin, [
+ '#!/bin/sh',
+ `printf '%s\\n' "$@" > "${join(root, `${label}.args`)}"`,
+ `printf '%s' "\${GRID_NO_UPDATE_CHECK-unset}" > "${join(root, `${label}.update-check`)}"`,
+ 'exit 0',
+ '',
+ ].join('\n'), { mode: 0o755 })
return bin
}
function ran(label: string): boolean { return existsSync(join(root, `${label}.args`)) }
function argsOf(label: string): string[] { return readFileSync(join(root, `${label}.args`), 'utf8').trim().split('\n') }
+function updateCheckSeenBy(label: string): string { return readFileSync(join(root, `${label}.update-check`), 'utf8') }
beforeEach(() => {
root = mkdtempSync(join(tmpdir(), 'grid-logout-'))
@@ -56,6 +63,8 @@ describe('passThroughToGridLogout — which grid it runs', () => {
expect(outcome).toEqual({ ran: true, exitCode: 0 })
expect(argsOf('override')).toEqual(['logout', '--force'])
+ // Same as the hand-off: a pinned binary must never be told to `grid update` itself.
+ expect(updateCheckSeenBy('override')).toBe('1')
})
it('prefers the managed runtime over a grid on PATH', async () => {
diff --git a/cli/src/lib/gridLogout.ts b/cli/src/lib/gridLogout.ts
index 9a955adb0..6f32842be 100644
--- a/cli/src/lib/gridLogout.ts
+++ b/cli/src/lib/gridLogout.ts
@@ -17,7 +17,7 @@
*/
import { spawn } from 'node:child_process'
import { binaryOnPath } from './binaryOnPath.js'
-import { GRID_BINARY, gridBinaryPath } from './gridExec.js'
+import { GRID_BINARY, gridBinaryPath, gridChildEnv } from './gridExec.js'
/** The verb, on the same binary the hand-off spawns. Deliberately NOT a cross-repo pin: rename it in
* autonomous-grid and argparse refuses it loudly, in the child's own words, on the child's own
@@ -57,7 +57,9 @@ export async function passThroughToGridLogout(args: string[]): Promise<GridLogou
return await new Promise<GridLogoutOutcome>((resolve) => {
// All three streams inherited: the child talks to the terminal directly, which is what makes
// this a passthrough rather than a re-narration of one.
- const child = spawn(binary, [GRID_LOGOUT_VERB, ...args], { stdio: 'inherit' })
+ // Inherited stderr is a terminal, where grid would offer `grid update` for a binary the harness
+ // pins — off, as for every child of this daemon (GRID_NO_UPDATE_CHECK_VAR in gridExec.ts).
+ const child = spawn(binary, [GRID_LOGOUT_VERB, ...args], { stdio: 'inherit', env: gridChildEnv() })
let settled = false
const settle = (outcome: GridLogoutOutcome): void => { if (!settled) { settled = true; resolve(outcome) } }
diff --git a/docs/skills/harness-compute.md b/docs/skills/harness-compute.md
index f4647917c..0cfd17bf0 100644
--- a/docs/skills/harness-compute.md
+++ b/docs/skills/harness-compute.md
@@ -71,6 +71,11 @@ a name or create one; a guessed name can collide with someone else's on the same
**If a command fails because the user isn't signed in**, stop and tell them to run
`harness login`. That's the only command in this whole feature that's ever theirs to run by hand.
+**Never run `grid update`, and ignore any "newer version available" line.** The `grid` in this
+pane is the one Harness ships and pins to its own release; Harness replaces it when Harness
+updates, and an update run from here would overwrite it under the running daemon. If a command
+refuses because grid is too old, say that Harness itself needs updating, and stop.
+
**Ask through a tool, not through prose.** Every point in this file that says "ask" means: use
whatever structured, interactive way your own agent has of putting a question to the user — real
selectable options, a real blocking prompt — not a sentence ending in a question mark inside a