diff --git a/cli/src/commands/copilot.ts b/cli/src/commands/copilot.ts index 22195f51..1722508d 100644 --- a/cli/src/commands/copilot.ts +++ b/cli/src/commands/copilot.ts @@ -17,6 +17,7 @@ export const copilotCommand: CommandDefinition = { startingMode?: 'local' | 'remote' permissionMode?: CopilotPermissionMode model?: string + effort?: string copilotAgentMode?: CopilotAgentMode resumeSessionId?: string existingSessionId?: string @@ -70,6 +71,12 @@ export const copilotCommand: CommandDefinition = { throw new Error('Missing --model value') } options.model = model + } else if (arg === '--effort') { + const effort = commandArgs[++i] + if (!effort) { + throw new Error('Missing --effort value') + } + options.effort = effort } else if (arg === '--copilot-agent-mode' || arg === '--mode') { const mode = commandArgs[++i] if (!mode || !isCopilotAgentMode(mode)) { diff --git a/cli/src/commands/resume.ts b/cli/src/commands/resume.ts index b39cb0ad..a38fdd56 100644 --- a/cli/src/commands/resume.ts +++ b/cli/src/commands/resume.ts @@ -188,6 +188,7 @@ async function dispatchLocalResume(target: LocalResumeTarget): Promise { permissionMode: base.permissionMode as CopilotPermissionMode | undefined, startingMode: 'local', model: target.model ?? undefined, + effort: target.effort ?? undefined, copilotAgentMode: target.copilotAgentMode }) return diff --git a/cli/src/copilot/copilotRemoteLauncher.test.ts b/cli/src/copilot/copilotRemoteLauncher.test.ts index a67196cb..da1f7e21 100644 --- a/cli/src/copilot/copilotRemoteLauncher.test.ts +++ b/cli/src/copilot/copilotRemoteLauncher.test.ts @@ -175,3 +175,65 @@ describe('CopilotRemoteLauncher.applyAgentMode', () => { expect(internals.currentBackendModel).toBe('gpt-5.6'); }); }); + +describe('CopilotRemoteLauncher effort', () => { + it('applies queued effort through the thought_level option and rolls back on failure', async () => { + const { launcher, session } = createLauncher(vi.fn()); + const onEffortRollback = vi.fn(); + const setConfigOption = vi.fn() + .mockResolvedValueOnce(undefined) + .mockResolvedValueOnce(undefined) + .mockRejectedValueOnce(new Error('unsupported')); + const internals = launcher as unknown as { + backend: unknown; + currentBackendEffort: string | null; + defaultBackendEffort: string | null; + onEffortRollback: typeof onEffortRollback; + applyQueuedEffort: (sessionId: string, mode: { effort?: string | null }) => Promise; + }; + internals.backend = { + setConfigOption, + getThoughtLevelConfigOption: () => ({ id: 'reasoning_effort', options: [] }) + }; + internals.onEffortRollback = onEffortRollback; + (session as unknown as { setEffort: unknown }).setEffort = vi.fn(); + internals.currentBackendEffort = 'medium'; + internals.defaultBackendEffort = 'medium'; + + await internals.applyQueuedEffort('s', { effort: 'high' }); + await internals.applyQueuedEffort('s', { effort: null }); + const mode = { effort: 'xhigh' as string | null }; + await internals.applyQueuedEffort('s', mode); + + expect(setConfigOption.mock.calls).toEqual([ + ['s', 'reasoning_effort', 'high'], + ['s', 'reasoning_effort', 'medium'], + ['s', 'reasoning_effort', 'xhigh'] + ]); + expect(internals.currentBackendEffort).toBe('medium'); + expect(mode.effort).toBeNull(); + expect(onEffortRollback).toHaveBeenCalledWith(null); + }); + + it('re-applies the selected effort when a model switch changes the agent level', async () => { + const { launcher } = createLauncher(vi.fn()); + const setConfigOption = vi.fn().mockResolvedValue(undefined); + const internals = launcher as unknown as { + backend: unknown; + currentBackendEffort: string | null; + captureEffortBaseline: (sessionId: string) => void; + applyQueuedEffort: (sessionId: string, mode: { effort?: string | null }) => Promise; + }; + // config_option_update for the new model reported `medium`. + internals.backend = { + setConfigOption, + getThoughtLevelConfigOption: () => ({ id: 'reasoning_effort', currentValue: 'medium', options: [] }) + }; + internals.currentBackendEffort = 'high'; + + internals.captureEffortBaseline('s'); + await internals.applyQueuedEffort('s', { effort: 'high' }); + + expect(setConfigOption).toHaveBeenCalledWith('s', 'reasoning_effort', 'high'); + }); +}); diff --git a/cli/src/copilot/copilotRemoteLauncher.ts b/cli/src/copilot/copilotRemoteLauncher.ts index 57d94848..7319ab2c 100644 --- a/cli/src/copilot/copilotRemoteLauncher.ts +++ b/cli/src/copilot/copilotRemoteLauncher.ts @@ -19,6 +19,8 @@ export class CopilotRemoteLauncher extends RemoteLauncherBase { private readonly session: CopilotSession; private readonly model?: string; private readonly onModelRollback?: (model: string | null) => void; + private readonly onEffortRollback?: (effort: string | null) => void; + private readonly getQueuedModel?: () => string | null; private backend: ReturnType | null = null; private permissionHandler: CopilotPermissionHandler | null = null; private happyServer: { stop: () => void } | null = null; @@ -28,6 +30,8 @@ export class CopilotRemoteLauncher extends RemoteLauncherBase { private displayAgentMode: CopilotAgentMode | null = null; private currentAgentMode: CopilotAgentMode = 'interactive'; private currentBackendModel: string | null = null; + private currentBackendEffort: string | null = null; + private defaultBackendEffort: string | null = null; private setModelSupported: boolean | undefined = undefined; private setModeSupported: boolean | undefined = undefined; private activeSessionId: string | null = null; @@ -36,11 +40,16 @@ export class CopilotRemoteLauncher extends RemoteLauncherBase { constructor(session: CopilotSession, opts: { model?: string; onModelRollback?: (model: string | null) => void; + onEffortRollback?: (effort: string | null) => void; + /** Model the next queued turn will carry; differs from the backend's while a switch is pending. */ + getQueuedModel?: () => string | null; }) { super(process.env.DEBUG ? session.logPath : undefined); this.session = session; this.model = opts.model; this.onModelRollback = opts.onModelRollback; + this.onEffortRollback = opts.onEffortRollback; + this.getQueuedModel = opts.getQueuedModel; } public async launch(): Promise { @@ -141,6 +150,17 @@ export class CopilotRemoteLauncher extends RemoteLauncherBase { session.client.rpcHandlerManager.registerHandler(RPC_METHODS.ListCopilotModels, async () => { return await buildCopilotModelsResponseFromBackend(acpSessionId, backend, session.path); }); + this.captureEffortBaseline(acpSessionId); + session.client.rpcHandlerManager.registerHandler(RPC_METHODS.ListCopilotReasoningEffortOptions, async () => { + // A model change is applied with the turn that carries it; until + // then the cached levels belong to the previous model. + const queuedModel = this.getQueuedModel?.() ?? null; + if (queuedModel !== null && queuedModel !== this.currentBackendModel) { + return { success: false, error: 'Copilot model switch pending' }; + } + const option = backend.getThoughtLevelConfigOption(acpSessionId); + return { success: true, options: option?.options ?? [], currentValue: option?.currentValue ?? null }; + }); this.setupAbortHandlers(session.client.rpcHandlerManager, { onAbort: () => this.handleAbort(), @@ -160,9 +180,14 @@ export class CopilotRemoteLauncher extends RemoteLauncherBase { break; } + const modelBeforeBatch = this.currentBackendModel; if (batch.mode.model && batch.mode.model !== this.currentBackendModel) { batch.mode.model = await this.applyQueuedModel(batch.mode.model) ?? undefined; } + if (this.currentBackendModel !== modelBeforeBatch) { + this.captureEffortBaseline(acpSessionId); + } + await this.applyQueuedEffort(acpSessionId, batch.mode); const desiredAgentMode = batch.mode.agentMode ?? session.getAgentMode(); if (desiredAgentMode !== this.currentAgentMode) { @@ -447,6 +472,35 @@ export class CopilotRemoteLauncher extends RemoteLauncherBase { } } + /** The agent's level for the active model; "Default" resets to it. */ + private captureEffortBaseline(sessionId: string): void { + this.currentBackendEffort = this.backend?.getThoughtLevelConfigOption(sessionId)?.currentValue ?? null; + this.defaultBackendEffort = this.currentBackendEffort; + } + + private async applyQueuedEffort(sessionId: string, mode: { effort?: string | null }): Promise { + const backend = this.backend; + const requested = mode.effort ?? this.defaultBackendEffort; + if (!backend || !requested || requested === this.currentBackendEffort) return; + const option = backend.getThoughtLevelConfigOption(sessionId); + try { + if (!option) throw new Error('no reasoning effort option'); + await backend.setConfigOption(sessionId, option.id, requested); + this.currentBackendEffort = requested; + } catch (error) { + logger.warn('[copilot-remote] Inline effort switch failed', error); + const effort = this.currentBackendEffort === this.defaultBackendEffort ? null : this.currentBackendEffort; + mode.effort = effort; + this.session.setEffort(effort); + this.session.pushKeepAlive(); + this.onEffortRollback?.(effort); + this.session.sendSessionEvent({ + type: 'message', + message: `Failed to switch Copilot effort to ${requested}.` + }); + } + } + private rollbackModel(): string | null { const model = this.currentBackendModel === 'auto' ? null : this.currentBackendModel; this.session.setModel(model); @@ -493,7 +547,7 @@ function toAcpMcpServers(config: Record void } + opts: ConstructorParameters[1] ): Promise<'switch' | 'exit'> { const launcher = new CopilotRemoteLauncher(session, opts); return launcher.launch(); diff --git a/cli/src/copilot/loop.ts b/cli/src/copilot/loop.ts index 6ebabb50..d8b11dc4 100644 --- a/cli/src/copilot/loop.ts +++ b/cli/src/copilot/loop.ts @@ -22,6 +22,8 @@ interface CopilotLoopOptions { resumeSessionId?: string; onSessionReady?: (session: CopilotSession) => void; onModelRollback?: (model: string | null) => void; + onEffortRollback?: (effort: string | null) => void; + getQueuedModel?: () => string | null; } export async function copilotLoop(opts: CopilotLoopOptions): Promise { @@ -59,7 +61,9 @@ export async function copilotLoop(opts: CopilotLoopOptions): Promise { }), runRemote: (instance) => copilotRemoteLauncher(instance, { model: getCurrentModel(), - onModelRollback: opts.onModelRollback + onModelRollback: opts.onModelRollback, + onEffortRollback: opts.onEffortRollback, + getQueuedModel: opts.getQueuedModel }), onSessionReady: opts.onSessionReady }); diff --git a/cli/src/copilot/runCopilot.ts b/cli/src/copilot/runCopilot.ts index 2c97eb56..659cb8a6 100644 --- a/cli/src/copilot/runCopilot.ts +++ b/cli/src/copilot/runCopilot.ts @@ -42,6 +42,7 @@ export async function runCopilot(opts: { startingMode?: 'local' | 'remote'; permissionMode?: PermissionMode; model?: string; + effort?: string; copilotAgentMode?: import('@hapi/protocol').CopilotAgentMode; resumeSessionId?: string; existingSessionId?: string; @@ -93,6 +94,7 @@ export async function runCopilot(opts: { const messageQueue = new MessageQueue2((mode) => hashObject({ permissionMode: mode.permissionMode, model: mode.model, + effort: mode.effort, agentMode: mode.agentMode })); @@ -101,6 +103,7 @@ export async function runCopilot(opts: { let currentAgentMode = opts.copilotAgentMode ?? 'interactive'; let sessionModel: string | null = persistedModel ?? null; let resolvedModel = sessionModel ?? runtimeConfig.model ?? null; + let sessionEffort: string | null = opts.effort ?? null; const lifecycle = createRunnerLifecycle({ session, @@ -119,6 +122,7 @@ export async function runCopilot(opts: { } sessionInstance.setPermissionMode(currentPermissionMode); sessionInstance.setModel(sessionModel); + sessionInstance.setEffort(sessionEffort); sessionInstance.setAgentMode(currentAgentMode); sessionInstance.pushKeepAlive(); @@ -128,6 +132,7 @@ export async function runCopilot(opts: { const buildMode = (): CopilotMode => ({ permissionMode: currentPermissionMode, model: resolvedModel ?? undefined, + effort: sessionEffort, agentMode: currentAgentMode }); @@ -263,12 +268,12 @@ export async function runCopilot(opts: { return parsed.data as PermissionMode; }; - const resolveModel = (value: unknown): string | null => { + const resolveModel = (value: unknown, label = 'model'): string | null => { if (value === null) { return null; } if (typeof value !== 'string' || value.trim().length === 0) { - throw new Error('Invalid model'); + throw new Error(`Invalid ${label}`); } return value.trim(); }; @@ -277,7 +282,7 @@ export async function runCopilot(opts: { if (!payload || typeof payload !== 'object') { throw new Error('Invalid session config payload'); } - const config = payload as { permissionMode?: unknown; model?: unknown; copilotAgentMode?: unknown }; + const config = payload as { permissionMode?: unknown; model?: unknown; effort?: unknown; copilotAgentMode?: unknown }; const applied: Record = {}; if (config.permissionMode !== undefined) { @@ -297,6 +302,14 @@ export async function runCopilot(opts: { applied.model = sessionModel; } + if (config.effort !== undefined) { + if (sessionWrapperRef.current?.mode === 'local') { + throw new Error('Copilot effort can only be changed for remote sessions'); + } + sessionEffort = resolveModel(config.effort, 'effort'); + applied.effort = sessionEffort; + } + if (config.copilotAgentMode !== undefined) { if (!isCopilotAgentMode(config.copilotAgentMode)) { throw new Error('Invalid copilot agent mode'); @@ -338,7 +351,11 @@ export async function runCopilot(opts: { onModelRollback: (model) => { sessionModel = model; resolvedModel = resolveCopilotQueueModel(model); - } + }, + onEffortRollback: (effort) => { + sessionEffort = effort; + }, + getQueuedModel: () => resolvedModel }); } catch (error) { crashed = true; diff --git a/cli/src/copilot/session.ts b/cli/src/copilot/session.ts index 335d6f7b..e2393c3e 100644 --- a/cli/src/copilot/session.ts +++ b/cli/src/copilot/session.ts @@ -64,6 +64,10 @@ export class CopilotSession extends AgentSessionBase { this.model = model; }; + setEffort = (effort: string | null): void => { + this.effort = effort; + }; + setAgentMode = (mode: CopilotAgentMode): void => { this.agentMode = mode; }; @@ -95,6 +99,7 @@ export class CopilotSession extends AgentSessionBase { this.client.keepAlive(this.thinking, this.mode, { permissionMode: this.permissionMode, model: this.model, + effort: this.effort, copilotAgentMode: this.agentMode }); }; diff --git a/cli/src/copilot/types.ts b/cli/src/copilot/types.ts index 1952c7ed..94963168 100644 --- a/cli/src/copilot/types.ts +++ b/cli/src/copilot/types.ts @@ -6,5 +6,6 @@ export type PermissionMode = CopilotPermissionMode; export interface CopilotMode { permissionMode: PermissionMode; model?: string; + effort?: string | null; agentMode?: CopilotAgentMode; } diff --git a/cli/src/copilot/utils/copilotBackend.ts b/cli/src/copilot/utils/copilotBackend.ts index d67f76c7..3e8e8903 100644 --- a/cli/src/copilot/utils/copilotBackend.ts +++ b/cli/src/copilot/utils/copilotBackend.ts @@ -25,6 +25,7 @@ export function createCopilotBackend(opts?: { agentMode?: CopilotAgentMode }): A return new AcpSdkBackend({ command: getAgentLaunchCommand('copilot'), args: buildCopilotAcpArgs(opts), - env: filterEnv(process.env) + env: filterEnv(process.env), + configOptionUpdates: true }); } diff --git a/cli/src/runner/buildCliArgs.test.ts b/cli/src/runner/buildCliArgs.test.ts index 5f86193b..1d456939 100644 --- a/cli/src/runner/buildCliArgs.test.ts +++ b/cli/src/runner/buildCliArgs.test.ts @@ -327,6 +327,14 @@ describe('buildCliArgs', () => { expect(args).toContain('high') }) + it('passes --effort for copilot agent so resume keeps the selection', () => { + const args = buildCliArgs('copilot', { + directory: '/tmp', + effort: 'high', + }) + expect(args.slice(args.indexOf('--effort'))).toEqual(expect.arrayContaining(['--effort', 'high'])) + }) + it('passes --effort for claude agent', () => { const args = buildCliArgs('claude', { directory: '/tmp', diff --git a/cli/src/runner/run.ts b/cli/src/runner/run.ts index 4c05bb36..284f3b2d 100644 --- a/cli/src/runner/run.ts +++ b/cli/src/runner/run.ts @@ -2128,7 +2128,7 @@ export function buildCliArgs( if (options.model) { args.push('--model', options.model); } - if (options.effort && (agent === 'claude' || agent === 'grok' || agent === 'pi' || agent === 'agy' || agent === 'kimi')) { + if (options.effort && (agent === 'claude' || agent === 'grok' || agent === 'pi' || agent === 'agy' || agent === 'kimi' || agent === 'copilot')) { args.push('--effort', options.effort); } if (options.modelReasoningEffort && (agent === 'codex' || agent === 'opencode')) { diff --git a/docs/api/client-contract/rest.md b/docs/api/client-contract/rest.md index cc1b7bfc..a0ac15bd 100644 --- a/docs/api/client-contract/rest.md +++ b/docs/api/client-contract/rest.md @@ -119,7 +119,7 @@ Source: `hub/src/web/routes/sessions.ts`; flavor gates in `shared/src/modes.ts` |---|---|---| | `POST /api/sessions/:id/permission-mode` | `{mode: PermissionMode}` | All flavors except `pi` and `dsh` (per-flavor allowed sets in `modes.ts`) | | `POST /api/sessions/:id/model` | `{model: string \| {provider, modelId} \| null, effort?: string \| null}` | Flavors with `supportsModelChange` (not `dsh`); remote-only for codex/cursor/grok. Only claude and agy accept `effort` with a model change. | -| `POST /api/sessions/:id/effort` | `{effort: string \| null}` | agy, claude, grok, kimi, pi (`supportsEffort`) | +| `POST /api/sessions/:id/effort` | `{effort: string \| null}` | agy, claude, copilot, grok, kimi, pi (`supportsEffort`) | | `POST /api/sessions/:id/model-reasoning-effort` | `{modelReasoningEffort: string \| null}` | codex, opencode (remote-only) | | `POST /api/sessions/:id/service-tier` | `{serviceTier: 'fast' \| 'standard'}` | codex (remote-only) | | `POST /api/sessions/:id/collaboration-mode` | `{mode: 'default' \| 'plan'}` | codex (remote-only) | @@ -153,7 +153,7 @@ The configuration routes in the table above respond `{ok: true}`; apply-failures | Method & path | Notes | |---|---| | `GET /api/sessions/:id/codex-models`, `/opencode-models`, `/cursor-models`, `/grok-models`, `/copilot-models`, `/kimi-models`, `/pi-models` | Active session of the matching flavor; 400 otherwise | -| `GET /api/sessions/:id/opencode-reasoning-effort-options`, `/grok-reasoning-effort-options`, `/kimi-reasoning-effort-options` | Same pattern | +| `GET /api/sessions/:id/opencode-reasoning-effort-options`, `/grok-reasoning-effort-options`, `/copilot-reasoning-effort-options`, `/kimi-reasoning-effort-options` | Same pattern | | `GET /api/machines/:id/agy-models`, `/pi-models`, `/codex-models`, `/cursor-models` | Machine-level (pre-spawn pickers). `agy-models` takes `?refresh=true` to skip the machine's cached catalog, and may answer `success: true` with an advisory `error` (see [Errors](./errors.md#rpc-wrapped-endpoints)) | | `GET /api/machines/:id/opencode-models?cwd=`, `/grok-models?cwd=`, `/copilot-models?cwd=`, `/kimi-models?cwd=` | `cwd` query required (400 without) | diff --git a/docs/guide/agents.md b/docs/guide/agents.md index aaa6a9f1..9b4514a2 100644 --- a/docs/guide/agents.md +++ b/docs/guide/agents.md @@ -312,7 +312,7 @@ the prompt is loaded by DSH through its own `skill` tool and catalog. - **Claude Code** (`hapi claude`) — local sessions wrap the native TUI, remote sessions drive the Claude Agent SDK. [Claude Code docs](https://docs.anthropic.com/en/docs/claude-code) - **Codex** (`hapi codex`) — OpenAI's Codex CLI, with terminal/Web control and a dedicated `plan` mode. See [Codex usage and limits](./codex-shared-sessions.md) for resume, terminal-exit behavior, and launch options. [openai/codex](https://github.com/openai/codex) -- **GitHub Copilot** (`hapi copilot`) — Copilot CLI over ACP (`copilot --acp --stdio`). [GitHub Copilot](https://github.com/features/copilot) +- **GitHub Copilot** (`hapi copilot`) — Copilot CLI over ACP (`copilot --acp --stdio`). Remote sessions can pick a reasoning effort in the composer when the active model offers one; HAPI applies it before the next turn through ACP `session/set_config_option`. [GitHub Copilot](https://github.com/features/copilot) - **Kimi** (`hapi kimi`) — Moonshot AI's Kimi CLI over ACP (`kimi acp`). Remote sessions can pick a thinking level in the composer when the active model offers one; HAPI applies it before the next turn through ACP `session/set_config_option`. [MoonshotAI/kimi-cli](https://github.com/MoonshotAI/kimi-cli) - **OpenCode** (`hapi opencode`) — the open-source OpenCode agent over ACP (`opencode acp`). [opencode.ai](https://opencode.ai) - **Antigravity** (`hapi agy`) — Google's Antigravity CLI (`agy`) over ACP diff --git a/hub/src/sync/rpcGateway.ts b/hub/src/sync/rpcGateway.ts index d1fb8f38..dc2d8513 100644 --- a/hub/src/sync/rpcGateway.ts +++ b/hub/src/sync/rpcGateway.ts @@ -25,6 +25,7 @@ import type { GeneratedImageResponse, ImplementCodexPlanResult, CopilotModelsResponse, + CopilotReasoningEffortResponse, GrokModelsResponse, KimiModelsResponse, KimiReasoningEffortResponse, @@ -582,6 +583,10 @@ export class RpcGateway { ) as RpcListCopilotModelsResponse } + async listCopilotReasoningEffortOptionsForSession(sessionId: string): Promise { + return await this.sessionRpc(sessionId, RPC_METHODS.ListCopilotReasoningEffortOptions, {}) as CopilotReasoningEffortResponse + } + async listCopilotModelsForSession(sessionId: string): Promise { return await this.sessionRpc( sessionId, diff --git a/hub/src/sync/syncEngine.ts b/hub/src/sync/syncEngine.ts index f2ba4edd..4c8e6c6a 100644 --- a/hub/src/sync/syncEngine.ts +++ b/hub/src/sync/syncEngine.ts @@ -14,7 +14,7 @@ import { } from '@hapi/protocol/runnerCapabilities' import type { CursorChatStoreStatus, CursorMigrateOutcome, CursorMigrateToAcpRequest, MessageContextResponse, MessageDeliveryMode, MessagesResponse, QueuedStateResponse, RewindConversationErrorCode, SlashCommandsResponse } from '@hapi/protocol/apiTypes' import type { SteerQueuedMessageResponse } from '@hapi/protocol/schemas' -import type { ImplementCodexPlanResult, KimiReasoningEffortResponse } from '@hapi/protocol/apiTypes' +import type { CopilotReasoningEffortResponse, ImplementCodexPlanResult, KimiReasoningEffortResponse } from '@hapi/protocol/apiTypes' import type { AgentFlavor, BackgroundTask, CodexCollaborationMode, CopilotAgentMode, DecryptedMessage, PermissionMode, Session, SyncEvent } from '@hapi/protocol/types' import { hasConversationMessageContent, unwrapRoleWrappedRecordEnvelope } from '@hapi/protocol/messages' import type { Server } from 'socket.io' @@ -5482,6 +5482,10 @@ export class SyncEngine { return await this.rpcGateway.listCopilotModelsForCwd(machineId, cwd) } + async listCopilotReasoningEffortOptionsForSession(sessionId: string): Promise { + return await this.rpcGateway.listCopilotReasoningEffortOptionsForSession(sessionId) + } + async listCopilotModelsForSession(sessionId: string): Promise { return await this.rpcGateway.listCopilotModelsForSession(sessionId) } diff --git a/hub/src/web/routes/sessions.ts b/hub/src/web/routes/sessions.ts index 5c6281d5..cf81e51c 100644 --- a/hub/src/web/routes/sessions.ts +++ b/hub/src/web/routes/sessions.ts @@ -1934,6 +1934,24 @@ export function createSessionsRoutes(getSyncEngine: () => SyncEngine | null): Ho } }) + app.get('/sessions/:id/copilot-reasoning-effort-options', async (c) => { + const engine = requireSyncEngine(c, getSyncEngine) + if (engine instanceof Response) return engine + const sessionResult = requireSessionFromParam(c, engine, { requireActive: true }) + if (sessionResult instanceof Response) return sessionResult + if (sessionResult.session.metadata?.flavor !== 'copilot') { + return c.json({ success: false, error: 'Copilot effort options are only available for Copilot sessions' }, 400) + } + try { + return c.json(await engine.listCopilotReasoningEffortOptionsForSession(sessionResult.sessionId)) + } catch (error) { + return c.json({ + success: false, + error: error instanceof Error ? error.message : 'Failed to list Copilot effort options' + }, 500) + } + }) + app.get('/sessions/:id/copilot-models', async (c) => { const engine = requireSyncEngine(c, getSyncEngine) if (engine instanceof Response) return engine diff --git a/shared/src/apiTypes.ts b/shared/src/apiTypes.ts index 125308b8..cb8eb9e7 100644 --- a/shared/src/apiTypes.ts +++ b/shared/src/apiTypes.ts @@ -1052,6 +1052,9 @@ export type GrokReasoningEffortResponse = { error?: string } +/** Copilot's ACP `thought_level` option for the active model. */ +export type CopilotReasoningEffortResponse = GrokReasoningEffortResponse + /** Kimi's ACP `thought_level` (`thinking`) option for the active model. */ export type KimiReasoningEffortResponse = GrokReasoningEffortResponse diff --git a/shared/src/flavors.test.ts b/shared/src/flavors.test.ts index 32122954..bfa2f669 100644 --- a/shared/src/flavors.test.ts +++ b/shared/src/flavors.test.ts @@ -58,9 +58,9 @@ describe('hasCapability', () => { expect(hasCapability('kimi', Capabilities.Effort)).toBe(true) }) - test('copilot supports model-change but not effort', () => { + test('copilot supports model-change and effort', () => { expect(hasCapability('copilot', Capabilities.ModelChange)).toBe(true) - expect(hasCapability('copilot', Capabilities.Effort)).toBe(false) + expect(hasCapability('copilot', Capabilities.Effort)).toBe(true) }) test('grok supports runtime model and effort switching through ACP', () => { diff --git a/shared/src/flavors.ts b/shared/src/flavors.ts index 66ef8320..fe92ea99 100644 --- a/shared/src/flavors.ts +++ b/shared/src/flavors.ts @@ -14,7 +14,7 @@ const FLAVOR_CAPS: Record> = { claude: new Set([Capabilities.ModelChange, Capabilities.Effort]), gemini: new Set([Capabilities.ModelChange]), kimi: new Set([Capabilities.ModelChange, Capabilities.Effort]), - copilot: new Set([Capabilities.ModelChange]), + copilot: new Set([Capabilities.ModelChange, Capabilities.Effort]), grok: new Set([Capabilities.ModelChange, Capabilities.Effort]), codex: new Set([Capabilities.ModelChange]), dsh: new Set([Capabilities.ModelChange]), diff --git a/shared/src/rpcMethods.ts b/shared/src/rpcMethods.ts index bbf81c38..8c0e4fab 100644 --- a/shared/src/rpcMethods.ts +++ b/shared/src/rpcMethods.ts @@ -51,6 +51,7 @@ export const RPC_METHODS = { ListGrokReasoningEffortOptions: 'listGrokReasoningEffortOptions', ListCopilotModelsForCwd: 'listCopilotModelsForCwd', ListCopilotModels: 'listCopilotModels', + ListCopilotReasoningEffortOptions: 'listCopilotReasoningEffortOptions', ListKimiReasoningEffortOptions: 'listKimiReasoningEffortOptions', ListKimiModelsForCwd: 'listKimiModelsForCwd', ListKimiModels: 'listKimiModels', diff --git a/web/src/api/client.ts b/web/src/api/client.ts index e7fb8ce0..ba682040 100644 --- a/web/src/api/client.ts +++ b/web/src/api/client.ts @@ -51,6 +51,7 @@ import type { KimiModelsResponse, CopilotModelsResponse, GrokReasoningEffortResponse, + CopilotReasoningEffortResponse, KimiReasoningEffortResponse, ListDirectoryResponse, MachineListDirectoryResponse, @@ -1172,6 +1173,12 @@ export class ApiClient { }) } + async getSessionCopilotReasoningEffortOptions(sessionId: string): Promise { + return await this.request( + `/api/sessions/${encodeURIComponent(sessionId)}/copilot-reasoning-effort-options` + ) + } + async getSessionKimiReasoningEffortOptions(sessionId: string): Promise { return await this.request( `/api/sessions/${encodeURIComponent(sessionId)}/kimi-reasoning-effort-options` diff --git a/web/src/components/AssistantChat/HappyComposer.tsx b/web/src/components/AssistantChat/HappyComposer.tsx index 60de54f2..b3f698bb 100644 --- a/web/src/components/AssistantChat/HappyComposer.tsx +++ b/web/src/components/AssistantChat/HappyComposer.tsx @@ -1130,7 +1130,7 @@ export function HappyComposer(props: { const claudeEffortOptions = useMemo( () => agentFlavor === 'pi' ? getPiThinkingLevelOptions(effort, selectedPiModel?.thinkingLevelMap) - : (agentFlavor === 'grok' || agentFlavor === 'agy' || agentFlavor === 'kimi') && availableEffortOptions && availableEffortOptions.length > 0 + : (agentFlavor === 'grok' || agentFlavor === 'agy' || agentFlavor === 'kimi' || agentFlavor === 'copilot') && availableEffortOptions && availableEffortOptions.length > 0 ? [ { value: null, label: 'Default' }, ...availableEffortOptions.map((option) => ({ diff --git a/web/src/components/SessionChat.tsx b/web/src/components/SessionChat.tsx index 5ed299a2..2ada969c 100644 --- a/web/src/components/SessionChat.tsx +++ b/web/src/components/SessionChat.tsx @@ -123,6 +123,7 @@ import { buildCursorEffortPickerOptionsWithDefaultFirst } from '@/lib/cursorMode import { useOpencodeModels } from '@/hooks/queries/useOpencodeModels' import { useGrokModels } from '@/hooks/queries/useGrokModels' import { useCopilotModels } from '@/hooks/queries/useCopilotModels' +import { useCopilotReasoningEffortOptions } from '@/hooks/queries/useCopilotReasoningEffortOptions' import { useKimiModelsForSession } from '@/hooks/queries/useKimiModelsForSession' import { useKimiReasoningEffortOptions } from '@/hooks/queries/useKimiReasoningEffortOptions' import { useDshModelsForSession } from '@/hooks/queries/useDshModels' @@ -1178,6 +1179,12 @@ function SessionChatInner(props: SessionChatProps) { sessionId: props.session.id, enabled: agentFlavor === 'copilot' && props.session.active && !controlledByUser }) + const copilotEffortOptions = useCopilotReasoningEffortOptions({ + api: props.api, + sessionId: props.session.id, + model: props.session.model, + enabled: agentFlavor === 'copilot' && props.session.active && !controlledByUser + }) const copilotModelOptions = useMemo(() => ( agentFlavor === 'copilot' ? [ @@ -2352,6 +2359,8 @@ function SessionChatInner(props: SessionChatProps) { ? agyEffortOptions : agentFlavor === 'grok' && grokEffortState.options.length > 0 ? grokEffortState.options + : agentFlavor === 'copilot' + ? copilotEffortOptions : agentFlavor === 'kimi' ? kimiEffortOptions : claudeEffortOptions @@ -2458,6 +2467,10 @@ function SessionChatInner(props: SessionChatProps) { ? (props.session.active && !controlledByUser && grokEffortState.options.length > 0 ? handleEffortChange : undefined) + : agentFlavor === 'copilot' + ? (props.session.active && !controlledByUser && copilotEffortOptions.length > 0 + ? handleEffortChange + : undefined) : agentFlavor === 'kimi' ? (props.session.active && !controlledByUser && kimiEffortOptions.length > 0 ? handleEffortChange diff --git a/web/src/hooks/queries/useCopilotReasoningEffortOptions.ts b/web/src/hooks/queries/useCopilotReasoningEffortOptions.ts new file mode 100644 index 00000000..37fccbbd --- /dev/null +++ b/web/src/hooks/queries/useCopilotReasoningEffortOptions.ts @@ -0,0 +1,30 @@ +import { useQuery } from '@tanstack/react-query' +import type { ApiClient } from '@/api/client' +import type { GrokReasoningEffortOption } from '@/types/api' +import { queryKeys } from '@/lib/query-keys' + +/** + * Effort levels Copilot's ACP `thought_level` option offers for the active + * model. Keyed by model so a switch hides the previous model's levels; the CLI + * answers `success: false` until the backend is ready and the switch has been + * applied (next turn), so poll until it succeeds. + */ +export function useCopilotReasoningEffortOptions(args: { + api: ApiClient | null + sessionId: string + model: string | null | undefined + enabled: boolean +}): GrokReasoningEffortOption[] { + const query = useQuery({ + queryKey: queryKeys.sessionCopilotReasoningEffortOptions(args.sessionId, args.model ?? null), + queryFn: async () => { + if (!args.api) throw new Error('Copilot session unavailable') + return await args.api.getSessionCopilotReasoningEffortOptions(args.sessionId) + }, + enabled: Boolean(args.enabled && args.api), + staleTime: 30_000, + retry: 3, + refetchInterval: (query) => (query.state.data?.success === true ? false : 5_000), + }) + return query.data?.success ? query.data.options ?? [] : [] +} diff --git a/web/src/lib/query-keys.ts b/web/src/lib/query-keys.ts index d319bf45..35ce1b9f 100644 --- a/web/src/lib/query-keys.ts +++ b/web/src/lib/query-keys.ts @@ -32,6 +32,7 @@ export const queryKeys = { machineGrokModelsForCwd: (machineId: string, cwd: string) => ['machine-grok-models', machineId, cwd] as const, sessionGrokModels: (sessionId: string) => ['session-grok-models', sessionId] as const, sessionCopilotModels: (sessionId: string) => ['session-copilot-models', sessionId] as const, + sessionCopilotReasoningEffortOptions: (sessionId: string, model: string | null) => ['session-copilot-reasoning-effort-options', sessionId, model] as const, machineCopilotModelsForCwd: (machineId: string, cwd: string) => ['machine-copilot-models', machineId, cwd] as const, machineKimiModelsForCwd: (machineId: string, cwd: string) => ['machine-kimi-models', machineId, cwd] as const, sessionKimiModels: (sessionId: string) => ['session-kimi-models', sessionId] as const, diff --git a/web/src/types/api.ts b/web/src/types/api.ts index 16bf9d7a..b85b3a0b 100644 --- a/web/src/types/api.ts +++ b/web/src/types/api.ts @@ -34,6 +34,7 @@ export type { CopilotModelsResponse, CopilotModelSummary, GrokReasoningEffortResponse, + CopilotReasoningEffortResponse, KimiReasoningEffortResponse, GrokReasoningEffortOption, ListDirectoryResponse,