diff --git a/apps/android/src/screens/host-sessions-drawer.tsx b/apps/android/src/screens/host-sessions-drawer.tsx
index b02e0a3..c60c18e 100644
--- a/apps/android/src/screens/host-sessions-drawer.tsx
+++ b/apps/android/src/screens/host-sessions-drawer.tsx
@@ -1,6 +1,5 @@
-import { useEffect, useMemo, useRef, useState } from 'react'
+import { useEffect, useMemo, useRef, useState, type MutableRefObject } from 'react'
import {
- Alert,
ActivityIndicator,
Animated,
Easing,
@@ -19,6 +18,7 @@ import {
View,
useWindowDimensions,
} from 'react-native'
+import { Alert } from '../ui/alert'
import * as Haptics from 'expo-haptics'
import * as Clipboard from 'expo-clipboard'
import Svg, { Path } from 'react-native-svg'
@@ -30,7 +30,6 @@ import {
ChevronRight,
ChevronsUpDown,
Clock,
- Puzzle,
Folder,
FolderOpen,
FolderPlus,
@@ -39,6 +38,7 @@ import {
Monitor,
MoreHorizontal,
Plus,
+ Puzzle,
MoreVertical,
Search,
Server,
@@ -50,6 +50,7 @@ import {
} from 'lucide-react-native'
import { useSafeAreaInsets } from 'react-native-safe-area-context'
import { useAppStore } from '../state/store'
+import { dispatchSessionCatalogCommand } from '../state/session-catalog-commands'
import { isKnownBotSessionId, useBotTeamStore } from '../state/bot-store'
import type { AgentBackend, RemoteSession, WorkspaceView } from '../types'
import { strings } from '../locales/i18n'
@@ -62,6 +63,7 @@ import { easingCurve, indicatorGeometry, motionTokens, resolveMotion } from '../
import { useReduceMotion } from '../ui/use-reduce-motion'
import { resolveSessionDisplayTitle } from './session-title'
import { OfficialMenuIcons } from '../ui/official-menu-icons'
+import { isVisibleSession } from '../lib/session-visibility'
import { browseStatus } from '../lib/backend-groups'
import { browseScope, saveHostMode, useBrowseMemory } from '../services/browse-memory'
import {
@@ -82,8 +84,8 @@ import { CreateWorkspaceModal, RenameWorkspaceModal, WorkspaceActionsModal } fro
const SESSION_PAGE_SIZE = 3
const DRAWER_WIDTH_RATIO = 1
-/** Padding inside the Agent / DS-Bot segmented track. */
-const MODE_SWITCHER_INSET = 3
+/** Padding inside the Agent / DS-Bot underline tab track. */
+const MODE_SWITCHER_INSET = 0
/** 浮窗相对工具栏底部的间距 */
const POPOVER_OFFSET = 4
@@ -142,20 +144,19 @@ interface DrawerSection {
}
interface HarnessOption {
- value: AgentBackend
+ value: AgentBackend & keyof typeof strings.sessions.backendDescriptions
name: string
- desc: string
}
const HARNESS_OPTIONS: HarnessOption[] = [
- { value: 'harness', name: 'DeepSeek Harness', desc: '官方 DeepSeek 智能体框架' },
- { value: 'codex', name: 'Codex', desc: 'OpenAI Codex 编程智能体' },
- { value: 'claude', name: 'Claude', desc: 'Anthropic Claude 智能体' },
- { value: 'hermes', name: 'Hermes', desc: 'Nous Research Hermes Agent 智能体' },
- { value: 'cursor', name: 'Cursor', desc: 'Cursor IDE 交互智能体' },
- { value: 'antigravity', name: 'Antigravity', desc: 'Antigravity 研发框架' },
- { value: 'opencode', name: 'OpenCode', desc: 'OpenCode 开源智能体' },
- { value: 'pi', name: 'Pi', desc: 'Personal Intelligence 智能体' },
+ { value: 'harness', name: 'DeepSeek Harness' },
+ { value: 'codex', name: 'Codex' },
+ { value: 'claude', name: 'Claude' },
+ { value: 'hermes', name: 'Hermes' },
+ { value: 'cursor', name: 'Cursor' },
+ { value: 'antigravity', name: 'Antigravity' },
+ { value: 'opencode', name: 'OpenCode' },
+ { value: 'pi', name: 'Pi' },
]
function harnessDisplayName(value: AgentBackend): string {
@@ -190,6 +191,8 @@ export function HostSessionsDrawer({
inline = false,
backLabel,
dismissible = true,
+ entrance = 'immediate',
+ backRef,
}: {
onBack?: () => void
onClose: () => void
@@ -209,6 +212,10 @@ export function HostSessionsDrawer({
backLabel?: string
/** 冷启动停留在侧边栏且尚未选择任何页面时,禁止手势/返回键把侧边栏划走。 */
dismissible?: boolean
+ /** 默认停留在列表或切换主机时直接就位,避免先露底层对话再滑入;从对话呼出时才滑入。 */
+ entrance?: 'immediate' | 'slide'
+ /** 由 ChatScreen 统一协调硬件返回键顺序。 */
+ backRef?: MutableRefObject<(() => boolean) | undefined>
}) {
const language = useAppStore(state => state.language)
const deviceId = useAppStore(state => state.selectedDevice?.deviceId)
@@ -243,12 +250,13 @@ export function HostSessionsDrawer({
const moveWorkspace = useAppStore(state => state.workspaceMove)
const deleteWorkspace = useAppStore(state => state.workspaceDelete)
const busy = useAppStore(state => state.busyAction)
+ const drawerLayoutMode = useAppStore(state => state.drawerLayoutMode)
+ const isClassicDrawer = drawerLayoutMode === 'classic'
const connected = useAppStore(state => state.connection.phase === 'connected')
const error = useAppStore(state => state.error)
const clearError = useAppStore(state => state.clearError)
const devicesRefreshing = useAppStore(state => state.refreshing)
const refreshDevices = useAppStore(state => state.refreshDevices)
- const refreshWorkspaces = useAppStore(state => state.refreshWorkspaces)
const createSession = useAppStore(state => state.createSession)
const pinSession = useAppStore(state => state.pinSession)
const unpinSession = useAppStore(state => state.unpinSession)
@@ -287,8 +295,18 @@ export function HostSessionsDrawer({
const handleSwitchMode = (nextMode: 'agent' | 'bot') => {
setDrawerMode(nextMode)
- saveHostMode(hostScope, nextMode)
- onBotModeChange?.(nextMode === 'bot')
+ // In single-pane phone overlay mode, switching tabs only browses the other
+ // roster without mutating the underlying conversation until an item is chosen.
+ if (inline) {
+ saveHostMode(hostScope, nextMode)
+ onBotModeChange?.(nextMode === 'bot')
+ }
+ }
+
+ const activateAgentMode = () => {
+ setDrawerMode('agent')
+ saveHostMode(hostScope, 'agent')
+ onBotModeChange?.(false)
}
const [createWorkspaceOpen, setCreateWorkspaceOpen] = useState(false)
@@ -330,8 +348,8 @@ export function HostSessionsDrawer({
setVisibleCounts({})
}, [deviceId, selected?.backend])
useEffect(() => {
- if (connected) void refreshWorkspaces(backend)
- }, [backend, connected, deviceId, refreshWorkspaces])
+ if (connected) void dispatchSessionCatalogCommand({ type: 'refresh-catalog', backend })
+ }, [backend, connected, deviceId])
const [harnessPickerOpen, setHarnessPickerOpen] = useState(false)
const windowDimensions = useWindowDimensions()
@@ -355,8 +373,8 @@ export function HostSessionsDrawer({
setHarnessPickerOpen(false)
if (!isBackendAvailable(target)) {
Alert.alert(
- strings.common.unavailable ?? '平台未启用',
- `当前连接的主机未启用 ${harnessDisplayName(target)} 服务,请在电脑端配置或启动该智能体。`,
+ strings.common.unavailable,
+ strings.sessions.backendUnavailable(harnessDisplayName(target)),
)
return
}
@@ -608,7 +626,7 @@ export function HostSessionsDrawer({
if (drawerMode === 'bot') {
await useBotTeamStore.getState().refresh(true)
} else {
- await refreshWorkspaces(backend)
+ await dispatchSessionCatalogCommand({ type: 'refresh-catalog', backend })
}
} finally {
setRefreshing(false)
@@ -619,7 +637,7 @@ export function HostSessionsDrawer({
const targetBackend = workspace.backend ?? backend
const created = await createSession(workspace.workspaceId, targetBackend)
if (created) {
- if (drawerMode !== 'agent') handleSwitchMode('agent')
+ activateAgentMode()
if (!inline) closeDrawer()
}
}
@@ -635,7 +653,7 @@ export function HostSessionsDrawer({
.filter(s => (s.backend ?? 'harness') === favBackend && matchedWs.sessionIds.includes(s.sessionId) && !archivedIds.includes(s.sessionId))
.sort((a, b) => (b.updatedAt ?? 0) - (a.updatedAt ?? 0))
if (wsSessions[0]) {
- if (drawerMode !== 'agent') handleSwitchMode('agent')
+ activateAgentMode()
await onSelect(wsSessions[0])
if (!inline) closeDrawer()
return
@@ -643,7 +661,7 @@ export function HostSessionsDrawer({
}
const created = await createSession(workspaceId, favBackend)
if (created) {
- if (drawerMode !== 'agent') handleSwitchMode('agent')
+ activateAgentMode()
if (!inline) closeDrawer()
}
}
@@ -654,8 +672,18 @@ export function HostSessionsDrawer({
strings.workspaces.deleteBody,
[
{ text: strings.common.cancel, style: 'cancel' },
- { text: strings.workspaces.delete, style: 'destructive', onPress: () => void deleteWorkspace(target.workspaceId) },
+ {
+ text: strings.workspaces.delete,
+ style: 'destructive',
+ onPress: () => {
+ setWorkspaceActionTarget(undefined)
+ void deleteWorkspace(target.workspaceId)
+ },
+ },
],
+ // Keep the actions sheet mounted while the confirmation is open: closing
+ // one Modal window while another fades in flickers on Android.
+ { onDismiss: () => setWorkspaceActionTarget(undefined) },
)
}
@@ -693,7 +721,9 @@ export function HostSessionsDrawer({
const filteredSessions = useMemo(() => {
const known = selected && !sessions.some(session => session.sessionId === selected.sessionId)
? [selected, ...sessions] : sessions
- let list = known.filter(session => (session.backend ?? 'harness') === backend && !isKnownBotSessionId(session.sessionId, botTeamState, hostScope))
+ let list = known.filter(session => (session.backend ?? 'harness') === backend
+ && !isKnownBotSessionId(session.sessionId, botTeamState, hostScope)
+ && isVisibleSession(session, selected?.sessionId, searchQuery))
if (filterMode === 'hideArchived') {
list = list.filter(s => !archivedIds.includes(s.sessionId))
} else if (filterMode === 'archivedOnly') {
@@ -794,8 +824,10 @@ export function HostSessionsDrawer({
// 手势与抽屉动画
const { width: screenWidth } = useWindowDimensions()
const drawerWidth = Math.round(screenWidth * DRAWER_WIDTH_RATIO)
- const translateX = useRef(new Animated.Value(-drawerWidth)).current
- const overlayOpacity = useRef(new Animated.Value(0)).current
+ const immediateMount = entrance === 'immediate'
+ const translateX = useRef(new Animated.Value(immediateMount ? 0 : -drawerWidth)).current
+ const overlayOpacity = useRef(new Animated.Value(immediateMount ? 1 : 0)).current
+ const hasSettledOpenRef = useRef(immediateMount)
const dragStartX = useRef(0)
const closingRef = useRef(false)
const animSeq = useRef(0)
@@ -803,13 +835,9 @@ export function HostSessionsDrawer({
const gestureSeq = useRef(0)
const dragReady = useRef(false)
const onCloseRef = useRef(onClose)
- useEffect(() => {
- onCloseRef.current = onClose
- }, [onClose])
+ onCloseRef.current = onClose
const dismissibleRef = useRef(dismissible)
- useEffect(() => {
- dismissibleRef.current = dismissible
- }, [dismissible])
+ dismissibleRef.current = dismissible
useEffect(() => {
if (showSearch) setSearchMounted(true)
@@ -875,22 +903,58 @@ export function HostSessionsDrawer({
useEffect(() => {
if (inline) return
+ if (immediateMount || hasSettledOpenRef.current) {
+ currentAnim.current?.stop()
+ closingRef.current = false
+ translateX.setValue(0)
+ overlayOpacity.setValue(1)
+ hasSettledOpenRef.current = true
+ return
+ }
const anim = Animated.parallel([
Animated.timing(translateX, { toValue: 0, duration: 220, useNativeDriver: true }),
Animated.timing(overlayOpacity, { toValue: 1, duration: 220, useNativeDriver: true }),
])
currentAnim.current = anim
- anim.start()
+ anim.start(({ finished }) => {
+ if (finished) hasSettledOpenRef.current = true
+ })
return () => currentAnim.current?.stop()
- }, [inline, drawerWidth, translateX, overlayOpacity])
+ }, [inline, immediateMount, translateX, overlayOpacity])
+
+ useEffect(() => {
+ if (backRef === undefined || inline) return
+ backRef.current = () => {
+ if (showConfigModal) {
+ setShowConfigModal(false)
+ return true
+ }
+ if (showSearch) {
+ setShowSearch(false)
+ setSearchQuery('')
+ return true
+ }
+ if (showBotSearch) {
+ setShowBotSearch(false)
+ setBotSearchQuery('')
+ return true
+ }
+ if (!dismissibleRef.current) return false
+ smoothClose(true)
+ return true
+ }
+ return () => {
+ backRef.current = undefined
+ }
+ })
const panResponder = useMemo(
() =>
PanResponder.create({
onStartShouldSetPanResponder: () => false,
onStartShouldSetPanResponderCapture: () => false,
- onMoveShouldSetPanResponder: (_e, g) => (!inline && dismissible && !closingRef.current ? shouldStartSwipeLeftToClose(g) : false),
- onMoveShouldSetPanResponderCapture: (_e, g) => (!inline && dismissible && !closingRef.current ? shouldStartSwipeLeftToClose(g) : false),
+ onMoveShouldSetPanResponder: (_e, g) => (!inline && dismissibleRef.current && !closingRef.current ? shouldStartSwipeLeftToClose(g) : false),
+ onMoveShouldSetPanResponderCapture: (_e, g) => (!inline && dismissibleRef.current && !closingRef.current ? shouldStartSwipeLeftToClose(g) : false),
onPanResponderTerminationRequest: () => false,
onPanResponderGrant: () => {
if (closingRef.current) return
@@ -1024,18 +1088,19 @@ export function HostSessionsDrawer({
disabled={connectionPhase !== 'connected' || onOpenDeviceInfo === undefined}
onPress={() => {
Keyboard.dismiss()
- if (!inline) closeDrawer()
onOpenDeviceInfo?.()
}}
+ hitSlop={6}
style={({ pressed }) => [styles.hostFooterIcon, pressed && styles.pressedFade]}
>
-
+
{ Keyboard.dismiss(); onOpenHostSwitcher?.() }}
+ hitSlop={6}
style={({ pressed }) => [styles.hostFooterInfo, pressed && styles.pressedBg]}
>
@@ -1045,7 +1110,7 @@ export function HostSessionsDrawer({
{hostStatusLabel}
- {onOpenHostSwitcher !== undefined && }
+ {onOpenHostSwitcher !== undefined && }
>
)
@@ -1060,15 +1125,14 @@ export function HostSessionsDrawer({
disabled={onOpenAbout === undefined}
onPress={() => {
Keyboard.dismiss()
- if (!inline) closeDrawer()
onOpenAbout?.()
}}
hitSlop={8}
style={({ pressed }) => [styles.brandLeft, pressed && styles.pressedFade]}
>