Skip to content

The agent that grows with you

fix(tui): apply a picker-issued --reasoning after the canonical model pick

liuhao102489428f4d30ad
diff --git a/ui-tui/src/__tests__/canonicalSessionControls.test.ts b/ui-tui/src/__tests__/canonicalSessionControls.test.ts
index c1da44d5fce..53a544022d9 100644
--- a/ui-tui/src/__tests__/canonicalSessionControls.test.ts
+++ b/ui-tui/src/__tests__/canonicalSessionControls.test.ts
@@ -246,3 +246,58 @@ it('a pick deferred by a running turn says it applies from the next turn', async
expect(ctx.transcript.sys.mock.calls[0][0]).toContain('applies next turn')
expect(getUiState().info?.model).toBe('old')
})
+
+it('a picker-issued --reasoning rides after the canonical model switch as its own mutation', async () => {
+ const { request, slash } = harness()
+ slash('/model picked --provider custom --reasoning HIGH --tui-session')
+ await flush()
+ await flush()
+
+ const sends = request.mock.calls
+ .filter(([method]) => method === 'session.mutate')
+ .map(([, params]) => [params.operation, params.payload])
+
+ expect(sends).toEqual([
+ ['model', { model: 'picked', provider: 'custom' }],
+ ['reasoning', { effort: 'high' }]
+ ])
+ expect(request.mock.calls.some(([method]) => method === 'config.set')).toBe(false)
+})
+
+it('an unknown --reasoning level is refused like any unsupported model option, mutating nothing', async () => {
+ const { request, slash } = harness()
+ slash('/model picked --reasoning warp --tui-session')
+ await flush()
+ await flush()
+ expect(request.mock.calls.filter(([method]) => method === 'session.mutate')).toHaveLength(0)
+})
+
+it('a guarded switch re-asks with the effort riding the confirmed re-send', async () => {
+ resetOverlayState()
+ const { request, slash } = harness()
+ request.mockImplementation(async (method: string, params: any) => {
+ if (method === 'session.resume') {
+ return { revision: 8, execution_generation: 4, info } as any
+ }
+
+ if (params.operation === 'reasoning') {
+ return { effort: params.payload.effort, execution_generation: 6 }
+ }
+
+ return params.payload.confirm === 'tok-1'
+ ? { model: 'pricey', execution_generation: 5 }
+ : { status: 'confirmation_required', confirm: 'tok-1', confirm_message: 'pricey IS EXPENSIVE', target_model: 'pricey' }
+ })
+ slash('/model pricey --reasoning max --tui-session')
+ await flush()
+ getOverlayState().confirm!.onConfirm()
+ await flush()
+ await flush()
+ const sends = request.mock.calls.filter(([method]) => method === 'session.mutate').map(([, params]) => params.payload)
+ expect(sends).toEqual([
+ { model: 'pricey' },
+ { model: 'pricey', confirm: 'tok-1' },
+ { effort: 'max' }
+ ])
+ expect(getUiState().info?.model).toBe('pricey')
+})
diff --git a/ui-tui/src/app/slash/canonicalSessionCommands.ts b/ui-tui/src/app/slash/canonicalSessionCommands.ts
index f344921cd19..5dcee65432e 100644
--- a/ui-tui/src/app/slash/canonicalSessionCommands.ts
+++ b/ui-tui/src/app/slash/canonicalSessionCommands.ts
@@ -3,6 +3,7 @@
// `session.mutate` rename / rewind (`gateway/session_mutations.py`), the committed admission
// result (`prompt.receipt include_result`) and the frozen launch policy (`session.info`).
+import { CANONICAL_REASONING_EFFORTS } from '../../domain/slash.js'
import { usageFromTick } from '../../domain/usage.js'
import { t } from '../../i18n/runtime.js'
import { asRpcResult } from '../../lib/rpc.js'
@@ -115,26 +116,12 @@ export async function renameCanonicalSession(
return mutation?.result ? String(mutation.result.title ?? title).trim() : undefined
}
-// The levels `hermes_constants.parse_reasoning_effort` accepts; the display words are config.yaml writes.
-const REASONING_EFFORTS = new Set([
- 'none',
- 'false',
- 'disabled',
- 'minimal',
- 'low',
- 'medium',
- 'high',
- 'xhigh',
- 'max',
- 'ultra'
-])
-
/** Session-scope `/reasoning <level>`: the owner's revision-fenced `reasoning` mutation of the frozen
* policy. False when the shared gateway has no verb for it (`--global`, a display word). */
export function canonicalReasoning(payload: { scope?: string; value: string }, ctx: SlashRunCtx): boolean {
const effort = payload.value.trim().toLowerCase()
- if (payload.scope === 'global' || !REASONING_EFFORTS.has(effort)) {
+ if (payload.scope === 'global' || !CANONICAL_REASONING_EFFORTS.has(effort)) {
return false
}
diff --git a/ui-tui/src/app/slash/canonicalSessionControls.ts b/ui-tui/src/app/slash/canonicalSessionControls.ts
index 054f50af245..d7886cc47cc 100644
--- a/ui-tui/src/app/slash/canonicalSessionControls.ts
+++ b/ui-tui/src/app/slash/canonicalSessionControls.ts
@@ -1,7 +1,7 @@
import { randomUUID } from 'node:crypto'
import { introMsg, toTranscriptMessages } from '../../domain/messages.js'
-import { TUI_SESSION_MODEL_FLAG } from '../../domain/slash.js'
+import { CANONICAL_REASONING_EFFORTS, TUI_SESSION_MODEL_FLAG } from '../../domain/slash.js'
import { t } from '../../i18n/runtime.js'
import { asRpcResult } from '../../lib/rpc.js'
import { patchOverlayState } from '../overlayStore.js'
@@ -45,6 +45,36 @@ function modelPayload(arg: string) {
return payload
}
+/** Split a picker-issued `--reasoning <level>` off a `/model` argument (#138856): the canonical
+ * model mutation has no effort field, so the level rides as the follow-up `reasoning` mutation the
+ * same value's `/reasoning` command issues. An unknown level is refused like any other flag the
+ * model mutation does not take (the backend writes the level into policy unvalidated). */
+function splitModelEffort(arg: string) {
+ const parts = arg.trim().split(/\s+/)
+ const rest: string[] = []
+ let effort = ''
+
+ while (parts.length) {
+ const part = parts.shift()!
+
+ if (part !== '--reasoning') {
+ rest.push(part)
+
+ continue
+ }
+
+ const level = parts.shift()
+
+ if (!level || !CANONICAL_REASONING_EFFORTS.has(level.toLowerCase())) {
+ throw new Error(t('canonical.controls.unsupportedModelOption', part))
+ }
+
+ effort = level.toLowerCase()
+ }
+
+ return { arg: rest.join(' '), effort }
+}
+
export type CanonicalOperation = 'model' | 'branch' | 'compress' | 'delete' | 'rename' | 'rewind' | 'reasoning'
/** The snapshot a mutation's CAS tuple was read from; `payload` may derive its target from it. */
@@ -177,7 +207,13 @@ const needsModelConfirmation = (result: CanonicalControlResult): result is Model
* nothing. Ask with the same dialog the legacy `config.set` path used; only "switch anyway"
* re-sends, once, with the owner's token. A confirmed send refused again (a turn or another
* switch landed first) is reported, never re-asked in a loop. */
-function askModelConfirmation(refusal: ModelConfirmation, arg: string, ctx: SlashRunCtx, confirmed: boolean) {
+function askModelConfirmation(
+ refusal: ModelConfirmation,
+ arg: string,
+ ctx: SlashRunCtx,
+ confirmed: boolean,
+ effort = ''
+) {
if (confirmed) {
throw new Error(`${refusal.confirm_message ?? ''}\n\n${t('slashCmd.session.model.confirmStale')}`.trim())
}
@@ -188,7 +224,7 @@ function askModelConfirmation(refusal: ModelConfirmation, arg: string, ctx: Slas
confirmLabel: t('slashCmd.session.model.switchAnyway'),
danger: true,
detail: refusal.confirm_message || t('slashCmd.session.model.expensiveDetail'),
- onConfirm: () => void runCanonicalSessionControl('model', arg, ctx, refusal.confirm),
+ onConfirm: () => void runCanonicalSessionControl('model', arg, ctx, refusal.confirm, effort),
title: t('slashCmd.session.model.confirmTitle', refusal.target_model ?? arg.trim().split(/\s+/)[0] ?? '')
}
})
@@ -258,6 +294,20 @@ function applyModelResult(result: CanonicalControlResult, ctx: SlashRunCtx) {
ctx.transcript.sys(t('session.main.modelSwitched', result.model))
}
+/** The picker's effort step applies after the pick lands, as the same revision-fenced `reasoning`
+ * mutation `/reasoning <level>` issues; a failed level reports without unwinding the switch. */
+async function applyModelEffort(gw: MutationGateway, ctx: SlashRunCtx, effort: string) {
+ if (!effort) {
+ return
+ }
+
+ const mutation = await mutateCanonical(gw, ctx.sid!, 'reasoning', { effort }, ctx.stale)
+
+ if (mutation?.result && !ctx.stale()) {
+ ctx.transcript.sys(t('slashCmd.session.reasoning.current', effort))
+ }
+}
+
type CompressSummary = { headline?: string; noop?: boolean; note?: string; token_line?: string } | null
/** The authority's report (headline, token line, note), as the native /compress prints it. */
@@ -301,15 +351,21 @@ export async function runCanonicalSessionControl(
operation: 'model' | 'branch' | 'compress',
arg: string,
ctx: SlashRunCtx,
- confirm?: string
+ confirm?: string,
+ confirmEffort = ''
) {
const gw = ctx.gateway.gw
+ let effort = confirmEffort
try {
if (!ctx.sid) {
throw new Error(t('slashCmd.core.status.noActiveSession'))
}
+ if (operation === 'model' && arg.includes('--reasoning')) {
+ ;({ arg, effort } = splitModelEffort(arg))
+ }
+
const mutation = await mutateCanonicalSession(gw, ctx.sid, operation, arg, ctx.stale, confirm)
if (!mutation) {
@@ -327,11 +383,12 @@ export async function runCanonicalSessionControl(
}
if (operation === 'model' && needsModelConfirmation(result)) {
- askModelConfirmation(result, arg, ctx, Boolean(confirm))
+ askModelConfirmation(result, arg, ctx, Boolean(confirm), effort)
} else if (operation === 'branch') {
await applyBranchResult(result, arg, ctx)
} else if (operation === 'model') {
applyModelResult(result, ctx)
+ await applyModelEffort(gw, ctx, effort)
} else if (result.status === 'preview') {
// `--preview` is a read-only report; nothing to re-hydrate.
ctx.transcript.sys((result.lines as string[]).join('\n'))
diff --git a/ui-tui/src/domain/slash.ts b/ui-tui/src/domain/slash.ts
index 81c55f66d81..8bf484fe0e4 100644
--- a/ui-tui/src/domain/slash.ts
+++ b/ui-tui/src/domain/slash.ts
@@ -1,6 +1,21 @@
/** Appended by TUI pickers; converted to the backend's `--session` flag before `config.set`. */
export const TUI_SESSION_MODEL_FLAG = '--tui-session'
+/** The levels `hermes_constants.parse_reasoning_effort` accepts; the display words are config.yaml
+ * writes. */
+export const CANONICAL_REASONING_EFFORTS = new Set([
+ 'none',
+ 'false',
+ 'disabled',
+ 'minimal',
+ 'low',
+ 'medium',
+ 'high',
+ 'xhigh',
+ 'max',
+ 'ultra'
+])
+
export const sessionScopedModelArg = (value: string) => {
const parts = value.trim().split(/\s+/).filter(Boolean)
const kept = parts.filter(part => part !== TUI_SESSION_MODEL_FLAG && part !== '--global' && part !== '--session')