Repository navigation
fix(cli): preserve Hermes light terminal hints #6391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
d14950b
7c0fb8c
68c9c26
ab1368f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { afterEach, beforeEach, describe, expect, it, type MockInstance, vi } from "vitest"; | ||
|
|
||
| import { | ||
| connectModulePath, | ||
| createConnectHarness, | ||
| requireDist, | ||
| } from "../../../../test/support/connect-flow-test-harness"; | ||
|
|
||
| describe("Hermes sandbox connect light terminal environment", () => { | ||
| let exitSpy: MockInstance; | ||
| const originalStdoutIsTty = process.stdout.isTTY; | ||
|
|
||
| beforeEach(() => { | ||
| process.env.NEMOCLAW_TEST_NO_SLEEP = "1"; | ||
| Object.defineProperty(process.stdout, "isTTY", { configurable: true, value: true }); | ||
| exitSpy = vi.spyOn(process, "exit").mockImplementation(((code?: number | string | null) => { | ||
| throw new Error(`process.exit(${code ?? 0})`); | ||
| }) as never); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| vi.unstubAllEnvs(); | ||
| if (originalStdoutIsTty === undefined) { | ||
| Object.defineProperty(process.stdout, "isTTY", { configurable: true, value: undefined }); | ||
| } else { | ||
| Object.defineProperty(process.stdout, "isTTY", { | ||
| configurable: true, | ||
| value: originalStdoutIsTty, | ||
| }); | ||
| } | ||
| delete process.env.NEMOCLAW_TEST_NO_SLEEP; | ||
| delete require.cache[requireDist.resolve(connectModulePath)]; | ||
| }); | ||
|
|
||
| it("marks Hermes connect sessions as light-mode when launched from light macOS Terminal.app (#6380)", async () => { | ||
| vi.stubEnv("TERM_PROGRAM", "Apple_Terminal"); | ||
| vi.stubEnv("COLORFGBG", "0;15"); | ||
| vi.stubEnv("HERMES_TUI_LIGHT", ""); | ||
| const harness = createConnectHarness({ | ||
| agentName: "hermes", | ||
| sessionAgent: { | ||
| name: "hermes", | ||
| runtime: { kind: "terminal", interactive_command: "hermes" }, | ||
| }, | ||
| }); | ||
|
|
||
| await expect(harness.connectSandbox("alpha")).rejects.toThrow("process.exit(0)"); | ||
|
|
||
| const connectCall = harness.spawnSyncSpy.mock.calls.find( | ||
| ([command, args]) => | ||
| command === "openshell" && | ||
| Array.isArray(args) && | ||
| args.join(" ") === "sandbox connect alpha", | ||
| ); | ||
| expect(connectCall?.[2]).toEqual( | ||
| expect.objectContaining({ | ||
| env: expect.objectContaining({ | ||
| COLORFGBG: "0;15", | ||
| HERMES_TUI_LIGHT: "1", | ||
| TERM_PROGRAM: "Apple_Terminal", | ||
| }), | ||
| }), | ||
| ); | ||
| expect(exitSpy).toHaveBeenCalledWith(0); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { buildSandboxConnectEnv } from "./connect-env"; | ||
|
|
||
| describe("sandbox connect environment helpers", () => { | ||
| it("marks Hermes connect sessions as light when COLORFGBG reports a light background (#6380)", () => { | ||
| expect( | ||
| buildSandboxConnectEnv( | ||
| { name: "hermes" }, | ||
| { COLORFGBG: "0;15", TERM_PROGRAM: "Apple_Terminal" }, | ||
| ), | ||
| ).toEqual( | ||
| expect.objectContaining({ | ||
| COLORFGBG: "0;15", | ||
| HERMES_TUI_LIGHT: "1", | ||
| TERM_PROGRAM: "Apple_Terminal", | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it("does not force Hermes light mode when COLORFGBG reports a dark background (#6380)", () => { | ||
| expect( | ||
| buildSandboxConnectEnv( | ||
| { name: "hermes" }, | ||
| { COLORFGBG: "0;0", TERM_PROGRAM: "Apple_Terminal" }, | ||
| ), | ||
| ).not.toHaveProperty("HERMES_TUI_LIGHT"); | ||
| }); | ||
|
|
||
| it("preserves explicit Hermes light-mode overrides (#6380)", () => { | ||
| for (const value of ["0", "false", "no", "off"]) { | ||
| expect( | ||
| buildSandboxConnectEnv({ name: "hermes" }, { COLORFGBG: "0;15", HERMES_TUI_LIGHT: value }) | ||
| .HERMES_TUI_LIGHT, | ||
| ).toBe(value); | ||
| } | ||
| }); | ||
|
|
||
| it("preserves explicit Hermes theme overrides (#6380)", () => { | ||
| expect( | ||
| buildSandboxConnectEnv({ name: "hermes" }, { COLORFGBG: "0;15", HERMES_TUI_THEME: "dark" }), | ||
| ).not.toHaveProperty("HERMES_TUI_LIGHT"); | ||
| }); | ||
|
|
||
| it("does not set Hermes light mode for non-Hermes agents (#6380)", () => { | ||
| expect(buildSandboxConnectEnv({ name: "openclaw" }, { COLORFGBG: "0;15" })).not.toHaveProperty( | ||
| "HERMES_TUI_LIGHT", | ||
| ); | ||
| }); | ||
|
|
||
| it("does not infer light mode from Apple Terminal without usable COLORFGBG (#6380)", () => { | ||
| expect( | ||
| buildSandboxConnectEnv({ name: "hermes" }, { TERM_PROGRAM: "Apple_Terminal" }), | ||
| ).not.toHaveProperty("HERMES_TUI_LIGHT"); | ||
| expect( | ||
| buildSandboxConnectEnv( | ||
| { name: "hermes" }, | ||
| { COLORFGBG: "not-a-color", TERM_PROGRAM: "Apple_Terminal" }, | ||
| ), | ||
| ).not.toHaveProperty("HERMES_TUI_LIGHT"); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,38 @@ | ||||||||||||||||||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||||||||||||||||||
| // SPDX-License-Identifier: Apache-2.0 | ||||||||||||||||||
|
|
||||||||||||||||||
| const TRUE_VALUES = new Set(["1", "true", "yes", "on"]); | ||||||||||||||||||
| const FALSE_VALUES = new Set(["0", "false", "no", "off"]); | ||||||||||||||||||
|
|
||||||||||||||||||
| function hasExplicitBoolean(value: string | undefined): boolean { | ||||||||||||||||||
| const normalized = String(value ?? "") | ||||||||||||||||||
| .trim() | ||||||||||||||||||
| .toLowerCase(); | ||||||||||||||||||
| return TRUE_VALUES.has(normalized) || FALSE_VALUES.has(normalized); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| function hostTerminalLooksLight(env: NodeJS.ProcessEnv): boolean { | ||||||||||||||||||
| const colorfgbg = String(env.COLORFGBG ?? "").trim(); | ||||||||||||||||||
| if (!colorfgbg) return false; | ||||||||||||||||||
|
|
||||||||||||||||||
| const lastField = colorfgbg.split(";").at(-1) ?? ""; | ||||||||||||||||||
| const bg = Number(lastField); | ||||||||||||||||||
| if (!Number.isInteger(bg) || bg < 0 || bg > 15) return false; | ||||||||||||||||||
| return bg === 7 || bg === 15; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| export function buildSandboxConnectEnv( | ||||||||||||||||||
| agent: { name?: string } | null | undefined, | ||||||||||||||||||
| env: NodeJS.ProcessEnv = process.env, | ||||||||||||||||||
| ): NodeJS.ProcessEnv { | ||||||||||||||||||
|
Comment on lines
+24
to
+27
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win Domain helper directly references
Make ♻️ Proposed fix export function buildSandboxConnectEnv(
agent: { name?: string } | null | undefined,
- env: NodeJS.ProcessEnv = process.env,
+ env: NodeJS.ProcessEnv,
): NodeJS.ProcessEnv {And update the call site in - env: buildSandboxConnectEnv(agent),
+ env: buildSandboxConnectEnv(agent, process.env),📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsSource: Path instructions |
||||||||||||||||||
| const nextEnv = { ...env }; | ||||||||||||||||||
| if ( | ||||||||||||||||||
| agent?.name === "hermes" && | ||||||||||||||||||
| !hasExplicitBoolean(nextEnv.HERMES_TUI_LIGHT) && | ||||||||||||||||||
| !String(nextEnv.HERMES_TUI_THEME ?? "").trim() && | ||||||||||||||||||
| hostTerminalLooksLight(nextEnv) | ||||||||||||||||||
| ) { | ||||||||||||||||||
| nextEnv.HERMES_TUI_LIGHT = "1"; | ||||||||||||||||||
| } | ||||||||||||||||||
| return nextEnv; | ||||||||||||||||||
| } | ||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.