Skip to content

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

fix(hermes): offer Hermes' own default model when nothing else is listed

AdityaUmaled98b12cde17c
diff --git a/server/drivers/acp/hermes.test.ts b/server/drivers/acp/hermes.test.ts
index 2ae67601a5..6407319d0a 100644
--- a/server/drivers/acp/hermes.test.ts
+++ b/server/drivers/acp/hermes.test.ts
@@ -14,6 +14,7 @@ import {
fetchHermesAcpModels,
hermesAcpModelId,
hermesConfiguredModel,
+ resolveHermesModels,
} from "./hermes.ts";
describe("Hermes OpenMaus screenshot compatibility binding", () => {
@@ -328,3 +329,59 @@ process.stdin.on("data", (chunk) => {
await new Promise((resolve) => setTimeout(resolve, 200));
});
});
+
+describe("resolveHermesModels when Hermes has no model to list", () => {
+ const dirs: string[] = [];
+ afterEach(async () => {
+ for (const d of dirs.splice(0)) await removeTempDir(d);
+ });
+
+ const DEFAULT = { id: HERMES_CONFIG_MODEL_ID, label: "Hermes default (config)", custom: true };
+
+ // A Hermes home plus a stand-in `hermes` that never answers, so a catalog probe ends at its deadline.
+ function setup(dotenv: string, configYaml?: string): { cli: string; missing: string; env: Record<string, string> } {
+ const root = mkdtempSync(join(tmpdir(), "omb-hermes-models-"));
+ dirs.push(root);
+ const home = join(root, ".hermes");
+ mkdirSync(home, { recursive: true });
+ writeFileSync(join(home, ".env"), dotenv);
+ if (configYaml !== undefined) writeFileSync(join(home, "config.yaml"), configYaml);
+ const cli = join(root, "fake-hermes.ts");
+ writeFileSync(cli, "#!/usr/bin/env node\nprocess.stdin.resume();\n", { mode: 0o755 });
+ return {
+ cli,
+ missing: join(root, "not-installed", "hermes"),
+ env: {
+ PATH: process.env.PATH ?? "", ...(process.env.SystemRoot ? { SystemRoot: process.env.SystemRoot } : {}),
+ HOME: root, USERPROFILE: root, HERMES_HOME: home, [HERMES_ACP_MODELS_TIMEOUT_ENV]: "300",
+ },
+ };
+ }
+
+ it("offers Hermes' own default when config.yaml uses a custom endpoint and nothing local answers", async () => {
+ const { cli, env } = setup("", "model:\n provider: custom\n default: gpt-6.1-sol\n base_url: http://127.0.0.1:9/v1\n");
+ await expect(resolveHermesModels(env, { cli })).resolves.toEqual({ default: HERMES_CONFIG_MODEL_ID, options: [DEFAULT] });
+ });
+
+ it("offers Hermes' own default when there is no config.yaml and no key (Hermes set up elsewhere, e.g. WSL)", async () => {
+ const { cli, env } = setup("");
+ await expect(resolveHermesModels(env, { cli })).resolves.toEqual({ default: HERMES_CONFIG_MODEL_ID, options: [DEFAULT] });
+ });
+
+ it("offers nothing when Hermes is not installed", async () => {
+ const { missing, env } = setup("");
+ await expect(resolveHermesModels(env, { cli: missing })).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({
+ default: HERMES_CONFIG_MODEL_ID,
+ options: [{ id: HERMES_CONFIG_MODEL_ID, label: "anthropic/claude-opus-4.6 (Hermes config)", custom: true }],
+ });
+ });
+
+ it("starts Hermes without choosing a model for the default entry", () => {
+ expect(hermesAcpModelId(HERMES_CONFIG_MODEL_ID)).toBeNull();
+ });
+});
diff --git a/server/drivers/acp/hermes.ts b/server/drivers/acp/hermes.ts
index c6bc2aa3ff..706712ac91 100644
--- a/server/drivers/acp/hermes.ts
+++ b/server/drivers/acp/hermes.ts
@@ -2,13 +2,13 @@
// 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 { mkdirSync, readFileSync, writeFileSync } from "node:fs";
+import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { homedir } from "node:os";
import { join } from "node:path";
import { parse as parseYaml } from "yaml";
import type { ModelCatalog } from "../../contracts.ts";
-import { harnessHome } from "../../env-path.ts";
+import { findCliCandidates, harnessHome } 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";
@@ -99,6 +99,15 @@ export function hermesAcpModelId(modelId: string | null | undefined): string | n
/** Not an inject id: no session/set_model and no -m, so Hermes runs the model in its own config.yaml. */
export const HERMES_CONFIG_MODEL_ID = "hermes-default";
+// `custom: true` is load-bearing: a custom-only agent's picker pane lists only options carrying it.
+function hermesConfigOption(model: string) {
+ return {
+ id: HERMES_CONFIG_MODEL_ID,
+ label: model ? `${model} (Hermes config)` : "Hermes default (config)",
+ custom: true as const,
+ };
+}
+
function nonEmptyDotenvValue(text: string, name: string): string | null {
const match = new RegExp(`^[ \\t]*(?:export[ \\t]+)?${name}[ \\t]*=[ \\t]*([^\\r\\n]*)$`, "m").exec(text);
if (!match) return null;
@@ -191,13 +200,12 @@ export function hermesConfiguredModel(
const configIsHosted = configuredDefault !== null;
if (!hasHostedProviderKey && !configIsHosted) return null;
- const model = configuredDefault?.model ?? "";
- // `custom: true` is load-bearing: a custom-only agent's picker pane lists only options carrying it.
- return {
- id: HERMES_CONFIG_MODEL_ID,
- label: model ? `${model} (Hermes config)` : "Hermes default (config)",
- custom: true as const,
- };
+ return hermesConfigOption(configuredDefault?.model ?? "");
+}
+
+function hermesInstalled(cli: string): boolean {
+ const found = findCliCandidates(cli)[0];
+ return Boolean(found && existsSync(found));
}
export const HERMES_ACP_MODELS_TIMEOUT_ENV = "HERMES_ACP_MODELS_TIMEOUT_MS";
@@ -313,19 +321,25 @@ export async function fetchHermesAcpModels(
});
}
-async function resolveModels(
+export async function resolveHermesModels(
env: Record<string, string | undefined>,
config?: { cli?: string },
): Promise<ModelCatalog> {
+ const cli = config?.cli || "hermes";
const catalog = await mergeLocalInject(EMPTY, env);
const configured = hermesConfiguredModel(env);
- const remote = configured ? await fetchHermesAcpModels(config?.cli || "hermes", env) : [];
+ const remote = configured ? await fetchHermesAcpModels(cli, env) : [];
const seen = new Set<string>();
const options = [...(configured ? [configured] : []), ...remote, ...catalog.options].filter((o) => {
if (seen.has(o.id)) return false;
seen.add(o.id);
return true;
});
+ // 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)) {
+ options.push(hermesConfigOption(""));
+ }
return { default: options[0]?.id ?? "", options };
}
@@ -347,7 +361,7 @@ const support: AcpSupport = {
displayName: "Hermes",
access: "custom",
models: EMPTY,
- resolveModels: (env: Record<string, string | undefined>, config: any) => resolveModels(env, config),
+ resolveModels: (env: Record<string, string | undefined>, config: any) => resolveHermesModels(env, config),
resolveTurnModel: (model, env) => {
// Never inherit a broad or stale compatibility grant from the parent; bind one concrete model.
bindHermesScreenshotCompat(env, model);