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
2 changes: 2 additions & 0 deletions DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Sidebar navigation keeps core actions (`New conversation`, `Search conversations

## Conversation stream

- On iOS, approaching a pagination edge shows a quiet loading label in place, with a retry action only on failure. Prepending history keeps the reading position without animation; live updates follow the end only while the reader is there.

- Assistant prose renders directly on the reading column without avatars.
- Inter-agent messages render inside tool activity rows rather than user speech bubbles, collapsed by default with expandable source links and payloads.
- Each turn renders a single summary header from start to finish: `Working for 22s` while running, updating in place to `Worked for 37s · 2 thoughts · 3 tools` and auto-collapsing to the final answer on clean completion (unless the user manually toggled it). Turns that fail, stop, or pause for user input lead with their terminal status (`Stopped after 12s`) and stay expanded.
Expand Down
2 changes: 2 additions & 0 deletions products/maka/ios-shell/app/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ export type {
AgentQueueMutationResult,
AgentSendResult,
HistoryOrder,
HistoryPosition,
HistoryRowAddress,
HistoryView,
QuoteRef,
AgentWorkspaceSelection,
AgentSession,
Expand Down
82 changes: 74 additions & 8 deletions products/maka/ios-shell/app/screens/chats/ChatListScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ import {
retryFailedSessions,
renameSession,
sessionSearchQuery,
canLoadMoreSessions,
hasMoreSessions,
loadingMoreSessions,
loadMoreSessions,
sessionPaginationFailed,
setSessionSearchQuery,
setShowingArchivedSessions,
showingArchivedSessions,
Expand Down Expand Up @@ -83,6 +85,8 @@ import { ConnectionProgress } from '../../ui/ConnectionProgress';
import { ListSkeleton } from '../../ui/Skeleton';
import { NewChatSheet } from './NewChatSheet';

const catalogEdge = 160;

function formatRelativeTime(timestampMs: number): string {
if (!timestampMs) return '';
const diffSec = Math.max(0, Math.floor((Date.now() - timestampMs) / 1000));
Expand Down Expand Up @@ -308,6 +312,20 @@ export function ChatListScreen(props: { onOpenSession: (item: ScopedSession) =>
const renamingBusy = signal(false);

const category = signal(0);
const pagingScope = computed(() =>
JSON.stringify([
selectedScopeRootId(),
showingArchivedSessions(),
sessionSearchQuery(),
category(),
connectedHosts().map(({ host, connection }) => [host.rootId, connection.generation]),
]),
);
let pagingDrag: string | undefined;
let lastCatalogScroll: { scope: string; height: number; viewport: number; y: number } | undefined;
const viewportHeight = signal(0);
const catalogEnd = signal(0);
const bottomPadding = () => insets().bottom + spacing.tabBarClearance;
const hasRooms = () => filteredSessions().some((item) => item.session.kind === 'room');
const inCategory = (items: ScopedSession[]) =>
!hasRooms() || category() === 0
Expand Down Expand Up @@ -352,9 +370,10 @@ export function ChatListScreen(props: { onOpenSession: (item: ScopedSession) =>
const state = connection();
return state.kind === 'offline' ? state.host : null;
};
const syncFailed = () => scopedSessionLoad().error !== null || sessionPaginationFailed();
const initialLoading = () => {
const load = scopedSessionLoad();
return load.error === null && !load.hasItems && (load.loading || connectionProgress());
return !syncFailed() && !load.hasItems && (load.loading || connectionProgress());
};
const refreshingEmptyList = () =>
!scopedSessionLoad().hasItems && scopedSessionLoad().refreshing && !initialLoading();
Expand Down Expand Up @@ -471,11 +490,45 @@ export function ChatListScreen(props: { onOpenSession: (item: ScopedSession) =>
>
<View style={{ flex: 1, backgroundColor: token('grouped-bg') }}>
<Scroll
testID="chat-catalog"
style={{ flex: 1 }}
onLayout={({ bounds }) => viewportHeight.set(bounds.size.height)}
onScrollDragStart={() => {
pagingDrag = canLoadMoreSessions() ? pagingScope() : undefined;
}}
onScroll={({ offset, delta, size, contentSize }) => {
const scope = pagingScope();
const height = contentSize.height;
const distance = height - size.height - offset.y;
const previous = lastCatalogScroll;
lastCatalogScroll = { scope, height, viewport: size.height, y: offset.y };
const sameLayout =
previous?.scope === scope &&
previous.height === height &&
previous.viewport === size.height;
const crossedEdge = sameLayout && height - size.height - previous.y > catalogEdge;
// A resize invalidates the old distance, not the user's offset movement.
const reachedBottom =
(!previous || (previous.scope === scope && offset.y > previous.y)) &&
height - size.height > 1 &&
distance <= 1 &&
distance + delta.y > 1;
if (
delta.y > 0 &&
distance <= catalogEdge &&
(pagingDrag === scope || (pagingDrag === undefined && (crossedEdge || reachedBottom)))
) {
pagingDrag = undefined;
void loadMoreSessions();
}
}}
onScrollEnd={() => {
pagingDrag = undefined;
}}
contentStyle={{
flexGrow: 1,
paddingTop: 8,
paddingBottom: insets().bottom + spacing.tabBarClearance,
paddingBottom: bottomPadding(),
}}
>
<SearchField
Expand Down Expand Up @@ -657,7 +710,7 @@ export function ChatListScreen(props: { onOpenSession: (item: ScopedSession) =>
)}
</If>

<If when={scopedSessionLoad().error !== null}>
<If when={syncFailed()}>
<BannerNotice
tone="warning"
title={tr('Could not sync chats')}
Expand Down Expand Up @@ -711,7 +764,7 @@ export function ChatListScreen(props: { onOpenSession: (item: ScopedSession) =>
!hasAnySessions() &&
!initialLoading() &&
!refreshingEmptyList() &&
scopedSessionLoad().error === null
(!syncFailed() || scopedSessionLoad().hasItems)
}
>
<View style={{ flex: 1, justifyContent: 'center', paddingBottom: 40 }}>
Expand Down Expand Up @@ -770,12 +823,25 @@ export function ChatListScreen(props: { onOpenSession: (item: ScopedSession) =>
</If>
</View>
</If>
<If when={!initialLoading() && (hasMoreSessions() || loadingMoreSessions())}>
<View style={{ paddingHorizontal: spacing.pageX }}>
<View onLayout={({ bounds }) => catalogEnd.set(bounds.origin.y)} />
<If when={loadingMoreSessions() && !initialLoading() && !refreshingEmptyList()}>
<Text
style={{ ...type.footnote, color: token('muted-foreground'), textAlign: 'center' }}
>
{tr('Loading…')}
</Text>
</If>
<If
when={
canLoadMoreSessions() &&
(!hasAnySessions() ||
(viewportHeight() > 0 && catalogEnd() + bottomPadding() <= viewportHeight() + 1))
}
>
<View style={{ alignItems: 'center', paddingHorizontal: spacing.pageX }}>
<ActionButton
variant="quiet"
title={loadingMoreSessions() ? tr('Loading…') : tr('Load more chats')}
disabled={loadingMoreSessions()}
title={tr('Load more chats')}
onPress={() => void loadMoreSessions()}
/>
</View>
Expand Down
51 changes: 39 additions & 12 deletions products/maka/ios-shell/app/screens/chats/ChatQuotes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export function MessageBody(props: {
return selected?.body === props.row.text && isQuotable(props.row) ? selected.text : '';
};
let area: ViewRef | undefined;
const sourceId = () =>
props.row.first.offset > 0 || props.row.last.offset > 0 ? props.row.key : undefined;
const quoteSelection = () => {
const text = selectedExcerpt();
if (text && !props.limitReached && props.onQuote(props.row, text)) {
Expand Down Expand Up @@ -101,6 +103,8 @@ export function MessageBody(props: {
else={
<TextView
markdown={props.row.text}
sourceId={sourceId()}
sourceOffset={props.row.first.offset}
classes={{ codeBlockHeader: 'px-3 text-foreground' }}
codeBlockActions={[{ id: 'copy', label: tr('Copy') }]}
styles={{
Expand All @@ -110,7 +114,14 @@ export function MessageBody(props: {
/>
}
>
<Text style={{ ...type.body, color: token('foreground') }}>{props.row.text}</Text>
<Text
textSource={
sourceId() ? { id: props.row.key, offset: props.row.first.offset } : undefined
}
style={{ ...type.body, color: token('foreground') }}
>
{props.row.text}
</Text>
</If>
</View>
<If when={selectedExcerpt()}>
Expand Down Expand Up @@ -147,26 +158,42 @@ const replyActionStyle = {

export function ReplyActions(props: {
bodies: readonly HistoryRow[];
loadBodies?: () => Promise<HistoryRow[] | undefined>;
limitReached: boolean;
onQuote: (row: HistoryRow, text: string, combined?: readonly HistoryRow[]) => boolean;
onAskSide?: () => void;
}) {
const sources = computed(() => props.bodies.filter(isQuotable));
const canQuote = () =>
sources().length > 0 && !props.limitReached && sources().every(isCompleteHistoryRow);
const copyReply = () => {
hapticSelection();
void Clipboard.writeText(props.bodies.map((row) => row.text).join('\n\n'));
showToast(tr('Copied'));
sources().length > 0 &&
!props.limitReached &&
(props.loadBodies !== undefined || sources().every(isCompleteHistoryRow));
const withReply = async (action: (bodies: readonly HistoryRow[]) => void | Promise<void>) => {
try {
const bodies = props.loadBodies ? await props.loadBodies() : props.bodies;
if (bodies?.length && bodies.every(isCompleteHistoryRow)) await action(bodies);
} catch (cause) {
showToast(cause instanceof Error ? cause.message : String(cause));
}
};
const copyReply = () =>
void withReply(async (bodies) => {
hapticSelection();
await Clipboard.writeText(bodies.map((row) => row.text).join('\n\n'));
showToast(tr('Copied'));
});
const quoteReply = () => {
if (!canQuote()) return;
const rows = sources();
props.onQuote(
rows[0],
rows.map((row) => row.text).join('\n\n'),
rows.length > 1 ? rows : undefined,
);
const onQuote = props.onQuote;
void withReply((bodies) => {
const rows = bodies.filter(isQuotable);
if (rows.length)
onQuote(
rows[0],
rows.map((row) => row.text).join('\n\n'),
rows.length > 1 ? rows : undefined,
);
});
};
const actions = (
<View style={{ flexDirection: 'row' }}>
Expand Down
Loading