Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 20 additions & 3 deletions src/mobile-web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { useConnectionHealth } from './hooks/useConnectionHealth';
import { useMobileViewport } from './hooks/useMobileViewport';
import { useWideLayout } from './hooks/useWideLayout';
import { useMobileStore } from './services/store';
import type { SessionWorkspaceContext } from './services/workspaceIdentity';
import RemoteHomePanel from './components/RemoteHomePanel';
import './styles/index.scss';

Expand Down Expand Up @@ -55,6 +56,7 @@ const AppContent: React.FC = () => {
const [activeSessionId, setActiveSessionId] = useState<string | null>(null);
const [activeSessionName, setActiveSessionName] = useState<string>('Session');
const [activeSessionAgentType, setActiveSessionAgentType] = useState('Standard');
const [activeSessionWorkspace, setActiveSessionWorkspace] = useState<SessionWorkspaceContext | undefined>();
const [chatAutoFocus, setChatAutoFocus] = useState(false);
const [compactSidebarOpen, setCompactSidebarOpen] = useState(false);
const isWideLayout = useWideLayout();
Expand Down Expand Up @@ -195,6 +197,7 @@ const AppContent: React.FC = () => {
setActiveSessionId(null);
setActiveSessionName('Session');
setActiveSessionAgentType('Standard');
setActiveSessionWorkspace(undefined);
setChatAutoFocus(false);
setPrevPage(null);
setNavDir(null);
Expand All @@ -216,7 +219,10 @@ const AppContent: React.FC = () => {
// Pop navigation handlers that can be called from both UI buttons and popstate
const doPopFromChat = useCallback(() => {
navigateTo('sessions', 'pop');
setTimeout(() => setActiveSessionId(null), NAV_DURATION);
setTimeout(() => {
setActiveSessionId(null);
setActiveSessionWorkspace(undefined);
}, NAV_DURATION);
}, [navigateTo]);

const doPopFromWorkspace = useCallback(() => {
Expand Down Expand Up @@ -279,11 +285,13 @@ const AppContent: React.FC = () => {
sessionName?: string,
isNew?: boolean,
agentType = 'Standard',
workspace?: SessionWorkspaceContext,
) => {
useMobileStore.getState().setError(null);
setActiveSessionId(sessionId);
setActiveSessionName(sessionName || 'Session');
setActiveSessionAgentType(agentType);
setActiveSessionWorkspace(workspace);
setChatAutoFocus(!!isNew);
setCompactSidebarOpen(false);
if (isWideLayout) {
Expand All @@ -302,7 +310,10 @@ const AppContent: React.FC = () => {

const handleBackToSessions = useCallback(() => {
navigateTo('sessions', 'pop');
setTimeout(() => setActiveSessionId(null), NAV_DURATION);
setTimeout(() => {
setActiveSessionId(null);
setActiveSessionWorkspace(undefined);
}, NAV_DURATION);
}, [navigateTo]);

const handleControlTargetChanged = useCallback(() => {
Expand All @@ -315,6 +326,7 @@ const AppContent: React.FC = () => {
setActiveSessionId(restored.session.id);
setActiveSessionName(restored.session.name);
setActiveSessionAgentType(restored.session.agentType);
setActiveSessionWorkspace(restored.session.workspace);
setChatAutoFocus(false);
setPrevPage(null);
setNavDir(null);
Expand All @@ -327,6 +339,7 @@ const AppContent: React.FC = () => {
setActiveSessionId(null);
setActiveSessionName('Session');
setActiveSessionAgentType('Standard');
setActiveSessionWorkspace(undefined);
setChatAutoFocus(false);
setPrevPage(null);
setNavDir(null);
Expand All @@ -352,6 +365,7 @@ const AppContent: React.FC = () => {
setActiveSessionId(null);
setActiveSessionName('Session');
setActiveSessionAgentType('Standard');
setActiveSessionWorkspace(undefined);
setChatAutoFocus(false);
setCompactSidebarOpen(false);
setPrevPage(null);
Expand Down Expand Up @@ -429,6 +443,7 @@ const AppContent: React.FC = () => {
setActiveSessionId(null);
setActiveSessionName('Session');
setActiveSessionAgentType('Standard');
setActiveSessionWorkspace(undefined);
setChatAutoFocus(false);
setCompactSidebarOpen(false);
setPrevPage(null);
Expand All @@ -454,9 +469,10 @@ const AppContent: React.FC = () => {
id: activeSessionId,
name: activeSessionName,
agentType: activeSessionAgentType,
workspace: activeSessionWorkspace,
} : undefined,
});
}, [accountDirectoryOpen, activeSessionAgentType, activeSessionId, activeSessionName, controlTarget, page]);
}, [accountDirectoryOpen, activeSessionAgentType, activeSessionId, activeSessionName, activeSessionWorkspace, controlTarget, page]);

const isAnimating = navDir !== null;
const currentPage: Page = page;
Expand Down Expand Up @@ -500,6 +516,7 @@ const AppContent: React.FC = () => {
sessionId={activeSessionId}
sessionName={activeSessionName}
agentType={activeSessionAgentType}
workspace={activeSessionWorkspace}
onBack={isWideLayout ? handleBackToSessions : () => setCompactSidebarOpen(true)}
autoFocus={chatAutoFocus}
wideLayout={isWideLayout}
Expand Down
27 changes: 22 additions & 5 deletions src/mobile-web/src/pages/ChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ import {
type PendingChatImage,
} from '../services/chatImageAttachments';
import { useMobileStore } from '../services/store';
import {
isRemoteSessionWorkspace,
resolveChatHeaderContext,
sessionWorkspaceContext,
type SessionWorkspaceContext,
} from '../services/workspaceIdentity';
import { createRemoteCacheScope, remoteCache } from '../services/RemoteCache';
import ChatHeader from '../components/ChatHeader';
import ChatComposerBar from '../components/ChatComposerBar';
Expand Down Expand Up @@ -51,6 +57,7 @@ interface ChatPageProps {
sessionId: string;
sessionName?: string;
agentType?: string;
workspace?: SessionWorkspaceContext;
onBack: () => void;
autoFocus?: boolean;
wideLayout?: boolean;
Expand All @@ -74,6 +81,7 @@ const ChatPage: React.FC<ChatPageProps> = ({
sessionId,
sessionName,
agentType: sessionAgentType = 'Standard',
workspace: sessionWorkspace,
onBack,
autoFocus,
wideLayout = false,
Expand All @@ -88,6 +96,9 @@ const ChatPage: React.FC<ChatPageProps> = ({
error,
setError,
currentWorkspace,
currentAssistant,
knownWorkspaces,
sessions,
authenticatedUserId,
controlTarget,
connectionHealth,
Expand Down Expand Up @@ -1152,12 +1163,18 @@ const ChatPage: React.FC<ChatPageProps> = ({
}
};

const workspaceName = currentWorkspace?.project_name || currentWorkspace?.path?.split('/').pop() || '';
const gitBranch = currentWorkspace?.git_branch;
// Restored navigation from an older build has no workspace; the loaded session row may.
const listedSession = sessionWorkspace ? undefined : sessions.find((session) => session.session_id === sessionId);
const sessionContext = sessionWorkspace ?? (listedSession && sessionWorkspaceContext(listedSession));
const { workspaceName, gitBranch } = resolveChatHeaderContext({
agentType: sessionAgentType,
session: sessionContext,
currentWorkspace,
currentAssistant,
assistantLabel: t('shared.agents.Claw'),
});
const displayName = liveTitle || sessionName || t('chat.session');
const isRemoteWorkspace = currentWorkspace?.workspace_kind === 'remote'
|| Boolean(currentWorkspace?.remote_connection_id)
|| Boolean(currentWorkspace?.remote_ssh_host);
const isRemoteWorkspace = isRemoteSessionWorkspace(sessionAgentType, sessionContext, currentWorkspace, knownWorkspaces);

return (
<div className={`chat-page${wideLayout ? ' chat-page--wide' : ''}`} style={{ '--chat-composer-height': `${composerHeight}px` } as React.CSSProperties}>
Expand Down
61 changes: 49 additions & 12 deletions src/mobile-web/src/pages/SessionListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,15 @@ import { describeRemoteError } from '../services/remoteErrorPresentation';
// Device-directory read failures share the device pages' relay-failure copy.
import { deviceFailurePresentation } from '../services/deviceFailureCopy';
import {
isClawAgent,
sameWorkspace,
selectedSessionWorkspaceContext,
sessionMatchesWorkspace,
sessionWorkspaceContext,
workspaceContext,
workspaceIdentityKey,
type SessionWorkspaceContext,
type SessionWorkspaceFacts,
type WorkspaceReference,
} from '../services/workspaceIdentity';
import { useTheme } from '../theme';
Expand Down Expand Up @@ -93,6 +99,7 @@ interface SessionListPageProps {
sessionName?: string,
isNew?: boolean,
agentType?: string,
workspace?: SessionWorkspaceContext,
) => void;
onOpenWorkspace: () => void;
onOpenDeviceTools: () => void;
Expand Down Expand Up @@ -139,6 +146,17 @@ function commandIdentity(
};
}

function createdSessionFacts(path: string, identity: RemoteWorkspaceIdentity): SessionWorkspaceFacts {
return {
workspace_id: identity.workspaceId,
workspace_path: path,
workspace_identity: {
remote_connection_id: identity.remoteConnectionId,
remote_ssh_host: identity.remoteSshHost,
},
};
}

function assistantIdentity(assistant: AssistantEntry | null | undefined): RemoteWorkspaceIdentity {
return { workspaceId: assistant?.workspace_id };
}
Expand Down Expand Up @@ -213,10 +231,6 @@ function isCoworkAgent(agentType: string): boolean {
return agentType === 'cowork' || agentType === 'Cowork';
}

function isClawAgent(agentType: string): boolean {
return agentType === 'claw' || agentType === 'Claw';
}

/** Pick first workspace suitable for Expert mode (exclude Claw assistant roots when kind is known). */
function pickFirstProWorkspace(list: RecentWorkspaceEntry[]): RecentWorkspaceEntry | undefined {
if (list.length === 0) return undefined;
Expand Down Expand Up @@ -319,6 +333,9 @@ const SessionListPage: React.FC<SessionListPageProps> = ({
const [assistantList, setAssistantList] = useState<AssistantEntry[]>([]);
const [showAssistantPicker, setShowAssistantPicker] = useState(false);
const [workspaceList, setWorkspaceList] = useState<RecentWorkspaceEntry[]>([]);
useEffect(() => {
useMobileStore.getState().setKnownWorkspaces(workspaceList);
}, [workspaceList]);
const [showWorkspacePicker, setShowWorkspacePicker] = useState(false);
const [workspaceCatalogSource, setWorkspaceCatalogSource] = useState<'opened' | 'recent' | null>(null);

Expand Down Expand Up @@ -434,15 +451,33 @@ const SessionListPage: React.FC<SessionListPageProps> = ({
clearLongPressTimer();
}, []);

const handleSessionClick = useCallback((s: SessionInfo, e: React.MouseEvent) => {
// The flat list is scoped by the selected mode; compact rows name their own owner.
const listWorkspaceOwner = useMemo(() => {
if (displayMode === 'assistant') {
return currentAssistant ? workspaceContext({ ...currentAssistant, workspace_kind: 'assistant' }) : undefined;
}
return currentWorkspace ? workspaceContext(currentWorkspace) : undefined;
}, [currentAssistant, currentWorkspace, displayMode]);

const listedSessionWorkspace = useCallback((session: SessionInfo) => (
selectedSessionWorkspaceContext(session, listWorkspaceOwner)
), [listWorkspaceOwner]);

const handleSessionClick = useCallback((s: SessionInfo, e: React.MouseEvent, owner?: RecentWorkspaceEntry) => {
if (longPressTriggeredRef.current) {
e.preventDefault();
e.stopPropagation();
longPressTriggeredRef.current = false;
return;
}
onSelectSession(s.session_id, s.name, false, s.agent_type);
}, [onSelectSession]);
onSelectSession(
s.session_id,
s.name,
false,
s.agent_type,
owner ? sessionWorkspaceContext(s, workspaceContext(owner)) : listedSessionWorkspace(s),
);
}, [listedSessionWorkspace, onSelectSession]);

// ── Session actions ─────────────────────────────────────────────
const showToast = useCallback((msg: string) => {
Expand Down Expand Up @@ -1031,7 +1066,7 @@ const SessionListPage: React.FC<SessionListPageProps> = ({
workspaceIdentity: createdIdentity,
replaceWorkspace: true,
});
onSelectSession(created.session_id, t(isClawAgent(agentType) ? 'sessions.remoteClawSession' : isCoworkAgent(agentType) ? 'sessions.remoteCoworkSession' : 'sessions.remoteCodeSession'), true, agentType);
onSelectSession(created.session_id, t(isClawAgent(agentType) ? 'sessions.remoteClawSession' : isCoworkAgent(agentType) ? 'sessions.remoteCoworkSession' : 'sessions.remoteCodeSession'), true, agentType, sessionWorkspaceContext(createdSessionFacts(createdPath, createdIdentity), workspaceContext(workspace)));
} catch (error: unknown) {
if (isSessionListCurrent(targetEpoch) && !isRemoteControlTargetChangedError(error)) {
setError(describeRemoteError(error, t));
Expand Down Expand Up @@ -1430,14 +1465,15 @@ const SessionListPage: React.FC<SessionListPageProps> = ({
remoteConnectionId: created.remote_connection_id ?? identity.remoteConnectionId,
remoteSshHost: created.remote_ssh_host ?? identity.remoteSshHost,
};
await loadFirstPage(created.workspace_path ?? workspacePath, searchQuery, createdIdentity);
const createdPath = created.workspace_path ?? workspacePath;
await loadFirstPage(createdPath, searchQuery, createdIdentity);
if (!isSessionListCurrent(targetEpoch)) return;
const label = isClawAgent(agentType)
? t('sessions.remoteClawSession')
: isCoworkAgent(agentType)
? t('sessions.remoteCoworkSession')
: t('sessions.remoteCodeSession');
onSelectSession(created.session_id, label, true, agentType);
onSelectSession(created.session_id, label, true, agentType, selectedSessionWorkspaceContext(createdSessionFacts(createdPath, createdIdentity), listWorkspaceOwner));
} catch (e: any) {
if (isSessionListCurrent(targetEpoch) && !isRemoteControlTargetChangedError(e)) {
setError(describeRemoteError(e, t));
Expand All @@ -1452,6 +1488,7 @@ const SessionListPage: React.FC<SessionListPageProps> = ({
currentAssistant,
displayMode,
isSessionListCurrent,
listWorkspaceOwner,
loadFirstPage,
onSelectSession,
searchQuery,
Expand Down Expand Up @@ -1686,7 +1723,7 @@ const SessionListPage: React.FC<SessionListPageProps> = ({
key={session.session_id}
onContextMenu={(event) => { event.preventDefault(); setMenuSession(session); }}
>
<MobileButton appearance="plain" block className="harmony-sidebar__session-main" onClick={(event) => handleSessionClick(session, event)}>
<MobileButton appearance="plain" block className="harmony-sidebar__session-main" onClick={(event) => handleSessionClick(session, event, workspace)}>
<span className="harmony-sidebar__session-icon" aria-hidden="true"><LucideMessageCircle width="18" height="18" stroke="currentColor" /></span>
<span className="harmony-sidebar__row-label">{session.name || t('sessions.untitledSession')}</span>
</MobileButton>
Expand Down Expand Up @@ -1859,7 +1896,7 @@ const SessionListPage: React.FC<SessionListPageProps> = ({
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
onSelectSession(sessions[0].session_id, sessions[0].name, false, sessions[0].agent_type);
onSelectSession(sessions[0].session_id, sessions[0].name, false, sessions[0].agent_type, listedSessionWorkspace(sessions[0]));
}
}}
>
Expand Down
28 changes: 26 additions & 2 deletions src/mobile-web/src/services/MobileNavigationStore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { canonicalAgentId } from '../../../shared/agent-harness/contract.generated';
import type { SessionWorkspaceContext } from './workspaceIdentity';
const STORAGE_KEY = 'openbitfun.mobile.navigation.v1';

export interface MobileNavigationScope {
Expand All @@ -11,7 +12,7 @@ export interface MobileNavigationScope {
export interface MobileNavigation {
deviceId: string;
disconnected?: boolean;
session?: { id: string; name: string; agentType: string };
session?: { id: string; name: string; agentType: string; workspace?: SessionWorkspaceContext };
}

export interface PairedNavigation {
Expand All @@ -21,6 +22,23 @@ export interface PairedNavigation {

type StorageLike = Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;

/** Additive session field: records from older builds omit it, and bad values are dropped. */
function readSessionWorkspace(value: unknown): SessionWorkspaceContext | undefined {
if (!value || typeof value !== 'object') return undefined;
const record = value as Record<string, unknown>;
const text = (field: string) => (typeof record[field] === 'string' ? record[field] as string : undefined);
const kind = text('workspace_kind');
const workspace: SessionWorkspaceContext = {
workspace_id: text('workspace_id'),
path: text('path'),
remote_connection_id: text('remote_connection_id'),
remote_ssh_host: text('remote_ssh_host'),
name: text('name'),
workspace_kind: kind === 'normal' || kind === 'assistant' || kind === 'remote' ? kind : undefined,
};
return workspace.workspace_id || workspace.path || workspace.name ? workspace : undefined;
}

function browserStorage(): StorageLike | null {
try { return typeof window === 'undefined' ? null : window.sessionStorage; }
catch { return null; }
Expand All @@ -42,12 +60,18 @@ export function loadMobileNavigation(
|| typeof record.deviceId !== 'string'
|| !record.deviceId.trim()) return null;
const session = record.session;
const workspace = readSessionWorkspace(session?.workspace);
return {
deviceId: record.deviceId,
...(record.disconnected === true ? { disconnected: true } : {}),
session: session && typeof session.id === 'string' && session.id.trim()
&& typeof session.name === 'string' && typeof session.agentType === 'string'
? { id: session.id, name: session.name, agentType: canonicalAgentId(session.agentType) }
? {
id: session.id,
name: session.name,
agentType: canonicalAgentId(session.agentType),
...(workspace ? { workspace } : {}),
}
: undefined,
};
} catch {
Expand Down
Loading
Loading