Skip to content
Open
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
16 changes: 15 additions & 1 deletion server/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,22 @@ describe("configuration boundaries", () => {
});

describe("default fleet", () => {
it("ships Qwen and Hermes as custom-only engines", () => {
it("ships Qwen, Hermes, and direct Mac/Windows models as custom-only engines", () => {
const map = instanceConfigs({});
expect(map.qwen).toEqual({ driver: "qwenAgent", environment: {} });
expect(map.hermes).toEqual({ driver: "hermesAgent", environment: {} });
expect(map.localMac).toEqual({
driver: "local",
displayName: "Mac M5 models",
config: { host: "ollama", fleetHost: "mac" },
environment: {},
});
expect(map.localWindows).toEqual({
driver: "local",
displayName: "Windows models",
config: { host: "custom", url: "http://127.0.0.1:18134/v1", fleetHost: "windows" },
environment: {},
});
});

it("ships Cursor as a default-fleet subscription engine", () => {
Expand All @@ -105,6 +117,8 @@ describe("default fleet", () => {
expect(map.claude.driver).toBe("claudeAgent");
expect(map.qwen?.driver).toBe("qwenAgent");
expect(map.hermes?.driver).toBe("hermesAgent");
expect(map.localMac?.driver).toBe("local");
expect(map.localWindows?.driver).toBe("local");
expect(map.cursor?.driver).toBe("cursorAgent");
});

Expand Down
12 changes: 12 additions & 0 deletions server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,23 @@ export function instanceConfigs(cfg: AppConfig): InstanceConfigMap {
qwen: { driver: "qwenAgent" },
hermes: { driver: "hermesAgent" },
pi: { driver: "piAgent" },
localMac: { driver: "local", displayName: "Mac M5 models", config: { host: "ollama", fleetHost: "mac" } },
localWindows: {
driver: "local",
displayName: "Windows models",
config: { host: "custom", url: "http://127.0.0.1:18134/v1", fleetHost: "windows" },
},
};
const CUSTOM_ONLY = {
qwen: { driver: "qwenAgent" },
hermes: { driver: "hermesAgent" },
pi: { driver: "piAgent" },
localMac: { driver: "local", displayName: "Mac M5 models", config: { host: "ollama", fleetHost: "mac" } },
localWindows: {
driver: "local",
displayName: "Windows models",
config: { host: "custom", url: "http://127.0.0.1:18134/v1", fleetHost: "windows" },
},
Comment thread
coderabbitai[bot] marked this conversation as resolved.
} as const;
// New default-fleet engines that existing product configs would otherwise
// never see. Custom-only engines stay in CUSTOM_ONLY so a one-off test map
Expand Down
49 changes: 39 additions & 10 deletions server/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,18 +290,47 @@ export interface EngineInstall {
// `create` owns ALL per-instance state; two create calls share nothing.
// Failures must reject, never throw synchronously — the registry downgrades
// a rejection to an unavailable shadow snapshot.
export type ModelCostClass = "free" | "paid" | "paid_subscription" | "paid_metered" | "local" | "unknown";

export interface ModelRuntimeStatus {
configured: boolean;
reachable: boolean;
verified: boolean;
admitted: boolean;
busy: boolean;
}

export interface ModelOption {
/** The model id understood by this concrete OpenMausBot driver. */
id: string;
label: string;
custom?: boolean;
loaded?: boolean;
/** Fleet-wide stable id. Present only for rows projected by the guarded
* secret-free AOS model catalog. */
canonicalId?: string;
provider?: string;
host?: string;
costClass?: ModelCostClass;
manualOnly?: boolean;
isDefault?: boolean;
capabilities?: string[];
status?: ModelRuntimeStatus;
/** False means the row stays visible for inventory/truth, but cannot be
* selected until a fresh catalog refresh marks it admitted and idle. */
selectable?: boolean;
reason?: string;
lastVerified?: string;
verificationReceipt?: string;
/** total context window in tokens, when the driver knows it — sizes
* the model-facing rebuild (server/context-rebuild.ts). Unknown falls
* back to a pattern table over the model id, then a conservative default. */
contextWindow?: number;
}

export interface ModelCatalog {
default: string;
options: Array<{
id: string;
label: string;
custom?: boolean;
loaded?: boolean;
/** total context window in tokens, when the driver knows it — sizes
* the model-facing rebuild (server/context-rebuild.ts). Unknown falls
* back to a pattern table over the model id, then a conservative default. */
contextWindow?: number;
}>;
options: ModelOption[];
}

export interface DriverCreateInput<Config> {
Expand Down
17 changes: 17 additions & 0 deletions server/drivers/acp/hermes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, expect, it } from "vitest";

import { hermesAcpModelId } from "./hermes.ts";

describe("hermes fleet model translation", () => {
it("passes a guarded Hermes route alias to session/set_model", () => {
expect(hermesAcpModelId("litellm-local:minimax-m3-light")).toBe("litellm-local:minimax-m3-light");
expect(hermesAcpModelId("litellm-local:MiniMax-M3")).toBe("litellm-local:MiniMax-M3");
expect(hermesAcpModelId("minimax-m3-light")).toBeNull();
});

it("keeps local host injection syntax and rejects malformed ids", () => {
expect(hermesAcpModelId("ollama::qwen3:14b")).toBe("custom:ollama:qwen3:14b");
expect(hermesAcpModelId("bad model\nnext")).toBeNull();
expect(hermesAcpModelId("litellm-local:qwen\n")).toBeNull();
});
});
11 changes: 8 additions & 3 deletions server/drivers/acp/hermes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import { decodeInjectId, hostApiKey, localHost, mergeLocalInject } from "../loca
import { createAcpDriver, type AcpSupport } from "./core.ts";

const EMPTY: ModelCatalog = { default: "", options: [] };
// Canonical fleet routes use Hermes' provider:model dialect. Keep ordinary
// provider slugs on the existing ACP default path; only a producer-owned
// route alias (or a guarded local inject id below) is sent to set_model.
const HERMES_FLEET_MODEL_ID = /^(?![\s\S]*[\r\n])[\w][\w./+-]*:[\w][\w./:+-]*$/;

function hermesHome(env: Record<string, string | undefined>): string {
return env.HERMES_HOME || join(env.HOME || env.USERPROFILE || homedir(), ".hermes");
Expand Down Expand Up @@ -75,11 +79,12 @@ export function ensureHermesInjectProvider(
return hermesAcpModelId(modelId) ?? modelId;
}

/** ACP session/set_model id. Hermes parse_model_input treats `custom:name:model`. */
/** ACP session/set_model id. Local inject rows become `custom:name:model`;
* fleet-catalog rows are already Hermes-native aliases and pass through. */
export function hermesAcpModelId(modelId: string | null | undefined): string | null {
const inject = decodeInjectId(modelId);
if (!inject) return null;
return `custom:${inject.host}:${inject.model}`;
if (inject) return `custom:${inject.host}:${inject.model}`;
return modelId && HERMES_FLEET_MODEL_ID.test(modelId) ? modelId : null;
}

async function resolveModels(env: Record<string, string | undefined>): Promise<ModelCatalog> {
Expand Down
2 changes: 2 additions & 0 deletions server/drivers/builtIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BoxAgentDriver } from "./boxagent.ts";
import { ClaudeDriver } from "./claude.ts";
import { CodexDriver } from "./codex.ts";
import { GrokDriver } from "./grok.ts";
import { LocalDriver } from "./local.ts";
import { GrokAgentDriver } from "./acp/grok.ts";
import { GeminiAgentDriver } from "./acp/gemini.ts";
import { KimiAgentDriver } from "./acp/kimi.ts";
Expand All @@ -31,4 +32,5 @@ export const BUILT_IN_DRIVERS: readonly AnyProviderDriver[] = [
CodexDriver,
AntigravityDriver,
BoxAgentDriver,
LocalDriver,
];
115 changes: 115 additions & 0 deletions server/drivers/local.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { createServer, type Server } from "node:http";
import { afterEach, describe, expect, it } from "vitest";
import { z } from "zod";

import type { ProviderInstance } from "../contracts.ts";
import { parseJson, type JsonValue } from "../schema.ts";
import { recordEvents, type EventRecorder } from "../testing/events.ts";
import { decodeFleetLocalSelector, LocalDriver } from "./local.ts";

let server: Server | null = null;
let instance: ProviderInstance | null = null;
let recorder: EventRecorder | null = null;
const requests: Array<{ url: string; body: JsonValue | null }> = [];
const chatRequestSchema = z.object({ model: z.string() }).passthrough();

async function fakeHost(finalFrameWithoutNewline = false): Promise<string> {
server = createServer((request, response) => {
let raw = "";
request.on("data", (chunk) => raw += chunk);
request.on("end", () => {
const body = raw ? parseJson(raw) : null;
requests.push({ url: request.url ?? "", body });
const json = (payload: JsonValue) => {
response.writeHead(200, { "content-type": "application/json" });
response.end(JSON.stringify(payload));
};
if (request.url === "/v1/models") return json({ data: [{ id: "qwen3.8:27b-mlx" }] });
if (request.url === "/api/ps") return json({
models: [{ name: "qwen3.8:27b-mlx", context_length: 65_536 }],
});
if (request.url === "/v1/chat/completions") {
response.writeHead(200, { "content-type": "text/event-stream" });
if (finalFrameWithoutNewline) {
response.end(`data: ${JSON.stringify({ choices: [{ delta: { content: "tail" } }] })}`);
return;
}
response.write(`data: ${JSON.stringify({ choices: [{ delta: { content: "hello" } }] })}\n\n`);
response.end("data: [DONE]\n\n");
return;
}
response.writeHead(404).end();
});
});
const running = server;
return new Promise((resolve) => running.listen(0, "127.0.0.1", () => {
// SAFETY: a TCP server listening on an ephemeral IPv4 port returns an AddressInfo object.
const address = running.address() as { port: number };
resolve(`http://127.0.0.1:${address.port}/v1`);
}));
}

afterEach(async () => {
recorder?.stop();
recorder = null;
await instance?.dispose();
instance = null;
const running = server;
await new Promise<void>((resolve) => {
if (!running) return resolve();
running.closeIdleConnections();
running.close(() => resolve());
});
server = null;
requests.length = 0;
});

describe("fleet local selectors", () => {
it("keeps Mac and Windows namespaces disjoint", () => {
expect(decodeFleetLocalSelector("ollama-mac/qwen3.8:27b-mlx", "mac")).toBe("qwen3.8:27b-mlx");
expect(decodeFleetLocalSelector("ollama-windows/qwen3.8:27b-mlx", "mac")).toBeNull();
expect(decodeFleetLocalSelector("bad model", "mac")).toBeNull();
});

it("runs the canonical Mac selector as the host-native model", async () => {
instance = await LocalDriver.create({
instanceId: "localMac",
displayName: "Mac M5 models",
environment: {},
enabled: true,
config: { host: "custom", url: await fakeHost(), fleetHost: "mac" },
});
recorder = recordEvents(instance.adapter);
// The transport checks only readiness; the guarded fleet projection owns
// every picker row and its chat/non-chat classification.
expect(instance.models.options).toEqual([]);
expect(await instance.snapshot()).toMatchObject({ state: "available" });
await instance.adapter.sendTurn({
threadId: "local-turn",
text: "hi",
model: "ollama-mac/qwen3.8:27b-mlx",
});
await recorder.until((event) => event.type === "turn.completed");
const chatRequest = requests.find((request) => request.url === "/v1/chat/completions");
expect(chatRequestSchema.parse(chatRequest?.body).model).toBe("qwen3.8:27b-mlx");
expect(recorder.events).toContainEqual(expect.objectContaining({ type: "item.completed", text: "hello" }));
});

it("processes a final SSE frame without a trailing newline", async () => {
instance = await LocalDriver.create({
instanceId: "localMac",
displayName: "Mac M5 models",
environment: {},
enabled: true,
config: { host: "custom", url: await fakeHost(true), fleetHost: "mac" },
});
recorder = recordEvents(instance.adapter);
await instance.adapter.sendTurn({
threadId: "local-tail-turn",
text: "hi",
model: "ollama-mac/qwen3.8:27b-mlx",
});
await recorder.until((event) => event.type === "turn.completed");
expect(recorder.events).toContainEqual(expect.objectContaining({ type: "item.completed", text: "tail" }));
});
});
Loading
Loading