Skip to content

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

fix(hermes): resolve an extensionless Windows path like launch does, and match the probe's protocol

AdityaUmalee790470b15f2
diff --git a/server/drivers/acp/hermes.test.ts b/server/drivers/acp/hermes.test.ts
index 028f12d70a..1d22025185 100644
--- a/server/drivers/acp/hermes.test.ts
+++ b/server/drivers/acp/hermes.test.ts
@@ -405,6 +405,26 @@ describe("resolveHermesModels when Hermes has no model to list", () => {
await expect(resolveHermesModels(env, { cli: `${cli} hermes` })).resolves.toEqual({ default: HERMES_CONFIG_MODEL_ID, options: [DEFAULT] });
});
+ it("finds a Windows Hermes path given without its .exe, as it is launched", async () => {
+ const { cli, env } = setup("");
+ const bare = join(dirname(cli), "hermes");
+ writeFileSync(`${bare}.EXE`, "#!/usr/bin/env node\nprocess.stdin.resume();\n", { mode: 0o755 });
+ const platform = process.platform;
+ Object.defineProperty(process, "platform", { value: "win32" });
+ vi.stubEnv("PATHEXT", ".EXE");
+ try {
+ await expect(resolveHermesModels(env, { cli: bare })).resolves.toEqual({ default: HERMES_CONFIG_MODEL_ID, options: [DEFAULT] });
+ } finally {
+ Object.defineProperty(process, "platform", { value: platform });
+ vi.unstubAllEnvs();
+ }
+ });
+
+ it("offers the default for an https endpoint on the probe's port, which the http probe can't list", async () => {
+ const { cli, env } = setup("", "model:\n provider: ollama\n default: llama3\n base_url: https://localhost:11434/v1\n");
+ await expect(resolveHermesModels(env, { cli })).resolves.toEqual({ default: HERMES_CONFIG_MODEL_ID, options: [DEFAULT] });
+ });
+
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 de484d52f0..864dd34efd 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 } from "../../env-path.ts";
+import { findCliCandidates, harnessHome, 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,10 +208,11 @@ 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;
return findCliCandidates(head).some((found) => {
try {
if (!statSync(found).isFile()) return false;
- if (process.platform !== "win32") accessSync(found, constants.X_OK);
+ accessSync(found, constants.X_OK);
return true;
} catch {
return false;
@@ -219,9 +220,6 @@ function hermesInstalled(cli: string): boolean {
});
}
-// The local probes list Ollama's and LM Studio's models on their usual local port: with none listed that server is
-// down, and an empty answer keeps the catalog's earlier models instead of replacing them with the default. A
-// base_url elsewhere (another host or port) is never probed, so it gets the default like a custom endpoint.
const HERMES_PROBED_PROVIDERS = new Set(["ollama", "lmstudio"]);
const LOOPBACK_HOSTS = new Set(["127.0.0.1", "localhost", "[::1]"]);
@@ -243,7 +241,12 @@ function hermesUsesProbedProvider(env: Record<string, string | undefined>): bool
yamlString(config.base_url);
if (!baseUrl) return true;
const configured = new URL(baseUrl);
- return LOOPBACK_HOSTS.has(configured.hostname) && configured.port === new URL(probe.baseUrl).port;
+ const probed = new URL(probe.baseUrl);
+ return (
+ LOOPBACK_HOSTS.has(configured.hostname) &&
+ configured.protocol === probed.protocol &&
+ configured.port === probed.port
+ );
} catch {
return false;
}
diff --git a/server/env-path.ts b/server/env-path.ts
index c89d980354..bb4475988e 100644
--- a/server/env-path.ts
+++ b/server/env-path.ts
@@ -217,7 +217,7 @@ function isFile(p: string): boolean {
}
}
-function whichWin(cli: string, env?: NodeJS.ProcessEnv): string | null {
+export function whichWin(cli: string, env?: NodeJS.ProcessEnv): string | null {
const exts = ((env ?? process.env).PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean);
// npm installs both `claude` (a sh script) and `claude.cmd`; an extensionless name is not runnable on Windows.
const probe = (base: string) => {