Skip to content
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
1f8beb9
fix(native-chat): an open chat moves to the account you switch to bef…
brennanb2025 Oct 20, 2026
253f941
fix(native-chat): declare the launch-account read for the runtime lay…
brennanb2025 Oct 20, 2026
f1e3681
fix(claude): find custom chat history before managed-account resume
brennanb2025 Oct 20, 2026
d951264
test(claude): assign the complete custom account home
brennanb2025 Oct 20, 2026
a9d0cba
Merge remote-tracking branch 'origin/main' into brennanb2025/chat-acc…
brennanb2025 Oct 20, 2026
59c6bcc
Preserve unknown account model facts and legacy option replay
brennanb2025 Oct 22, 2026
1454518
Clarify terminal account-switch feedback in translated locales
brennanb2025 Oct 22, 2026
9f7bc1a
Merge main and preserve chat account routing
brennanb2025 Oct 26, 2026
bdb1efb
Keep option mutation plans checked against their contract
brennanb2025 Oct 26, 2026
8b9c641
Cover unknown model choices across chat consumers
brennanb2025 Oct 26, 2026
9d6c783
Keep consumer fixtures aligned with canonical types
brennanb2025 Oct 26, 2026
0534fe8
Match the mobile picker label in its consumer test
brennanb2025 Oct 26, 2026
327138e
fix: clarify terminal scope in translated Claude account settings
brennanb2025 Oct 26, 2026
f3f1904
Merge main and retain account retirement on the current delivery seam
brennanb2025 Oct 27, 2026
1d809a3
Update integration tests for current session and remote client contracts
brennanb2025 Oct 27, 2026
4e3a83c
Keep native worker replies on their receiving account
brennanb2025 Oct 27, 2026
94c8623
Preserve receiving accounts across cold starts and nested reports
brennanb2025 Oct 28, 2026
4bee36d
Merge main into chat account switching
brennanb2025 Oct 28, 2026
b9bac09
Preserve the delivery receiver when reading chat commands
brennanb2025 Oct 28, 2026
20ffa6a
Clarify native reply matching and consolidate imports
brennanb2025 Oct 28, 2026
e4a4b86
Resolve catalog scope without re-entering conversation queues
brennanb2025 Oct 28, 2026
2cc13f3
Align catalog and mobile test fixtures with current contracts
brennanb2025 Oct 28, 2026
506dc97
Align receiving-account readers and fixtures with typed contracts
brennanb2025 Oct 28, 2026
1053b01
Repair account-switch fixtures and measure receiving work
brennanb2025 Oct 28, 2026
92d9a58
Use the checked account-home path in catalog tests
brennanb2025 Oct 28, 2026
173d1e4
Merge main while preserving account-aware catalog reads
brennanb2025 Oct 29, 2026
5d201c4
Restore executed-option recorder context
brennanb2025 Oct 29, 2026
8150a51
Control receiving catalog deadline test clock
brennanb2025 Oct 29, 2026
f9d581c
Merge main and retain account-aware catalog contracts
brennanb2025 Oct 29, 2026
6f15008
Merge main and preserve account-aware recovery
brennanb2025 Oct 29, 2026
057118f
Merge main and preserve account-aware recovery
brennanb2025 Oct 29, 2026
990dd6e
Merge main and preserve structured options coverage
brennanb2025 Oct 29, 2026
f04ae5c
Merge latest main before pushing account-switch integration
brennanb2025 Oct 29, 2026
3e63cfc
Align unknown-model consumer fixtures with send capture
brennanb2025 Oct 30, 2026
89bcedb
Merge main and preserve account-aware option contracts
brennanb2025 Oct 30, 2026
a75d195
Merge main and retain integrated option contracts
brennanb2025 Oct 30, 2026
d2b1e36
Consolidate session host type imports
brennanb2025 Oct 30, 2026
bc20e16
Align cross-version catalog fixtures with host read contracts
brennanb2025 Oct 30, 2026
adaadd6
Merge main and preserve account-aware session contracts
brennanb2025 Oct 30, 2026
8ecb6c1
Merge main and keep one workspace sleeper with account-aware session …
brennanb2025 Oct 30, 2026
6ade96e
test(native-chat): bind Runs through the current start authority in r…
brennanb2025 Oct 30, 2026
d254c91
Merge main and keep account-aware launch publication with the renamed…
brennanb2025 Oct 31, 2026
46a325f
fix(native-chat): follow the selected account before its folder exists
brennanb2025 Oct 31, 2026
7ea925b
test(ai-vault): build the stale acquisition receipt without a type as…
brennanb2025 Oct 31, 2026
9ec20b2
test(native-chat): narrow the rig acquisition link before relinking it
brennanb2025 Oct 31, 2026
78af492
Merge main so chat admission follows each agent's Chat or CLI choice
brennanb2025 Oct 31, 2026
bb726c9
test(native-chat): follow main's chat admission in fixtures and bound…
brennanb2025 Oct 31, 2026
e0659ca
test(native-chat): give the declared-effort catalog fake its capture …
brennanb2025 Oct 31, 2026
8960978
Merge main and keep the account-aware worker listing beside owner-rou…
brennanb2025 Oct 31, 2026
8d1ba5d
Merge main and keep the legacy no-choice replay contracts beside the …
brennanb2025 Oct 31, 2026
2078637
Consume main's outcome change feed in the receiving-account index
brennanb2025 Oct 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 174 additions & 0 deletions mobile/src/session/mobile-structured-unknown-consumer.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import { createElement, useState, type ReactNode } from 'react'
import { act, create, type ReactTestRenderer } from 'react-test-renderer'
import { expect, it, vi } from 'vitest'
import type { RpcClient } from '../transport/rpc-client'
import type { AgentSessionOptionsResult } from '../../../src/shared/agent-session-wire'
import { EMPTY_STRUCTURED_AGENT_SESSION } from '../../../src/shared/structured-agent-session-reducer'
import { useMobileStructuredAgentMutate } from './use-mobile-structured-agent-mutation'
import { fieldsOf } from './use-mobile-structured-agent-session-queued.test-fixture'
import { useMobileStructuredAgentOptions } from './use-mobile-structured-agent-options'
import {
MobileNativeChatSessionOptionPickers,
type MobileNativeChatPickerPresentation
} from './native-chat/input/MobileNativeChatSessionOptionPickers'
import { findAllByHostType } from '../test-support/react-test-renderer-host-nodes'

