Skip to content

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

fix(hermes): offer the default only for a runnable Hermes, and keep Ollama/LM Studio lists when their server is down

AdityaUmaled377390950f5
diff --git a/server/drivers/acp/hermes.test.ts b/server/drivers/acp/hermes.test.ts
index 6407319d0a..883897be6b 100644
--- a/server/drivers/acp/hermes.test.ts
+++ b/server/drivers/acp/hermes.test.ts
@@ -373,6 +373,22 @@ describe("resolveHermesModels when Hermes has no model to list", () => {
await expect(resolveHermesModels(env, { cli: missing })).resolves.toEqual({ default: "", options: [] });
});
+ it("offers nothing when the Hermes path is a directory or can't run", async () => {
+ const { cli, env } = setup("");
+ await expect(resolveHermesModels(env, { cli: dirname(cli) })).resolves.toEqual({ default: "", options: [] });
+ if (process.platform === "win32") return;
+ const plain = join(dirname(cli), "plain-hermes");
+ writeFileSync(plain, "", { mode: 0o644 });
+ await expect(resolveHermesModels(env, { cli: plain })).resolves.toEqual({ default: "", options: [] });
+ });
+
+ it("answers empty for an Ollama or LM Studio setup whose server is down, so earlier models stay", async () => {
+ for (const provider of ["ollama", "lmstudio"]) {
+ const { cli, env } = setup("", `model:\n provider: ${provider}\n default: llama3\n`);
+ await expect(resolveHermesModels(env, { cli })).resolves.toEqual({ default: "", options: [] });
+ }
+ });
+
it("keeps today's list when a hosted provider is configured", async () => {
const { cli, env } = setup("OPENROUTER_API_KEY=sk-or-v1-test\n", "model:\n default: anthropic/claude-opus-4.6\n");
await expect(resolveHermesModels(env, { cli })).resolves.toEqual({
diff --git a/server/drivers/acp/hermes.ts b/server/drivers/acp/hermes.ts
index 706712ac91..83e45154e7 100644
--- a/server/drivers/acp/hermes.ts
+++ b/server/drivers/acp/hermes.ts
@@ -2,7 +2,7 @@
// forward it), and OPENAI_API_KEY makes provider:auto resolve to OpenRouter without its key ("HTTP 401:
// Missing Authentication header"), so injects write providers.<host> and set_model `custom:<host>:<model>`.
import { spawn } from "node:child_process";
-import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
+import { accessSync, constants, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
import { homedir } from "node:os";
import { join } from "node:path";
import { parse as parseYaml } from "yaml";
@@ -203,9 +203,31 @@ export function hermesConfiguredModel(
return hermesConfigOption(configuredDefault?.model ?? "");
}
+/** A runnable file, so the default entry never points at a directory or a file that can't start. */
function hermesInstalled(cli: string): boolean {
const found = findCliCandidates(cli)[0];
- return Boolean(found && existsSync(found));
+ if (!found) return false;
+ try {
+ if (!statSync(found).isFile()) return false;
+ if (process.platform !== "win32") accessSync(found, constants.X_OK);
+ return true;
+ } catch {
+ return false;
+ }
+}
+
+// The local probes list Ollama's and LM Studio's models: with none listed that server is down, and an empty
+// answer keeps the catalog's earlier models instead of replacing them with the default.
+const HERMES_PROBED_PROVIDERS = new Set(["ollama", "lmstudio"]);
+
+function hermesUsesProbedProvider(env: Record<string, string | undefined>): boolean {
+ const dir = env.HERMES_HOME || harnessHome("hermes", env);
+ try {
+ const provider = hermesConfigDefault(readFileSync(join(dir, "config.yaml"), "utf8"))?.provider.toLowerCase() ?? "";
+ return HERMES_PROBED_PROVIDERS.has(provider);
+ } catch {
+ return false;
+ }
}
export const HERMES_ACP_MODELS_TIMEOUT_ENV = "HERMES_ACP_MODELS_TIMEOUT_MS";
@@ -337,7 +359,7 @@ export async function resolveHermesModels(
});
// A custom endpoint or a config we can't read (another HERMES_HOME, WSL) would leave no choice and no way to
// create a Hermes bot: offer Hermes' own config.yaml model, which starts `hermes acp` without picking one.
- if (!options.length && hermesInstalled(cli)) {
+ if (!options.length && !hermesUsesProbedProvider(env) && hermesInstalled(cli)) {
options.push(hermesConfigOption(""));
}
return { default: options[0]?.id ?? "", options };