Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions src/lib/actions/sandbox/connect-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type ConnectHarnessOptions = {
spawnSignal?: NodeJS.Signals | null;
spawnStatus?: number | null;
sttyThrows?: boolean;
versionCheck?: unknown;
versionWarningLines?: string[];
};

function throwSttyFailure(): never {
Expand Down Expand Up @@ -108,8 +110,12 @@ function createConnectHarness(options: ConnectHarnessOptions = {}): ConnectHarne
detected: true,
sessions: [{ pid: 1 }, { pid: 2 }],
});
vi.spyOn(sandboxVersion, "checkAgentVersion").mockReturnValue({ isStale: false });
vi.spyOn(sandboxVersion, "formatStalenessWarning").mockReturnValue([]);
vi.spyOn(sandboxVersion, "checkAgentVersion").mockReturnValue(
(options.versionCheck ?? { isStale: false }) as never,
);
vi.spyOn(sandboxVersion, "formatStalenessWarning").mockReturnValue(
options.versionWarningLines ?? [],
);
const checkAndRecoverSpy = vi
.spyOn(processRecovery, "checkAndRecoverSandboxProcesses")
.mockReturnValue(options.processCheck ?? { checked: true, wasRunning: true, recovered: false });
Expand Down Expand Up @@ -373,6 +379,30 @@ describe("connectSandbox flow", () => {
expect(exitSpy).toHaveBeenCalledWith(0);
});

it("prints stale Hermes Desktop compatibility guidance before connecting", async () => {
const harness = createConnectHarness({
agentName: "hermes",
versionCheck: {
sandboxVersion: "2026.5.16",
expectedVersion: "2026.6.19",
isStale: true,
detectionMethod: "registry",
},
versionWarningLines: [
"",
" Hermes Desktop requires Hermes Agent v2026.6.5+ (2026.5.16 lacks /api/profiles/sessions).",
" Rebuild this sandbox before connecting it from Hermes Desktop.",
],
});

await expect(harness.connectSandbox("alpha")).rejects.toThrow("process.exit(0)");

const errorOutput = harness.errorSpy.mock.calls.map((call) => String(call[0] ?? "")).join("\n");
expect(errorOutput).toContain("Hermes Desktop requires Hermes Agent v2026.6.5+");
expect(errorOutput).toContain("/api/profiles/sessions");
expect(errorOutput).toContain("Rebuild this sandbox");
});

it("stops before opening SSH when the sandbox list reports a terminal failure phase", async () => {
const harness = createConnectHarness({ listOutput: "alpha Error" });

Expand Down
22 changes: 22 additions & 0 deletions src/lib/actions/sandbox/status-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,28 @@ describe("showSandboxStatus flow", () => {
});
});

it("prints Hermes Desktop compatibility guidance for stale Hermes backends", async () => {
const harness = createStatusFlowHarness({
sandboxEntry: {
agent: "hermes",
agentVersion: "2026.5.16",
},
});
harness.checkAgentVersionSpy.mockReturnValue({
sandboxVersion: "2026.5.16",
expectedVersion: "2026.6.19",
isStale: true,
detectionMethod: "registry",
});

await expect(harness.showSandboxStatus("alpha")).resolves.toBeUndefined();

const output = harness.logSpy.mock.calls.map((call) => String(call[0])).join("\n");
expect(output).toContain("Hermes Desktop requires Hermes Agent v2026.6.5+");
expect(output).toContain("/api/profiles/sessions");
expect(output).toContain("Rebuild this sandbox");
});