vi.mock('react-native', () => ({
AccessibilityInfo: { announceForAccessibilityWithOptions: vi.fn() },
ActivityIndicator: 'ActivityIndicator',
Keyboard: { dismiss: vi.fn() },
Platform: { OS: 'ios' },
Pressable: 'Pressable',
Switch: 'Switch',
StyleSheet: { create: (styles: unknown) => styles, hairlineWidth: 1 },
Text: 'Text',
View: 'View'
}))
vi.mock('lucide-react-native', () => ({
Check: 'Check',
ChevronDown: 'ChevronDown',
ChevronLeft: 'ChevronLeft',
ChevronRight: 'ChevronRight',
FilePenLine: 'FilePenLine',
Hand: 'Hand',
LockKeyhole: 'LockKeyhole',
ShieldAlert: 'ShieldAlert',
ShieldCheck: 'ShieldCheck',
X: 'X'
}))
vi.mock('../components/BottomDrawer', () => ({
BottomDrawer: ({ visible, children }: { visible: boolean; children?: ReactNode }) =>
visible ? createElement('BottomDrawer', null, children) : null
}))

it('shows an unknown model without sending or remembering a guess, then applies a real row pick', async () => {
let answer: AgentSessionOptionsResult = {
models: [{ id: 'sonnet', label: 'Sonnet', isDefault: false, efforts: [] }],
current: {},
conversationCommands: ['clear']
}
const writes: unknown[] = []
const sendRequest = vi.fn<RpcClient['sendRequest']>(async (method, params) => {
if (method === 'agentSession.setOption') {
expect(fieldsOf(params)).toMatchObject({ key: 'model', value: 'sonnet' })
answer = { ...answer, current: { model: 'sonnet', confirmed: ['model'] } }
return {
id: 'rpc',
ok: true,
result: {
ok: true,
replayed: false,
value: { key: 'model', value: 'sonnet', options: { model: 'sonnet' } }
},
_meta: { runtimeId: 'host-b' }
}
}
if (method === 'settings.mutateNativeChatSessionOptions') {
writes.push(params)
}
return {
id: 'rpc',
ok: true,
result:
method === 'agentSession.options'
? answer
: method === 'agentSession.modelCatalog'
? { origin: 'unknown' }
: {},
_meta: { runtimeId: 'host-b' }
}
})
const client: RpcClient = {
sendRequest,
subscribe: () => () => {},
updateTerminalSubscriptionViewport: () => {},
getState: () => 'connected',
getReconnectAttempt: () => 0,
getLastConnectedAt: () => null,
onStateChange: () => () => {},
notifyForeground: () => {},
close: () => {}
}
const stateRef = { current: { ...EMPTY_STRUCTURED_AGENT_SESSION, fence: 1 } }
let options!: ReturnType<typeof useMobileStructuredAgentOptions>
function Chat() {
const mutate = useMobileStructuredAgentMutate({
client,
sessionId: 'unknown-mobile',
enabled: true,
stateRef,
onSendError: (message) => {
throw new Error(message)
}
})
options = useMobileStructuredAgentOptions({
agent: 'claude',
client,
sessionId: 'unknown-mobile',
enabled: true,
fence: 1,
turnId: null,
mutate,
hostSupport: { permissionModes: false, coherentModelCatalog: true, statusFeed: false }
})
const [presentation, setPresentation] = useState<MobileNativeChatPickerPresentation | null>(
null
)
return createElement(MobileNativeChatSessionOptionPickers, {
controller: {
snapshot: options.optionSnapshot,
pendingId: options.pendingOptionId,
setOption: options.setStructuredOption,
invokeAction: options.invokeStructuredOption,
recordCommand: () => {}
},
isWorking: false,
presentation,
onDrawerOpen: (page) => setPresentation({ page, refocus: false }),
onNavigate: (page) => setPresentation((previous) => previous && { ...previous, page })
})
}
let renderer!: ReactTestRenderer
await act(async () => {
renderer = create(createElement(Chat))
})
try {
await vi.waitFor(() =>
expect(options.conversationCommands).toEqual(answer.conversationCommands)
)
const pill = () =>
renderer.root.find(
(node) =>
String(node.type) === 'Pressable' &&
String(node.props.accessibilityLabel).startsWith('Model,')
)
expect(pill().props.accessibilityLabel).toBe('Model, Model')
expect(options.sendSelection()).toBeUndefined()
expect(writes).toEqual([])
expect(
sendRequest.mock.calls.filter(([method]) => method === 'agentSession.setOption')
).toHaveLength(0)
await act(async () => pill().props.onPress())
const row = renderer.root.find(
(node) =>
String(node.type) === 'Pressable' &&
node.props.accessibilityRole === 'radio' &&
findAllByHostType(node, 'Text').some((text) => text.props.children === 'Sonnet')
)
expect(row.props.accessibilityState.checked).toBe(false)
await act(async () => row.props.onPress())
expect(options.sendSelection()).toEqual({ model: 'sonnet' })
expect(pill().props.accessibilityLabel).toBe('Model, Sonnet')
await vi.waitFor(() =>
expect(writes).toEqual([
{
type: 'apply-picks',
agent: 'claude',
picks: [{ modelId: 'sonnet', optionId: 'model', value: 'sonnet' }]
}
])
)
} finally {
await act(async () => renderer.unmount())
}
})
12 changes: 9 additions & 3 deletions src/main/acp/acp-structured-host-live-listing.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import {
hostTestCatalogReadOperation,
HOST_TEST_SESSION as SESSION
} from '../native-chat/agent-session-wire/structured-agent-session-host-test-data'
import { AcpStructuredOptions } from './acp-structured-options'
import { createAgentModelCatalogService } from '../native-chat/agent-model-catalog/agent-model-catalog-service'
import {
createAgentModelCatalogService,
type AgentModelCatalogService
} from '../native-chat/agent-model-catalog/agent-model-catalog-service'
import {
AgentModelCatalogStore,
type AgentModelCatalogEntry
Expand All @@ -14,8 +21,6 @@ import { GROK_CONFIG_OPTIONS, PROVIDER_SESSION } from './acp-structured-adapter.

import { afterEach, describe, expect, it, onTestFinished, vi } from 'vitest'
import { closeProviderTimelineRigs } from '../native-chat/agent-session-timeline/provider-timeline-assembler-test-support'
import { HOST_TEST_SESSION as SESSION } from '../native-chat/agent-session-wire/structured-agent-session-host-test-data'
import type { AgentModelCatalogService } from '../native-chat/agent-model-catalog/agent-model-catalog-service'
import { attachParams, openAttachedHostRig, openHostRig } from './acp-structured-host.test-support'

afterEach(async () => {
Expand Down Expand Up @@ -92,6 +97,7 @@ describe('a live Grok listing', () => {

it('starts the chat even when saving its start listing throws', async () => {
const modelCatalog: AgentModelCatalogService = {
captureRead: hostTestCatalogReadOperation,
snapshot: vi.fn(() => ({ origin: 'unknown' as const })),
demand: vi.fn(async () => {}),
prepareSaved: vi.fn(async () => ({ origin: 'unknown' as const })),
Expand Down
16 changes: 12 additions & 4 deletions src/main/acp/acp-structured-host-restore-failed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,25 @@ describe('a created Grok session Grok reports missing on the first reopen', () =
describe('a replacement after its earlier attach failed to open the journal', () => {
async function failAttachBeforeReplacement() {
const opened = await openRestoreRig(-32603, 'session file is corrupt')
const { host, store, fence, warnings, ready } = opened
const { host, store, fence, warnings, ready, rig } = opened
expect(await host.attach(CALLER, attachParams())).toMatchObject({ ok: true })
await ready()
await host.close(SESSION, 'user-close')
const spawnedBefore = [...rig.spawned]
const chainBefore = structuredClone(store.getRecord(SESSION)?.providerHandleChain)
// Fail before the spawned child's background handshake can prove a replacement link.
vi.spyOn(AgentSessionJournal.prototype, 'open').mockRejectedValueOnce(
new Error('journal path unavailable')
)
await expect(host.attach(CALLER, attachParams(fence()))).rejects.toThrow(
'journal path unavailable'
)
expect(await host.attach(CALLER, attachParams(fence()))).toMatchObject({
ok: false,
refusal: {
code: 'agent_session_journal_unreadable',
details: { reason: 'journalUnavailable' }
}
})
expect(rig.spawned).toEqual(spawnedBefore)
expect(store.getRecord(SESSION)?.providerHandleChain).toEqual(chainBefore)
expect(
agentSessionProviderHandleChainHead(store.getRecord(SESSION)?.providerHandleChain ?? [])
).toMatchObject({
Expand Down
23 changes: 23 additions & 0 deletions src/main/claude-accounts/claude-profile-launch-preparation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { existsSync } from 'node:fs'
import { claudeProfileMarkerPath, type ClaudeProfileDescriptor } from './claude-profile-paths'
import type { ClaudeProfileSetupReport } from './claude-profile-setup'
import { claudeProfileSetupFailed } from './claude-profile-launch-errors'

/** First construction requires setup; a prepared profile keeps its existing bounded refresh behavior. */
export async function prepareClaudeProfileForLaunch(
profile: ClaudeProfileDescriptor,
setUp: (profile: ClaudeProfileDescriptor) => Promise<ClaudeProfileSetupReport>,
waitMs = 5_000
): Promise<void> {
if (!existsSync(claudeProfileMarkerPath(profile))) {
const report = await setUp(profile).catch(() => null)
if (report?.outcome !== 'prepared') {
throw claudeProfileSetupFailed()
}
return
}
const refresh = setUp(profile).catch((error: unknown) => {
console.warn('[claude-profile] Account refresh failed:', error)
})
await Promise.race([refresh, new Promise((resolve) => setTimeout(resolve, waitMs).unref())])
}
36 changes: 18 additions & 18 deletions src/main/claude-accounts/claude-profile-router.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { prepareClaudeProfileForLaunch } from './claude-profile-launch-preparation'
import { getClaudeAgentViewService } from '../claude/agent-view-service'
import { existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs'
import { homedir } from 'node:os'
Expand All @@ -9,13 +10,12 @@ import {
CLAUDE_PROFILE_SETUP_FAILED_MESSAGE,
CLAUDE_USER_CONFIG_DIR_ENV
} from '../../shared/claude-profile-routing'
import { claudeProfileMissing, claudeProfileSetupFailed } from './claude-profile-launch-errors'
import { claudeProfileMissing } from './claude-profile-launch-errors'
import type { GlobalSettings } from '../../shared/global-settings-types'
import { probeRecentClaudeCliVersion } from '../claude/claude-hook-event-versions'
import { writeFileAtomically } from '../codex-accounts/fs-utils'
import { resolveClaudeCommand } from '../codex-cli/command'
import {
claudeProfileMarkerPath,
describeClaudeProfile,
type ClaudeProfileDescriptor,
readUserClaudeConfigDir,
Expand All @@ -42,8 +42,6 @@ import {
} from './claude-account-folder'
import { resolveLoginShellEnvironment } from '../startup/login-shell-environment'

const REFRESH_WAIT_MS = 5_000

export type ClaudeProfileRouterSettings = Pick<
GlobalSettings,
| 'claudeManagedAccounts'
Expand Down Expand Up @@ -178,23 +176,25 @@ export class ClaudeProfileRouter {
if (!profile) {
return this.preparation()
}
// A missing marker means initial setup has not completed.
if (!existsSync(claudeProfileMarkerPath(profile))) {
const report = await this.setUp(profile).catch(() => null)
if (report?.outcome !== 'prepared') {
throw claudeProfileSetupFailed()
}
return this.preparation()
}
// Run with the previous setup if refreshing fails or exceeds the deadline.
const refresh = this.setUp(profile).catch((error: unknown) => {
console.warn('[claude-profile] Account refresh failed:', error)
})
const waitMs = this.args.refreshWaitMs ?? REFRESH_WAIT_MS
await Promise.race([refresh, new Promise((resolve) => setTimeout(resolve, waitMs).unref())])
await prepareClaudeProfileForLaunch(
profile,
(value) => this.setUp(value),
this.args.refreshWaitMs
)
return this.preparation()
}

/** Prepare an observed receiving route without mutating selection or adopting a System-default alias. */
async prepareReceivingAccount(accountId: string): Promise<string> {
const profile = this.describe(accountId)
await prepareClaudeProfileForLaunch(
profile,
(value) => this.setUp(value),
this.args.refreshWaitMs
)
return profile.home
}

accountHome(accountId: string): string {
return this.describe(accountId).home
}
Expand Down
47 changes: 47 additions & 0 deletions src/main/claude/claude-receiving-account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { CLAUDE_INJECTED_CONFIG_DIR_ENV } from '../../shared/claude-profile-routing'
import type { ClaudeAccountRecipe } from '../../shared/agent-session-acquired-account'
import type { ClaudeProfileRouter } from '../claude-accounts/claude-profile-router'
import { claudeProfileMissing } from '../claude-accounts/claude-profile-launch-errors'
import { applyClaudeEnvPatch } from '../claude-accounts/environment'
import { resolveStructuredClaudeAccountHomePath } from '../runtime/structured-agent-account-home'

/** Only actual preparation produces a receipt; selection is never backfilled as acquisition. */
export async function prepareClaudeReceivingAccount(
router: ClaudeProfileRouter | undefined,
env: Record<string, string>,
recordHome: string,
receiving?: ClaudeAccountRecipe
): Promise<ClaudeAccountRecipe> {
if (receiving?.route === 'managed') {
if (!router) {
throw claudeProfileMissing()
}
const home = await router.prepareReceivingAccount(receiving.accountId)
applyClaudeEnvPatch(env, { CLAUDE_CONFIG_DIR: home, [CLAUDE_INJECTED_CONFIG_DIR_ENV]: home })
return { ...receiving, home }
}
if (receiving) {
if (receiving.configDir === null) {
delete env.CLAUDE_CONFIG_DIR
} else {
env.CLAUDE_CONFIG_DIR = receiving.configDir
}
return receiving
}
if (!router) {
return { route: 'system', home: recordHome, configDir: env.CLAUDE_CONFIG_DIR ?? null }
}
const preparation = await router.prepareLaunch()
const home =
preparation.provenance === 'system'
? resolveStructuredClaudeAccountHomePath({
launchEnv: env,
wslDistro: null,
getClaudeConfigDirectory: () => router.systemDefaultHome()
})
: preparation.configDir
applyClaudeEnvPatch(env, preparation.envPatch)
return preparation.provenance.startsWith('profile:')
? { route: 'managed', accountId: preparation.provenance.slice('profile:'.length), home }
: { route: 'system', home, configDir: env.CLAUDE_CONFIG_DIR ?? null }
}
1 change: 1 addition & 0 deletions src/main/claude/claude-structured-acquisition-launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export async function resolveClaudeAcquisitionLaunch(args: {
.resolveLaunch({
identity: launchIdentity,
spawnToken: input.spawnToken,
...(input.accountRecipe ? { accountRecipe: input.accountRecipe } : {}),
...(input.permissionMode ? { permissionMode: input.permissionMode } : {})
})
.catch((error: unknown) => {
Expand Down
Loading