* feat(mobile): native-chat model/session-option picker + shared slash catalog (STA-3332) Piece A — shared slash catalog + send classification: - Mobile composer now serves getVerifiedNativeChatCommands from the shared catalog (agent-aware, with description rows) instead of a hardcoded provider-agnostic list that advertised commands Claude does not have. - classifyNativeChatSend moves to src/shared/native-chat-slash-commands.ts (renderer re-exports keep desktop import paths stable); mobile's send seam now gates optimistic echoes on it, so slash sends no longer create a 'Queued' bubble that no transcript echo can ever retire, and the ack-lost hold only arms for chat sends. Piece B — mobile model/session-option pickers: - New per-tab session-option tracking (state/commands/labels modules) ported from the desktop live flow, reading the shared agent-session-option catalog for Claude AND Codex. - Composer pill row (model + options) opening an inline choice card in the proven Ask-card pattern; applies use catalog modelApply semantics (/model <value> via the existing send path), Codex-style agent-picker entries dispatch the picker command and flip the tab to the terminal view. - Current model seeds from the hook-reported provider model when derivable; typed /model-style commands update tracked state (recordOutgoingCommand parity); dispatched values render as sent-not-confirmed. * fix(mobile): keep session option sends scoped * fix(mobile): synchronize native chat refs after commit * refactor: share native chat session option logic * fix(mobile): keep the live tab's session-option record from eviction `getScopedRecord` returned an existing record without re-inserting it, so the per-tab record map evicted by insertion order rather than recency. A long-lived active tab is the oldest key, so crossing the 32-scope cap silently dropped its tracked model and reset the pill to "Model". Desktop's scope cache does delete-then-set for exactly this reason. Also moves the shared session-option tests to src/shared so the root suite runs them (they only exercised src/shared logic the Electron renderer consumes, but sat under mobile/ where only mobile's vitest project sees them), and restores two "why" comments dropped while extracting the shared modules. * fix(mobile): stop a stale session-start report reverting a model pick Re-entering a chat tab re-delivers the same `agentStatus.model`, and the reported-model effect re-applied it unconditionally — so picking a model, moving to another tab, and coming back reverted the pill to the model the agent reported at session start, which cannot have observed the `/model` sent after it. The status stream reconnecting had the same effect. A report is now only treated as evidence when the matched catalog id CHANGES for that scope; a genuinely new report still supersedes a local pick. Mobile has no screen read to confirm a switch against, so the repeat is all we can key off. * fix(mobile): close four session-option picker defects found in review D1 — a picker apply could interleave with a composer send. The composer already blocks a text send while an apply is dispatching, but not the reverse: the host spaces a send's body and its Enter ~500ms apart, so an apply tapped inside that window was submitted as part of the user's prompt, and the pill then claimed a model change that never ran as a command. The pickers render inside the composer, so they now take its in-flight state directly — the same guard, mirrored. D2 — an option was filed under the wrong model. `setTrackedSessionOption` resolves the owning model when it commits, not when the command was built, and the report effect mutates the same record off-queue. A report landing mid-dispatch therefore recorded `/effort low` against the model it switched TO. Ports desktop's supersession guard, which skips the commit when the baseline moved. D3 — a command template's prefix also matches prose that starts with it, so "/model is a weird word" tracked that prose as the current model, rendered it as the pill label, and matched no catalog model, dropping every per-model option. Parsed values are now canonicalized against the catalog; a typed value containing whitespace is treated as a prompt rather than a command. Perf — `/` on a Codex tab returned all 45 commands into a non-virtualized ScrollView showing ~5, re-reconciled on every streaming tick above the transcript. Capped at 12. Also splits the row primitives out of MobileNativeChatSessionOptionPickers.tsx, which the D1 guard pushed to 402 effective lines against a 400 cap. * refactor: share the session-option display ordering CATEGORY_ORDER and the non-model sort were byte-identical in NativeChatSessionOptionPickers.tsx and mobile's labels module — pure logic with no i18n in it, so there was no reason for two copies that can drift. Both now call sortNativeChatSessionOptions from the shared snapshot module. * refactor(mobile): align model picker layout * style(mobile): round native chat composer * fix(mobile): inset rounded chat composer
232 lines
8.4 KiB
TypeScript
232 lines
8.4 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
||
import {
|
||
CLAUDE_SESSION_OPTION_CATALOG,
|
||
CODEX_SESSION_OPTION_CATALOG
|
||
} from './agent-session-option-catalog-claude-codex'
|
||
import {
|
||
buildNativeChatSessionOptionCommand,
|
||
parseBuiltSessionOptionCommand,
|
||
recordNativeChatSessionOptionCommand
|
||
} from './native-chat-session-option-commands'
|
||
import {
|
||
createNativeChatSessionOptionRecord,
|
||
type NativeChatSessionOptionRecord
|
||
} from './native-chat-session-option-state'
|
||
|
||
function claudeRecord(model?: string): NativeChatSessionOptionRecord {
|
||
const record = createNativeChatSessionOptionRecord('claude')
|
||
if (model) {
|
||
record.model = { value: model, source: 'dispatched' }
|
||
}
|
||
return record
|
||
}
|
||
|
||
describe('buildNativeChatSessionOptionCommand', () => {
|
||
it('builds the catalog midSession command for model and options', () => {
|
||
expect(
|
||
buildNativeChatSessionOptionCommand({
|
||
optionId: 'model',
|
||
value: 'opus',
|
||
apply: CLAUDE_SESSION_OPTION_CATALOG.modelApply,
|
||
modelId: null,
|
||
catalog: CLAUDE_SESSION_OPTION_CATALOG,
|
||
models: CLAUDE_SESSION_OPTION_CATALOG.models,
|
||
record: claudeRecord()
|
||
})
|
||
).toBe('/model opus')
|
||
const effortApply = CLAUDE_SESSION_OPTION_CATALOG.models
|
||
.find((model) => model.id === 'sonnet')!
|
||
.options.find((option) => option.id === 'effort')!.apply
|
||
expect(
|
||
buildNativeChatSessionOptionCommand({
|
||
optionId: 'effort',
|
||
value: 'high',
|
||
apply: effortApply,
|
||
modelId: 'sonnet',
|
||
catalog: CLAUDE_SESSION_OPTION_CATALOG,
|
||
models: CLAUDE_SESSION_OPTION_CATALOG.models,
|
||
record: claudeRecord('sonnet')
|
||
})
|
||
).toBe('/effort high')
|
||
})
|
||
|
||
it('returns the bare toggle command for flip-only options', () => {
|
||
const fastModeApply = CLAUDE_SESSION_OPTION_CATALOG.models
|
||
.find((model) => model.id === 'opus')!
|
||
.options.find((option) => option.id === 'fastMode')!.apply
|
||
expect(
|
||
buildNativeChatSessionOptionCommand({
|
||
optionId: 'fastMode',
|
||
value: true,
|
||
apply: fastModeApply,
|
||
modelId: 'opus',
|
||
catalog: CLAUDE_SESSION_OPTION_CATALOG,
|
||
models: CLAUDE_SESSION_OPTION_CATALOG.models,
|
||
record: claudeRecord('opus')
|
||
})
|
||
).toBe('/fast')
|
||
})
|
||
|
||
it('has no absolute command for agent-picker applies (Codex model)', () => {
|
||
expect(
|
||
buildNativeChatSessionOptionCommand({
|
||
optionId: 'model',
|
||
value: 'gpt-5.5',
|
||
apply: CODEX_SESSION_OPTION_CATALOG.modelApply,
|
||
modelId: null,
|
||
catalog: CODEX_SESSION_OPTION_CATALOG,
|
||
models: CODEX_SESSION_OPTION_CATALOG.models,
|
||
record: createNativeChatSessionOptionRecord('codex')
|
||
})
|
||
).toBeNull()
|
||
})
|
||
})
|
||
|
||
describe('parseBuiltSessionOptionCommand', () => {
|
||
it('recovers the value from a built command and rejects other text', () => {
|
||
const build = (value: unknown): string => `/model ${String(value)}`
|
||
expect(parseBuiltSessionOptionCommand(build, '/model opus')).toBe('opus')
|
||
expect(parseBuiltSessionOptionCommand(build, '/effort high')).toBeNull()
|
||
expect(parseBuiltSessionOptionCommand(build, '/model ')).toBeNull()
|
||
})
|
||
})
|
||
|
||
describe('recordNativeChatSessionOptionCommand', () => {
|
||
it('tracks a typed /model value as dispatched truth', () => {
|
||
const record = claudeRecord()
|
||
const result = recordNativeChatSessionOptionCommand({
|
||
catalog: CLAUDE_SESSION_OPTION_CATALOG,
|
||
models: CLAUDE_SESSION_OPTION_CATALOG.models,
|
||
record,
|
||
command: '/model sonnet'
|
||
})
|
||
expect(result).toEqual({ changed: true, opensAgentPicker: false })
|
||
expect(record.model).toEqual({ value: 'sonnet', source: 'dispatched' })
|
||
})
|
||
|
||
it('tracks a typed option value under the current model', () => {
|
||
const record = claudeRecord('sonnet')
|
||
recordNativeChatSessionOptionCommand({
|
||
catalog: CLAUDE_SESSION_OPTION_CATALOG,
|
||
models: CLAUDE_SESSION_OPTION_CATALOG.models,
|
||
record,
|
||
command: '/effort low'
|
||
})
|
||
expect(record.valuesByModel.sonnet?.effort).toEqual({ value: 'low', source: 'dispatched' })
|
||
})
|
||
|
||
it('clears tracked truth for a bare picker command and reports the agent picker', () => {
|
||
const claudeResult = recordNativeChatSessionOptionCommand({
|
||
catalog: CLAUDE_SESSION_OPTION_CATALOG,
|
||
models: CLAUDE_SESSION_OPTION_CATALOG.models,
|
||
record: claudeRecord('sonnet'),
|
||
command: '/model'
|
||
})
|
||
expect(claudeResult.opensAgentPicker).toBe(true)
|
||
const codexRecord = createNativeChatSessionOptionRecord('codex')
|
||
codexRecord.model = { value: 'gpt-5.5', source: 'dispatched' }
|
||
const codexResult = recordNativeChatSessionOptionCommand({
|
||
catalog: CODEX_SESSION_OPTION_CATALOG,
|
||
models: CODEX_SESSION_OPTION_CATALOG.models,
|
||
record: codexRecord,
|
||
command: '/model'
|
||
})
|
||
expect(codexResult).toEqual({ changed: true, opensAgentPicker: true })
|
||
expect(codexRecord.model).toBeUndefined()
|
||
})
|
||
|
||
it('clears a flip-only toggle’s tracked baseline on a typed flip', () => {
|
||
const record = claudeRecord('opus')
|
||
record.valuesByModel.opus = { fastMode: { value: true, source: 'applied' } }
|
||
recordNativeChatSessionOptionCommand({
|
||
catalog: CLAUDE_SESSION_OPTION_CATALOG,
|
||
models: CLAUDE_SESSION_OPTION_CATALOG.models,
|
||
record,
|
||
command: '/fast'
|
||
})
|
||
// A typed flip inverts an unknown-to-us direction; the baseline is gone.
|
||
expect(record.valuesByModel.opus?.fastMode).toBeUndefined()
|
||
})
|
||
|
||
it('rejects prose that merely starts with a command template', () => {
|
||
// The `/model ` prefix matches this, so an unvalidated parse tracked
|
||
// "is a weird word" as the current model — which then rendered as the pill
|
||
// label and, matching no catalog model, dropped every per-model option.
|
||
const record = claudeRecord('sonnet')
|
||
expect(
|
||
recordNativeChatSessionOptionCommand({
|
||
catalog: CLAUDE_SESSION_OPTION_CATALOG,
|
||
models: CLAUDE_SESSION_OPTION_CATALOG.models,
|
||
record,
|
||
command: '/model is a weird word'
|
||
})
|
||
).toEqual({ changed: false, opensAgentPicker: false })
|
||
expect(record.model).toEqual({ value: 'sonnet', source: 'dispatched' })
|
||
})
|
||
|
||
it('rejects an option value outside the catalog choices', () => {
|
||
const record = claudeRecord('sonnet')
|
||
recordNativeChatSessionOptionCommand({
|
||
catalog: CLAUDE_SESSION_OPTION_CATALOG,
|
||
models: CLAUDE_SESSION_OPTION_CATALOG.models,
|
||
record,
|
||
command: '/effort of will is required'
|
||
})
|
||
expect(record.valuesByModel.sonnet?.effort).toBeUndefined()
|
||
})
|
||
|
||
it('tracks nothing for a multi-line paste whose first line looks like a command', () => {
|
||
const record = claudeRecord('opus')
|
||
recordNativeChatSessionOptionCommand({
|
||
catalog: CLAUDE_SESSION_OPTION_CATALOG,
|
||
models: CLAUDE_SESSION_OPTION_CATALOG.models,
|
||
record,
|
||
command: '/model sonnet\nplease review this'
|
||
})
|
||
expect(record.model).toEqual({ value: 'opus', source: 'dispatched' })
|
||
})
|
||
|
||
it('still accepts an alias, a full provider id, and extra spacing', () => {
|
||
for (const [command, expected] of [
|
||
['/model opus', 'opus'],
|
||
['/model claude-sonnet-5', 'sonnet'],
|
||
['/model sonnet', 'sonnet']
|
||
] as const) {
|
||
const record = claudeRecord()
|
||
recordNativeChatSessionOptionCommand({
|
||
catalog: CLAUDE_SESSION_OPTION_CATALOG,
|
||
models: CLAUDE_SESSION_OPTION_CATALOG.models,
|
||
record,
|
||
command
|
||
})
|
||
expect(record.model).toEqual({ value: expected, source: 'dispatched' })
|
||
}
|
||
})
|
||
|
||
it('still tracks an alias the active model list no longer carries', () => {
|
||
// Per-host discovery can drop the `opus` alias; typing it is still valid and
|
||
// callers reconcile the row back, so rejecting it would lose the selection.
|
||
const record = claudeRecord('sonnet')
|
||
const discovered = CLAUDE_SESSION_OPTION_CATALOG.models.filter((model) => model.id !== 'opus')
|
||
recordNativeChatSessionOptionCommand({
|
||
catalog: CLAUDE_SESSION_OPTION_CATALOG,
|
||
models: discovered,
|
||
record,
|
||
command: '/model opus'
|
||
})
|
||
expect(record.model).toEqual({ value: 'opus', source: 'dispatched' })
|
||
})
|
||
|
||
it('ignores unrelated commands', () => {
|
||
const record = claudeRecord('sonnet')
|
||
expect(
|
||
recordNativeChatSessionOptionCommand({
|
||
catalog: CLAUDE_SESSION_OPTION_CATALOG,
|
||
models: CLAUDE_SESSION_OPTION_CATALOG.models,
|
||
record,
|
||
command: '/clear'
|
||
})
|
||
).toEqual({ changed: false, opensAgentPicker: false })
|
||
})
|
||
})
|