From 6ac832e2fdf23d8618dea77df0a717c7ebad2759 Mon Sep 17 00:00:00 2001 From: Sanchit Rk <0xsanchit@gmail.com> Date: Wed, 11 Nov 2026 17:31:51 +0530 Subject: [PATCH 1/3] feat(harness): pick a model from configured providers when settings name none Drop the hardcoded openai/gpt-5.6-luna default. A session runs the model its runtime or settings name; otherwise the first preferred model a configured provider has, then that provider's first model. With neither, a run fails with Runner.NoModelError, and model.list leaves out its default. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/components/model.tsx | 24 +++++---- apps/widget/src/codework.ts | 23 +++++---- packages/codework/src/cli/error.ts | 9 ++++ packages/codework/src/server/contract.ts | 27 +++++----- packages/codework/src/server/handlers.ts | 22 +++++--- .../test/__artifacts__/acp.custom-models.json | 3 +- .../test/__artifacts__/acp.models.json | 3 +- .../test/__artifacts__/server.model-list.json | 8 +-- packages/codework/test/acp.test.ts | 2 + packages/codework/test/desktop.test.ts | 4 +- packages/codework/test/plugin.cmd.test.ts | 3 +- packages/codework/test/server.test.ts | 12 +++-- packages/codework/test/sync.test.ts | 7 ++- packages/codework/test/utils/model.ts | 2 + packages/harness/src/model/catalog.ts | 51 ++++++++++++++++++- packages/harness/src/runner/run.ts | 7 +++ packages/harness/src/session/failure.ts | 2 + packages/harness/src/settings/resolve.ts | 15 +++--- packages/harness/src/state/state.ts | 22 ++++++-- .../harness/test/fixtures/instruction.spec.ts | 2 + packages/harness/test/fixtures/model.ts | 13 +++++ .../test/fixtures/runner.cycle.spec.ts | 2 + packages/harness/test/fixtures/settings.ts | 10 +++- packages/harness/test/fixtures/skill.spec.ts | 2 + packages/harness/test/plugin.external.test.ts | 11 ++-- .../harness/test/plugin.instruction.test.ts | 3 +- packages/harness/test/plugin.passes.test.ts | 9 +++- packages/harness/test/plugin.skill.test.ts | 3 +- packages/harness/test/runner.loop.test.ts | 12 ++--- .../harness/test/settings.hostdir.test.ts | 6 ++- packages/harness/test/settings.llm.test.ts | 1 + packages/harness/test/settings.loop.test.ts | 14 +++-- .../harness/test/settings.resolve.test.ts | 10 ++-- packages/harness/test/settings.test.ts | 4 +- packages/harness/test/store.test.ts | 4 +- packages/harness/test/thread.test.ts | 4 +- .../harness/test/tools.toolsearch.test.ts | 4 +- packages/plugin/src/settings.ts | 5 +- 38 files changed, 267 insertions(+), 98 deletions(-) create mode 100644 packages/codework/test/utils/model.ts create mode 100644 packages/harness/test/fixtures/model.ts diff --git a/apps/web/src/components/model.tsx b/apps/web/src/components/model.tsx index 8bc2b3bf..b1df5224 100644 --- a/apps/web/src/components/model.tsx +++ b/apps/web/src/components/model.tsx @@ -101,12 +101,14 @@ export function useModelName(hostDir: string | undefined, value: ModelRef | unde if (list !== undefined) { const found = lookup(list.providers, current); if (found !== undefined) return found.model.name; + const fallback = list.default; if ( - current.provider === list.default.provider && - current.id === list.default.id && - list.default.name !== undefined + fallback !== undefined && + current.provider === fallback.provider && + current.id === fallback.id && + fallback.name !== undefined ) { - return list.default.name; + return fallback.name; } } return current.id; @@ -145,15 +147,16 @@ function Models({ hostDir, value, onChange }: ModelPickerProps) { // in view, unavailable, so the model a session gets by default never silently drops out of sight. const usable = list?.providers.map((provider) => ({ ...provider, available: true })) ?? []; // With nothing to call, there is no model to keep in view either. + const fallback = list?.default; const providers: ReadonlyArray = - list === undefined || usable.length === 0 || lookup(usable, list.default) !== undefined + fallback === undefined || usable.length === 0 || lookup(usable, fallback) !== undefined ? usable : [ - ...usable.filter((provider) => provider.id !== list.default.provider), + ...usable.filter((provider) => provider.id !== fallback.provider), { - id: list.default.provider, - name: list.default.providerName ?? list.default.provider, - models: [{ id: list.default.id, name: list.default.name ?? list.default.id, thinkingLevels: [] }], + id: fallback.provider, + name: fallback.providerName ?? fallback.provider, + models: [{ id: fallback.id, name: fallback.name ?? fallback.id, thinkingLevels: [] }], available: false, }, ]; @@ -373,7 +376,8 @@ function Thinking({ hostDir, model, value, onChange }: ThinkingPickerProps) { const levels = list === undefined || current === undefined ? [] : (lookup(list.providers, current)?.model.thinkingLevels ?? []); const picked = useRef(null); - const shown = list === undefined ? undefined : clamp(value ?? list.default.thinkingLevel, levels); + const level = value ?? list?.default?.thinkingLevel; + const shown = level === undefined ? undefined : clamp(level, levels); const choosable = shown !== undefined && levels.some((level) => level !== "off"); return ( diff --git a/apps/widget/src/codework.ts b/apps/widget/src/codework.ts index 732670e1..d2bae8da 100644 --- a/apps/widget/src/codework.ts +++ b/apps/widget/src/codework.ts @@ -333,17 +333,22 @@ export const ModelProvider = Schema.Struct({ }); export type ModelProvider = typeof ModelProvider.Type; -/** What `model.list` answers: the usable providers, and the model settings pick when none is chosen. */ +/** + * What `model.list` answers: the usable providers, and the model a session runs when none is chosen, + * absent when settings name none and no provider is configured. + */ export const ModelList = Schema.Struct({ providers: Schema.Array(ModelProvider), - default: Schema.Struct({ - provider: Schema.String, - id: Schema.String, - thinkingLevel: ThinkingLevel, - /** Display names from the catalog, present even when its provider is not listed. */ - name: Schema.optionalKey(Schema.String), - providerName: Schema.optionalKey(Schema.String), - }), + default: Schema.optionalKey( + Schema.Struct({ + provider: Schema.String, + id: Schema.String, + thinkingLevel: ThinkingLevel, + /** Display names from the catalog, present even when its provider is not listed. */ + name: Schema.optionalKey(Schema.String), + providerName: Schema.optionalKey(Schema.String), + }), + ), }); export type ModelList = typeof ModelList.Type; diff --git a/packages/codework/src/cli/error.ts b/packages/codework/src/cli/error.ts index 4cf365d9..82387abe 100644 --- a/packages/codework/src/cli/error.ts +++ b/packages/codework/src/cli/error.ts @@ -35,6 +35,7 @@ const isProviderError = Schema.is(Runner.ProviderError); const isModelCatalogError = Schema.is(Runner.ModelCatalogError); const isModelCatalogRefreshError = Schema.is(ModelCatalog.RefreshError); const isModelNotFoundError = Schema.is(Runner.ModelNotFoundError); +const isNoModelError = Schema.is(Runner.NoModelError); const isLLMStreamError = Schema.is(Runner.LLMStreamError); const isSandboxProviderError = Schema.is(SandboxProvider.SandboxProviderError); const isPluginInstallError = Schema.is(Plugin.InstallError); @@ -298,6 +299,14 @@ export const renderError = (error: unknown): string => { ].join("\n") + "\n" ); } + if (isNoModelError(error)) { + return ( + [ + `error[no-model-error]: ${error.message}`, + "hint: set a provider API key, run `codework auth login`, or set model.provider and model.id in settings", + ].join("\n") + "\n" + ); + } if (isLLMStreamError(error)) { return `error[llm-stream-error]: ${error.message}\n`; } diff --git a/packages/codework/src/server/contract.ts b/packages/codework/src/server/contract.ts index 405d9b2e..7b38ddf3 100644 --- a/packages/codework/src/server/contract.ts +++ b/packages/codework/src/server/contract.ts @@ -560,23 +560,26 @@ export const Api = RpcGroup.make( }), /** * The models a session anchored at `hostDir` can use: providers this server holds credentials - * for, in the catalog plus that project's settings, and the model settings pick when a session - * names none. Without `hostDir`, only the user's settings apply. Credentials are checked for - * presence, not validity. + * for, in the catalog plus that project's settings, and the model a session runs when it names + * none: the one settings name, else one picked from those providers. `default` is absent when + * neither gives one. Without `hostDir`, only the user's settings apply. Credentials are checked + * for presence, not validity. */ Rpc.make("model.list", { payload: { hostDir: optional(Session.AbsolutePath) }, success: Schema.Struct({ providers: Schema.Array(ModelProvider), - default: Schema.Struct({ - provider: Schema.String, - id: Schema.String, - /** As settings name it; a run clamps it to what the model supports. */ - thinkingLevel: Schema.Enum(Model.ThinkingLevelEnum), - /** Display names from the catalog, present even when its provider is not listed. */ - name: optional(Schema.String), - providerName: optional(Schema.String), - }), + default: optional( + Schema.Struct({ + provider: Schema.String, + id: Schema.String, + /** As settings name it; a run clamps it to what the model supports. */ + thinkingLevel: Schema.Enum(Model.ThinkingLevelEnum), + /** Display names from the catalog, present even when its provider is not listed. */ + name: optional(Schema.String), + providerName: optional(Schema.String), + }), + ), }), error: Schema.Union([Settings.SettingsError, Runner.ModelCatalogError]), }), diff --git a/packages/codework/src/server/handlers.ts b/packages/codework/src/server/handlers.ts index 7b3857ad..b8f2386e 100644 --- a/packages/codework/src/server/handlers.ts +++ b/packages/codework/src/server/handlers.ts @@ -289,10 +289,13 @@ export const layer = Contract.Api.toLayer( const filter = hostDir === undefined ? {} : { hostDir }; const settings = yield* Settings.Service; const loaded = yield* settings.load(hostDir); - const { model } = loaded; const providers = yield* ModelCatalog.available(filter); + const chosen = yield* ModelCatalog.selected(loaded, hostDir); // Named from the whole catalog, so a default without credentials still reads as itself. - const entry = (yield* ModelCatalog.effective(loaded.models))[model.provider]?.[model.id]; + const entry = + chosen === undefined + ? undefined + : (yield* ModelCatalog.effective(loaded.models))[chosen.provider]?.[chosen.id]; return { providers: providers.flatMap((provider) => { const models = Object.values(provider.models); @@ -311,12 +314,15 @@ export const layer = Contract.Api.toLayer( }, ]; }), - default: { - provider: model.provider, - id: model.id, - thinkingLevel: model.thinkingLevel, - ...(entry === undefined ? {} : { name: entry.name, providerName: entry.provider.name }), - }, + ...(chosen === undefined + ? {} + : { + default: { + ...chosen, + thinkingLevel: loaded.model.thinkingLevel, + ...(entry === undefined ? {} : { name: entry.name, providerName: entry.provider.name }), + }, + }), }; }), "project.remote": Effect.fnUntraced(function* ({ projectId }) { diff --git a/packages/codework/test/__artifacts__/acp.custom-models.json b/packages/codework/test/__artifacts__/acp.custom-models.json index 82389104..ecade102 100644 --- a/packages/codework/test/__artifacts__/acp.custom-models.json +++ b/packages/codework/test/__artifacts__/acp.custom-models.json @@ -22,12 +22,11 @@ } }, "userOnly": { - "current": "openai/gpt-5.6-luna", + "current": "openrouter/moonshotai/kimi-k2.7-code", "thinking": "medium", "providers": [ "gateway", "ollama", - "openai", "openrouter" ], "haiku": "OpenRouter: User Haiku" diff --git a/packages/codework/test/__artifacts__/acp.models.json b/packages/codework/test/__artifacts__/acp.models.json index 245b0834..4caaeea1 100644 --- a/packages/codework/test/__artifacts__/acp.models.json +++ b/packages/codework/test/__artifacts__/acp.models.json @@ -8,10 +8,9 @@ "thinking": "low" }, "withoutProjectSettings": { - "current": "openai/gpt-5.6-luna", + "current": "github-copilot/gpt-6.1-sol", "providers": [ "github-copilot", - "openai", "openrouter" ], "thinking": "medium" diff --git a/packages/codework/test/__artifacts__/server.model-list.json b/packages/codework/test/__artifacts__/server.model-list.json index f1b3115b..65dc588b 100644 --- a/packages/codework/test/__artifacts__/server.model-list.json +++ b/packages/codework/test/__artifacts__/server.model-list.json @@ -4,11 +4,11 @@ "anthropic" ], "default": { - "provider": "openai", - "id": "gpt-5.6-luna", + "provider": "anthropic", + "id": "claude-opus-5-5", "thinkingLevel": "medium", - "name": "GPT-5.6 Luna", - "providerName": "OpenAI" + "name": "Claude Opus 5.5", + "providerName": "Anthropic" } }, "project": { diff --git a/packages/codework/test/acp.test.ts b/packages/codework/test/acp.test.ts index be7a3fb6..d2f47620 100644 --- a/packages/codework/test/acp.test.ts +++ b/packages/codework/test/acp.test.ts @@ -14,6 +14,7 @@ import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; import { afterAll, describe, expect, it } from "vite-plus/test"; import { streaming, toolCalls } from "./fixtures/cli.ts"; +import { testModel } from "./utils/model.ts"; const cli = fileURLToPath(new URL("../src/index.ts", import.meta.url)); const models = fileURLToPath(new URL("../../../models.gen.json", import.meta.url)); @@ -250,6 +251,7 @@ describe("codework acp", () => { it("answers the protocol surface over stdio", () => { const { home, project } = workspace(); + writeFileSync(join(home, "settings.jsonc"), JSON.stringify({ model: testModel })); return run( withAgent(home, (acp) => Effect.gen(function* () { diff --git a/packages/codework/test/desktop.test.ts b/packages/codework/test/desktop.test.ts index 21515896..80f22e72 100644 --- a/packages/codework/test/desktop.test.ts +++ b/packages/codework/test/desktop.test.ts @@ -5,7 +5,7 @@ import { HttpServer } from "effect/http"; import { RpcClient, RpcSerialization } from "effect/rpc"; import { Socket } from "effect/socket"; import { spawn } from "node:child_process"; -import { mkdtempSync, rmSync } from "node:fs"; +import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { createInterface } from "node:readline"; @@ -17,6 +17,7 @@ import { Json, threadKey, topics, type ThreadRef } from "../../../apps/web/src/w import { immediateOpen } from "../../harness/test/fixtures/llm.ts"; import * as Client from "../src/server/client.ts"; import * as Server from "../src/server/server.ts"; +import { testModel } from "./utils/model.ts"; const protocol = (url: string) => RpcClient.layerProtocolSocket().pipe( @@ -27,6 +28,7 @@ const protocol = (url: string) => it("desktop keeps fork history, configuration and prompts separate from main", async () => { const home = mkdtempSync(join(tmpdir(), "codework-desktop-threads-")); + writeFileSync(join(home, "settings.jsonc"), JSON.stringify({ model: testModel })); try { const artifact = await Effect.gen(function* () { const listener = yield* HttpServer.HttpServer; diff --git a/packages/codework/test/plugin.cmd.test.ts b/packages/codework/test/plugin.cmd.test.ts index d3fb5ee9..f564bd8f 100644 --- a/packages/codework/test/plugin.cmd.test.ts +++ b/packages/codework/test/plugin.cmd.test.ts @@ -20,6 +20,7 @@ import { Effect } from "effect"; import { describe, expect, it } from "vite-plus/test"; import { immediateOpen } from "../../harness/test/fixtures/llm.ts"; import { NAME, npmrc, withRegistry } from "../../harness/test/fixtures/registry.ts"; +import { testModel } from "./utils/model.ts"; // The runtime half of an E2E boots the harness in-process, which reads the workspace catalog. process.env.CODEWORK_MODELS_FILE ??= fileURLToPath(new URL("../../../models.gen.json", import.meta.url)); @@ -119,7 +120,7 @@ const exchanges = async ( Effect.gen(function* () { const sessions = new Map>>(); for (const hostDir of hostDirs) { - const session = sessions.get(hostDir) ?? (yield* Session.create({ hostDir })); + const session = sessions.get(hostDir) ?? (yield* Session.create({ hostDir, model: testModel })); sessions.set(hostDir, session); yield* session.main.prompt({ text: "go", delivery: "followUp" }); yield* session.main.resume(); diff --git a/packages/codework/test/server.test.ts b/packages/codework/test/server.test.ts index 5b4fdd7e..6e9d83d7 100644 --- a/packages/codework/test/server.test.ts +++ b/packages/codework/test/server.test.ts @@ -563,7 +563,7 @@ describe("server", () => { ); }, 60_000); - it("model.list lists credentialed providers and the settings default, per project", () => { + it("model.list lists credentialed providers and the default model, per project", () => { const root = realpathSync(mkdtempSync(join(tmpdir(), "codework-server-models-"))); homes.push(root); const project = join(root, "project"); @@ -621,12 +621,14 @@ describe("server", () => { message: invalid.message.replaceAll(root, ""), }, }; - expect(artifact.user.default).toMatchObject({ - provider: "openai", - id: "gpt-5.6-luna", + // No model in settings: the logged-in provider's preferred model. + expect(artifact.user.default).toEqual({ + provider: "anthropic", + id: "claude-opus-5-5", thinkingLevel: "medium", + name: "Claude Opus 5.5", + providerName: "Anthropic", }); - expect(artifact.user.default.providerName).toBe("OpenAI"); expect(artifact.user.providers).toContain("anthropic"); expect(artifact.user.providers).not.toContain("local"); expect(artifact.project.local).toEqual({ diff --git a/packages/codework/test/sync.test.ts b/packages/codework/test/sync.test.ts index a912a8a6..ab66228a 100644 --- a/packages/codework/test/sync.test.ts +++ b/packages/codework/test/sync.test.ts @@ -3,7 +3,7 @@ import { createAssistantMessageEventStream, type Message } from "@codeworksh/aik import { Effect, Layer, Queue, Stream } from "effect"; import { Session } from "@codeworksh/harness/effect"; import { HttpServer } from "effect/http"; -import { mkdtempSync, realpathSync, rmSync } from "node:fs"; +import { mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { expect, it } from "vite-plus/test"; @@ -12,11 +12,13 @@ import { assistant, immediateOpen } from "../../harness/test/fixtures/llm.ts"; import * as Client from "../src/server/client.ts"; import type { IndexItem, ThreadItem } from "../src/server/contract.ts"; import * as Server from "../src/server/server.ts"; +import { testModel } from "./utils/model.ts"; type Synced = Extract; it("index.sync sends the index, resumes from a revision, and follows configure, rename and delete", async () => { const home = realpathSync(mkdtempSync(join(tmpdir(), "codework-sync-index-"))); + writeFileSync(join(home, "settings.jsonc"), JSON.stringify({ model: testModel })); try { const artifact = await Effect.gen(function* () { const listener = yield* HttpServer.HttpServer; @@ -141,6 +143,7 @@ it("index.sync sends the index, resumes from a revision, and follows configure, it("updatedAt moves a thread with any change to it or below it, and its session with its own row or a new thread", async () => { const home = realpathSync(mkdtempSync(join(tmpdir(), "codework-sync-updated-"))); + writeFileSync(join(home, "settings.jsonc"), JSON.stringify({ model: testModel })); try { const artifact = await Effect.gen(function* () { const listener = yield* HttpServer.HttpServer; @@ -303,6 +306,7 @@ type ThreadSynced = Extract; it("thread.sync opens a fork's line within a budget, resumes from a revision, and streams live deltas", async () => { const home = realpathSync(mkdtempSync(join(tmpdir(), "codework-sync-thread-"))); + writeFileSync(join(home, "settings.jsonc"), JSON.stringify({ model: testModel })); let release = () => {}; const held = new Promise((resolve) => { release = resolve; @@ -489,6 +493,7 @@ it("thread.sync opens a fork's line within a budget, resumes from a revision, an it("thread.page reads a fork's line below thread.sync's floor, page by page, within a budget", async () => { const home = realpathSync(mkdtempSync(join(tmpdir(), "codework-sync-page-"))); + writeFileSync(join(home, "settings.jsonc"), JSON.stringify({ model: testModel })); try { const artifact = await Effect.gen(function* () { const listener = yield* HttpServer.HttpServer; diff --git a/packages/codework/test/utils/model.ts b/packages/codework/test/utils/model.ts new file mode 100644 index 00000000..83546bd1 --- /dev/null +++ b/packages/codework/test/utils/model.ts @@ -0,0 +1,2 @@ +/** The model tests run: settings or the session must name one, as no provider is configured in a test. */ +export const testModel = { provider: "openai", id: "gpt-5.6-luna" } as const; diff --git a/packages/harness/src/model/catalog.ts b/packages/harness/src/model/catalog.ts index 013f9694..ee9a3774 100644 --- a/packages/harness/src/model/catalog.ts +++ b/packages/harness/src/model/catalog.ts @@ -19,7 +19,7 @@ import { getOpenAICodexApiKey, JsonOpenAICodexAuthStorage } from "@codeworksh/ai import { Clock, Config, Context, Duration, Effect, Layer, Option, Ref, Schedule, Schema } from "effect"; import { fileSystem, hostPath } from "../host.ts"; import * as Runner from "../runner/run.ts"; -import { type DeclaredModel, keyName } from "../settings/schema.ts"; +import { type DeclaredModel, type Info, keyName } from "../settings/schema.ts"; import * as Settings from "../settings/settings.ts"; export const filename = "models.gen.json"; @@ -333,3 +333,52 @@ export const available = Effect.fn("ModelCatalog.available")(function* ( } return usable; }); + +/** The model each provider starts on, tried in this order when settings name none. */ +const preferred: ReadonlyArray = [ + ["anthropic", "claude-opus-5-5"], + ["openai", "gpt-6.1-sol"], + ["openai-codex", "gpt-6.1-sol"], + ["nvidia", "nvidia/nemotron-3.5-super-vl-120b-a12b"], + ["deepseek", "deepseek-v4-pro"], + ["google", "gemini-4-argon"], + ["google-vertex", "gemini-4-argon"], + ["github-copilot", "gpt-6.1-sol"], + ["openrouter", "moonshotai/kimi-k2.7-code"], + ["xai", "grok-4.7"], + ["zai", "glm-5.3"], + ["minimax", "MiniMax-M3"], + ["minimax-cn", "MiniMax-M3"], + ["moonshotai", "kimi-k2.7-code"], + ["moonshotai-cn", "kimi-k2.7-code"], + ["huggingface", "moonshotai/Kimi-K2.7-Code"], + ["baseten", "zai-org/GLM-5.3"], + ["opencode", "kimi-k2.7-code"], + ["opencode-go", "kimi-k3.1-pro"], + ["meta", "muse-spark-1.3"], + ["cloudflare-workers-ai", "@cf/moonshotai/kimi-k2.7-code"], + ["xiaomi", "mimo-v2.6-pro"], + ["xiaomi-token-plan-cn", "mimo-v2.6-pro"], + ["xiaomi-token-plan-ams", "mimo-v2.6-pro"], + ["xiaomi-token-plan-sgp", "mimo-v2.6-pro"], +]; + +/** + * The model a session runs when nothing at runtime names one: the one settings name, else the first + * {@link preferred} model a logged-in provider has, else that provider list's first model. Undefined + * when settings name none and no provider is logged in. + */ +export const selected = Effect.fn("ModelCatalog.selected")(function* (settings: Info, hostDir?: string) { + const { provider, id } = settings.model; + if (provider !== undefined && id !== undefined) return { provider, id }; + const usable = yield* available(hostDir === undefined ? {} : { hostDir }); + const match = preferred.find(([name, model]) => usable.some((one) => one.id === name && model in one.models)); + if (match !== undefined) return { provider: match[0], id: match[1] }; + for (const one of usable) { + const [first] = Object.keys(one.models); + if (first !== undefined) return { provider: one.id, id: first }; + } + return undefined; +}); + +export * as ModelCatalog from "./catalog.ts"; diff --git a/packages/harness/src/runner/run.ts b/packages/harness/src/runner/run.ts index ee3833da..fa944d4c 100644 --- a/packages/harness/src/runner/run.ts +++ b/packages/harness/src/runner/run.ts @@ -160,6 +160,12 @@ export class ModelNotFoundError extends Schema.TaggedError() } } +export class NoModelError extends Schema.TaggedError()("Runner.NoModelError", {}) { + override get message(): string { + return "no model available: no model is set in settings and no provider is configured"; + } +} + export class LLMStreamError extends Schema.TaggedError()("Runner.LLMStreamError", { threadId: Schema.String, reason: Schema.String, @@ -172,6 +178,7 @@ export class LLMStreamError extends Schema.TaggedError()("Runner export type RunError = | ModelCatalogError | ModelNotFoundError + | NoModelError | ProviderError | LLMStreamError | ContextDecodeError diff --git a/packages/harness/src/session/failure.ts b/packages/harness/src/session/failure.ts index 96b20c9c..7276e757 100644 --- a/packages/harness/src/session/failure.ts +++ b/packages/harness/src/session/failure.ts @@ -54,6 +54,8 @@ const category = (tag: string): string => { return "model-catalog-error"; case "Runner.ModelNotFoundError": return "model-not-found-error"; + case "Runner.NoModelError": + return "no-model-error"; case "Runner.LLMStreamError": return "llm-stream-error"; case "ContextDecodeError": diff --git a/packages/harness/src/settings/resolve.ts b/packages/harness/src/settings/resolve.ts index 16d5ea4a..567bd279 100644 --- a/packages/harness/src/settings/resolve.ts +++ b/packages/harness/src/settings/resolve.ts @@ -98,11 +98,12 @@ const resolveControls = (settings: Info, block: Block, runtime: State.Options) = toolExecution: runtime.toolExecution ?? block.toolExecution ?? settings.model.toolExecution, }); -/** Pure configuration composition. Domain selections need not exist in the catalog. */ -export function compose(settings: Info, options: State.Options = {}, session: State.Options = {}) { - const runtime = merge(options, session); - const provider = runtime.provider ?? settings.model.provider; - const model = runtime.model ?? settings.model.id; - const block = collect(settings, provider, model); - return { provider, model, ...resolveControls(settings, block, runtime), block, runtime }; +/** Pure configuration composition for the chosen model. Domain selections need not exist in the catalog. */ +export function compose( + settings: Info, + chosen: { readonly provider: string; readonly id: string }, + runtime: State.Options = {}, +) { + const block = collect(settings, chosen.provider, chosen.id); + return { provider: chosen.provider, model: chosen.id, ...resolveControls(settings, block, runtime), block, runtime }; } diff --git a/packages/harness/src/state/state.ts b/packages/harness/src/state/state.ts index c3b72fb2..0f6ee37d 100644 --- a/packages/harness/src/state/state.ts +++ b/packages/harness/src/state/state.ts @@ -23,8 +23,9 @@ import { makeEvents, type PromptResolver } from "../plugin/context.ts"; import { run as setup } from "../plugin/host.ts"; import type { Plugin } from "../plugin/plugin.ts"; import * as Mcp from "../mcp/mcp.ts"; +import * as ModelCatalog from "../model/catalog.ts"; import * as LLM from "../runner/llm.ts"; -import type * as Runner from "../runner/run.ts"; +import * as Runner from "../runner/run.ts"; import { SandboxIO } from "../sandbox/io.ts"; import * as Document from "../document/document.ts"; import * as SessionRuntime from "../session/runtime.ts"; @@ -175,7 +176,11 @@ export interface Interface { threadId: ThreadSchema.ID, ) => Effect.Effect< Configuration, - Settings.SettingsError | Runner.ModelCatalogError | Runner.ModelNotFoundError | Runner.ProviderError + | Settings.SettingsError + | Runner.ModelCatalogError + | Runner.ModelNotFoundError + | Runner.NoModelError + | Runner.ProviderError >; /** * Capture runtime state for one request. Called inside a thread drain, @@ -189,6 +194,7 @@ export interface Interface { | Settings.SettingsError | Runner.ModelCatalogError | Runner.ModelNotFoundError + | Runner.NoModelError | Runner.ProviderError, SandboxIO.Provides | Location.Service >; @@ -261,6 +267,7 @@ export const layer = ( const events = makeEvents(eventService); const global = yield* Global.Service; const mcp = yield* Mcp.Service; + const credentials = yield* ModelCatalog.Credentials; /* * One load pass at a time, for the whole process. * @@ -368,7 +375,16 @@ export const layer = ( // Not wrapped: a file the user can fix is more useful to a client as a settings // failure carrying its path and key than as an anonymous snapshot failure. const loadedSettings = yield* settings.load(hostDir); - const composed = compose(loadedSettings, options, sessionOptions); + const bound = merge(options, sessionOptions); + const selection = + bound.provider !== undefined && bound.model !== undefined + ? { provider: bound.provider, id: bound.model } + : yield* ModelCatalog.selected(loadedSettings, hostDir).pipe( + Effect.provideService(ModelCatalog.Credentials, credentials), + Effect.provideService(Settings.Service, settings), + ); + if (selection === undefined) return yield* new Runner.NoModelError(); + const composed = compose(loadedSettings, selection, bound); const resolvedModel = yield* LLM.resolve({ provider: composed.provider, model: composed.model, diff --git a/packages/harness/test/fixtures/instruction.spec.ts b/packages/harness/test/fixtures/instruction.spec.ts index aeeac89f..9717e9bf 100644 --- a/packages/harness/test/fixtures/instruction.spec.ts +++ b/packages/harness/test/fixtures/instruction.spec.ts @@ -11,6 +11,7 @@ import * as Git from "../../src/git/git.ts"; import * as SandboxController from "../../src/sandbox/control.ts"; import { SandboxIO } from "../../src/sandbox/io.ts"; import { immediateOpen } from "./llm.ts"; +import { testModel } from "./model.ts"; const context = (text: string) => /\n[\s\S]*?\n<\/project_context>/.exec(text)?.[0]; @@ -37,6 +38,7 @@ const withHost = async (use: (host: Host) => Promise) => { }; try { await write(path.join(root, "home", "AGENTS.md"), "Home: never shown.\n"); + await write(path.join(root, "home", "settings.jsonc"), JSON.stringify({ model: testModel })); await write(path.join(root, "cwd", "AGENTS.md"), "Host cwd: never shown.\n"); await write(path.join(root, "anchor", "AGENTS.md"), "Host dir: never shown.\n"); await write(path.join(root, "anchor", ".codework", "settings.jsonc"), "{}"); diff --git a/packages/harness/test/fixtures/model.ts b/packages/harness/test/fixtures/model.ts new file mode 100644 index 00000000..3aa9ee30 --- /dev/null +++ b/packages/harness/test/fixtures/model.ts @@ -0,0 +1,13 @@ +import { Layer } from "effect"; +import * as ModelCatalog from "../../src/model/catalog.ts"; +import type { Info } from "../../src/settings/schema.ts"; +import * as Settings from "../../src/settings/settings.ts"; + +/** The model tests run: settings must name one, as no provider is configured in a test. */ +export const testModel = { provider: "openai", id: "gpt-5.6-luna" } as const; + +/** The built-in settings with {@link testModel} named, for tests that stub settings rather than read files. */ +export const named: Info = { ...Settings.defaults, model: { ...Settings.defaults.model, ...testModel } }; + +/** No stored logins: a test that names no model reaches the catalog through the environment only. */ +export const credentials = Layer.succeed(ModelCatalog.Credentials, { authFile: "/unused/home/aikit/auth.json" }); diff --git a/packages/harness/test/fixtures/runner.cycle.spec.ts b/packages/harness/test/fixtures/runner.cycle.spec.ts index 9ef24272..ec5a89b0 100644 --- a/packages/harness/test/fixtures/runner.cycle.spec.ts +++ b/packages/harness/test/fixtures/runner.cycle.spec.ts @@ -33,6 +33,7 @@ import * as State from "../../src/state/state.ts"; import { pooled } from "./pool.ts"; import * as Mcp from "../../src/mcp/mcp.ts"; import * as Process from "../../src/sandbox/utils/process.ts"; +import { credentials } from "./model.ts"; const database = Database.layer(":memory:"); const vercel = VercelSandboxDriver.make(); @@ -46,6 +47,7 @@ const runtime = (root: string, custom: string) => Layer.provideMerge( ((seeded) => State.layer({}, seeded.ref, seeded.references, seeded.follow, seeded.rebuild))(pooled(builtins)), ), + Layer.provideMerge(credentials), Layer.provideMerge(Mcp.layer({ hostCwd: "/", home: "/unused/home" }).pipe(Layer.provide(Process.host))), Layer.provideMerge(SessionRuntime.layer), Layer.provideMerge( diff --git a/packages/harness/test/fixtures/settings.ts b/packages/harness/test/fixtures/settings.ts index 5a5dad5c..0b103df2 100644 --- a/packages/harness/test/fixtures/settings.ts +++ b/packages/harness/test/fixtures/settings.ts @@ -1,7 +1,12 @@ -import { mkdir, mkdtemp, rm } from "node:fs/promises"; +import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join } from "node:path"; +import { testModel } from "./model.ts"; +/** + * A temp root with a project (`local`), a user config dir (`custom`) and a home (`global`). Both + * user settings files name {@link testModel}; a test replacing one names it too. + */ export const withSettings = async ( test: (input: { root: string; local: string; custom: string; global: string }) => Promise, ) => { @@ -11,6 +16,9 @@ export const withSettings = async ( const global = join(root, "home"); try { await Promise.all([local, custom, global].map((dir) => mkdir(dir, { recursive: true }))); + await Promise.all( + [global, custom].map((dir) => writeFile(join(dir, "settings.jsonc"), JSON.stringify({ model: testModel }))), + ); await test({ root, local, custom, global }); } finally { await rm(root, { recursive: true, force: true }); diff --git a/packages/harness/test/fixtures/skill.spec.ts b/packages/harness/test/fixtures/skill.spec.ts index 4c60e423..4159b87a 100644 --- a/packages/harness/test/fixtures/skill.spec.ts +++ b/packages/harness/test/fixtures/skill.spec.ts @@ -10,6 +10,7 @@ import * as Session from "../../src/effect/session.ts"; import * as SandboxController from "../../src/sandbox/control.ts"; import { SandboxIO } from "../../src/sandbox/io.ts"; import { immediateOpen } from "./llm.ts"; +import { testModel } from "./model.ts"; const skills = (text: string) => /\n[\s\S]*?\n<\/skills>/.exec(text)?.[0]; @@ -35,6 +36,7 @@ const withHost = async (use: (host: Host) => Promise) => { await fs.writeFile(file, text); }; try { + await write(path.join(root, "home", "settings.jsonc"), JSON.stringify({ model: testModel })); await write( path.join(root, "home", ".codework", "skills", "home-skill", "SKILL.md"), "---\nname: home-skill\ndescription: Home: never shown.\n---\n", diff --git a/packages/harness/test/plugin.external.test.ts b/packages/harness/test/plugin.external.test.ts index 039f107d..cc0eefc1 100644 --- a/packages/harness/test/plugin.external.test.ts +++ b/packages/harness/test/plugin.external.test.ts @@ -18,6 +18,7 @@ import { defaultPromptPlugin } from "../src/plugin/builtin/prompt/default.ts"; import { immediateOpen, toolTurn } from "./fixtures/llm.ts"; import { withSettings } from "./fixtures/settings.ts"; import { pendingCall } from "./tools.fixture.ts"; +import { testModel } from "./fixtures/model.ts"; /** * Third-party plugins as they exist in production: TypeScript modules loaded by @@ -75,7 +76,10 @@ describe("third-party plugins", () => { // Settings entries land after the built-ins, so this tool's entry is written after the // prompt plugin's. Domain order decides setup order, so the tool still registers first // and the prompt that indexes tools sees it — which is the whole point of `kind`. - await writeFile(join(custom, "settings.jsonc"), JSON.stringify({ plugins: [pluginPath("tool/acme-echo")] })); + await writeFile( + join(custom, "settings.jsonc"), + JSON.stringify({ model: testModel, plugins: [pluginPath("tool/acme-echo")] }), + ); const { contexts, prompts } = await exchange({ root, userConfigDir: custom }); expect(contexts[0]?.tools?.map((entry) => entry.name)).toEqual(["bash", "read", "write", "edit", "acme_echo"]); expect(prompts[0]).toContain("- acme_echo: Echo a value back"); @@ -86,7 +90,7 @@ describe("third-party plugins", () => { // The broken plugin would fail preparation if settings still contributed. await writeFile( join(custom, "settings.jsonc"), - JSON.stringify({ plugins: [pluginPath("host/acme-broken.ts")] }), + JSON.stringify({ model: testModel, plugins: [pluginPath("host/acme-broken.ts")] }), ); const { contexts, prompts } = await exchange({ root, userConfigDir: custom, plugins: [] }); expect(contexts[0]?.tools ?? []).toEqual([]); @@ -99,7 +103,7 @@ describe("third-party plugins", () => { withSettings(async ({ root, custom }) => { await writeFile( join(custom, "settings.jsonc"), - JSON.stringify({ plugins: [pluginPath("host/acme-broken.ts")] }), + JSON.stringify({ model: testModel, plugins: [pluginPath("host/acme-broken.ts")] }), ); let calls = 0; await expect( @@ -359,6 +363,7 @@ describe("opt-in built-ins", () => { await writeFile( join(custom, "settings.jsonc"), JSON.stringify({ + model: testModel, plugins: [ { plugin: "codework.tool.grep", enabled: true }, { plugin: "codework.tool.ls", enabled: true }, diff --git a/packages/harness/test/plugin.instruction.test.ts b/packages/harness/test/plugin.instruction.test.ts index f764ff1e..9815f305 100644 --- a/packages/harness/test/plugin.instruction.test.ts +++ b/packages/harness/test/plugin.instruction.test.ts @@ -19,6 +19,7 @@ import * as Space from "../src/space/space.ts"; import { scenario } from "./fixtures/instruction.spec.ts"; import { immediateOpen } from "./fixtures/llm.ts"; import { withSettings } from "./fixtures/settings.ts"; +import { testModel } from "./fixtures/model.ts"; const exec = promisify(execFile); const git = (cwd: string, ...args: string[]) => @@ -227,7 +228,7 @@ describe("codework.prompt.instruction", () => { await write(join(root, "repo", "AGENTS.md"), "Repo.\n"); await write( join(root, "home", "settings.jsonc"), - JSON.stringify({ plugins: [{ plugin: "codework.prompt.instruction", enabled: false }] }), + JSON.stringify({ model: testModel, plugins: [{ plugin: "codework.prompt.instruction", enabled: false }] }), ); const text = await prompt({ root, directory: join(root, "repo"), hostCwd: root }); expect(text).toContain(""); diff --git a/packages/harness/test/plugin.passes.test.ts b/packages/harness/test/plugin.passes.test.ts index ddd7e47e..1b7db35b 100644 --- a/packages/harness/test/plugin.passes.test.ts +++ b/packages/harness/test/plugin.passes.test.ts @@ -14,6 +14,7 @@ import * as State from "../src/state/state.ts"; import { define } from "../src/plugin/plugin.ts"; import type { Fetchable } from "../src/plugin/source.ts"; import { immediateOpen } from "./fixtures/llm.ts"; +import { testModel } from "./fixtures/model.ts"; /* * The split: loading a module costs a store lookup and an ESM import, so it happens at boot and at @@ -50,6 +51,7 @@ const withProject = async (body: (dirs: { root: string; project: string }) => Pr const project = join(root, "project"); await mkdir(join(project, ".codework"), { recursive: true }); await mkdir(join(root, "home"), { recursive: true }); + await writeFile(join(root, "home", "settings.jsonc"), JSON.stringify({ model: testModel })); try { await body({ root, project }); } finally { @@ -304,7 +306,7 @@ describe("boot", () => { // boot, never a fetch. await writeFile( join(root, "home", "settings.jsonc"), - JSON.stringify({ plugins: ["@acme/never-published-anywhere"] }), + JSON.stringify({ model: testModel, plugins: ["@acme/never-published-anywhere"] }), ); const failure = await Effect.runPromise( @@ -646,7 +648,10 @@ describe("reload", () => { // layer, which is the only layer `reload` reads. const broken = join(project, "broken.mjs"); yield* Effect.promise(() => - writeFile(join(root, "home", "settings.jsonc"), JSON.stringify({ plugins: [broken] })), + writeFile( + join(root, "home", "settings.jsonc"), + JSON.stringify({ model: testModel, plugins: [broken] }), + ), ); yield* Effect.promise(() => writeFile(broken, "export default { nope: true };")); yield* state.reload; diff --git a/packages/harness/test/plugin.skill.test.ts b/packages/harness/test/plugin.skill.test.ts index 1547102f..eeed6891 100644 --- a/packages/harness/test/plugin.skill.test.ts +++ b/packages/harness/test/plugin.skill.test.ts @@ -25,6 +25,7 @@ import { immediateOpen, toolTurn } from "./fixtures/llm.ts"; import { withSettings } from "./fixtures/settings.ts"; import { scenario } from "./fixtures/skill.spec.ts"; import { pendingCall } from "./tools.fixture.ts"; +import { testModel } from "./fixtures/model.ts"; const exec = promisify(execFile); const git = (cwd: string, ...args: string[]) => @@ -418,7 +419,7 @@ describe("codework.prompt.skill", () => { ); await write( join(root, "home", "settings.jsonc"), - JSON.stringify({ plugins: [{ plugin: "codework.prompt.skill", enabled: false }] }), + JSON.stringify({ model: testModel, plugins: [{ plugin: "codework.prompt.skill", enabled: false }] }), ); const text = await prompt({ root, directory: dir, hostCwd: root }); diff --git a/packages/harness/test/runner.loop.test.ts b/packages/harness/test/runner.loop.test.ts index e050cbca..005bb7dc 100644 --- a/packages/harness/test/runner.loop.test.ts +++ b/packages/harness/test/runner.loop.test.ts @@ -40,6 +40,7 @@ import { seedSpace } from "./fixtures/space.ts"; import { testEffect } from "./utils/effect.ts"; import * as Mcp from "../src/mcp/mcp.ts"; import * as Process from "../src/sandbox/utils/process.ts"; +import { named, credentials } from "./fixtures/model.ts"; const runtime = ( options: { @@ -76,13 +77,14 @@ const runtime = ( pooled(options.plugins ?? plugins), ), ), + Layer.provideMerge(credentials), Layer.provideMerge(Mcp.layer({ hostCwd: "/", home: "/unused/home" }).pipe(Layer.provide(Process.host))), Layer.provideMerge(SessionRuntime.layer), Layer.provideMerge( Layer.succeed(Settings.Service, { load: () => Effect.suspend(() => options.beforeSettings?.run ?? Effect.void).pipe( - Effect.as(options.settings ?? Settings.defaults), + Effect.as(options.settings ?? named), ), locate: () => Effect.die("unused"), }), @@ -628,9 +630,7 @@ describe("runner loop — provider failure", () => { expect(Option.isSome(failure) && failure.value._tag).toBe("Runner.ProviderError"); if (Option.isSome(failure) && failure.value._tag === "Runner.ProviderError") { expect(failure.value.reason._tag).toBe("Runner.ProviderAuthenticationError"); - expect(failure.value.message).toBe( - `${Settings.defaults.model.provider}/${Settings.defaults.model.id}: provider failed`, - ); + expect(failure.value.message).toBe(`${named.model.provider}/${named.model.id}: provider failed`); } } @@ -716,8 +716,8 @@ const scripted = ( }; const settings = (retry: Partial): Info => ({ - ...Settings.defaults, - retry: { ...Settings.defaults.retry, ...retry }, + ...named, + retry: { ...named.retry, ...retry }, }); describe("runner loop — retry", () => { diff --git a/packages/harness/test/settings.hostdir.test.ts b/packages/harness/test/settings.hostdir.test.ts index 27167b33..203083a5 100644 --- a/packages/harness/test/settings.hostdir.test.ts +++ b/packages/harness/test/settings.hostdir.test.ts @@ -9,6 +9,7 @@ import * as Session from "../src/effect/session.ts"; import * as LLM from "../src/runner/llm.ts"; import { defaultPromptPlugin } from "../src/plugin/builtin/prompt/default.ts"; import { immediateOpen } from "./fixtures/llm.ts"; +import { testModel } from "./fixtures/model.ts"; /** * A session's settings come from the host directory the session was given, and from nothing else. @@ -43,7 +44,10 @@ const withProjects = async ( // The user layer. `home` is `--home`, so its settings file sits at the top level. // Every level written here is one the built-in default ("high") is not, so an // assertion names the file that was read rather than agreeing with the fallback. - writeFile(join(dirs.home, "settings.jsonc"), JSON.stringify({ model: { thinkingLevel: "off" } })), + writeFile( + join(dirs.home, "settings.jsonc"), + JSON.stringify({ model: { ...testModel, thinkingLevel: "off" } }), + ), level(dirs.alpha, "low"), level(dirs.beta, "medium"), level(dirs.outer, "max"), diff --git a/packages/harness/test/settings.llm.test.ts b/packages/harness/test/settings.llm.test.ts index 7ad4ca9e..e7bbe979 100644 --- a/packages/harness/test/settings.llm.test.ts +++ b/packages/harness/test/settings.llm.test.ts @@ -303,6 +303,7 @@ describe("settings at the LLM boundary", () => { }, }, }), + { provider: "lmstudio", id: "qwen/qwen3-coder-30b" }, ); const events = await Effect.runPromise( LLM.open( diff --git a/packages/harness/test/settings.loop.test.ts b/packages/harness/test/settings.loop.test.ts index 40581bc5..0622a292 100644 --- a/packages/harness/test/settings.loop.test.ts +++ b/packages/harness/test/settings.loop.test.ts @@ -14,12 +14,13 @@ import { defaults } from "../src/settings/schema.ts"; import * as Tool from "../src/tool/tool.ts"; import { defaultPromptPlugin } from "../src/plugin/builtin/prompt/default.ts"; import { assistant } from "./fixtures/llm.ts"; +import { testModel } from "./fixtures/model.ts"; import { withSettings } from "./fixtures/settings.ts"; const file = (dir: string, thinkingLevel: string) => writeFile( join(dir, "settings.jsonc"), - JSON.stringify({ model: { thinkingLevel, options: { headers: { revision: thinkingLevel } } } }), + JSON.stringify({ model: { ...testModel, thinkingLevel, options: { headers: { revision: thinkingLevel } } } }), ); const terminal = (input: LLM.Input, index: number, tool = false) => { @@ -137,7 +138,11 @@ describe("settings at turn boundaries", () => { writeFile( join(custom, "settings.jsonc"), JSON.stringify({ - model: { toolExecution: "sequential", providerOptions: { openai: { "*": { toolExecution } } } }, + model: { + ...testModel, + toolExecution: "sequential", + providerOptions: { openai: { "*": { toolExecution } } }, + }, }), ); await configure("parallel"); @@ -304,7 +309,7 @@ describe("settings at turn boundaries", () => { yield* Effect.promise(() => writeFile( join(custom, "settings.jsonc"), - JSON.stringify({ model: { options: { timeoutMs: "wrong" } } }), + JSON.stringify({ model: { ...testModel, options: { timeoutMs: "wrong" } } }), ), ); yield* handle.run("second"); @@ -472,7 +477,8 @@ describe("settings at turn boundaries", () => { it("tracks a settings file edited forward and reverted across successive runs", () => withSettings(async ({ root, custom }) => { - const write = (model: object) => writeFile(join(custom, "settings.jsonc"), JSON.stringify({ model })); + const write = (model: object) => + writeFile(join(custom, "settings.jsonc"), JSON.stringify({ model: { ...testModel, ...model } })); // A carries a header and a retry count that B does not mention at all. const A = { thinkingLevel: "low", options: { maxRetries: 7, headers: { only: "a" } } }; const B = { thinkingLevel: "high", options: { headers: { shared: "b" } } }; diff --git a/packages/harness/test/settings.resolve.test.ts b/packages/harness/test/settings.resolve.test.ts index 2f5030f8..7f089907 100644 --- a/packages/harness/test/settings.resolve.test.ts +++ b/packages/harness/test/settings.resolve.test.ts @@ -69,7 +69,7 @@ describe("settings resolution", () => { extras: { organization: "org" }, }); expect(base.model.options?.providerArray).toEqual(["one", "two"]); - expect(merge(defaults, patch).model.provider).toBe("openai"); + expect(merge(configured({ model: { provider: "openai" } }), patch).model.provider).toBe("openai"); }); it("routes harness controls separately and matches the runtime selection before resolving", () => { @@ -91,7 +91,7 @@ describe("settings resolution", () => { }, }, }); - const result = compose(settings, {}, { provider: "lmstudio", model: "qwen/model" }); + const result = compose(settings, { provider: "lmstudio", id: "qwen/model" }); expect(result).toMatchObject({ thinkingLevel: "off", toolExecution: "parallel", @@ -109,11 +109,11 @@ describe("settings resolution", () => { expect(resolveOverrides(result.block)).toEqual({ contextWindow: 1234 }); expect(request).not.toHaveProperty("contextWindow"); expect(request).not.toHaveProperty("thinkingLevel"); - expect(compose(settings).thinkingLevel).toBe("low"); + expect(compose(settings, { provider: "openai", id: "gpt-5.6-luna" }).thinkingLevel).toBe("low"); expect( - compose(settings, { thinkingLevel: "medium" }, { provider: "lmstudio", thinkingLevel: "high" }).thinkingLevel, + compose(settings, { provider: "lmstudio", id: "qwen/model" }, { thinkingLevel: "high" }).thinkingLevel, ).toBe("high"); - expect(compose(settings, { provider: "unknown", model: "missing" })).toMatchObject({ + expect(compose(settings, { provider: "unknown", id: "missing" })).toMatchObject({ provider: "unknown", model: "missing", }); diff --git a/packages/harness/test/settings.test.ts b/packages/harness/test/settings.test.ts index bd61dcd4..7557d40c 100644 --- a/packages/harness/test/settings.test.ts +++ b/packages/harness/test/settings.test.ts @@ -6,6 +6,7 @@ import * as Global from "../src/global.ts"; import * as Settings from "../src/settings/settings.ts"; import { parse } from "../src/settings/settings.ts"; +import { named } from "./fixtures/model.ts"; import { withSettings } from "./fixtures/settings.ts"; describe("host settings loader", () => { @@ -104,6 +105,7 @@ describe("host settings loader", () => { it("fails on a layer it cannot read", () => withSettings(async ({ root, local, global, custom }) => { + await unlink(join(global, "settings.jsonc")); await mkdir(join(global, "settings.jsonc")); await writeFile(join(local, "settings.jsonc"), JSON.stringify({ model: { thinkingLevel: "max" } })); await writeFile(join(custom, "settings.jsonc"), JSON.stringify({ model: { options: { maxRetries: 4 } } })); @@ -165,7 +167,7 @@ describe("host settings loader", () => { await Effect.runPromise( Effect.gen(function* () { const settings = yield* Settings.Service; - expect(yield* settings.load(root)).toEqual(Settings.defaults); + expect(yield* settings.load(root)).toEqual(named); // Replaced by the override, so never part of the result. yield* Effect.promise(() => write(global, { options: { timeoutMs: 100, headers: { global: "yes" } } })); yield* Effect.promise(() => write(local, { options: { timeoutMs: 200, headers: { local: "yes" } } })); diff --git a/packages/harness/test/store.test.ts b/packages/harness/test/store.test.ts index 5970c9ed..ab51b26a 100644 --- a/packages/harness/test/store.test.ts +++ b/packages/harness/test/store.test.ts @@ -40,6 +40,7 @@ import { pooled } from "./fixtures/pool.ts"; import { seedSpace } from "./fixtures/space.ts"; import { tmpdir } from "./fixtures/tempdir.ts"; import { testEffect } from "./utils/effect.ts"; +import { named, credentials } from "./fixtures/model.ts"; // The first request calls `echo`, every one after replies: one turn settles a tool call. let requests = 0; @@ -104,11 +105,12 @@ const layer = () => { ), ), Layer.provideMerge(State.layer({}, seeded.ref, seeded.references, seeded.follow, seeded.rebuild)), + Layer.provideMerge(credentials), Layer.provideMerge(Mcp.layer({ hostCwd: "/", home: "/unused/home" }).pipe(Layer.provide(Process.host))), Layer.provideMerge(SessionRuntime.layer), Layer.provideMerge( Layer.succeed(Settings.Service, { - load: () => Effect.succeed(Settings.defaults), + load: () => Effect.succeed(named), locate: () => Effect.die("unused"), }), ), diff --git a/packages/harness/test/thread.test.ts b/packages/harness/test/thread.test.ts index 59491d99..6711f938 100644 --- a/packages/harness/test/thread.test.ts +++ b/packages/harness/test/thread.test.ts @@ -38,6 +38,7 @@ import { seedSpace } from "./fixtures/space.ts"; import { testEffect } from "./utils/effect.ts"; import * as Mcp from "../src/mcp/mcp.ts"; import * as Process from "../src/sandbox/utils/process.ts"; +import { named, credentials } from "./fixtures/model.ts"; /** What the model is asked to do next, per thread: reply, call `find`, or wait on a gate. */ type Step = @@ -137,11 +138,12 @@ const layer = () => { ), ), Layer.provideMerge(State.layer({}, seeded.ref, seeded.references, seeded.follow, seeded.rebuild)), + Layer.provideMerge(credentials), Layer.provideMerge(Mcp.layer({ hostCwd: "/", home: "/unused/home" }).pipe(Layer.provide(Process.host))), Layer.provideMerge(SessionRuntime.layer), Layer.provideMerge( Layer.succeed(Settings.Service, { - load: () => Effect.succeed(Settings.defaults), + load: () => Effect.succeed(named), locate: () => Effect.die("unused"), }), ), diff --git a/packages/harness/test/tools.toolsearch.test.ts b/packages/harness/test/tools.toolsearch.test.ts index 147570d4..3b2b28e1 100644 --- a/packages/harness/test/tools.toolsearch.test.ts +++ b/packages/harness/test/tools.toolsearch.test.ts @@ -37,6 +37,7 @@ import { seedSpace } from "./fixtures/space.ts"; import { testEffect } from "./utils/effect.ts"; import * as Mcp from "../src/mcp/mcp.ts"; import * as Process from "../src/sandbox/utils/process.ts"; +import { named, credentials } from "./fixtures/model.ts"; /** * `toolsearch` end to end, against a scripted model: what a search loads, how the next request @@ -197,11 +198,12 @@ const layer = (tools: Plugin) => { ), ), Layer.provideMerge(State.layer({}, seeded.ref, seeded.references, seeded.follow, seeded.rebuild)), + Layer.provideMerge(credentials), Layer.provideMerge(Mcp.layer({ hostCwd: "/", home: "/unused/home" }).pipe(Layer.provide(Process.host))), Layer.provideMerge(SessionRuntime.layer), Layer.provideMerge( Layer.succeed(Settings.Service, { - load: () => Effect.succeed(Settings.defaults), + load: () => Effect.succeed(named), locate: () => Effect.die("unused"), }), ), diff --git a/packages/plugin/src/settings.ts b/packages/plugin/src/settings.ts index dd26b16a..cd6a95bf 100644 --- a/packages/plugin/src/settings.ts +++ b/packages/plugin/src/settings.ts @@ -236,9 +236,8 @@ export interface Info { * in this order, so for one `provider.id` + `id` the last entry wins. */ readonly models: ReadonlyArray; + /** Without `provider` and `id`, a session runs a model picked from the logged-in providers. */ readonly model: typeof Model.Type & { - readonly provider: string; - readonly id: string; readonly thinkingLevel: AikitModel.ThinkingLevel; readonly toolExecution: ToolExecution; }; @@ -252,8 +251,6 @@ export const defaults: Info = { declared: [], models: [], model: { - provider: "openai", - id: "gpt-5.6-luna", thinkingLevel: "medium", toolExecution: "sequential", options: { timeoutMs: 3_600_000, idleTimeoutMs: 300_000, maxRetries: 0 }, From f7ffc183709891ea0de35a9118981cf288b4e31d Mon Sep 17 00:00:00 2001 From: Sanchit Rk <0xsanchit@gmail.com> Date: Wed, 11 Nov 2026 17:31:51 +0530 Subject: [PATCH 2/3] fix(aikit): point the Copilot missing-key hint at GitHub Copilot sign-in Co-Authored-By: Claude Opus 5.5 --- packages/aikit/src/providers/github-copilot/copilot-fetch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aikit/src/providers/github-copilot/copilot-fetch.ts b/packages/aikit/src/providers/github-copilot/copilot-fetch.ts index a8fb4c3d..14b33fc4 100644 --- a/packages/aikit/src/providers/github-copilot/copilot-fetch.ts +++ b/packages/aikit/src/providers/github-copilot/copilot-fetch.ts @@ -23,7 +23,7 @@ async function resolveToken(apiKey: GitHubCopilotApiKey | undefined): Promise Date: Wed, 11 Nov 2026 17:31:51 +0530 Subject: [PATCH 3/3] feat(web): stack queued prompts as cards behind a notice above the composer Queued steers and follow-ups collapse into a card stack that opens on hover or focus without moving the conversation. A notice is the front card, tinted by its tone, with the queue behind it. Parked prompts show a pulsing dot, edits happen in place, and a prompt typed while another send is on its way is no longer cleared when that send lands. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/components/banner.tsx | 76 ++++++-- apps/web/src/widgets/session/composer.tsx | 18 +- apps/web/src/widgets/session/queue.tsx | 212 +++++++++++++++------- apps/web/src/widgets/session/view.tsx | 59 ++++-- 4 files changed, 255 insertions(+), 110 deletions(-) diff --git a/apps/web/src/components/banner.tsx b/apps/web/src/components/banner.tsx index 50a820cf..f5dffd27 100644 --- a/apps/web/src/components/banner.tsx +++ b/apps/web/src/components/banner.tsx @@ -44,34 +44,32 @@ const tones: Record tones[tone].surface; + /** - * A notice tucked behind the composer's top edge, as its tray is tucked under the bottom one: subtle - * and attached to what it is about. Dismissible when `onDismiss` is given; a notice about a state + * A notice as a card of its own. Dismissible when `onDismiss` is given; a notice about a state * clears itself instead. The description is clamped to two lines, whole on hover. */ -export function ComposerNotice({ +function NoticeCard({ title, description, tone, actions = [], onDismiss, - detached = false, -}: Notice & { - readonly onDismiss?: () => void; - /** A card of its own rather than tucked behind the composer's top edge. */ - readonly detached?: boolean; -}) { +}: Notice & { readonly onDismiss?: () => void }) { const { icon: Icon, text, surface } = tones[tone]; return (
- + {/* Centered on the title's line, so a two-line description does not pull it down. */} +
-

{title}

+

{title}

{description !== undefined && ( -

+

{description}

)} @@ -82,7 +80,7 @@ export function ComposerNotice({ type="button" disabled={action.disabled} onClick={action.onClick} - className="inline-flex shrink-0 items-center gap-1.5 rounded-md border border-edge px-2 py-0.5 font-medium text-ink-muted transition-[transform,background-color,color] duration-150 ease-out outline-none hover:bg-ink/5 hover:text-ink focus-visible:bg-ink/5 enabled:active:scale-[0.97] disabled:pointer-events-none disabled:opacity-60" + className="inline-flex shrink-0 items-center gap-1.5 self-center rounded-md border border-edge px-2 py-0.5 text-xs font-medium text-ink-muted transition-[transform,background-color,color] duration-150 ease-out outline-none hover:bg-ink/5 hover:text-ink focus-visible:bg-ink/5 enabled:active:scale-[0.97] disabled:pointer-events-none disabled:opacity-60" > {action.icon !== undefined && } {action.label} @@ -102,6 +100,54 @@ export function ComposerNotice({ ); } +/** + * A notice as a line of the conversation, where a reply would be: the tone's icon, the title, and + * the fact after it, with no box around them. Its dismiss and actions show on hover. + */ +export function NoticeLine({ + title, + description, + tone, + actions = [], + onDismiss, +}: Notice & { readonly onDismiss?: () => void }) { + const { icon: Icon, text } = tones[tone]; + return ( +
+ +

+ {title} + {description !== undefined && · {description}} +

+ {actions.map((action) => ( + + ))} + {onDismiss !== undefined && ( + + )} +
+ ); +} + /** * A notice detached below the composer and out of its flow, so it comes and goes without moving * anything. It eases in, and fades out quicker on the last notice it showed. @@ -115,7 +161,7 @@ export function NoticeSlot({ notice }: { readonly notice: Notice | undefined }) inert={notice === undefined} className="absolute inset-x-0 top-full z-10 pt-2 transition-[opacity,translate] duration-200 ease-out data-[shown=false]:-translate-y-1 data-[shown=false]:opacity-0 data-[shown=false]:duration-150 data-[shown=false]:ease-out motion-reduce:transition-none" > - +
); } diff --git a/apps/web/src/widgets/session/composer.tsx b/apps/web/src/widgets/session/composer.tsx index 58550dad..e0a70ce5 100644 --- a/apps/web/src/widgets/session/composer.tsx +++ b/apps/web/src/widgets/session/composer.tsx @@ -62,7 +62,8 @@ export const SessionComposer = memo(function SessionComposer({ const kv = useKv(); const [text, setText] = useState(""); const [loaded, setLoaded] = useState(false); - const [pending, setPending] = useState(false); + // Prompts on their way: the same text twice is a double press, a different one is a new prompt. + const [sending, setSending] = useState>(() => new Set()); // Picks not yet reflected in the session's info; the info wins once it carries them. const [picked, setPicked] = useState<{ model?: ModelRef; thinkingLevel?: ThinkingLevel }>({}); const model = picked.model ?? info.model; @@ -113,7 +114,7 @@ export const SessionComposer = memo(function SessionComposer({ const send = async (submit: Submit) => { const prompt = text.trim(); - if (prompt === "" || pending) return; + if (prompt === "" || sending.has(prompt)) return; const delivery = deliveryFor(running, submit); const messageId = crypto.randomUUID(); // An idle send shows in the conversation at once, so it moves out of the composer with it; a @@ -123,15 +124,20 @@ export const SessionComposer = memo(function SessionComposer({ onSending({ id: messageId, text: prompt, createdAt: Date.now() }); setText(""); } - setPending(true); + setSending((current) => new Set(current).add(prompt)); inFlight.prompt(key, messageId); const sent = await ask( topics.prompt, encodePrompt({ ...thread, messageId, text: prompt, ...(delivery === undefined ? {} : { delivery }) }), ); - setPending(false); + setSending((current) => { + const next = new Set(current); + next.delete(prompt); + return next; + }); if (sent) { - if (!immediate) setText(""); + // Only what was sent leaves: anything typed while it was on its way stays. + if (!immediate) setText((current) => (current.trim() === prompt ? "" : current)); return; } // Refused: never pending again. @@ -184,7 +190,7 @@ export const SessionComposer = memo(function SessionComposer({ )} diff --git a/apps/web/src/widgets/session/queue.tsx b/apps/web/src/widgets/session/queue.tsx index 078171f9..2be21bbe 100644 --- a/apps/web/src/widgets/session/queue.tsx +++ b/apps/web/src/widgets/session/queue.tsx @@ -18,11 +18,24 @@ const decodeReply = Schema.decodeUnknownOption(Json.Reply); const decodeCancelled = Schema.decodeUnknownOption(Json.Cancelled); const unreachable = "The CodeWork server is not reachable."; +/** The shape of a card stacked on the composer's top edge, a queued prompt or a notice; each brings its own colors. */ +export const trayCard = + "border border-b-0 px-3 text-ui text-ink shadow-[0_-2px_6px_-3px_rgb(0_0_0/0.12)] backdrop-blur-xl"; + +/** A card's height, how much of each card behind the front one shows, and how many show at most. */ +const ROW = 32; +const PEEK = 7; +const PEEKS = 3; +/** How much narrower each card further back is, per side. */ +const INSET = 8; +/** Without hover the stack cannot open on demand, so it stays open. */ +const coarse = typeof matchMedia === "function" && matchMedia("(pointer: coarse)").matches; + /** * Prompts sent while the agent works and not yet taken in, tucked behind the composer's top edge * like a notice: steers join at the agent's next step, follow-ups after its turn. Each leaves once - * it is in the conversation, or once removed. Past four, a count heads the list and it scrolls, - * cut mid-row and faded at its edges so more reads as more. + * it is in the conversation, or once removed. Several stack as cards, the newest in front, all behind + * a notice when there is one; hovering or focusing the stack opens it. * * A row moves to the other lane (or, while idle, sends now), is rewritten in place, goes back to the * composer, or is removed. Every action is a request on the session backend; the row changes when @@ -33,6 +46,7 @@ export const Queue = memo(function Queue({ queued, running, parked, + behind, onError, onRestore, }: { @@ -41,11 +55,15 @@ export const Queue = memo(function Queue({ readonly running: boolean; /** Left waiting by a stop or a failure: they run with the next message, not by themselves. */ readonly parked: boolean; + /** A notice holds the front: every prompt sits behind it, and the stack opens above it. */ + readonly behind: boolean; readonly onError: (message: string | undefined) => void; /** Puts a withdrawn prompt's text back in the composer. */ readonly onRestore: (text: string) => void; }) { const bus = useBus(); + const [hovered, setHovered] = useState(false); + const [focused, setFocused] = useState(false); // Rows with a request out; their actions wait for its answer. const [busy, setBusy] = useState>(() => new Set()); const [editing, setEditing] = useState<{ readonly id: string; readonly text: string }>(); @@ -100,90 +118,146 @@ export const Queue = memo(function Queue({ void change(prompt, { text: trimmed }); }; - const many = queued.length > 4; + // Collapsed, the next prompts peek above the front one as a stack; open, every card shows. Open + // overflows upward from a fixed footprint, so it never moves the conversation underneath. + const spread = hovered || focused || editing !== undefined || coarse; + // Behind a notice the newest prompt is one step back too, so only edges show. + const lift = behind ? 1 : 0; + const peeks = Math.min(queued.length - 1 + lift, PEEKS); return ( -
- {parked ? ( -

- {queued.length > 3 ? `${queued.length} parked` : "Parked"} - · Runs with your next message -

- ) : ( - queued.length > 3 &&

{queued.length} queued

- )} +
setHovered(true)} + onPointerLeave={() => setHovered(false)} + onFocus={() => setFocused(true)} + onBlur={(event) => { + if (!event.currentTarget.contains(event.relatedTarget)) setFocused(false); + }} + >