it("preserves the registry entry and exits when the live gateway is missing the sandbox", async () => {
const harness = createStatusFlowHarness({ lookupState: "missing" });

Expand Down
6 changes: 6 additions & 0 deletions src/lib/actions/sandbox/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ export async function showSandboxStatus(sandboxName: string): Promise<void> {
if (versionCheck.isStale) {
console.log(` ${YW}Update: v${versionCheck.expectedVersion} available${R}`);
console.log(` Run \`${CLI_NAME} ${sandboxName} rebuild\` to upgrade`);
for (const line of sandboxVersion.formatHermesDesktopCompatibilityWarning(
sandboxName,
versionCheck,
)) {
console.log(line);
}
} else if (
shouldProbeRuntimeVersion &&
versionCheck.detectionMethod === "unavailable" &&
Expand Down
44 changes: 43 additions & 1 deletion src/lib/sandbox/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ import { spawnSync } from "child_process";
import { captureSandboxSshConfigCommand } from "../adapters/openshell/client.js";
import { OPENSHELL_PROBE_TIMEOUT_MS } from "../adapters/openshell/timeouts.js";
import * as registry from "../state/registry.js";
import { checkAgentVersion, formatStalenessWarning } from "./version.js";
import {
checkAgentVersion,
formatHermesDesktopCompatibilityWarning,
formatStalenessWarning,
} from "./version.js";

describe("checkAgentVersion", () => {
let tmpDir: string;
Expand Down Expand Up @@ -261,4 +265,42 @@ describe("formatStalenessWarning", () => {
expect(joined).toContain("2026.5.27");
expect(joined).toContain("rebuild");
});

it("explains the Hermes Desktop API mismatch for old Hermes sandboxes", () => {
registry.registerSandbox({ name: "my-hermes", agent: "hermes" });

const lines = formatHermesDesktopCompatibilityWarning("my-hermes", {
sandboxVersion: "2026.5.16",
expectedVersion: "2026.6.19",
isStale: true,
detectionMethod: "registry",
});
const joined = lines.join("\n");

expect(joined).toContain("Hermes Desktop requires Hermes Agent v2026.6.5+");
expect(joined).toContain("/api/profiles/sessions");
expect(joined).toContain("Rebuild this sandbox");
});

it("does not show the Hermes Desktop warning for current Hermes or other agents", () => {
registry.registerSandbox({ name: "my-hermes", agent: "hermes" });

expect(
formatHermesDesktopCompatibilityWarning("my-hermes", {
sandboxVersion: "2026.6.19",
expectedVersion: "2026.6.19",
isStale: false,
detectionMethod: "registry",
}),
).toEqual([]);

expect(
formatHermesDesktopCompatibilityWarning("my-sb", {
sandboxVersion: "2026.5.16",
expectedVersion: "2026.6.19",
isStale: true,
detectionMethod: "registry",
}),
).toEqual([]);
});
});
21 changes: 21 additions & 0 deletions src/lib/sandbox/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ import {
import { resolveOpenshell } from "../adapters/openshell/resolve.js";
import { OPENSHELL_PROBE_TIMEOUT_MS } from "../adapters/openshell/timeouts.js";
import { loadAgent } from "../agent/defs.js";
import { D, R } from "../cli/terminal-style.js";
import * as registry from "../state/registry.js";
import { createTempSshConfig } from "./temp-ssh-config.js";

const HERMES_DESKTOP_MIN_VERSION = "2026.6.5";

export interface VersionCheckResult {
sandboxVersion: string | null;
expectedVersion: string | null;
Expand Down Expand Up @@ -170,6 +173,24 @@ export function formatStalenessWarning(sandboxName: string, result: VersionCheck
"",
` \u26a0 Sandbox '${sandboxName}' is running ${agentName} ${result.sandboxVersion} (current: ${result.expectedVersion})`,
` Run: nemoclaw ${sandboxName} rebuild`,
...formatHermesDesktopCompatibilityWarning(sandboxName, result),
"",
];
}

/**
* Explain the Hermes Desktop/backend API mismatch for old Hermes sandboxes.
*/
export function formatHermesDesktopCompatibilityWarning(
sandboxName: string,
result: VersionCheckResult,
): string[] {
const agent = resolveAgentForSandbox(sandboxName);
if (agent.name !== "hermes") return [];
if (!result.sandboxVersion) return [];
if (versionGte(result.sandboxVersion, HERMES_DESKTOP_MIN_VERSION)) return [];
return [
` ${D}Hermes Desktop requires Hermes Agent v${HERMES_DESKTOP_MIN_VERSION}+ (${result.sandboxVersion} lacks /api/profiles/sessions).${R}`,
" Rebuild this sandbox before connecting it from Hermes Desktop.",
];
}