A desktop coding agent with free access to frontier models.
TypeScript
fix: send the shown effort
ogsamrat84f725da098d
diff --git a/apps/app/src/app/constants.ts b/apps/app/src/app/constants.tsindex 5d2c9130..f8e3d8df 100644--- a/apps/app/src/app/constants.ts+++ b/apps/app/src/app/constants.ts@@ -56,6 +56,13 @@ export function isOmniRushModelID(modelID: string): boolean {*/export const OMNIRUSH_REASONING_EFFORTS = ["none", "minimal", "low", "medium", "high", "xhigh", "max"] as const;+/**+ * The effort an omnirush.ai model runs at when the chat picked none, where the+ * model offers it (the CLI's default). PARITY: apps/server/src/omnirush-model-catalog.ts+ * OMNIRUSH_DEFAULT_EFFORT, the engine's model-level default.+ */+export const OMNIRUSH_DEFAULT_REASONING_EFFORT = "xhigh";+export const SUGGESTED_PLUGINS: SuggestedPlugin[] = [];export type ExtensionKind = "mcp" | "plugin" | "skill" | "ui-control" | "extension";diff --git a/apps/app/src/app/lib/model-behavior.ts b/apps/app/src/app/lib/model-behavior.tsindex fba611f6..7f6c49fa 100644--- a/apps/app/src/app/lib/model-behavior.ts+++ b/apps/app/src/app/lib/model-behavior.ts@@ -1,6 +1,6 @@import type { ProviderListItem } from "../types";import type { ModelBehaviorOption } from "../types";-import { OMNIRUSH_REASONING_EFFORTS } from "../constants";+import { OMNIRUSH_DEFAULT_REASONING_EFFORT, OMNIRUSH_REASONING_EFFORTS } from "../constants";import { t } from "../../i18n";type ProviderModel = ProviderListItem["models"][string];@@ -71,7 +71,8 @@ const sortVariantKeys = (keys: string[]) =>return a.localeCompare(b);});-const getDefaultVariantKey = (keys: string[]) => {+const getDefaultVariantKey = (keys: string[], preferred: string | null = null) => {+ if (preferred && keys.includes(preferred)) return preferred;let selected: string | null = null;let selectedScore: number | null = null;@@ -248,8 +249,13 @@ export const getModelBehaviorSummary = () => {const options = getModelBehaviorOptions(providerID, model, providerName);const sanitized = sanitizeModelBehaviorValue(providerID, model, value, providerName);+ // omnirush.ai models default to the CLI's effort where they offer it, else+ // the level nearest medium: the same default the server gives the engine+ // (omnirush-model-catalog.ts omnirushDefaultEffort), so a chat that never+ // picked an effort shows the one it runs at.const selectedValue = sanitized ?? getDefaultVariantKey(options.flatMap((option) => option.value == null ? [] : [option.value]),+ isOmniRushProvider(providerID) ? OMNIRUSH_DEFAULT_REASONING_EFFORT : null,);const selected = options.find((option) => option.value === selectedValue) ?? options[0] ?? null;const title = getBehaviorTitle(providerID, model, getVariantKeys(model), providerName);@@ -282,3 +288,21 @@ export const getModelBehaviorSummary = (options,};};++/**+ * The effort a send carries: exactly the value the picker shows for this+ * model and stored choice (getModelBehaviorSummary), so the two cannot drift.+ * A stored choice the model does not offer, or none, resolves to the model's+ * default. Without the model's details (providers not loaded yet) the stored+ * choice is passed through as is; with none, the engine's model-level default+ * applies, which is the same effort.+ */+export const resolveModelBehaviorValue = (+ providerID: string,+ model: ProviderModel | null | undefined,+ value: string | null,+ providerName?: string | null,+): string | null => {+ if (!model) return normalizeModelBehaviorValue(value);+ return getModelBehaviorSummary(providerID, model, value, providerName).value;+};diff --git a/apps/app/src/react-app/domains/session/surface/session-model-store.ts b/apps/app/src/react-app/domains/session/surface/session-model-store.tsindex ce2e1d04..c58aa5a4 100644--- a/apps/app/src/react-app/domains/session/surface/session-model-store.ts+++ b/apps/app/src/react-app/domains/session/surface/session-model-store.ts@@ -6,7 +6,7 @@import { useMemo } from "react";import { create } from "zustand";-import { formatGenericBehaviorLabel, getModelBehaviorSummary } from "@/app/lib/model-behavior";+import { formatGenericBehaviorLabel, getModelBehaviorSummary, resolveModelBehaviorValue } from "@/app/lib/model-behavior";import type { ModelRef } from "@/app/types";type BehaviorOption = { value: string | null; label: string };@@ -101,6 +101,29 @@ export function getSessionModelSelection(sessionId: string): SessionModelSelectireturn useSessionModelStore.getState().bySessionId[sessionId] ?? null;}+// The provider catalog the picker last rendered from (useModelBehavior keeps+// it current), so send paths outside React (the queue drainer) resolve the+// effort from the same model details the picker shows.+let providerCatalogSnapshot: ProviderCatalog = {};++export function rememberProviderCatalog(catalog: ProviderCatalog) {+ providerCatalogSnapshot = catalog;+}++/**+ * The effort a send with `model` carries for the stored choice `variant`: the+ * value the picker shows for them (resolveModelBehaviorValue), never null+ * while the picker shows an effort.+ */+export function resolveSendVariant(+ model: ModelRef | null | undefined,+ variant: string | null | undefined,+ catalog: ProviderCatalog = providerCatalogSnapshot,+): string | null {+ if (!model) return variant ?? null;+ return resolveModelBehaviorValue(model.providerID, catalog[model.providerID]?.[model.modelID], variant ?? null);+}+export type UseSessionModelSelectionInput = {sessionId: string;/** Global default model (route prefs) used when the session has no memory. */diff --git a/apps/app/src/react-app/domains/session/surface/use-model-behavior.ts b/apps/app/src/react-app/domains/session/surface/use-model-behavior.tsindex 66c6c4a2..71e12bb8 100644--- a/apps/app/src/react-app/domains/session/surface/use-model-behavior.ts+++ b/apps/app/src/react-app/domains/session/surface/use-model-behavior.ts@@ -6,6 +6,7 @@ import { useEffect, useMemo, useState } from "react";import { formatGenericBehaviorLabel, getModelBehaviorSummary } from "@/app/lib/model-behavior";import type { ModelRef, ProviderListItem } from "@/app/types";+import { rememberProviderCatalog } from "./session-model-store";import { t } from "@/i18n";type ProviderModel = ProviderListItem["models"][string];@@ -35,6 +36,7 @@ export function useModelBehavior(input: UseModelBehaviorInput) {for (const provider of providerList.all) {next[provider.id] = { ...(provider.models ?? {}) };}+ rememberProviderCatalog(next);setProviderCatalog(next);}, [providerList]);diff --git a/apps/app/src/react-app/domains/session/sync/global-queue-drainer.ts b/apps/app/src/react-app/domains/session/sync/global-queue-drainer.tsindex f2a19bbe..3deb7263 100644--- a/apps/app/src/react-app/domains/session/sync/global-queue-drainer.ts+++ b/apps/app/src/react-app/domains/session/sync/global-queue-drainer.ts@@ -23,7 +23,7 @@ import {nextObservationProbeAt,subscribeQueuedDrain,} from "../surface/queued-drain-machine";-import { getSessionModelSelection, useSessionModelStore } from "../surface/session-model-store";+import { getSessionModelSelection, resolveSendVariant, useSessionModelStore } from "../surface/session-model-store";import { draftToParts } from "./draft-parts";import { buildOmniRushSessionSystemContext } from "./env-context";import {@@ -102,7 +102,8 @@ async function performQueuedDraftSend(const sessionModelSelection = getSessionModelSelection(sessionId);const sendModel = sessionModelSelection?.model ?? readStoredDefaultModelSafely() ?? context.model;- const sendVariant = sessionModelSelection ? sessionModelSelection.variant : context.variant;+ // The effort the picker shows for this model, never a null it hides.+ const sendVariant = resolveSendVariant(sendModel, sessionModelSelection ? sessionModelSelection.variant : context.variant);const createEngineClient = isOpencodeV2BaseUrl(context.opencodeBaseUrl) ? createClientV2 : createClient;const opencodeClient = createEngineClient(context.opencodeBaseUrl,@@ -121,6 +122,7 @@ async function performQueuedDraftSend(messageID: draft.messageId,command: draft.command.name,arguments: draft.command.arguments,+ ...(sendVariant ? { variant: sendVariant } : {}),});if (result.error) throw new Error(serializeSDKError(result.error));return;diff --git a/apps/app/src/react-app/shell/session-route.tsx b/apps/app/src/react-app/shell/session-route.tsxindex c2091422..eeb5f2ea 100644--- a/apps/app/src/react-app/shell/session-route.tsx+++ b/apps/app/src/react-app/shell/session-route.tsx@@ -139,7 +139,7 @@ import { getModelBehaviorSummary, nextModelBehaviorValue, previousModelBehaviorVimport { computeModelAvailability, createUnavailableConfirmationGate, type ModelAvailability } from "@/react-app/domains/session/surface/model-availability";import { useSessionFindStore } from "@/react-app/domains/session/surface/find-store";import { useModelPicker } from "@/react-app/domains/session/modals/use-model-picker";-import { getSessionModelSelection, useSessionModelStore } from "@/react-app/domains/session/surface/session-model-store";+import { getSessionModelSelection, resolveSendVariant, useSessionModelStore } from "@/react-app/domains/session/surface/session-model-store";import { useWorkbenchStore } from "@/react-app/domains/session/chat/workbench-store";import { resolveWorkbenchPaneEndpoint } from "@/react-app/domains/session/chat/pane-runtime";import {@@ -1396,7 +1396,8 @@ export function SessionRoute() {const sessionModelSelection = getSessionModelSelection(targetSessionId);const configuredSendModel = sessionModelSelection?.model ?? local.prefs.defaultModel;const sendModel = configuredSendModel;- const sendVariant = sessionModelSelection ? sessionModelSelection.variant : modelVariantValue;+ // The effort the picker shows for this model, never a null it hides.+ const sendVariant = resolveSendVariant(sendModel, sessionModelSelection ? sessionModelSelection.variant : modelVariantValue);// Send-time validation targets the exact provider/model identity this// conversation displays and will submit — not the global default.if (resolveModelAvailability(sendModel ?? null).status === "unavailable") {@@ -1468,6 +1469,7 @@ export function SessionRoute() {messageID: draft.messageId,command: draft.command.name,arguments: draft.command.arguments,+ ...(sendVariant ? { variant: sendVariant } : {}),});if (result.error) {throw new Error(serializeSDKError(result.error));@@ -1754,7 +1756,8 @@ export function SessionRoute() {const sessionModelSelection = getSessionModelSelection(targetSessionId);const configuredSendModel = sessionModelSelection?.model ?? local.prefs.defaultModel;const sendModel = configuredSendModel;- const sendVariant = sessionModelSelection ? sessionModelSelection.variant : modelVariantValue;+ // The effort the picker shows for this model, never a null it hides.+ const sendVariant = resolveSendVariant(sendModel, sessionModelSelection ? sessionModelSelection.variant : modelVariantValue);return submitWithCloudMcpReadiness({skipGate: true,send: async () => {@@ -1806,6 +1809,7 @@ export function SessionRoute() {messageID: draft.messageId,command: draft.command.name,arguments: draft.command.arguments,+ ...(sendVariant ? { variant: sendVariant } : {}),});if (result.error) throw new Error(serializeSDKError(result.error));return;@@ -3314,16 +3318,17 @@ export function SessionRoute() {runtimeKey: environmentRuntimeKey,});const model = local.prefs.defaultModel;+ const variant = resolveSendVariant(model, modelVariantValue);const result = await engine.session.promptAsync({sessionID: session.id,parts: [{ type: "text", text: prompt }],model: model ?? undefined,agent: selectedAgent ?? undefined,- ...(modelVariantValue ? { variant: modelVariantValue } : {}),+ ...(variant ? { variant } : {}),system,});if (result.error) throw new Error(serializeSDKError(result.error));- if (model) useSessionModelStore.getState().setModel(session.id, model, modelVariantValue ?? null);+ if (model) useSessionModelStore.getState().setModel(session.id, model, variant);writeLastSessionFor(taskWorkspace.id, session.id);void queryClient.invalidateQueries({ queryKey: workspaceTasksQueryKey(workspaceId) });return created.task;diff --git a/apps/app/tests/model-behavior.test.ts b/apps/app/tests/model-behavior.test.tsindex 0baa6f7a..01be6623 100644--- a/apps/app/tests/model-behavior.test.ts+++ b/apps/app/tests/model-behavior.test.ts@@ -88,10 +88,10 @@ const omnirushModel = (id: string, name: string): ProviderModel => ({providerID: "omnirush",api: { id, url: "http://127.0.0.1:8090/omnirush-gateway/v1", npm: "@ai-sdk/openai" },variants: {- low: { reasoning_effort: "low" },- high: { reasoning_effort: "high" },- xhigh: { reasoning_effort: "xhigh" },- max: { reasoning_effort: "max" },+ low: { reasoningEffort: "low" },+ high: { reasoningEffort: "high" },+ xhigh: { reasoningEffort: "xhigh" },+ max: { reasoningEffort: "max" },},});@@ -117,7 +117,7 @@ describe("model behavior options", () => {const summary = getModelBehaviorSummary("omnirush", internal, "max", "omnirush.ai");expect(summary.value).toBe("max");expect(summary.label).toBe("Max");- expect(getModelBehaviorSummary("omnirush", internal, null, "omnirush.ai").value).toBe("high");+ expect(getModelBehaviorSummary("omnirush", internal, null, "omnirush.ai").value).toBe("xhigh");}});@@ -131,26 +131,27 @@ describe("model behavior options", () => {family: "Meta Muse",variants: {minimal: { reasoning_effort: "minimal" },- low: { reasoning_effort: "low" },+ low: { reasoningEffort: "low" },medium: { reasoning_effort: "medium", reasoningEffort: "medium", reasoningSummary: "auto" },- high: { reasoning_effort: "high" },- xhigh: { reasoning_effort: "xhigh" },+ high: { reasoningEffort: "high" },+ xhigh: { reasoningEffort: "xhigh" },ultra: { reasoningEffort: "ultra" },},};const options = getModelBehaviorOptions("omnirush", museSpark, "omnirush.ai");expect(options.map((option) => option.value)).toEqual(["minimal", "low", "medium", "high", "xhigh"]);- expect(getModelBehaviorSummary("omnirush", museSpark, null, "omnirush.ai").value).toBe("medium");- expect(getModelBehaviorSummary("omnirush", museSpark, "xhigh", "omnirush.ai").value).toBe("xhigh");+ // The CLI's default (xhigh) wherever the model offers it.+ expect(getModelBehaviorSummary("omnirush", museSpark, null, "omnirush.ai").value).toBe("xhigh");+ expect(getModelBehaviorSummary("omnirush", museSpark, "low", "omnirush.ai").value).toBe("low");// An effort Muse does not offer (Astra's max) falls back to its default.- expect(getModelBehaviorSummary("omnirush", museSpark, "max", "omnirush.ai").value).toBe("medium");- expect(getModelBehaviorSummary("omnirush", museSpark, "ultra", "omnirush.ai").value).toBe("medium");+ expect(getModelBehaviorSummary("omnirush", museSpark, "max", "omnirush.ai").value).toBe("xhigh");+ expect(getModelBehaviorSummary("omnirush", museSpark, "ultra", "omnirush.ai").value).toBe("xhigh");- // Astra and Sol keep their v1.0.9 levels and default.+ // Astra and Sol keep their v1.0.9 levels; their default is the CLI's xhigh.for (const internal of OMNIRUSH_MODELS) {expect(getModelBehaviorOptions("omnirush", internal, "omnirush.ai").map((option) => option.value)).toEqual(["low", "high", "xhigh", "max"]);- expect(getModelBehaviorSummary("omnirush", internal, null, "omnirush.ai").value).toBe("high");- expect(getModelBehaviorSummary("omnirush", internal, "medium", "omnirush.ai").value).toBe("high");+ expect(getModelBehaviorSummary("omnirush", internal, null, "omnirush.ai").value).toBe("xhigh");+ expect(getModelBehaviorSummary("omnirush", internal, "medium", "omnirush.ai").value).toBe("xhigh");}});diff --git a/apps/app/tests/send-effort.test.ts b/apps/app/tests/send-effort.test.tsnew file mode 100644index 00000000..9af9696b--- /dev/null+++ b/apps/app/tests/send-effort.test.ts@@ -0,0 +1,162 @@+import { afterAll, describe, expect, mock, test } from "bun:test";++import type { ComposerDraft, ProviderListItem } from "../src/app/types";+import { OMNIRUSH_REASONING_EFFORTS } from "../src/app/constants";+import { getModelBehaviorSummary, resolveModelBehaviorValue } from "../src/app/lib/model-behavior";++type ProviderModel = ProviderListItem["models"][string];++const omnirushModel = (id: string, levels: string[]): ProviderModel => ({+ id,+ providerID: "omnirush",+ name: id,+ api: { id, url: "http://127.0.0.1:8090/omnirush/v1", npm: "@ai-sdk/openai" },+ status: "active",+ headers: {},+ options: {},+ cost: { input: 0, output: 0, cache: { read: 0, write: 0 } },+ limit: { context: 400_000, output: 128_000 },+ capabilities: {+ temperature: true,+ reasoning: true,+ attachment: true,+ toolcall: true,+ input: { text: true, audio: false, image: true, video: false, pdf: true },+ output: { text: true, audio: false, image: false, video: false, pdf: false },+ interleaved: false,+ },+ release_date: "2026-10-01",+ variants: Object.fromEntries(levels.map((level) => [level, { reasoningEffort: level }])),+}) as ProviderModel;++const astra = omnirushModel("gpt-6-astra", ["low", "high", "xhigh", "max"]);+const nova = omnirushModel("nova-9", ["low", "high"]);+const catalog = { omnirush: { "gpt-6-astra": astra, "nova-9": nova } };+const astraRef = { providerID: "omnirush", modelID: "gpt-6-astra" };++describe("the effort a send carries is the one the picker shows", () => {+ test("resolver and picker agree for every stored choice", () => {+ for (const model of [astra, nova]) {+ for (const stored of [null, "", "default", ...OMNIRUSH_REASONING_EFFORTS, "ultra", "turbo", "High"]) {+ const shown = getModelBehaviorSummary("omnirush", model, stored).value;+ expect(shown).not.toBeNull();+ expect(resolveModelBehaviorValue("omnirush", model, stored)).toBe(shown);+ }+ }+ });++ test("no choice (a new chat, or one copied from a chat that had none) sends the default", () => {+ expect(resolveModelBehaviorValue("omnirush", astra, null)).toBe("xhigh");+ // A model without xhigh: the level nearest medium, as the server's engine default.+ expect(resolveModelBehaviorValue("omnirush", nova, null)).toBe("high");+ });++ test("a user choice is kept, an effort the model lacks falls back to the default", () => {+ expect(resolveModelBehaviorValue("omnirush", astra, "low")).toBe("low");+ expect(resolveModelBehaviorValue("omnirush", astra, "max")).toBe("max");+ expect(resolveModelBehaviorValue("omnirush", astra, "medium")).toBe("xhigh");+ expect(resolveModelBehaviorValue("omnirush", nova, "xhigh")).toBe("high");+ });++ test("before providers load, a stored choice passes through and none stays none (engine default)", () => {+ expect(resolveModelBehaviorValue("omnirush", undefined, "low")).toBe("low");+ expect(resolveModelBehaviorValue("omnirush", undefined, null)).toBeNull();+ expect(resolveModelBehaviorValue("omnirush", undefined, "default")).toBeNull();+ });+});++describe("send paths", () => {+ test("resolveSendVariant uses the catalog the picker rendered from", async () => {+ const { rememberProviderCatalog, resolveSendVariant } = await import("../src/react-app/domains/session/surface/session-model-store");+ expect(resolveSendVariant(astraRef, null, {})).toBeNull();+ rememberProviderCatalog(catalog);+ expect(resolveSendVariant(astraRef, null)).toBe("xhigh");+ expect(resolveSendVariant(astraRef, "low")).toBe("low");+ expect(resolveSendVariant({ providerID: "omnirush", modelID: "nova-9" }, undefined)).toBe("high");+ expect(resolveSendVariant(null, "low")).toBe("low");+ });++ test("every prompt and command send in the route and the queue drainer carries the resolved effort", async () => {+ const { readFile } = await import("node:fs/promises");+ for (const file of ["../src/react-app/shell/session-route.tsx", "../src/react-app/domains/session/sync/global-queue-drainer.ts"]) {+ const source = await readFile(new URL(file, import.meta.url), "utf8");+ const sends = [...source.matchAll(/\.session\.(promptAsync|command)\(\{([\s\S]*?)\}\);/g)];+ expect(sends.length).toBeGreaterThan(0);+ for (const [, , body] of sends) expect(body).toMatch(/\.\.\.\((sendVariant|variant) \? \{ variant/);+ // No send effort is taken from a stored value without the resolver.+ const assignments = [...source.matchAll(/const sendVariant = [^\n]*/g)].map(([line]) => line);+ expect(assignments.length).toBeGreaterThan(0);+ for (const line of assignments) expect(line).toContain("resolveSendVariant(");+ }+ });+});++describe("queued message drain", () => {+ const calls: Array<{ kind: string; input: Record<string, unknown> }> = [];+ const restore: Array<() => void> = [];+ afterAll(() => restore.forEach((fn) => fn()));++ test("a queued message and a queued command send the shown effort, not the stored null", async () => {+ const realOpencode = await import("../src/app/lib/opencode");+ const fakeClient = {+ session: {+ promptAsync: async (input: Record<string, unknown>) => { calls.push({ kind: "prompt", input }); return { data: {} }; },+ command: async (input: Record<string, unknown>) => { calls.push({ kind: "command", input }); return { data: {} }; },+ },+ };+ mock.module("@/app/lib/opencode", () => ({ ...realOpencode, createClient: () => fakeClient }));+ mock.module("@/app/lib/opencode-v2-adapter", () => ({ createClientV2: () => fakeClient, isOpencodeV2BaseUrl: () => false }));+ mock.module("@/app/lib/opencode-interruption", () => ({+ submitAfterInterruption: (_base: string, _id: string, send: (afterStop: boolean) => Promise<unknown>) => send(false),+ }));+ mock.module("@/app/lib/opencode-session-native", () => ({+ composeNativeSessionSnapshot: async () => ({ status: { type: "idle" } }),+ }));+ mock.module("@/react-app/domains/session/sync/session-sync", () => ({+ ensureWorkspaceSessionSync: () => () => {},+ trackWorkspaceSessionSync: () => () => {},+ }));+ mock.module("@/react-app/domains/session/sync/draft-parts", () => ({+ draftToParts: async (draft: ComposerDraft) => [{ type: "text", text: draft.text }],+ }));+ mock.module("@/react-app/domains/session/sync/env-context", () => ({ buildOmniRushSessionSystemContext: async () => undefined }));+ mock.module("@/app/lib/analytics", () => ({ markTaskRunStart: () => {} }));+ mock.module("@/react-app/kernel/model-config", () => ({ readStoredDefaultModel: () => astraRef }));++ const { rememberProviderCatalog, getSessionModelSelection, useSessionModelStore } = await import("../src/react-app/domains/session/surface/session-model-store");+ const { useComposerStateStore } = await import("../src/react-app/domains/session/surface/composer-state-store");+ const { setQueuedSendContext } = await import("../src/react-app/domains/session/sync/queued-send-context");+ const { startGlobalQueueDrainer } = await import("../src/react-app/domains/session/sync/global-queue-drainer");+ rememberProviderCatalog(catalog);++ const sessionId = "ses_queue_effort";+ // The chat was opened with the previous chat's settings: its model, no effort.+ useSessionModelStore.getState().setModel(sessionId, astraRef, null);+ setQueuedSendContext(sessionId, {+ workspaceId: "ws", workspaceRoot: "/tmp/ws", opencodeBaseUrl: "http://127.0.0.1:1/opencode", omnirushToken: "t",+ client: {} as never, agent: null, variant: null, model: astraRef, environmentRuntimeKey: null,+ });+ const draft = (text: string, command?: { name: string; arguments: string }): ComposerDraft => ({+ mode: "prompt", parts: [], attachments: [], text, ...(command ? { command } : {}),+ });+ useComposerStateStore.getState().appendQueuedDraft(sessionId, draft("queued message"));+ const stop = startGlobalQueueDrainer();+ restore.push(stop);+ const deadline = Date.now() + 3_000;+ while (calls.length < 1 && Date.now() < deadline) await new Promise((resolve) => setTimeout(resolve, 10));+ expect(calls[0]).toMatchObject({ kind: "prompt", input: { variant: "xhigh", model: astraRef } });+ // The stored choice stays the user's (none); only the send resolves it.+ expect(getSessionModelSelection(sessionId)?.variant).toBeNull();++ useSessionModelStore.getState().setVariant(sessionId, "low");+ const { resetQueuedDrainForTests } = await import("../src/react-app/domains/session/surface/queued-drain-machine");+ resetQueuedDrainForTests?.();+ setQueuedSendContext(sessionId, {+ workspaceId: "ws", workspaceRoot: "/tmp/ws", opencodeBaseUrl: "http://127.0.0.1:1/opencode", omnirushToken: "t",+ client: {} as never, agent: null, variant: null, model: astraRef, environmentRuntimeKey: null,+ });+ useComposerStateStore.getState().appendQueuedDraft(sessionId, draft("/review", { name: "review", arguments: "" }));+ while (calls.length < 2 && Date.now() < deadline + 3_000) await new Promise((resolve) => setTimeout(resolve, 10));+ expect(calls[1]).toMatchObject({ kind: "command", input: { command: "review", variant: "low" } });+ });+});diff --git a/apps/server/src/omnirush-model-catalog.test.ts b/apps/server/src/omnirush-model-catalog.test.tsindex 66febac5..a99a30ee 100644--- a/apps/server/src/omnirush-model-catalog.test.ts+++ b/apps/server/src/omnirush-model-catalog.test.ts@@ -8,6 +8,8 @@ import {canonicalOmniRushModelCatalog,clearOmniRushModelCatalog,engineModelsFromCatalog,+ OMNIRUSH_DEFAULT_EFFORT,+ omnirushDefaultEffort,omnirushDefaultModelId,omnirushModelCatalogPath,omnirushModelWantsReasoningSummary,@@ -265,10 +267,41 @@ describe("omnirush engine models from the catalog", () => {for (const id of ["meta-muse-spark", "muse-spark-1.1", "muse-spark-1.3"]) {expect(enabled(models[id]!)).toEqual(["minimal", "low", "medium", "high", "xhigh"]);expect(disabled(models[id]!)).toEqual(["none", "max"]);- expect(models[id]!.variants).toMatchObject({ xhigh: { reasoning_effort: "xhigh" } });+ expect(models[id]!.variants).toMatchObject({ xhigh: { reasoningEffort: "xhigh" } });}});+ test("variants carry the camelCase reasoningEffort the engine's OpenAI adapter reads", () => {+ const models = engineModelsFromCatalog(sanitizeOmniRushModelCatalog(backendCatalogBody())!);+ for (const model of Object.values(models)) {+ for (const [level, options] of Object.entries(model.variants as Record<string, Record<string, unknown>>)) {+ // An unsupported level is only ever disabled; a supported one names itself.+ expect(options).toEqual(options.disabled === true ? { disabled: true } : { reasoningEffort: level });+ expect(options).not.toHaveProperty("reasoning_effort");+ }+ }+ });++ test("every model with efforts gets a model-level default: xhigh where offered, else the level nearest medium", () => {+ const catalog = sanitizeOmniRushModelCatalog({+ data: [+ { id: "gpt-6-astra", reasoning_levels: ["low", "high", "xhigh", "max"] },+ { id: "muse", reasoning_levels: ["minimal", "low", "medium", "high", "xhigh"] },+ { id: "nova", reasoning_levels: ["low", "high"] },+ { id: "tiny", reasoning_levels: ["minimal", "low"] },+ { id: "mid", reasoning_levels: ["none", "medium", "max"] },+ { id: "plain", reasoning_levels: [], capabilities: { reasoning: false } },+ ],+ })!;+ const models = engineModelsFromCatalog(catalog);+ const defaults: Record<string, string | null> = Object.fromEntries(Object.entries(models).map(([id, model]) => [id, (model.options as { reasoningEffort?: string } | undefined)?.reasoningEffort ?? null]));+ expect(defaults).toEqual({ "gpt-6-astra": "xhigh", muse: "xhigh", nova: "high", tiny: "low", mid: "medium", plain: null });+ expect(models.plain!.options).toBeUndefined();+ expect(models.nova!.options).not.toHaveProperty("reasoning_effort");+ for (const model of catalog) expect<string | null>(omnirushDefaultEffort(model.reasoning_levels)).toBe(defaults[model.id] ?? null);+ expect(OMNIRUSH_DEFAULT_EFFORT).toBe("xhigh");+ });+test("labels Muse by family, keeps 1.3 beta and text-only, and never sets attachment", () => {const models = engineModelsFromCatalog(sanitizeOmniRushModelCatalog(backendCatalogBody())!);expect(models["meta-muse-spark"]).toMatchObject({diff --git a/apps/server/src/omnirush-model-catalog.ts b/apps/server/src/omnirush-model-catalog.tsindex a8989df9..fe9ec9de 100644--- a/apps/server/src/omnirush-model-catalog.ts+++ b/apps/server/src/omnirush-model-catalog.ts@@ -25,6 +25,8 @@ import { modelHasWebSearch, type WebSearchSwitch } from "./web-search.js";/** Every effort a catalog model may list, lowest first. */export const OMNIRUSH_MODEL_EFFORTS = ["none", "minimal", "low", "medium", "high", "xhigh", "max"] as const;export type OmniRushModelEffort = (typeof OMNIRUSH_MODEL_EFFORTS)[number];+/** The CLI's default effort (omnirush-cli DEFAULT_ENGINE_EFFORT). */+export const OMNIRUSH_DEFAULT_EFFORT: OmniRushModelEffort = "xhigh";const MODEL_STATUSES = ["active", "beta", "deprecated"] as const;export type OmniRushModelStatus = (typeof MODEL_STATUSES)[number];@@ -210,43 +212,76 @@ export async function clearOmniRushModelCatalog(config: ServerConfig): Promise<vawait rm(omnirushModelCatalogPath(config), { force: true });}+/**+ * The effort a catalog model runs at when the chat picked none: xhigh where the+ * model offers it (the CLI's default), otherwise the level closest to medium+ * (the higher one on a tie). Null for a model without effort control.+ *+ * PARITY: apps/app/src/app/lib/model-behavior.ts (getModelBehaviorSummary's+ * default for the omnirush provider) picks the same level, so the effort the+ * picker shows is the one the engine sends.+ */+export function omnirushDefaultEffort(levels: readonly OmniRushModelEffort[]): OmniRushModelEffort | null {+ if (levels.includes(OMNIRUSH_DEFAULT_EFFORT)) return OMNIRUSH_DEFAULT_EFFORT;+ const medium = OMNIRUSH_MODEL_EFFORTS.indexOf("medium");+ let best: OmniRushModelEffort | null = null;+ for (const level of levels) {+ if (best === null) { best = level; continue; }+ const distance = Math.abs(OMNIRUSH_MODEL_EFFORTS.indexOf(level) - medium);+ const bestDistance = Math.abs(OMNIRUSH_MODEL_EFFORTS.indexOf(best) - medium);+ if (distance < bestDistance || (distance === bestDistance && OMNIRUSH_MODEL_EFFORTS.indexOf(level) > OMNIRUSH_MODEL_EFFORTS.indexOf(best))) best = level;+ }+ return best;+}+/*** The `omnirush` provider's engine models. Each model's efforts become- * variants carrying the client-facing `reasoning_effort` (the- * omnirush-reasoning-effort plugin and the broker put it on the wire); every- * other effort is declared disabled, because the engine merges its own- * OpenAI reasoning defaults into a model's variants and drops only entries- * marked disabled. `deprecated` is never passed on: the engine deletes- * deprecated models, which would strand the sessions pinned to one.+ * variants carrying `reasoningEffort` (the key the engine's OpenAI adapter+ * reads; the omnirush-reasoning-effort plugin and the broker also put it on+ * the wire); every other effort is declared disabled, because the engine+ * merges its own OpenAI reasoning defaults into a model's variants and drops+ * only entries marked disabled. The model-level `options.reasoningEffort` is+ * the default effort (omnirushDefaultEffort): a message without a variant+ * (a sub-agent on its own model, a send before the app knew the model's+ * efforts) still runs at the effort the picker shows. `deprecated` is never+ * passed on: the engine deletes deprecated models, which would strand the+ * sessions pinned to one.*/export function engineModelsFromCatalog(catalog: OmniRushModelCatalog, webSearch: WebSearchSwitch | null = null): Record<string, Record<string, unknown>> {- return Object.fromEntries(catalog.map((model) => [model.id, {- name: model.display_name,- reasoning: model.capabilities.reasoning,- tool_call: model.capabilities.tool_call,- structured_output: true,- temperature: true,- variants: {- ...Object.fromEntries(model.reasoning_levels.map((effort) => [effort, { reasoning_effort: effort }])),- ...Object.fromEntries(OMNIRUSH_MODEL_EFFORTS- .filter((effort) => !model.reasoning_levels.includes(effort))- .map((effort) => [effort, { disabled: true }])),- },- limit: { context: model.limits.context, output: model.limits.output },- modalities: {- input: [- "text",- ...(model.capabilities.image_input ? ["image"] : []),- ...(model.capabilities.file_input ? ["pdf"] : []),- ],- output: ["text"],- },- ...(model.family && model.family !== PROVIDER_FAMILY ? { family: model.family } : {}),- ...(model.status === "beta" ? { status: "beta" } : {}),- // The model's own web search (web-search.ts): the engine declares the- // provider's web_search tool for it. Off, no `options` key at all.- ...(modelHasWebSearch(model, webSearch) ? { options: { hostedWebSearch: { searchContextSize: webSearch!.searchContextSize } } } : {}),- }]));+ return Object.fromEntries(catalog.map((model) => {+ const effort = omnirushDefaultEffort(model.reasoning_levels);+ const options = {+ ...(effort ? { reasoningEffort: effort } : {}),+ // The model's own web search (web-search.ts): the engine declares the+ // provider's web_search tool for it. Off, no `hostedWebSearch` key.+ ...(modelHasWebSearch(model, webSearch) ? { hostedWebSearch: { searchContextSize: webSearch!.searchContextSize } } : {}),+ };+ return [model.id, {+ name: model.display_name,+ reasoning: model.capabilities.reasoning,+ tool_call: model.capabilities.tool_call,+ structured_output: true,+ temperature: true,+ variants: {+ ...Object.fromEntries(model.reasoning_levels.map((level) => [level, { reasoningEffort: level }])),+ ...Object.fromEntries(OMNIRUSH_MODEL_EFFORTS+ .filter((level) => !model.reasoning_levels.includes(level))+ .map((level) => [level, { disabled: true }])),+ },+ limit: { context: model.limits.context, output: model.limits.output },+ modalities: {+ input: [+ "text",+ ...(model.capabilities.image_input ? ["image"] : []),+ ...(model.capabilities.file_input ? ["pdf"] : []),+ ],+ output: ["text"],+ },+ ...(model.family && model.family !== PROVIDER_FAMILY ? { family: model.family } : {}),+ ...(model.status === "beta" ? { status: "beta" } : {}),+ ...(Object.keys(options).length > 0 ? { options } : {}),+ }];+ }));}/**diff --git a/apps/server/src/omnirush-runtime-config.test.ts b/apps/server/src/omnirush-runtime-config.test.tsindex 72e7200a..c459bbed 100644--- a/apps/server/src/omnirush-runtime-config.test.ts+++ b/apps/server/src/omnirush-runtime-config.test.ts@@ -227,10 +227,10 @@ describe("omnirush runtime config file", () => {const providers = parsed.provider as Record<string, { models: Record<string, Record<string, unknown>> }>;const models = providers.omnirush!.models;const variants = {- low: { reasoning_effort: "low" },- high: { reasoning_effort: "high" },- xhigh: { reasoning_effort: "xhigh" },- max: { reasoning_effort: "max" },+ low: { reasoningEffort: "low" },+ high: { reasoningEffort: "high" },+ xhigh: { reasoningEffort: "xhigh" },+ max: { reasoningEffort: "max" },// The engine merges its own OpenAI reasoning defaults into a model's// variants and only drops entries marked disabled; these keep the// resolved picker at exactly the four levels above.@@ -249,6 +249,8 @@ describe("omnirush runtime config file", () => {for (const id of ["gpt-6-astra", "gpt-6.1-sol", "gpt-6-sol"]) {expect(Object.keys(models[id]!.variants as object).sort()).toEqual(Object.keys(variants).sort());expect(enabledVariants(models[id]!)).toEqual(["low", "high", "xhigh", "max"]);+ // The default effort (the CLI's xhigh), for a message that names no variant.+ expect(models[id]!.options).toEqual({ reasoningEffort: "xhigh" });}expect(parsed.model).toBe("omnirush/gpt-6-astra");expect((parsed.plugin as string[]).some((plugin) => /omnirush-reasoning-effort\.(?:ts|js)$/.test(plugin))).toBe(true);@@ -663,11 +665,13 @@ describe("omnirush runtime config file", () => {});/**- * The omnirush provider exactly as v1.0.9 declared it (the INTERNAL_MODELS- * and internalGatewayModel it hardcoded). Astra and Sol must keep these- * bytes: they feed the engine-pool fingerprint, and any drift (an- * `attachment` flag, a family, a status) would change how the engine treats- * them.+ * The omnirush provider as v1.0.9 declared it (the INTERNAL_MODELS and+ * internalGatewayModel it hardcoded), with two deliberate changes: variants+ * carry the camelCase `reasoningEffort` the engine's OpenAI adapter reads, and+ * each model has the CLI's default effort (`options.reasoningEffort`). Astra+ * and Sol must keep these bytes otherwise: they feed the engine-pool+ * fingerprint, and any other drift (an `attachment` flag, a family, a status)+ * would change how the engine treats them.*/function v109OmniRushProvider(baseURL: string) {const model = (name: string) => ({@@ -677,14 +681,15 @@ function v109OmniRushProvider(baseURL: string) {structured_output: true,temperature: true,variants: {- low: { reasoning_effort: "low" },- high: { reasoning_effort: "high" },- xhigh: { reasoning_effort: "xhigh" },- max: { reasoning_effort: "max" },+ low: { reasoningEffort: "low" },+ high: { reasoningEffort: "high" },+ xhigh: { reasoningEffort: "xhigh" },+ max: { reasoningEffort: "max" },none: { disabled: true },minimal: { disabled: true },medium: { disabled: true },},+ options: { reasoningEffort: "xhigh" },limit: { context: 400_000, output: 128_000 },modalities: { input: ["text", "image", "pdf"], output: ["text"] },});@@ -750,11 +755,11 @@ describe("omnirush runtime config from the model catalog", () => {const provider = providerOf(parsed);const models = provider.models as Record<string, Record<string, unknown>>;const museVariants = {- minimal: { reasoning_effort: "minimal" },- low: { reasoning_effort: "low" },- medium: { reasoning_effort: "medium" },- high: { reasoning_effort: "high" },- xhigh: { reasoning_effort: "xhigh" },+ minimal: { reasoningEffort: "minimal" },+ low: { reasoningEffort: "low" },+ medium: { reasoningEffort: "medium" },+ high: { reasoningEffort: "high" },+ xhigh: { reasoningEffort: "xhigh" },// Muse answers none and max with 400; the engine's own defaults are disabled.none: { disabled: true },max: { disabled: true },@@ -774,6 +779,7 @@ describe("omnirush runtime config from the model catalog", () => {structured_output: true,temperature: true,variants: museVariants,+ options: { reasoningEffort: "xhigh" },limit: { context: 158_000, output: 32_000 },modalities: { input: ["text", "image", "pdf"], output: ["text"] },});@@ -786,6 +792,7 @@ describe("omnirush runtime config from the model catalog", () => {structured_output: true,temperature: true,variants: museVariants,+ options: { reasoningEffort: "xhigh" },limit: { context: 99_000, output: 16_000 },modalities: { input: ["text"], output: ["text"] },});diff --git a/apps/server/src/opencode-plugins/omnirush-reasoning-effort.test.ts b/apps/server/src/opencode-plugins/omnirush-reasoning-effort.test.tsindex 841b710a..bf047761 100644--- a/apps/server/src/opencode-plugins/omnirush-reasoning-effort.test.ts+++ b/apps/server/src/opencode-plugins/omnirush-reasoning-effort.test.ts@@ -101,6 +101,62 @@ describe("OmniRushReasoningEffort", () => {expect(title.headers).toEqual({});});+ test("a message without a variant runs at the model-level default effort", async () => {+ const hooks = await OmniRushReasoningEffort();+ const result = await run(+ hooks,+ { agent: "explore", model: astra, message: { id: "msg_8", model: {} } },+ { reasoningEffort: "xhigh" },+ );+ expect(result.options).toEqual({ reasoningEffort: "xhigh" });+ expect(result.headers).toEqual({ "x-omnirush-reasoning-effort": "xhigh" });+ });++ test("a chosen variant wins over the model-level default", async () => {+ const hooks = await OmniRushReasoningEffort();+ // The engine merges model options, then agent options, then the variant's.+ const result = await run(+ hooks,+ { agent: "omnirush", model: astra, message: { id: "msg_9", model: { variant: "low" } } },+ { ...{ reasoningEffort: "xhigh" }, ...{ reasoningEffort: "low" } },+ );+ expect(result.options.reasoningEffort).toBe("low");+ expect(result.headers["x-omnirush-reasoning-effort"]).toBe("low");+ });++ test("small side requests keep the model's first variant, not the model-level default", async () => {+ const hooks = await OmniRushReasoningEffort();+ // As the engine reports a model's variants: its own OpenAI defaults merged with the config's.+ const variants = { low: { reasoningEffort: "low", reasoningSummary: "auto" }, high: { reasoningEffort: "high" }, xhigh: { reasoningEffort: "xhigh" } };+ // smallOptions(first variant) merged with the model options (the default).+ const small = { store: false, reasoningEffort: "xhigh", reasoningSummary: "auto" };+ const title = await run(+ hooks,+ { agent: "title", model: { ...astra, variants }, message: { id: "msg_10", model: { variant: "max" } } },+ { ...small },+ );+ // Titles: the first variant's effort, and still no private header (as before).+ expect(title.options).toEqual({ store: false, reasoningEffort: "low", reasoningSummary: "auto" });+ expect(title.headers).toEqual({});+ const copyName = await run(+ hooks,+ { agent: "project-copy-name", model: { ...astra, variants }, message: { id: "msg_11", model: {} } },+ { ...small },+ );+ expect(copyName.options).toEqual({ store: false, reasoningEffort: "low", reasoningSummary: "auto" });+ expect(copyName.headers).toEqual({ "x-omnirush-reasoning-effort": "low" });+ // A model without variants: no effort at all on its side requests.+ const bare = await run(hooks, { agent: "title", model: astra, message: { id: "msg_12", model: {} } }, { reasoningEffort: "xhigh" });+ expect(bare.options).toEqual({});+ // Another provider's title request is not touched.+ const external = await run(+ hooks,+ { agent: "title", model: { id: "gpt-5.5", providerID: "openai" }, message: { id: "msg_13", model: {} } },+ { reasoningEffort: "xhigh" },+ );+ expect(external.options).toEqual({ reasoningEffort: "xhigh" });+ });+test("module exposes only the plugin factory", async () => {const mod = await import("./omnirush-reasoning-effort.js");expect(Object.keys(mod)).toEqual(["OmniRushReasoningEffort"]);diff --git a/apps/server/src/opencode-plugins/omnirush-reasoning-effort.ts b/apps/server/src/opencode-plugins/omnirush-reasoning-effort.tsindex 367672ad..898a6e92 100644--- a/apps/server/src/opencode-plugins/omnirush-reasoning-effort.ts+++ b/apps/server/src/opencode-plugins/omnirush-reasoning-effort.ts@@ -16,6 +16,13 @@** The header never leaves the machine: the broker only forwards an explicit* allow-list of headers to omnirush.ai.+ *+ * Each model also carries a model-level default `reasoningEffort` (the effort+ * the picker shows when none is chosen), which the engine merges into every+ * request of that model, side requests included. The engine's small side+ * requests (titles, the project-copy name) keep the effort they had before+ * the default existed: the model's first variant, which is what the engine's+ * small-request options pick.*/const PROVIDER_ID = "omnirush";/** Read by OmniRushGatewayBroker; keep the two definitions identical. */@@ -23,11 +30,13 @@ const EFFORT_HEADER = "x-omnirush-reasoning-effort";const EFFORTS = new Set(["none", "minimal", "low", "medium", "high", "xhigh", "ultra", "max"]);/** Cheap side requests never carry the conversation's effort selection. */const SKIPPED_AGENTS = new Set(["title"]);+/** Small side requests: they run at the model's first variant (engine small-request options). */+const SMALL_AGENTS = new Set(["title", "project-copy-name"]);const MAX_PENDING = 512;type HookInput = {agent?: string;- model: { id: string; providerID: string };+ model: { id: string; providerID: string; variants?: Record<string, Record<string, unknown>> };message?: { id?: string; model?: { variant?: string } };};@@ -42,9 +51,17 @@ function normalizeEffort(value: unknown): string | null {return EFFORTS.has(effort) ? effort : null;}+function isOmniRushModel(input: HookInput): boolean {+ return input.model.providerID.trim().toLowerCase() === PROVIDER_ID;+}+function isInternalModel(input: HookInput): boolean {- return input.model.providerID.trim().toLowerCase() === PROVIDER_ID- && !SKIPPED_AGENTS.has(input.agent ?? "");+ return isOmniRushModel(input) && !SKIPPED_AGENTS.has(input.agent ?? "");+}++function firstVariantEffort(input: HookInput): string | null {+ const first = Object.values(input.model.variants ?? {})[0];+ return first ? optionEffort(first) : null;}function optionEffort(options: Record<string, unknown>): string | null {@@ -68,6 +85,12 @@ function recall(input: HookInput): string | null {// module as a plugin factory, so helpers must stay module-private.export const OmniRushReasoningEffort = async () => ({"chat.params": async (input: HookInput, output: { options: Record<string, unknown> }) => {+ if (isOmniRushModel(input) && SMALL_AGENTS.has(input.agent ?? "")) {+ // The model-level default must not override the small request's own effort.+ const first = firstVariantEffort(input);+ if (first) output.options.reasoningEffort = first;+ else delete output.options.reasoningEffort;+ }if (!isInternalModel(input)) return;const effort = optionEffort(output.options) ?? normalizeEffort(input.message?.model?.variant);if (!effort) return;diff --git a/apps/server/src/web-search.test.ts b/apps/server/src/web-search.test.tsindex 15151994..57dedae8 100644--- a/apps/server/src/web-search.test.ts+++ b/apps/server/src/web-search.test.ts@@ -111,7 +111,7 @@ describe("engine config", () => {]) {expect(JSON.stringify(buildOmniRushRuntimeConfigObjectFromSnapshot({}, gateway, {}, catalog, undefined, undefined, setting))).toBe(before);}- for (const model of Object.values(engineModelsFromCatalog(catalog))) expect(model.options).toBeUndefined();+ for (const model of Object.values(engineModelsFromCatalog(catalog))) expect(model.options).not.toHaveProperty("hostedWebSearch");});test("on: hostedWebSearch only on the models the server lists; nothing else changes", () => {@@ -119,11 +119,12 @@ describe("engine config", () => {const off = buildOmniRushRuntimeConfigObjectFromSnapshot({}, gateway, {}, catalog) as { provider: { omnirush: { models: Record<string, Record<string, unknown>> } } };const on = buildOmniRushRuntimeConfigObjectFromSnapshot({}, gateway, {}, catalog, undefined, undefined, setting) as typeof off;const models = on.provider.omnirush.models;- for (const id of serverBlock.models) expect(models[id]!.options).toEqual({ hostedWebSearch: { searchContextSize: "low" } });- for (const id of ["meta-muse-spark", "muse-spark-1.1", "muse-spark-1.3"]) expect(models[id]!.options).toBeUndefined();+ for (const id of serverBlock.models) expect(models[id]!.options).toEqual({ reasoningEffort: "xhigh", hostedWebSearch: { searchContextSize: "low" } });+ for (const id of ["meta-muse-spark", "muse-spark-1.1", "muse-spark-1.3"]) expect(models[id]!.options).toEqual({ reasoningEffort: "xhigh" });for (const [id, model] of Object.entries(models)) {- const { options: _options, ...rest } = model;- expect([id, rest]).toEqual([id, off.provider.omnirush.models[id]]);+ // Only hostedWebSearch is added; the default effort and the rest stay as they were.+ const { hostedWebSearch: _search, ...options } = model.options as Record<string, unknown>;+ expect([id, { ...model, options } as Record<string, unknown>]).toEqual([id, off.provider.omnirush.models[id]!]);}const strip = (config: typeof off) => JSON.stringify({ ...config, provider: null });expect(strip(on)).toBe(strip(off));