Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(hermes): don't count IPv6 loopback as probed, and skip a Windows .cmd shim that can't launch

AdityaUmale77df052e039a
diff --git a/server/drivers/acp/hermes.test.ts b/server/drivers/acp/hermes.test.ts
index 1d22025185..d803e0d729 100644
--- a/server/drivers/acp/hermes.test.ts
+++ b/server/drivers/acp/hermes.test.ts
@@ -425,6 +425,26 @@ describe("resolveHermesModels when Hermes has no model to list", () => {
await expect(resolveHermesModels(env, { cli })).resolves.toEqual({ default: HERMES_CONFIG_MODEL_ID, options: [DEFAULT] });
});
+ it("offers the default for an Ollama on IPv6 loopback, which the 127.0.0.1 probe can't reach", async () => {
+ const { cli, env } = setup("", "model:\n provider: ollama\n default: llama3\n base_url: http://[::1]:11434/v1\n");
+ await expect(resolveHermesModels(env, { cli })).resolves.toEqual({ default: HERMES_CONFIG_MODEL_ID, options: [DEFAULT] });
+ });
+
+ it("does not offer the default for a Windows .cmd shim that can't launch without a shell", async () => {
+ const { cli, env } = setup("");
+ const bare = join(dirname(cli), "hermes");
+ writeFileSync(`${bare}.CMD`, "@echo off\r\nsomething-unknown %*\r\n");
+ const platform = process.platform;
+ Object.defineProperty(process, "platform", { value: "win32" });
+ vi.stubEnv("PATHEXT", ".CMD");
+ try {
+ await expect(resolveHermesModels(env, { cli: bare })).resolves.toEqual({ default: "", options: [] });
+ } finally {
+ Object.defineProperty(process, "platform", { value: platform });
+ vi.unstubAllEnvs();
+ }
+ });
+
it.skipIf(process.platform === "win32")("looks past a PATH entry that can't run to a later runnable hermes", async () => {
const { cli, env } = setup("");
const blocked = join(dirname(cli), "blocked");
diff --git a/server/drivers/acp/hermes.ts b/server/drivers/acp/hermes.ts
index 864dd34efd..47ad0484f2 100644
--- a/server/drivers/acp/hermes.ts
+++ b/server/drivers/acp/hermes.ts
@@ -8,7 +8,7 @@ import { join } from "node:path";
import { parse as parseYaml } from "yaml";
import type { ModelCatalog } from "../../contracts.ts";
-import { findCliCandidates, harnessHome, splitCliString, whichWin } from "../../env-path.ts";
+import { findCliCandidates, harnessHome, resolveCliSpawn, splitCliString, whichWin } from "../../env-path.ts";
import { resolveCli } from "../../procs.ts";
import { decodeInjectId, hostApiKey, INJECT_SEP, localHost, mergeLocalInject } from "../local-inject.ts";
import { createAcpDriver, type AcpSupport } from "./core.ts";
@@ -208,7 +208,10 @@ export function hermesConfiguredModel(
function hermesInstalled(cli: string): boolean {
const trimmed = cli.trim();
const head = trimmed.includes(" ") && existsSync(trimmed) ? trimmed : (splitCliString(trimmed)[0] ?? "");
- if (process.platform === "win32") return whichWin(head) !== null;
+ // An unrecognized .cmd/.bat shim stays a shim after resolution, and Node can't spawn it without a shell.
+ if (process.platform === "win32") {
+ return whichWin(head) !== null && !/\.(cmd|bat)$/i.test(resolveCliSpawn(trimmed, []).command);
+ }
return findCliCandidates(head).some((found) => {
try {
if (!statSync(found).isFile()) return false;
@@ -221,7 +224,8 @@ function hermesInstalled(cli: string): boolean {
}
const HERMES_PROBED_PROVIDERS = new Set(["ollama", "lmstudio"]);
-const LOOPBACK_HOSTS = new Set(["127.0.0.1", "localhost", "[::1]"]);
+/** Hosts the IPv4 probe reaches; IPv6 loopback ([::1]) is not one of them. */
+const PROBED_LOOPBACK_HOSTS = new Set(["127.0.0.1", "localhost"]);
function yamlMap(value: unknown): Record<string, unknown> {
return value && typeof value === "object" && !Array.isArray(value) ? (value as Record<string, unknown>) : {};
@@ -243,7 +247,7 @@ function hermesUsesProbedProvider(env: Record<string, string | undefined>): bool
const configured = new URL(baseUrl);
const probed = new URL(probe.baseUrl);
return (
- LOOPBACK_HOSTS.has(configured.hostname) &&
+ PROBED_LOOPBACK_HOSTS.has(configured.hostname) &&
configured.protocol === probed.protocol &&
configured.port === probed.port
);