Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

feat(ios,desktop): show bot messages whole and pop them in

leepokai656b55751bc1
diff --git a/apps/desktop/src/renderer/views/thread/ChatRows.tsx b/apps/desktop/src/renderer/views/thread/ChatRows.tsx
index 71e70923..d03bd146 100644
--- a/apps/desktop/src/renderer/views/thread/ChatRows.tsx
+++ b/apps/desktop/src/renderer/views/thread/ChatRows.tsx
@@ -211,7 +211,7 @@ export function AgentBubble({ entry, openTrace, reply }: { entry: Entry; openTra
{ title: 'Show what it did', icon: 'list.bullet', action: openTrace },
]}
>
- <MarkdownText text={entry.data.text ?? ''} streaming={entry.data.final === false} />
+ <MarkdownText text={entry.data.text ?? ''} />
</Bubble>
<MessageActions className="trailing" visible={hovering} reactions={reactionPick(store, entry)} reply={reply} trace={openTrace} copy={copy} />
</div>
diff --git a/apps/desktop/src/renderer/views/thread/Markdown.tsx b/apps/desktop/src/renderer/views/thread/Markdown.tsx
index 5015ddd0..75a4e55e 100644
--- a/apps/desktop/src/renderer/views/thread/Markdown.tsx
+++ b/apps/desktop/src/renderer/views/thread/Markdown.tsx
@@ -1,5 +1,5 @@
import { memo, type ReactNode } from 'react'
-import { parseStreaming, type Block } from './markdown-blocks.ts'
+import { parseMarkdown, type Block } from './markdown-blocks.ts'
// The Mac's Markdown for messages: the blocks from `markdown-blocks.ts`, with inline styling like
// `AttributedString(markdown:)`.
@@ -104,12 +104,9 @@ const MarkdownBlock = memo(function MarkdownBlock({ block }: { block: Block }) {
}
}, (a, b) => JSON.stringify(a.block) === JSON.stringify(b.block))
-/**
- * The Mac's Markdown for messages. Completed blocks keep their rendering while text streams;
- * only the block being written renders again.
- */
-export const MarkdownText = memo(function MarkdownText({ text, streaming = false }: { text: string; streaming?: boolean }) {
- const blocks = parseStreaming(text, streaming)
+/** The desktop's Markdown for messages; a block that didn't change keeps its rendering. */
+export const MarkdownText = memo(function MarkdownText({ text }: { text: string }) {
+ const blocks = parseMarkdown(text)
return (
<div className="markdown selectable" style={{ display: 'flex', flexDirection: 'column', gap: 10, minWidth: 0 }}>
{blocks.map((b, i) => (
diff --git a/apps/desktop/src/renderer/views/thread/RepliesView.tsx b/apps/desktop/src/renderer/views/thread/RepliesView.tsx
index 2d6496ae..d6906d9c 100644
--- a/apps/desktop/src/renderer/views/thread/RepliesView.tsx
+++ b/apps/desktop/src/renderer/views/thread/RepliesView.tsx
@@ -5,7 +5,7 @@ import { Sheet } from '../../components/Overlay'
import { font } from '../../lib/fonts'
import { useStore } from '../../store/context'
import { UpdateNeededCard } from '../UpdateNeededCard'
-import { buildChat } from './chat-items'
+import { buildChat, rowIn, useArrivals } from './chat-items'
import { ChatRow, WorkingIndicator } from './ChatRows'
import { Composer } from './Composer'
import { TraceView } from './TraceView'
@@ -22,6 +22,8 @@ export function RepliesView({ botId, rootId, close }: { botId: string; rootId: s
const root = store.allEntries(botId).find((e) => e.id === rootId)
const replies = store.replies(botId, rootId)
const live = !!chat && isWorkingIn(chat, botId, rootId) && !store.isOffline
+ const items = buildChat(replies)
+ const arrivals = useArrivals([...items.map((i) => i.id), ...(live ? ['working'] : [])], true)
const [showTrace, setShowTrace] = useState(false)
const scroller = useRef<HTMLDivElement>(null)
useReading(store, botId, rootId)
@@ -59,11 +61,15 @@ export function RepliesView({ botId, rootId, close }: { botId: string; rootId: s
</div>
</>
) : null}
- {buildChat(replies, live).map((item) =>
- item.kind === 'entry' ? <ChatRow key={item.id} entry={item.entry} groupStart={item.groupStart} chat={chat} openTrace={openTrace} /> : null,
+ {items.map((item) =>
+ item.kind === 'entry' ? (
+ <div key={item.id} className={arrivals.has(item.id) ? rowIn(item) : undefined}>
+ <ChatRow entry={item.entry} groupStart={item.groupStart} chat={chat} openTrace={openTrace} />
+ </div>
+ ) : null,
)}
{chat && live ? (
- <div style={{ paddingTop: 6 }}>
+ <div className={arrivals.has('working') ? 'row-in' : undefined} style={{ paddingTop: 6 }}>
<WorkingIndicator bot={chat} thinking={store.currentThinking(botId, rootId)} />
</div>
) : null}
diff --git a/apps/desktop/src/renderer/views/thread/ThreadView.tsx b/apps/desktop/src/renderer/views/thread/ThreadView.tsx
index 620a1854..0bd58d1f 100644
--- a/apps/desktop/src/renderer/views/thread/ThreadView.tsx
+++ b/apps/desktop/src/renderer/views/thread/ThreadView.tsx
@@ -7,7 +7,7 @@ import { Sheet } from '../../components/Overlay'
import { font } from '../../lib/fonts'
import { useStore } from '../../store/context'
import { UpdateNeededCard } from '../UpdateNeededCard'
-import { buildChat, relativeTime, type ChatItem } from './chat-items'
+import { buildChat, relativeTime, rowIn, useArrivals, type ChatItem } from './chat-items'
import { ChatRow, WorkingIndicator } from './ChatRows'
import { Composer } from './Composer'
import { ChatSidePanel } from './ChatSidePanel'
@@ -223,7 +223,7 @@ function Transcript({ botId, openTrace, openThread, openRoutine }: { botId: stri
const bot = store.bots.get(botId) ?? null
const thread = store.chat(botId)
const live = !!bot && isWorkingIn(bot, botId, null) && !store.isOffline
- const all = buildChat(thread, live, true)
+ const all = buildChat(thread)
// The newest 40 items first; older pages come in near the top.
const [firstShown, setFirstShown] = useState<string | null>(null)
const [loadingEarlier, setLoadingEarlier] = useState(false)
@@ -240,6 +240,7 @@ function Transcript({ botId, openTrace, openThread, openRoutine }: { botId: stri
const lastScrollTop = useRef(0)
const keepPlace = useRef<number | null>(null)
const last = items[items.length - 1]
+ const arrivals = useArrivals([...items.map((i) => i.id), ...(live ? ['working'] : [])], following)
const toBottom = (smooth = false) => {
const el = scroller.current
@@ -260,7 +261,7 @@ function Transcript({ botId, openTrace, openThread, openRoutine }: { botId: stri
if (at === 0) {
const anchor = list[0]?.id
await store.loadOlder(botId)
- list = buildChat(store.chat(botId), live, true)
+ list = buildChat(store.chat(botId))
at = anchor ? Math.max(0, list.findIndex((i) => i.id === anchor)) : 0
}
if (at > 0) setFirstShown(list[Math.max(0, at - PAGE)]!.id)
@@ -317,10 +318,12 @@ function Transcript({ botId, openTrace, openThread, openRoutine }: { botId: stri
) : null}
{items.length === 0 && bot ? <div style={{ paddingTop: 40 }}>{isGroup(bot) ? <GroupIntroCard group={bot} /> : <IntroCard bot={bot} />}</div> : null}
{items.map((item) => (
- <Row key={item.id} item={item} chat={bot} openTrace={openTrace} openThread={openThread} openRoutine={openRoutine} />
+ <div key={item.id} className={arrivals.has(item.id) ? rowIn(item) : undefined}>
+ <Row item={item} chat={bot} openTrace={openTrace} openThread={openThread} openRoutine={openRoutine} />
+ </div>
))}
{bot && live ? (
- <div style={{ paddingTop: 6 }}>
+ <div className={arrivals.has('working') ? 'row-in' : undefined} style={{ paddingTop: 6 }}>
<WorkingIndicator bot={bot} thinking={store.currentThinking(botId, null)} />
</div>
) : null}
diff --git a/apps/desktop/src/renderer/views/thread/chat-items.ts b/apps/desktop/src/renderer/views/thread/chat-items.ts
index 46e9389b..44aaa537 100644
--- a/apps/desktop/src/renderer/views/thread/chat-items.ts
+++ b/apps/desktop/src/renderer/views/thread/chat-items.ts
@@ -1,3 +1,4 @@
+import { useRef } from 'react'
import { isChat, type Entry } from '@shared/models'
export type ChatItem =
@@ -5,25 +6,16 @@ export type ChatItem =
| { id: string; kind: 'entry'; entry: Entry; groupStart: boolean }
/**
- * Chat-visible entries plus time separators (gaps > 1 h) and author grouping. `streaming`: a
- * turn is running in this chat, so the text being generated right now (the lane's last entry,
- * still `final == false`) shows in place and never pops in later.
+ * Chat-visible entries plus time separators (gaps > 1 h) and author grouping. A bot's messages
+ * arrive whole (Grok Bot's `send_message`); what it writes along the way is trace.
*/
-export function buildChat(entries: Entry[], streaming = false, steady = false): ChatItem[] {
+export function buildChat(entries: Entry[]): ChatItem[] {
const out: ChatItem[] = []
- const used = new Set<string>()
let lastDate: number | null = null
let lastAuthor: string | null = null
- const lastEntry = entries[entries.length - 1]
- const live = !streaming ? null : steady ? liveText(entries) : lastEntry && lastEntry.kind === 'agent' && lastEntry.data.final === false ? lastEntry.id : null
for (const e of entries) {
- if (!(isChat(e) || (e.id === live && e.data.text && e.data.text !== '(pass)'))) continue
- let id = e.kind === 'user' && e.data.clientNonce ? `user-${e.data.clientNonce}` : e.id
- // `steady`: a reply is one item per author and turn, from its first words to the final
- // message, so its bubble never pops out and back in.
- const reply = `reply-${e.data.author ?? ''}-${e.turn}`
- if (steady && e.kind === 'agent' && !used.has(reply)) id = reply
- used.add(id)
+ if (!isChat(e)) continue
+ const id = e.kind === 'user' && e.data.clientNonce ? `user-${e.data.clientNonce}` : e.id
if (lastDate === null || e.createdAt - lastDate > 3_600_000) {
out.push({ id: `sep-${id}`, kind: 'separator', date: e.createdAt })
lastAuthor = null
@@ -37,14 +29,25 @@ export function buildChat(entries: Entry[], streaming = false, steady = false):
return out
}
-/** The running turn's newest text, if any since the last message or final reply. */
-function liveText(entries: Entry[]): string | null {
- for (let i = entries.length - 1; i >= 0; i--) {
- const e = entries[i]!
- if (e.kind === 'user' || (e.kind === 'agent' && e.data.final === true)) return null
- if (e.kind === 'agent' && e.data.text) return e.data.text === '(pass)' ? null : e.id
+/**
+ * Rows that arrived after the list first showed, while it follows the newest: they pop in
+ * (`.row-in`, Grok Bot's). Earlier pages and rows that came in while reading history don't.
+ */
+export function useArrivals(ids: string[], following: boolean): Set<string> {
+ const seen = useRef<Set<string> | null>(null)
+ const fresh = useRef(new Set<string>())
+ if (seen.current === null) seen.current = new Set(ids)
+ for (const id of ids) {
+ if (seen.current.has(id)) continue
+ seen.current.add(id)
+ if (following) fresh.current.add(id)
}
- return null
+ return fresh.current
+}
+
+/** A new row pops in from its bubble's side. */
+export function rowIn(item: ChatItem): string {
+ return item.kind === 'entry' && item.entry.kind === 'user' ? 'row-in mine' : 'row-in'
}
const time = new Intl.DateTimeFormat(undefined, { hour: 'numeric', minute: '2-digit' })
diff --git a/apps/desktop/src/renderer/views/thread/markdown-blocks.test.ts b/apps/desktop/src/renderer/views/thread/markdown-blocks.test.ts
index 2af9abe8..9226d0f9 100644
--- a/apps/desktop/src/renderer/views/thread/markdown-blocks.test.ts
+++ b/apps/desktop/src/renderer/views/thread/markdown-blocks.test.ts
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict'
import { test } from 'node:test'
-import { heal, parseMarkdown, parseStreaming } from './markdown-blocks.ts'
+import { parseMarkdown } from './markdown-blocks.ts'
test('blocks: headings, nested lists, rules, tables and code', () => {
const blocks = parseMarkdown('# Title\n- one\n - two\n1. first\n---\n| A | B |\n|---|---|\n| 1 | 2 |\n```js\nx = 1\n```\n> quoted')
@@ -19,11 +19,3 @@ test('blocks: headings, nested lists, rules, tables and code', () => {
test('a pipe line without its rule stays text', () => {
assert.deepEqual(parseMarkdown('| not a table'), [{ kind: 'paragraph', text: '| not a table' }])
})
-
-test('streaming heals half-written syntax', () => {
- assert.equal(heal('so **bo'), 'so **bo**')
- assert.equal(heal('run `co'), 'run `co`')
- assert.equal(heal('see [docs](http'), 'see docs')
- assert.equal(heal('`**` stays'), '`**` stays')
- assert.deepEqual(parseStreaming('a ~~b', true), [{ kind: 'paragraph', text: 'a ~~b~~' }])
-})
diff --git a/apps/desktop/src/renderer/views/thread/markdown-blocks.ts b/apps/desktop/src/renderer/views/thread/markdown-blocks.ts
index 6186681c..039acab5 100644
--- a/apps/desktop/src/renderer/views/thread/markdown-blocks.ts
+++ b/apps/desktop/src/renderer/views/thread/markdown-blocks.ts
@@ -84,34 +84,3 @@ export function parseMarkdown(source: string): Block[] {
flush()
return blocks
}
-
-/** Closes the inline markers left open at the end of text being written. */
-export function heal(text: string): string {
- let t = text
- // A link still being typed shows as its label: `[label](partial` or `[label`.
- const open = t.lastIndexOf('[')
- if (open >= 0) {
- const rest = t.slice(open + 1)
- const close = rest.indexOf(']')
- if (close >= 0) {
- const after = rest.slice(close + 1)
- if (after.startsWith('(') && !after.includes(')')) t = t.slice(0, open) + rest.slice(0, close)
- } else if (!rest.includes('\n') && rest.length < 120) {
- t = t.slice(0, open) + rest
- }
- }
- if ([...t].filter((c) => c === '`').length % 2 === 1) t += '`'
- // Outside inline code only.
- const plain = t.split('`').filter((_, i) => i % 2 === 0).join('')
- for (const marker of ['**', '~~']) if (plain.split(marker).length % 2 === 0) t += marker
- return t
-}
-
-/** Blocks of `source`; while `streaming`, the last one is healed so half-written syntax doesn't flash. */
-export function parseStreaming(source: string, streaming: boolean): Block[] {
- const blocks = parseMarkdown(source)
- const last = blocks[blocks.length - 1]
- if (streaming && last && 'text' in last && last.kind !== 'code') blocks[blocks.length - 1] = { ...last, text: heal(last.text) }
- return blocks
-}
-
diff --git a/apps/desktop/src/renderer/views/thread/thread.css b/apps/desktop/src/renderer/views/thread/thread.css
index a402c4fb..8b593265 100644
--- a/apps/desktop/src/renderer/views/thread/thread.css
+++ b/apps/desktop/src/renderer/views/thread/thread.css
@@ -457,3 +457,28 @@
transform: translateX(-30%);
}
}
+
+/* A message arriving while the list follows the newest pops in from its bubble's side (Grok Bot's). */
+.row-in {
+ animation: row-in 0.24s cubic-bezier(0.23, 1, 0.32, 1) both;
+ transform-origin: bottom left;
+}
+.row-in.mine {
+ transform-origin: bottom right;
+}
+@keyframes row-in {
+ from {
+ opacity: 0;
+ transform: translateY(12px) scale(0.94);
+ }
+}
+@media (prefers-reduced-motion: reduce) {
+ .row-in {
+ animation: row-fade 0.12s both;
+ }
+}
+@keyframes row-fade {
+ from {
+ opacity: 0;
+ }
+}
diff --git a/apps/ios/Kit/Sources/CodyncUI/Thread/ChatRows.swift b/apps/ios/Kit/Sources/CodyncUI/Thread/ChatRows.swift
index ae9cc73e..e68fc4bf 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Thread/ChatRows.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Thread/ChatRows.swift
@@ -197,19 +197,11 @@ struct AgentBubble: View {
let openTrace: () -> Void
var reply: (() -> Void)?
@Environment(BotStore.self) private var model
- @Environment(\.accessibilityReduceMotion) private var reduceMotion
-
- /// The reply's text. iPhone: revealed steadily as it's written; the turn's next text
- /// segment takes the bubble over with a cross-fade instead of retyping.
- @ViewBuilder private var text: some View {
- StreamingMarkdown(text: entry.data.text ?? "", live: entry.data.final == false)
- .id(entry.id)
- .transition(.opacity)
- }
var body: some View {
VStack(alignment: .leading, spacing: 4) {
- text
+ MarkdownText(entry.data.text ?? "")
+ .equatable()
.padding(.horizontal, 16)
.padding(.vertical, 10)
.background(Palette.bubbleAgent, in: RoundedRectangle(cornerRadius: 22, style: .continuous))
@@ -223,8 +215,7 @@ struct AgentBubble: View {
}
}
.frame(maxWidth: .infinity, alignment: .leading)
- .animation(Motion.reduced(Motion.layout, reduceMotion), value: entry.id)
- .padding(.trailing, 40)
+ .padding(.trailing, 40)
}
}
@@ -390,62 +381,3 @@ extension ChatRow: @MainActor Equatable {
&& a.chat?.isWorking == b.chat?.isWorking && (a.openThread == nil) == (b.openThread == nil)
}
}
-
-/// A reply as it's written. The host sends text in bursts; in between, what arrived is
-/// revealed at a steady pace, so the reply flows instead of jumping a line at a time.
-struct StreamingMarkdown: View {
- let text: String
- /// Still being written (`final == false`).
- let live: Bool
- /// Characters shown while revealing; nil shows all of it.
- @State private var shown: Int?
- /// Text is surfacing right now (caught up, the fade settles).
- @State private var revealing = false
- @Environment(\.accessibilityReduceMotion) private var reduceMotion
- @Environment(\.conversationScrolling) private var scrolling
-
- /// How long a burst takes to reveal: a bit over the host's flush interval, so bursts join up.
- private static let window = 0.32
- private static let frame = 1.0 / 60
-
- var body: some View {
- MarkdownText(shown.map { String(text.prefix($0)) } ?? text, streaming: live, revealing: revealing)
- .equatable()
- .onAppear {
- // A reply already well under way when it scrolls in shows as it is.
- if live, !reduceMotion, shown == nil { shown = text.count > 280 ? text.count : 0 }
- }
- .task(id: RevealTarget(text: text, live: live, paused: scrolling)) { await reveal() }
- }
-
- private func reveal() async {
- // While the reader scrolls, the text holds still: scrolling never competes with layout.
- guard let start = shown, !scrolling else { return }
- let total = text.count
- var position = Double(min(start, total))
- let step = max((Double(total) - position) / (Self.window / Self.frame), 0.5)
- revealing = position < Double(total)
- defer { if !Task.isCancelled { revealing = false } }
- while position < Double(total) {
- try? await Task.sleep(for: .seconds(Self.frame))
- if Task.isCancelled { return }
- position = min(Double(total), position + step)
- shown = Int(position)
- }
- // Between bursts the open end keeps its fade a moment, so it doesn't flicker.
- if live { try? await Task.sleep(for: .seconds(0.6)) }
- if Task.isCancelled { return }
- if !live { shown = nil }
- }
-
- private struct RevealTarget: Equatable {
- let text: String
- let live: Bool
- let paused: Bool
- }
-}
-
-extension EnvironmentValues {
- /// The reader is scrolling the conversation: streamed text holds still until they stop.
- @Entry var conversationScrolling = false
-}
diff --git a/apps/ios/Kit/Sources/CodyncUI/Thread/ConversationList.swift b/apps/ios/Kit/Sources/CodyncUI/Thread/ConversationList.swift
index 44e54589..cacdedb1 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Thread/ConversationList.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Thread/ConversationList.swift
@@ -74,7 +74,6 @@ private struct ConversationCollection: UIViewRepresentable {
private var dataSource: UICollectionViewDiffableDataSource<Int, String>!
private var contents: [String: AnyView] = [:]
private var environment = EnvironmentValues()
- private let scrolling = ScrollingFlag()
private var parent: ConversationCollection?
/// What the list is telling `following` (it reaches the binding after the update).
private var pending: Bool?
@@ -87,7 +86,7 @@ private struct ConversationCollection: UIViewRepresentable {
let group = NSCollectionLayoutGroup.vertical(layoutSize: size, subitems: [NSCollectionLayoutItem(layoutSize: size)])
let section = NSCollectionLayoutSection(group: group)
section.contentInsets = NSDirectionalEdgeInsets(top: 8, leading: 0, bottom: 8, trailing: 0)
- let view = ConversationCollectionView(frame: .zero, collectionViewLayout: UICollectionViewCompositionalLayout(section: section))
+ let view = ConversationCollectionView(frame: .zero, collectionViewLayout: ConversationLayout(section: section))
view.backgroundColor = .clear
view.contentInsetAdjustmentBehavior = .never
view.showsVerticalScrollIndicator = false
@@ -106,7 +105,7 @@ private struct ConversationCollection: UIViewRepresentable {
guard let self else { return }
cell.backgroundConfiguration = .clear()
cell.contentConfiguration = UIHostingConfiguration {
- ConversationCell(scrolling: scrolling, content: contents[id] ?? AnyView(EmptyView()))
+ ConversationCell(content: contents[id] ?? AnyView(EmptyView()))
.environment(\.self, environment)
// A reused cell starts fresh (no state carried over from another row).
.id(id)
@@ -162,12 +161,15 @@ private struct ConversationCollection: UIViewRepresentable {
if old == ids || first {
dataSource.apply(snapshot, animatingDifferences: false)
} else if view.following, !reduceMotion {
- // New rows slide in as the list moves up to them, in one motion.
- UIView.animate(springDuration: 0.42, bounce: 0) {
+ // New rows pop in as the list moves up to them, in one motion (Grok Bot's
+ // 0.24 s ease-out).
+ UIViewPropertyAnimator(duration: 0.24, controlPoint1: CGPoint(x: 0.23, y: 1),
+ controlPoint2: CGPoint(x: 0.32, y: 1)) {
self.dataSource.apply(snapshot, animatingDifferences: true)
self.view.layoutIfNeeded()
self.view.pinToEnd()
}
+ .startAnimation()
} else {
applyKeepingPlace(snapshot)
}
@@ -205,10 +207,6 @@ private struct ConversationCollection: UIViewRepresentable {
// MARK: scrolling
- func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
- scrolling.active = true
- }
-
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let y = scrollView.contentOffset.y
defer { lastOffset = y }
@@ -248,13 +246,36 @@ private struct ConversationCollection: UIViewRepresentable {
/// The reader stopped scrolling: resting at the end follows again; anywhere else stays put.
private func settle() {
- scrolling.active = false
setFollowing(view.endOffset - view.contentOffset.y < ConversationCollectionView.nearEnd)
if view.following { view.pinToEnd() }
}
}
}
+/// A row going in rises into place from slightly below and smaller (Grok Bot's message pop).
+private final class ConversationLayout: UICollectionViewCompositionalLayout {
+ private var inserted = Set<IndexPath>()
+
+ override func prepare(forCollectionViewUpdates updateItems: [UICollectionViewUpdateItem]) {
+ super.prepare(forCollectionViewUpdates: updateItems)
+ inserted = Set(updateItems.filter { $0.updateAction == .insert }.compactMap(\.indexPathAfterUpdate))
+ }
+
+ override func finalizeCollectionViewUpdates() {
+ super.finalizeCollectionViewUpdates()
+ inserted = []
+ }
+
+ override func initialLayoutAttributesForAppearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
+ let attributes = super.initialLayoutAttributesForAppearingItem(at: itemIndexPath)
+ guard inserted.contains(itemIndexPath), let attributes = attributes?.copy() as? UICollectionViewLayoutAttributes
+ else { return attributes }
+ attributes.alpha = 0
+ attributes.transform = CGAffineTransform(translationX: 0, y: 12).scaledBy(x: 0.94, y: 0.94)
+ return attributes
+ }
+}
+
/// Holds the end in place: while following, every layout pass (a reply growing, a row going
/// in, the keyboard) ends at the bottom, unless the reader has the list in hand.
private final class ConversationCollectionView: UICollectionView {
@@ -318,20 +339,13 @@ private final class ConversationContainer: UIView {
}
}
-/// The reader is scrolling: rows read it through `conversationScrolling`.
-@Observable @MainActor private final class ScrollingFlag {
- var active = false
-}
-
private struct ConversationCell: View {
- let scrolling: ScrollingFlag
let content: AnyView
var body: some View {
content
.padding(.horizontal, 16)
.frame(maxWidth: .infinity, alignment: .leading)
- .environment(\.conversationScrolling, scrolling.active)
}
}
diff --git a/apps/ios/Kit/Sources/CodyncUI/Thread/MarkdownBlocks.swift b/apps/ios/Kit/Sources/CodyncUI/Thread/MarkdownBlocks.swift
index 1085d513..5e0e29b4 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Thread/MarkdownBlocks.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Thread/MarkdownBlocks.swift
@@ -12,53 +12,6 @@ enum MarkdownBlocks {
case code(String, language: String)
case table(header: [String], rows: [[String]])
case rule
-
- /// Flowing text (where a fading end reads as words arriving).
- var isText: Bool {
- switch self {
- case .paragraph, .heading, .bullet, .quote: true
- case .code, .table, .rule: false
- }
- }
- }
-
- /// Blocks of `source`; while `streaming`, the last one is healed so a marker that's only
- /// half there (`**bo`, `` `co ``, `[link](ht`) doesn't flash as raw syntax.
- static func parse(_ source: String, streaming: Bool) -> [Block] {
- var blocks = parse(source)
- guard streaming, let last = blocks.last else { return blocks }
- switch last {
- case let .paragraph(t): blocks[blocks.count - 1] = .paragraph(heal(t))
- case let .heading(t, level): blocks[blocks.count - 1] = .heading(heal(t), level: level)
- case let .bullet(t, marker, depth): blocks[blocks.count - 1] = .bullet(heal(t), marker: marker, depth: depth)
- case let .quote(t): blocks[blocks.count - 1] = .quote(heal(t))
- case .code, .table, .rule: break
- }
- return blocks
- }
-
- /// Closes the inline markers left open at the end of text being written.
- static func heal(_ text: String) -> String {
- var t = text
- // A link still being typed shows as its label: `[label](partial` or `[label`.
- if let open = t.lastIndex(of: "[") {
- let rest = t[t.index(after: open)...]
- if let close = rest.firstIndex(of: "]") {
- let after = rest[rest.index(after: close)...]
- if after.hasPrefix("("), !after.contains(")") { t = String(t[..<open]) + rest[..<close] }
- } else if !rest.contains("\n"), rest.count < 120 {
- t = String(t[..<open]) + rest
- }
- }
- let ticks = t.count(where: { $0 == "`" })
- if ticks % 2 == 1 { t += "`" }
- // Outside inline code only.
- let plain = t.split(separator: "`", omittingEmptySubsequences: false).enumerated()
- .filter { $0.offset % 2 == 0 }.map(\.element).joined()
- for marker in ["**", "~~"] where plain.components(separatedBy: marker).count % 2 == 0 {
- t += marker
- }
- return t
}
static func parse(_ source: String) -> [Block] {
diff --git a/apps/ios/Kit/Sources/CodyncUI/Thread/MarkdownText.swift b/apps/ios/Kit/Sources/CodyncUI/Thread/MarkdownText.swift
index a027a01d..fa33b587 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Thread/MarkdownText.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Thread/MarkdownText.swift
@@ -3,26 +3,19 @@ import SwiftUI
/// The iPhone's Markdown renderer for messages (`MarkdownBlocks`: tables, rules, nested lists
/// too); inline styling comes from `AttributedString(markdown:)`.
-/// Equatable so a reply that didn't change skips its body; each block is equatable too, so
-/// while text streams only the block being written renders again.
+/// Equatable so a reply that didn't change skips its body.
public struct MarkdownText: View, Equatable {
let source: String
- /// Text is still arriving: the open end hides half-written syntax.
- let streaming: Bool
- /// New text is surfacing right now: the open end fades in.
- let revealing: Bool
- public init(_ source: String, streaming: Bool = false, revealing: Bool = false) {
+ public init(_ source: String) {
self.source = source
- self.streaming = streaming
- self.revealing = revealing
}
public var body: some View {
- let blocks = MarkdownBlocks.parse(source, streaming: streaming)
+ let blocks = MarkdownBlocks.parse(source)
VStack(alignment: .leading, spacing: 8) {
- ForEach(Array(blocks.enumerated()), id: \.offset) { i, block in
- MarkdownBlock(block: block, writing: revealing && i == blocks.count - 1).equatable()
+ ForEach(Array(blocks.enumerated()), id: \.offset) { _, block in
+ MarkdownBlock(block: block)
}
}
.textSelection(.enabled)
@@ -39,23 +32,11 @@ public struct MarkdownText: View, Equatable {
}
}
-/// One block of a reply. The block being written (`writing`) fades in toward its end, so
-/// new words surface instead of popping in; once it's done the fade settles.
-private struct MarkdownBlock: View, @MainActor Equatable {
+/// One block of a reply.
+private struct MarkdownBlock: View {
let block: MarkdownBlocks.Block
- let writing: Bool
- @Environment(\.accessibilityReduceMotion) private var reduceMotion
- nonisolated static func == (a: Self, b: Self) -> Bool { a.block == b.block && a.writing == b.writing }
-
- var body: some View {
- // The fade alone eases out; text and layout changes stay unanimated.
- content.animation(Motion.reduced(.easeOut(duration: 0.35), reduceMotion)) {
- $0.writingFade(writing && !reduceMotion && block.isText)
- }
- }
-
- @ViewBuilder private var content: some View {
+ @ViewBuilder var body: some View {
switch block {
case let .paragraph(t):
Text(MarkdownText.inline(t))
@@ -124,52 +105,3 @@ private struct MarkdownTable: View {
}
}
}
-
-private extension View {
- @ViewBuilder func writingFade(_ on: Bool) -> some View {
- if #available(iOS 18, *) {
- textRenderer(TrailingFade(length: on ? TrailingFade.writingLength : 0))
- } else {
- self
- }
- }
-}
-
-/// Draws text with its last `length` glyphs fading out toward the end, the soft edge of text
-/// being written. As more arrives, earlier glyphs move out of the fade and settle.
-@available(iOS 18, *)
-private struct TrailingFade: TextRenderer {
- static let writingLength: Double = 28
- var length: Double
-
- var animatableData: Double {
- get { length }
- set { length = newValue }
- }
-
- func draw(layout: Text.Layout, in context: inout GraphicsContext) {
- guard length > 0.5 else {
- for line in layout { context.draw(line) }
- return
- }
- let total = layout.reduce(0) { $0 + $1.reduce(0) { $0 + $1.count } }
- var index = 0
- for line in layout {
- for run in line {
- // Whole runs before the fade draw as they are.
- if Double(total - index - run.count) >= length {
- context.draw(run)
- index += run.count
- continue
- }
- for slice in run {
- let fromEnd = Double(total - index)
- index += 1
- var glyph = context
- if fromEnd <= length { glyph.opacity = (fromEnd / (length + 1)) * 0.9 + 0.1 }
- glyph.draw(slice)
- }
- }
- }
- }
-}
diff --git a/apps/ios/Kit/Sources/CodyncUI/Thread/RepliesView.swift b/apps/ios/Kit/Sources/CodyncUI/Thread/RepliesView.swift
index 5880b4c2..223277db 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Thread/RepliesView.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Thread/RepliesView.swift
@@ -64,7 +64,7 @@ extension RepliesView {
var messages: some View {
let replies = model.replies(botId, root: rootId)
let working = chat?.isWorking(in: botId, thread: rootId) == true && !model.isOffline
- let items = ChatItem.build(replies, streaming: working, steady: true)
+ let items = ChatItem.build(replies)
var rows: [ConversationRow] = []
if let root {
rows.append(ConversationRow("root") {
diff --git a/apps/ios/Kit/Sources/CodyncUI/Thread/ThreadView.swift b/apps/ios/Kit/Sources/CodyncUI/Thread/ThreadView.swift
index 2695c037..4e85fe69 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Thread/ThreadView.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Thread/ThreadView.swift
@@ -233,35 +233,17 @@ struct ChatItem: Identifiable {
let id: String
let kind: Kind
- /// Chat-visible entries plus time separators (gaps > 1 h) and author grouping.
- /// `streaming`: a turn is running in this chat, so the text being generated right now
- /// (the lane's last entry, still `final == false`) shows in place and never pops in later.
- /// Earlier segments of the turn, tool calls in between, and a room pass stay trace-only.
- /// `steady` (iPhone): the turn's newest text stays while the agent works on (tools,
- /// thinking) until newer text replaces it, and a reply is one item per author and turn,
- /// from its first words to the final message, so its bubble never pops out and back in.
- static func build(_ entries: [Entry], streaming: Bool = false, steady: Bool = false) -> [ChatItem] {
+ /// Chat-visible entries plus time separators (gaps > 1 h) and author grouping. A bot's
+ /// messages arrive whole (Grok Bot's `send_message`); what it writes along the way is trace.
+ static func build(_ entries: [Entry]) -> [ChatItem] {
var out: [ChatItem] = []
- var used = Set<String>()
var lastDate: Date?
var lastAuthor: String?
- let live = !streaming ? nil
- : steady ? liveText(entries)
- : entries.last.flatMap { $0.kind == "agent" && $0.data.final == false ? $0.id : nil }
- for e in entries where e.isChat || (e.id == live && !(e.data.text ?? "").isEmpty && e.data.text != "(pass)") {
+ for e in entries where e.isChat {
let date = e.date
// Bot-originated messages carry an empty nonce. Their entry IDs
// distinguish them; only real nonces identify optimistic echoes.
- var id: String
- if e.kind == "user", let nonce = e.data.clientNonce, !nonce.isEmpty {
- id = "user-\(nonce)"
- } else {
- id = e.id
- }
- if steady, e.kind == "agent", !used.contains("reply-\(e.data.author ?? "")-\(e.turn)") {
- id = "reply-\(e.data.author ?? "")-\(e.turn)"
- }
- used.insert(id)
+ let id = if e.kind == "user", let nonce = e.data.clientNonce, !nonce.isEmpty { "user-\(nonce)" } else { e.id }
if lastDate.map({ date.timeIntervalSince($0) > 3600 }) ?? true {
out.append(ChatItem(id: "sep-\(id)", kind: .separator(date)))
lastAuthor = nil
@@ -275,17 +257,6 @@ struct ChatItem: Identifiable {
return out
}
- /// The running turn's newest text, if any since the last message or final reply.
- static func liveText(_ entries: [Entry]) -> String? {
- for e in entries.reversed() {
- if e.kind == "user" || (e.kind == "agent" && e.data.final == true) { return nil }
- if e.kind == "agent", let text = e.data.text, !text.isEmpty {
- return text == "(pass)" ? nil : e.id
- }
- }
- return nil
- }
-
var isUserMessage: Bool {
if case let .entry(entry, _) = kind { entry.kind == "user" } else { false }
}
@@ -359,14 +330,14 @@ extension ThreadView {
}
}
- private var streaming: Bool { bot?.isWorking(in: botId, thread: nil) == true && !model.isOffline }
+ private var working: Bool { bot?.isWorking(in: botId, thread: nil) == true && !model.isOffline }
/// iPhone's messages: all this device has, earlier ones from the computer as the reader
/// scrolls up; the chat follows the newest message until they scroll away, and a reply is
/// revealed steadily as it's written.
var transcript: some View {
let thread = model.chat(botId)
- let items = ChatItem.build(thread, streaming: streaming, steady: true)
+ let items = ChatItem.build(thread)
var rows: [ConversationRow] = []
if moreOnComputer {
rows.append(ConversationRow("earlier") {
@@ -383,7 +354,7 @@ extension ThreadView {
}
rows += items.map { item in ConversationRow(item.id, isUserMessage: item.isUserMessage) { row(item) } }
// Offline, "working" is only what the computer last said; don't show it as live.
- if let bot, streaming {
+ if let bot, working {
rows.append(ConversationRow("working") {
WorkingIndicator(bot: bot, thinking: model.currentThinking(botId, thread: nil))
.padding(.top, 6)
diff --git a/apps/ios/Kit/Tests/CodyncUITests/ChatItemTests.swift b/apps/ios/Kit/Tests/CodyncUITests/ChatItemTests.swift
index d338c6b6..75c2d21a 100644
--- a/apps/ios/Kit/Tests/CodyncUITests/ChatItemTests.swift
+++ b/apps/ios/Kit/Tests/CodyncUITests/ChatItemTests.swift
@@ -3,9 +3,9 @@ import Testing
@testable import CodyncKit
@testable import CodyncUI
-/// The chat shows user messages and final replies; while a turn runs, only the text being
-/// generated right now joins them. Earlier narration and room passes never do.
-@Test func chatShowsOnlyFinalRepliesAndTheTextBeingGenerated() {
+/// The chat shows user messages and the bot's messages (Grok Bot's `send_message`), each its
+/// own bubble; what the bot writes along the way, and room passes, stay in the trace.
+@Test func chatShowsOnlyMessagesForTheUser() {
func entry(_ seq: Int64, _ kind: String, _ text: String? = nil, final: Bool? = nil) -> Entry {
var data = EntryData(text: text)
data.final = final
@@ -13,56 +13,10 @@ import Testing
}
let ids = { (items: [ChatItem]) in items.compactMap { if case let .entry(e, _) = $0.kind { e.id } else { nil } } }
- // Mid-turn: narration closed by a tool call, then the answer streaming.
- let running = [entry(1, "user", "Fix it"), entry(2, "agent", "I'll read it first.", final: false),
- entry(3, "tool_call", "Read"), entry(4, "agent", "Done. It raced", final: false)]
- #expect(ids(ChatItem.build(running, streaming: true)) == ["e1", "e4"])
- #expect(ids(ChatItem.build(running)) == ["e1"])
- // Idle: the last text has been marked final; narration stays trace-only.
- let done = [running[0], running[1], running[2], entry(4, "agent", "Done. It raced the refresh.", final: true)]
- #expect(ids(ChatItem.build(done)) == ["e1", "e4"])
- // A room pass is being generated: still not chat.
- #expect(ids(ChatItem.build([running[0], entry(2, "agent", "(pass)", final: false)], streaming: true)) == ["e1"])
-}
-
-/// iPhone (`steady`): the turn's newest text stays while tools run, and a reply is one item
-/// from its first words to the final message.
-@Test func steadyChatKeepsTheTurnsNewestTextInOneBubble() {
- func entry(_ seq: Int64, _ kind: String, _ text: String? = nil, final: Bool? = nil) -> Entry {
- var data = EntryData(text: text)
- data.final = final
- return Entry(id: "e\(seq)", seq: seq, botId: "b", rev: seq, kind: kind, turn: 1, data: data, createdAt: 0, updatedAt: 0)
- }
- let ids = { (items: [ChatItem]) in items.compactMap { if case let .entry(e, _) = $0.kind { e.id } else { nil } } }
- let build = { (entries: [Entry], streaming: Bool) in ChatItem.build(entries, streaming: streaming, steady: true) }
-
- let running = [entry(1, "user", "Fix it"), entry(2, "agent", "I'll read it first.", final: false),
- entry(3, "tool_call", "Read"), entry(4, "agent", "Done. It raced", final: false)]
- let done = [running[0], running[1], running[2], entry(4, "agent", "Done. It raced the refresh.", final: true)]
- #expect(ids(build(running, true)) == ["e1", "e4"])
- #expect(ids(build(running, false)) == ["e1"])
- #expect(ids(build(done, false)) == ["e1", "e4"])
- // A tool runs after the narration: the narration stays until newer text comes.
- #expect(ids(build(Array(running.prefix(3)), true)) == ["e1", "e2"])
- // Narration, the answer being written and the final reply are the same bubble.
- let live = build(running, true).last?.id
- #expect(live == build(done, false).last?.id)
- #expect(build(Array(running.prefix(3)), true).last?.id == live)
- // A room pass is being generated: still not chat.
- #expect(ids(build([running[0], entry(2, "agent", "(pass)", final: false)], true)) == ["e1"])
-}
-
-/// Text being written hides half-typed markers instead of flashing them raw.
-@Test func markdownBlocksHealTheOpenEnd() {
- #expect(MarkdownBlocks.heal("so **bo") == "so **bo**")
- #expect(MarkdownBlocks.heal("run `ls") == "run `ls`")
- #expect(MarkdownBlocks.heal("`a**b` and **c") == "`a**b` and **c**")
- #expect(MarkdownBlocks.heal("see [the docs](https://exa") == "see the docs")
- #expect(MarkdownBlocks.heal("see [the do") == "see the do")
- #expect(MarkdownBlocks.heal("- [ ] task") == "- [ ] task")
- #expect(MarkdownBlocks.heal("done [x](y) **ok**") == "done [x](y) **ok**")
- // Only the block being written is healed.
- #expect(MarkdownBlocks.parse("**a\n\nb **c", streaming: true) == [.paragraph("**a"), .paragraph("b **c**")])
+ let turn = [entry(1, "user", "Fix it"), entry(2, "agent", "I'll read it first.", final: false),
+ entry(3, "agent", "Found it.", final: true), entry(4, "tool_call", "Edit"),
+ entry(5, "agent", "Fixed.", final: true), entry(6, "agent", "(pass)", final: false)]
+ #expect(ids(ChatItem.build(turn)) == ["e1", "e3", "e5"])
}
/// Tables, rules and nested lists, as agents write them.
diff --git a/docs/design/ui-conventions.md b/docs/design/ui-conventions.md
index f60d1700..20d8118c 100644
--- a/docs/design/ui-conventions.md
+++ b/docs/design/ui-conventions.md
@@ -35,7 +35,7 @@ The chat window's account menu copies Grok Bot's: Usage, Get Codync for mobile,
The iPhone and the desktop no longer share UI code. `CodyncUI` (`apps/ios/Kit/`) is the iPhone app's own package; the desktop app (`apps/desktop/src/renderer/`) is a TypeScript port of the same screens with its own `BotStore`, chat items (`views/thread/chat-items.ts`) and Markdown blocks (`markdown-blocks.ts`).
-- The iPhone chat's chrome is in `ThreadView.swift` (`body`, `chrome`, `header`). The iPhone conversation (chat and thread) is a UIKit collection view of hosted SwiftUI rows (`ConversationList.swift`): it loads earlier messages from the computer as the reader scrolls up, runs under the bars and the composer (the list sits in the safe area and reaches past it, so rows never get a safe area of their own), and follows the newest message until they scroll away (with a round "Jump to latest" button), and reveals a reply steadily as it's written (`ChatRows.swift`, `MarkdownText.swift`).
+- The iPhone chat's chrome is in `ThreadView.swift` (`body`, `chrome`, `header`). The iPhone conversation (chat and thread) is a UIKit collection view of hosted SwiftUI rows (`ConversationList.swift`): it loads earlier messages from the computer as the reader scrolls up, runs under the bars and the composer (the list sits in the safe area and reaches past it, so rows never get a safe area of their own), follows the newest message until they scroll away (with a round "Jump to latest" button), and pops each new message in ([chat messages](../features/chat-messages.md)).
- The desktop UI rules (custom controls, no system menus except the tray, icon-only buttons, fill or border) are implemented in `apps/desktop/src/renderer/components/` (`Controls.tsx`, `Overlay.tsx`, `Icon.tsx`).
- A change to one lands in the other and the TUI in the same change; see [native client parity](#native-client-parity).