Skip to content
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a9401b7
refactor(mobile): add host operation interfaces and native adapters
Jinwoo-H Sep 9, 2026
ee61c99
refactor(mobile): route task screens through HostTaskOperations
Jinwoo-H Sep 9, 2026
2139480
refactor(mobile): route session, file and account screens through ope…
Jinwoo-H Sep 9, 2026
222134e
test(mobile): ratchet inline RPC out of screens
Jinwoo-H Sep 9, 2026
538bfd2
fix(mobile): match main's observable behavior in the host adapters
Jinwoo-H Sep 9, 2026
654db50
fix(mobile): keep two adapter improvements over the calls they replaced
Jinwoo-H Sep 9, 2026
1b86a68
fix(mobile): close the seven defects the adapter review found
Jinwoo-H Sep 9, 2026
aefdf2d
fix(mobile): await each per-repo GitHub count so one failure is a zero
Jinwoo-H Sep 9, 2026
e1b7aa8
refactor(mobile): drop the browser adapter methods nothing calls
Jinwoo-H Sep 9, 2026
cb10440
fix(mobile): remove a stream error callback that could never fire
Jinwoo-H Sep 9, 2026
cac6346
refactor(mobile): drop the resolve request field the wire never carried
Jinwoo-H Sep 9, 2026
d07fe48
fix(mobile): restore the state commit between the two Tasks hydration…
Jinwoo-H Sep 9, 2026
0aaa70e
test(mobile): restore the four assertions the extraction weakened
Jinwoo-H Sep 9, 2026
b1f1ff7
test(mobile): bound the Project host oracle to its own adapter method
Jinwoo-H Sep 9, 2026
5cbbadf
refactor(mobile): drop the five adapter methods with no live caller
Jinwoo-H Sep 9, 2026
66e698a
refactor(mobile): drop the capability projection its last caller left…
Jinwoo-H Sep 9, 2026
892c6fc
refactor(mobile): drop the per-namespace default factories nothing im…
Jinwoo-H Sep 9, 2026
753ec13
test(mobile): bound the Project host oracle to a real method boundary
Jinwoo-H Sep 9, 2026
3220919
fix(mobile): delete the Ctrl+U prefix send path this PR added
Jinwoo-H Sep 9, 2026
73125e3
fix(mobile): prune a closed session tab on ok alone, as main did
Jinwoo-H Sep 9, 2026
14e0c47
fix(mobile): send Stop on whatever budget is left, and pin the device…
Jinwoo-H Sep 9, 2026
df248c4
refactor(mobile): drop the two create fields with no producer or cons…
Jinwoo-H Sep 9, 2026
3924105
fix(mobile): check the quick-command load envelope outside the cutove…
Jinwoo-H Sep 9, 2026
d0994be
refactor(mobile): delete the seam surface with no production reader
Jinwoo-H Sep 9, 2026
d96f684
fix(mobile): restore main's guard conditions on the four Project-row …
Jinwoo-H Sep 9, 2026
888d999
fix(mobile): drop the defensive normalizers main did not have
Jinwoo-H Sep 9, 2026
0121543
test(mobile): fix the contracts target shape and pin the send option …
Jinwoo-H Sep 9, 2026
59e5e6e
refactor(mobile): call the transport directly for Retry, and fix thre…
Jinwoo-H Sep 9, 2026
bcba08b
test(mobile): pin that a refused tab close still prunes, and drop two…
Jinwoo-H Sep 9, 2026
1ec6db4
fix mobile project payload and account fixtures
Jinwoo-H Sep 9, 2026
5586569
Fix stale legacy file inventory generation guard
Jinwoo-H Sep 9, 2026
18d8062
fix mobile test fixtures
Jinwoo-H Sep 9, 2026
053d6d4
Fix Project mutation acceptance and Linear detail ordering
Jinwoo-H Sep 9, 2026
f25dd7d
Guard stale legacy inventory completions
Jinwoo-H Sep 9, 2026
76c8fc3
fix mobile task detail projections and list types
Jinwoo-H Sep 9, 2026
be4a2da
Fix mobile task detail projections and list result types
Jinwoo-H Sep 9, 2026
5e93f06
Fix mobile legacy inventory reset and stale completion regression
Jinwoo-H Sep 9, 2026
dace3bc
Fix Project mutation acceptance and Linear detail ordering tests
Jinwoo-H Sep 9, 2026
3d2c11e
Repair mobile fixture types, detail shape, workspace type and parity …
Jinwoo-H Sep 9, 2026
1043e1e
style(mobile): format native-host-task-operation-contracts test
Jinwoo-H Sep 9, 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
72 changes: 24 additions & 48 deletions mobile/app/h/[hostId]/accounts.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState, useCallback } from 'react'
import { useEffect, useMemo, useState, useCallback } from 'react'
import {
View,
Text,
Expand All @@ -20,7 +20,6 @@ import { ClaudeIcon, OpenAIIcon } from '../../../src/components/AgentIcons'
import {
type AccountsSnapshot,
type ProviderKey,
decodeAccountsSnapshot,
getActiveProviderRateLimits,
getInactiveProviderUsage,
getUsageBarState,
Expand All @@ -34,6 +33,7 @@ import {
} from '../../../src/components/codex-reset-credit'
import { CodexResetCreditAction } from '../../../src/components/CodexResetCreditAction'
import { useCodexResetCreditAction } from '../../../src/components/use-codex-reset-credit-action'
import { defaultHostAccountOperations } from '../../../src/accounts/default-host-account-operations'

export default function AccountsScreen() {
const router = useRouter()
Expand All @@ -42,6 +42,10 @@ export default function AccountsScreen() {

// Why: shared client per host. See docs/mobile-shared-client-per-host.md.
const { client, state: connState } = useHostClient(hostId)
const operations = useMemo(
() => (client && hostId ? defaultHostAccountOperations(client) : null),
[client, hostId]
)
const [hostName, setHostName] = useState<string>('')
const [snapshot, setSnapshot] = useState<AccountsSnapshot | null>(null)
const [error, setError] = useState<string | null>(null)
Expand All @@ -66,6 +70,8 @@ export default function AccountsScreen() {
scopeLabel: resetScopeLabel,
confirmReset: confirmCodexReset
} = useCodexResetCreditAction({
// Why: still the client — the capability probe behind this hook retries a failed
// status.get, which a one-shot operations read cannot reproduce.
client,
connected: connState === 'connected',
hostId,
Expand All @@ -88,6 +94,8 @@ export default function AccountsScreen() {
return
}
let stale = false
// Why: the local host catalog, not the adapter — `operations` is null in exactly the
// host-missing case this reports, so routing it there would show a blank screen instead.
void loadHosts().then((hosts) => {
if (stale) {
return
Expand All @@ -109,37 +117,19 @@ export default function AccountsScreen() {
// when the user switches accounts. Falls back to a one-shot accounts.list
// if the subscription stream errors.
useEffect(() => {
if (!client || connState !== 'connected') {
if (!operations || connState !== 'connected') {
return
}
const unsubscribe = client.subscribe('accounts.subscribe', null, (payload) => {
if (!payload || typeof payload !== 'object') {
return
}
const evt = payload as { type?: string; snapshot?: unknown }
if (evt.type === 'ready' || evt.type === 'snapshot') {
try {
acceptSnapshot(decodeAccountsSnapshot(evt.snapshot))
} catch {
rejectInvalidSnapshot()
}
}
})
return unsubscribe
}, [acceptSnapshot, client, connState, rejectInvalidSnapshot])
return operations.subscribe(acceptSnapshot, rejectInvalidSnapshot)
}, [acceptSnapshot, connState, operations, rejectInvalidSnapshot])

const refresh = useCallback(async () => {
if (!client) {
if (!operations) {
return
}
setRefreshing(true)
try {
const res = await client.sendRequest('accounts.list')
if (res.ok) {
acceptSnapshot(decodeAccountsSnapshot(res.result))
} else {
setError(res.error.message)
}
acceptSnapshot(await operations.snapshot())
} catch (e) {
if (e instanceof Error && e.message === 'Invalid accounts snapshot from host') {
rejectInvalidSnapshot()
Expand All @@ -149,45 +139,31 @@ export default function AccountsScreen() {
} finally {
setRefreshing(false)
}
}, [acceptSnapshot, client, rejectInvalidSnapshot])
}, [acceptSnapshot, operations, rejectInvalidSnapshot])

const selectAccount = useCallback(
async (provider: ProviderKey, accountId: string | null) => {
if (!client) {
if (!operations) {
return
}
const codexTarget = provider === 'codex' ? snapshot?.rateLimits.codexTarget : null
if (provider === 'codex' && !codexTarget) {
return
}
setBusyAccountId(accountId ?? `${provider}:default`)
const method =
provider === 'claude'
? 'accounts.selectClaude'
: codexTarget?.runtime === 'wsl'
? 'accounts.selectCodexForTarget'
: 'accounts.selectCodex'
try {
// Why: old hosts silently strip unknown target fields. Use the distinct
// targeted RPC for WSL so version skew fails before mutating host state.
const params =
codexTarget?.runtime === 'wsl' ? { accountId, target: codexTarget } : { accountId }
const res = await client.sendRequest(method, params)
if (!res.ok) {
Alert.alert('Could not switch account', res.error.message)
} else {
// Why: optimistic refresh — the streaming subscription will also
// emit, but a one-shot keeps the UI responsive even if the stream
// is temporarily disconnected.
await refresh()
}
await operations.select(provider, accountId, codexTarget)
// Why: optimistic refresh — the streaming subscription will also
// emit, but a one-shot keeps the UI responsive even if the stream
// is temporarily disconnected.
await refresh()
} catch (e) {
Alert.alert('Could not switch account', e instanceof Error ? e.message : String(e))
} finally {
setBusyAccountId(null)
}
},
[client, refresh, snapshot]
[operations, refresh, snapshot]
)

const renderProviderSection = (provider: ProviderKey, title: string) => {
Expand Down Expand Up @@ -343,7 +319,7 @@ export default function AccountsScreen() {
<Pressable
style={styles.iconButton}
onPress={refresh}
disabled={!client || refreshing || connState !== 'connected'}
disabled={!operations || refreshing || connState !== 'connected'}
>
{refreshing ? (
<ActivityIndicator size="small" color={colors.textSecondary} />
Expand Down
13 changes: 13 additions & 0 deletions mobile/src/accounts-route-reset-credit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ vi.mock('expo-router', async () => {

vi.mock('expo-crypto', () => ({ randomUUID: dependencies.randomUUID }))

// The account adapter reaches device operations for its idempotency nonce, which pulls the
// native expo modules into this module graph.
vi.mock('expo-clipboard', () => ({ setStringAsync: vi.fn() }))
vi.mock('expo-haptics', () => ({
AndroidHaptics: {},
ImpactFeedbackStyle: {},
NotificationFeedbackType: {},
impactAsync: vi.fn(),
notificationAsync: vi.fn(),
performAndroidHapticsAsync: vi.fn(),
selectionAsync: vi.fn()
}))

vi.mock('lucide-react-native', () => ({
Check: 'Check',
ChevronLeft: 'ChevronLeft',
Expand Down
7 changes: 7 additions & 0 deletions mobile/src/accounts/default-host-account-operations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { RpcClient } from '../transport/rpc-client'
import type { HostAccountOperations } from './host-account-operations'
import { nativeHostAccountOperations } from './native-host-account-operations'

export function defaultHostAccountOperations(client: RpcClient): HostAccountOperations {
return nativeHostAccountOperations(client)
}
15 changes: 15 additions & 0 deletions mobile/src/accounts/host-account-operations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type {
AccountsSnapshot,
ProviderKey,
RateLimitRuntimeTarget
} from '../components/account-usage-state'

export type HostAccountOperations = {
snapshot(): Promise<AccountsSnapshot>
select(
provider: ProviderKey,
accountId: string | null,
codexTarget?: RateLimitRuntimeTarget | null
): Promise<void>
subscribe(listener: (snapshot: AccountsSnapshot) => void, onInvalid?: () => void): () => void
}
59 changes: 59 additions & 0 deletions mobile/src/accounts/native-host-account-operations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {
decodeAccountsSnapshot,
type ProviderKey,
type RateLimitRuntimeTarget
} from '../components/account-usage-state'
import type { RpcClient } from '../transport/rpc-client'
import type { RpcSuccess } from '../transport/types'
import type { HostAccountOperations } from './host-account-operations'

export function nativeHostAccountOperations(client: RpcClient): HostAccountOperations {
return {
async snapshot() {
const response = await client.sendRequest('accounts.list')
requireSuccess(response)
return decodeAccountsSnapshot((response as RpcSuccess).result)
},
async select(provider, accountId, codexTarget) {
// Why: old hosts silently strip unknown target fields. Use the distinct
// targeted RPC for WSL so version skew fails before mutating host state.
const method = selectionMethod(provider, codexTarget)
const params =
provider === 'codex' && codexTarget?.runtime === 'wsl'
? { accountId, target: codexTarget }
: { accountId }
requireSuccess(await client.sendRequest(method, params))
},
subscribe(listener, onInvalid) {
return client.subscribe('accounts.subscribe', null, (payload) => {
if (!payload || typeof payload !== 'object') {
return
}
const event = payload as { type?: string; snapshot?: unknown }
if (event.type === 'ready' || event.type === 'snapshot') {
try {
listener(decodeAccountsSnapshot(event.snapshot))
} catch {
onInvalid?.()
}
}
})
}
}
}

function selectionMethod(
provider: ProviderKey,
target?: RateLimitRuntimeTarget | null
): 'accounts.selectClaude' | 'accounts.selectCodex' | 'accounts.selectCodexForTarget' {
if (provider === 'claude') {
return 'accounts.selectClaude'
}
return target?.runtime === 'wsl' ? 'accounts.selectCodexForTarget' : 'accounts.selectCodex'
}

function requireSuccess(response: { ok: boolean; error?: { message?: string } }): void {
if (!response.ok) {
throw new Error(response.error?.message ?? 'Account operation failed')
}
}
23 changes: 16 additions & 7 deletions mobile/src/components/NewWorktreeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { SmartModeAvailabilityInput } from '../tasks/mobile-smart-source-mo
import { deriveRepoSlug, type PasteRepoCandidate } from '../tasks/smart-source-paste-intent'
import { useMobileComposerSource } from '../tasks/use-mobile-composer-source'
import { useNewWorktreeRuntimeCapabilities } from '../tasks/worktree-create-capability'
import { defaultHostWorkspaceCreationOperations } from '../worktree/default-host-workspace-creation-operations'
import {
buildRetiredWorktreeNamesRefreshKey,
useRetiredWorktreeNames
Expand Down Expand Up @@ -57,24 +58,28 @@ export function NewWorktreeModal(props: NewWorktreeModalProps) {
function NewWorktreeModalContent(props: NewWorktreeModalProps) {
const { visible, client, hostId, existingWorktreePaths, existingWorktrees, onCreated, onClose } =
props
const operations = useMemo(
() => (client ? defaultHostWorkspaceCreationOperations(client) : null),
[client]
)
const { repos, selectedRepo, setSelectedRepo, loading } = useNewWorkspaceRepositories({
client,
operations,
hostId,
visible
})
const navigation = useNewWorktreeDrawerNavigation(visible)
const [note, setNote] = useState('')
const [error, setError] = useState('')
const runtime = useNewWorkspaceRuntimeContext(client, visible, hostId)
const runtime = useNewWorkspaceRuntimeContext(operations, visible, hostId)
const { tasksSupported, hostPlatform, getWorktreeCreateCutoverSupport } =
useNewWorktreeRuntimeCapabilities(client, visible)
useNewWorktreeRuntimeCapabilities(operations, visible)
const selectedRepoConnectionId = selectedRepo?.connectionId ?? null
const executionTarget = useNewWorkspaceExecutionTarget({
client,
operations,
connectionId: selectedRepoConnectionId,
visible
})
const setupScript = useNewWorkspaceSetupScript({ client, selectedRepo })
const setupScript = useNewWorkspaceSetupScript({ operations, selectedRepo })
const selectedRepoWorktreeBranches = useMemo(
() => getComposerRepoWorktreeBranches(existingWorktrees ?? [], selectedRepo?.id ?? null),
[existingWorktrees, selectedRepo]
Expand All @@ -94,8 +99,12 @@ function NewWorktreeModalContent(props: NewWorktreeModalProps) {
() => buildRetiredWorktreeNamesRefreshKey(existingWorktreePaths),
[existingWorktreePaths]
)
const readRetiredWorktreeNames = useMemo(
() => (operations ? (repoId: string) => operations.readRetiredWorktreeNames(repoId) : null),
[operations]
)
const retiredWorktreeNames = useRetiredWorktreeNames(
client,
readRetiredWorktreeNames,
selectedRepo?.id,
retiredNamesRefreshKey
)
Expand Down Expand Up @@ -233,7 +242,7 @@ function NewWorktreeModalContent(props: NewWorktreeModalProps) {
<NewWorktreeModalDrawers
visible={visible}
drawerView={navigation.drawerView}
client={client}
operations={operations}
composer={composer}
sourceAvailability={sourceAvailability}
selectedRepo={selectedRepo}
Expand Down
4 changes: 2 additions & 2 deletions mobile/src/components/NewWorktreeModalDrawers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Composer = ReturnType<typeof useMobileComposerSource>
export function NewWorktreeModalDrawers(props: {
visible: boolean
drawerView: NewWorktreeDrawerView
client: Parameters<typeof SmartWorkspaceSourceDrawer>[0]['client']
operations: Parameters<typeof SmartWorkspaceSourceDrawer>[0]['operations']
composer: Composer
sourceAvailability: SmartModeAvailabilityInput
selectedRepo: MobileWorkspaceRepo | null
Expand All @@ -49,7 +49,7 @@ export function NewWorktreeModalDrawers(props: {
<>
<SmartWorkspaceSourceDrawer
visible={props.visible && props.drawerView === 'source'}
client={props.client}
operations={props.operations}
composer={props.composer}
availability={props.sourceAvailability}
repoId={props.selectedRepo?.id ?? null}
Expand Down
12 changes: 6 additions & 6 deletions mobile/src/components/SmartWorkspaceSourceDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
TextInput,
View
} from 'react-native'
import type { RpcClient } from '../transport/rpc-client'
import type { HostWorkspaceCreationOperations } from '../worktree/host-workspace-creation-operations'
import type { SmartWorkspaceSourceRow as SourceRow } from '../../../src/shared/new-workspace/smart-workspace-source-results'
import {
MR_STATE_FILTER_OPTIONS,
Expand Down Expand Up @@ -37,7 +37,7 @@ const SOURCE_INPUT_FOCUS_DELAY_MS = 120

type Props = {
visible: boolean
client: RpcClient | null
operations: HostWorkspaceCreationOperations | null
composer: MobileComposerSource
availability: SmartModeAvailabilityInput
repoId: string | null
Expand All @@ -50,7 +50,7 @@ type Props = {

export function SmartWorkspaceSourceDrawer({
visible,
client,
operations,
composer,
availability,
repoId,
Expand Down Expand Up @@ -113,7 +113,7 @@ export function SmartWorkspaceSourceDrawer({
crossRepoPrompt,
dismissCrossRepoPrompt
} = useSmartWorkspaceSource({
client,
operations,
enabled: searchEnabled,
mode: effectiveMode,
query: composer.name,
Expand Down Expand Up @@ -151,13 +151,13 @@ export function SmartWorkspaceSourceDrawer({
}

async function handleAcceptCrossRepo(): Promise<void> {
if (!client || !crossRepoPrompt) {
if (!operations || !crossRepoPrompt) {
return
}
const { link, matchingRepo } = crossRepoPrompt
try {
const item = await lookupGitHubItemByOwnerRepo(
client,
operations,
matchingRepo.id,
link.slug,
link.number,
Expand Down
Loading