Skip to content
5 changes: 4 additions & 1 deletion mobile/src/session/MobileNativeChatSessionOptionPickers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ChevronLeft, X } from 'lucide-react-native'
import { BottomDrawer } from '../components/BottomDrawer'
import { colors, radii, spacing, typography } from '../theme/mobile-theme'
import {
isReadOnlySessionOptionValue,
sessionOptionDispatchUnconfirmed,
type SessionOptionDescriptor,
type SessionOptionValue
Expand Down Expand Up @@ -260,7 +261,9 @@ function OptionRows({
valueColor={isPermission ? permissionColor : undefined}
disabled={disabled}
divided={index < descriptors.length - 1}
onPress={() => onNavigate(descriptor.id)}
onPress={
isReadOnlySessionOptionValue(descriptor) ? undefined : () => onNavigate(descriptor.id)
}
/>
)
})}
Expand Down
17 changes: 16 additions & 1 deletion mobile/src/session/MobileNativeChatSessionOptionRows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,23 @@ export function SessionOptionSummaryRow({
valueColor?: string
disabled: boolean
divided: boolean
onPress: () => void
/** Absent for a value with no choice to make: the row reads as text, with no page behind it. */
onPress?: () => void
}): React.JSX.Element {
if (!onPress) {
return (
<View
accessible
accessibilityLabel={`${label}, ${value}`}
style={[styles.summaryRow, divided && styles.rowDivided]}
>
<Text style={styles.summaryLabel}>{label}</Text>
<Text style={styles.summaryValue} numberOfLines={1}>
{value}
</Text>
</View>
)
}
return (
<Pressable
accessibilityLabel={`${label}, ${value}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function mount(initial: Props) {
enabled: true,
fence: props.fence,
mutate,
hostSupport: { sendOptions: true, permissionModes: true }
hostSupport: { permissionModes: true }
})
frames.push(modelChoices(options.optionSnapshot))
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async function mountOptions(props: ProbeProps) {
hostSupport:
probe.hostAdvertisesPermissionModes === null
? null
: { sendOptions: true, permissionModes: probe.hostAdvertisesPermissionModes ?? true }
: { permissionModes: probe.hostAdvertisesPermissionModes ?? true }
})
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function Probe(props: ProbeProps): null {
enabled: true,
fence: props.fence,
mutate: props.mutate,
hostSupport: { sendOptions: true, permissionModes: true }
hostSupport: { permissionModes: true }
})
)
return null
Expand Down
14 changes: 6 additions & 8 deletions mobile/src/session/use-mobile-structured-agent-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ export function useMobileStructuredAgentOptions(args: {
/** Moves when the host's status says a session option changed; each move re-reads them. */
optionStamp?: string
/** What the host advertised; null until its status probe answers. */
hostSupport: Pick<StructuredAgentSessionHostSupport, 'sendOptions' | 'permissionModes'> | null
hostSupport: Pick<StructuredAgentSessionHostSupport, 'permissionModes'> | null
}) {
const { agent, client, enabled, fence, mutate, optionStamp, sessionId, hostSupport } = args
const takesSendOptions = hostSupport?.sendOptions === true
// Every agent's seed, as on the desktop: a built-in list or the provider-default pill.
const optionCatalog = useMemo(
() => (agent ? structuredAgentSessionSeedCatalog(agent) : null),
Expand Down Expand Up @@ -181,9 +180,9 @@ export function useMobileStructuredAgentOptions(args: {
!imageSupport.statesPermissionMode &&
optionState.permissionMode === null
const optionSnapshot = useMemo(() => {
const shown = structuredAgentSessionShownSnapshot(optionState, takesSendOptions)
const shown = structuredAgentSessionShownSnapshot(optionState)
return legacyHostPermissions ? [...shown, legacyHostPermissionDescriptor()] : shown
}, [legacyHostPermissions, optionState, takesSendOptions])
}, [legacyHostPermissions, optionState])

const setStructuredOption = useCallback(
async (id: string, value: SessionOptionValue): Promise<boolean> => {
Expand All @@ -196,7 +195,7 @@ export function useMobileStructuredAgentOptions(args: {
!optionCatalog ||
encoded === null ||
!canSetStructuredAgentSessionOption(
structuredAgentSessionOptionView(currentState, undefined, {}, takesSendOptions),
structuredAgentSessionOptionView(currentState, undefined, {}),
id,
value
)
Expand Down Expand Up @@ -287,15 +286,14 @@ export function useMobileStructuredAgentOptions(args: {
}
}
},
[agent, client, mutate, optionCatalog, sessionId, takesSendOptions, updateOptionState]
[agent, client, mutate, optionCatalog, sessionId, updateOptionState]
)

const { optionPickerRequest, invokeStructuredOption, optionSurface } =
useMobileStructuredOptionSurface({
optionSnapshot,
setStructuredOption,
optionStateRef,
takesSendOptions
optionStateRef
})

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,31 +198,29 @@ describe('mobile structured send actions', () => {
}
})

it('takes an effort the replacement it shows offers, and sends on that replacement', async () => {
it("keeps a chat's model its CLI stopped listing, and sends on it and its effort", async () => {
agent = 'claude'
hostSupport = structuredAgentSessionHostSupport([AGENT_SESSION_SEND_OPTIONS_RUNTIME_CAPABILITY])
const efforts = [
{ value: 'low', label: 'Low' },
{ value: 'high', label: 'High' }
]
const opus = {
id: 'opus',
label: 'Opus',
isDefault: true,
efforts: [{ value: 'high', label: 'High' }]
}
sendRequest.mockImplementation(async (method) =>
method === 'agentSession.send'
? sendResult('accepted')
: method === 'agentSession.modelCatalog'
? ok({
origin: 'probe',
fetchedAt: 1,
models: [{ id: 'opus[1m]', label: 'Opus', isDefault: true, efforts }]
})
? ok({ origin: 'probe', fetchedAt: 1, models: [opus] })
: method === 'agentSession.options'
? ok({
// A stopped chat lists the host's rows and its own model.
models: [
{ id: 'opus[1m]', label: 'Opus', isDefault: true, efforts },
{ id: 'claude-gone', label: 'claude-gone', isDefault: false, efforts: [] }
opus,
{ id: 'opus[1m]', label: 'opus[1m]', isDefault: false, efforts: [] }
],
listedModelIds: ['opus[1m]'],
current: { model: 'claude-gone', effort: 'high' }
listedModelIds: ['opus'],
current: { model: 'opus[1m]', effort: 'max' }
})
: ok({})
)
Expand All @@ -233,15 +231,14 @@ describe('mobile structured send actions', () => {
hook!.optionSnapshot.find((descriptor) => descriptor.id === 'model')?.kind
).toMatchObject({ currentValue: 'opus[1m]' })
})
await act(async () => {
await hook!.setStructuredOption('effort', 'low')
expect(hook!.optionSnapshot.find((descriptor) => descriptor.id === 'effort')).toMatchObject({
settable: false,
kind: { currentValue: 'max' }
})
const picks = sendRequest.mock.calls.filter(([method]) => method === 'agentSession.setOption')
expect(picks.map(([, params]) => fieldsOf(params).value)).toEqual(['low'])
await act(async () => {
expect(await hook!.sendWithOutcome('hello')).toBe('accepted')
})
expect(fieldsOf(calls()[0]![1]).options).toMatchObject({ model: 'opus[1m]' })
expect(fieldsOf(calls()[0]![1]).options).toEqual({ model: 'opus[1m]', effort: 'max' })
})

it("sends a command the chat's own agent runs as a message, though Codex's host claims it", async () => {
Expand Down
9 changes: 3 additions & 6 deletions mobile/src/session/use-mobile-structured-option-surface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ export function useMobileStructuredOptionSurface(args: {
setStructuredOption: (id: string, value: SessionOptionValue) => Promise<boolean>
/** The latest option state, which a settled pick's snapshot is read from. */
optionStateRef: RefObject<StructuredAgentSessionOptionState>
takesSendOptions: boolean
}) {
const { optionSnapshot, optionStateRef, setStructuredOption, takesSendOptions } = args
const { optionSnapshot, optionStateRef, setStructuredOption } = args
const [optionPickerRequest, setOptionPickerRequest] = useState<{
id: string
sequence: number
Expand All @@ -35,11 +34,9 @@ export function useMobileStructuredOptionSurface(args: {
const setOption = useCallback(
async (id: string, value: SessionOptionValue) => {
await setStructuredOption(id, value)
return {
snapshot: structuredAgentSessionShownSnapshot(optionStateRef.current, takesSendOptions)
}
return { snapshot: structuredAgentSessionShownSnapshot(optionStateRef.current) }
},
[optionStateRef, setStructuredOption, takesSendOptions]
[optionStateRef, setStructuredOption]
)

const optionSurface = useMemo<SessionOptionsSurface>(
Expand Down
29 changes: 23 additions & 6 deletions src/main/claude/claude-structured-effort-default-at-rest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,27 @@ function readAtRest(store: AgentModelCatalogStore, record: AgentSessionRecord) {
return readStructuredAgentSessionOptions(context, SESSION, { readsWithoutModel: true })
}

function pickerEffort(result: Awaited<ReturnType<typeof readAtRest>>, agent = 'claude') {
function pickerEffortRow(result: Awaited<ReturnType<typeof readAtRest>>, agent = 'claude') {
const seed = getAgentSessionOptionCatalog(agent)!
const state = applyStructuredAgentSessionOptions(
createStructuredAgentSessionOptionState(agent, seed),
seed,
result
)
const effort = structuredAgentSessionOptionSnapshot(state).find((row) => row.id === 'effort')
return structuredAgentSessionOptionSnapshot(state).find((row) => row.id === 'effort')
}

function pickerEffort(result: Awaited<ReturnType<typeof readAtRest>>, agent = 'claude') {
const effort = pickerEffortRow(result, agent)
return effort?.kind.type === 'select' ? effort.kind.currentValue : undefined
}

/** The chat's own effort under a model its list does not name: one value, read-only. */
const READ_ONLY_EFFORT = (value: string, label = value) => ({
settable: false,
kind: { type: 'select', currentValue: value, choices: [{ value, label }] }
})

describe('Claude effort default at rest', () => {
it("learns the model's default from a live child's applied effort", async () => {
const store = new AgentModelCatalogStore()
Expand Down Expand Up @@ -246,7 +256,7 @@ describe('Claude effort default at rest', () => {
expect(catalogDefault(other, 'opus[1m]')).toBe('medium')
})

it('offers no effort for a model the catalog does not list, at rest as live', async () => {
it('offers no effort menu for a model the catalog does not list, at rest as live', async () => {
const store = new AgentModelCatalogStore()
const unlisted = { model: 'claude-unlisted-9', effort: 'medium' }
// The CLI runs a model its own catalog does not list, as a newer or pinned model can be.
Expand All @@ -259,8 +269,12 @@ describe('Claude effort default at rest', () => {
result.models.find((entry) => entry.id === unlisted.model)
expect(row(live)).toEqual(expect.objectContaining({ id: unlisted.model, efforts: [] }))
expect(row(resting)).toEqual(row(live))
expect(pickerEffort(live)).toBeUndefined()
expect(pickerEffort(resting)).toBeUndefined()
// No menu: the chat's own effort shows read-only, named as a listed row names it. The host names
// the saved listing's ids for a live child that lists none of its own.
expect(pickerEffortRow({ ...live, listedModelIds: resting.listedModelIds })).toMatchObject(
READ_ONLY_EFFORT(unlisted.effort, 'Medium')
)
expect(pickerEffortRow(resting)).toMatchObject(READ_ONLY_EFFORT(unlisted.effort, 'Medium'))
})

it('lists an unlisted Codex model at rest exactly as its live child does', async () => {
Expand Down Expand Up @@ -302,7 +316,10 @@ describe('Claude effort default at rest', () => {

expect(resting.models).toEqual(live.models)
expect(live.models.find((entry) => entry.id === 'gpt-unlisted')).toMatchObject({ efforts: [] })
expect(pickerEffort(resting, 'codex')).toBeUndefined()
// The host names the saved listing's ids for a live child that lists none of its own.
for (const answer of [resting, { ...live, listedModelIds: resting.listedModelIds }]) {
expect(pickerEffortRow(answer, 'codex')).toMatchObject(READ_ONLY_EFFORT('high', 'High'))
}
})

it("keeps a Claude model's effort at rest with no catalog yet, as a live child with none does", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// The models a session's options answer lists, the same whether a child answers live or the host
// answers for a chat at rest: the catalog's rows, plus the current model when the catalog does not
// list it. Nothing says which efforts an unlisted model takes, so its row offers none, and a client
// shows no effort control for it.
// list it. Nothing says which efforts an unlisted model takes, so its row offers none.

import type { AgentSessionModelOption } from '../../../shared/agent-session-wire'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,40 @@ describe('options at rest', () => {
expect(read).toHaveBeenLastCalledWith({ agent: 'codex', sessionId: SESSION, savedOnly: true })
})

it("names the saved listing's ids for a live child with no listing of its own, as at rest", async () => {
const record = { ...restingRecord(), options: { model: 'gpt-unlisted', effort: 'high' } }
const listed = { id: 'gpt-5.5', label: 'GPT-5.5', isDefault: true, efforts: [] }
let live = false
const conversation = () => ({
child: live ? { fence: 7 } : null,
params: { provider: 'codex' },
journal: { threadGoal: () => null, context: { floor: () => null } }
})
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: this read touches only the declared context fields.
const context = {
deps: {
adapter: {
readOptions: async () => ({
models: [listed, { ...listed, id: 'gpt-unlisted', isDefault: false }],
current: { model: 'gpt-unlisted', effort: 'high' }
})
},
agents: NO_STRUCTURED_AGENTS,
store: { getRecord: () => record },
modelCatalog: { read: async () => ({ origin: 'probe', models: [listed], fetchedAt: 1 }) }
},
serialize: (_sessionId: string, task: () => Promise<unknown>) => task(),
openConversation: async () => conversation(),
conversation: async () => conversation()
} as unknown as StructuredAgentSessionMutationContext
const read = () =>
readStructuredAgentSessionOptions(context, SESSION, { readsWithoutModel: true })
const resting = await read()
live = true
expect((await read()).listedModelIds).toEqual(resting.listedModelIds)
expect(resting.listedModelIds).toEqual(['gpt-5.5'])
})

it.each(['codex', 'omp', 'grok', 'opencode'] as const)(
'%s keeps an unknown model and learns menus from later options',
async (provider) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,19 @@ export async function readStructuredAgentSessionOptions(
})
)
: null
let rested: RestingOptions | undefined
const atRest = async (): Promise<RestingOptions> =>
(rested ??= await readStructuredAgentSessionOptionsAtRest(context.deps, sessionId, reader))
let options: Omit<AgentSessionOptionsResult, 'rewind'>
if (live) {
const { catalogListing, ...answer } = live
options = answer
// A child with no listing of its own reads the saved one, as at rest, so a row reads the same.
// With no record there is nothing saved to read, and the answer stays the child's own.
if (!catalogListing && !answer.listedModelIds && store.getRecord(sessionId)) {
const { listedModelIds } = await atRest()
options = listedModelIds ? { ...answer, listedModelIds } : answer
}
if (catalogListing) {
// Check prior membership before saving: a launch-added row cannot verify itself.
const listedModelIds = context.deps.modelCatalog
Expand All @@ -246,7 +255,7 @@ export async function readStructuredAgentSessionOptions(
options = { ...answer, listedModelIds }
}
} else {
options = await readStructuredAgentSessionOptionsAtRest(context.deps, sessionId, reader)
options = await atRest()
}
// Re-acquired after the reads above: the handle they saw may have closed and reopened since.
const session = await context.conversation(sessionId)
Expand All @@ -260,15 +269,17 @@ export async function readStructuredAgentSessionOptions(
const permissionMode = record
? await structuredAgentSessionLaunchPermission(context.deps, record)
: null
// The saved pick shows, except one the running child could not take (a model its provider says
// does not exist): that shows what the child runs instead.
const refused = live ? (adapter.readOptionRestoreFailures?.(sessionId) ?? []) : []
const saved = record?.options
const selected =
live && (saved?.model !== undefined || saved?.effort !== undefined)
? await readStructuredAgentSessionOptionsAtRest(context.deps, sessionId, reader)
: options
const shownSaved = (key: 'model' | 'effort'): boolean =>
saved?.[key] !== undefined && !refused.includes(key)
const selected = live && (shownSaved('model') || shownSaved('effort')) ? await atRest() : options
const current = {
...options.current,
...(saved?.model !== undefined ? { model: selected.current.model } : {}),
...(saved?.effort !== undefined ? { effort: selected.current.effort } : {})
...(shownSaved('model') ? { model: selected.current.model } : {}),
...(shownSaved('effort') ? { effort: selected.current.effort } : {})
}
const confirmed = current.confirmed?.filter((key) =>
key === 'model'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ describe("a Claude chat whose saved model the CLI says doesn't exist", () => {
model: RETIRED,
effort: 'high'
})
// The picker shows what the child runs now, so the next send moves the chat off the model.
await vi.waitFor(async () =>
expect((await host.readOptions(SESSION, { readsWithoutModel: true })).current.model).not.toBe(
RETIRED
)
)
})

it("keeps a model the reply did not come from: a subagent's own error", async () => {
Expand Down
Loading
Loading