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(desktop): match the current Mac chat design

leepokaie45919a2898f
diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.ts
index 0cd1c833..cb6f30cd 100644
--- a/apps/desktop/src/main/index.ts
+++ b/apps/desktop/src/main/index.ts
@@ -25,6 +25,9 @@ function computerName() {
return hostname()
}
+// UI checks drive the renderer over the DevTools protocol (development builds only).
+if (!app.isPackaged && process.env.CODYNC_REMOTE_DEBUG) app.commandLine.appendSwitch('remote-debugging-port', process.env.CODYNC_REMOTE_DEBUG)
+
const host = new HostController()
const account = new AccountService()
const updates = new Updates(host)
@@ -136,6 +139,7 @@ function registerIPC(tray: Tray) {
registerHostProxy()
ipcMain.on('app:version', (e) => (e.returnValue = app.getVersion()))
ipcMain.on('app:computerName', (e) => (e.returnValue = computerName()))
+ ipcMain.on('app:debugOpen', (e) => (e.returnValue = app.isPackaged ? null : (process.env.CODYNC_DEBUG_OPEN ?? null)))
ipcMain.handle('host:snapshot', () => snapshot())
ipcMain.handle('host:health', (_e, url: string) => fetchHealth(url))
ipcMain.on('host:install', () => void host.install())
diff --git a/apps/desktop/src/preload/index.ts b/apps/desktop/src/preload/index.ts
index 0a5f0d70..8b79014a 100644
--- a/apps/desktop/src/preload/index.ts
+++ b/apps/desktop/src/preload/index.ts
@@ -22,6 +22,7 @@ const bridge: CodyncBridge = {
platform: process.platform as CodyncBridge['platform'],
appVersion: ipcRenderer.sendSync('app:version') as string,
computerName: ipcRenderer.sendSync('app:computerName') as string,
+ debugOpen: ipcRenderer.sendSync('app:debugOpen') as string | null,
host: {
snapshot: () => ipcRenderer.invoke('host:snapshot') as Promise<HostSnapshot>,
onChange: (cb) => listen('host:change', cb),
diff --git a/apps/desktop/src/renderer/components/Overlay.tsx b/apps/desktop/src/renderer/components/Overlay.tsx
index b0e2626b..60b74a96 100644
--- a/apps/desktop/src/renderer/components/Overlay.tsx
+++ b/apps/desktop/src/renderer/components/Overlay.tsx
@@ -193,7 +193,7 @@ export function MenuPanel({ items, reactions, dismiss, maxHeight }: { items: Men
return (
<div className="menu-panel" style={{ maxHeight }}>
{reactions ? (
- <div style={{ paddingBottom: 4 }}>
+ <div style={{ paddingBottom: items.length ? 4 : 0 }}>
<ReactionStrip pick={reactions} dismiss={dismiss} />
</div>
) : null}
diff --git a/apps/desktop/src/renderer/components/controls.css b/apps/desktop/src/renderer/components/controls.css
index c611d91f..851ff262 100644
--- a/apps/desktop/src/renderer/components/controls.css
+++ b/apps/desktop/src/renderer/components/controls.css
@@ -171,7 +171,8 @@
flex-direction: column;
}
.card-row {
- min-height: 28px;
+ /* 28 pt of content plus the row's own padding. */
+ min-height: 52px;
padding: 12px 16px;
display: flex;
align-items: center;
diff --git a/apps/desktop/src/renderer/components/overlay.css b/apps/desktop/src/renderer/components/overlay.css
index 2c3e87e4..73431c39 100644
--- a/apps/desktop/src/renderer/components/overlay.css
+++ b/apps/desktop/src/renderer/components/overlay.css
@@ -136,7 +136,6 @@
flex-direction: column;
gap: 2px;
overflow-y: auto;
- min-width: 160px;
}
.menu-divider {
height: 0.5px;
@@ -215,3 +214,9 @@
.icon-button:disabled {
opacity: 0.35;
}
+
+/* SwiftUI centers modals below the hidden title bar (28 pt on macOS). */
+html[data-platform="darwin"] .modal-card,
+html[data-platform="darwin"] .dialog {
+ padding-top: 28px;
+}
diff --git a/apps/desktop/src/renderer/components/symbols.json b/apps/desktop/src/renderer/components/symbols.json
index 00cea764..e7b6fc55 100644
--- a/apps/desktop/src/renderer/components/symbols.json
+++ b/apps/desktop/src/renderer/components/symbols.json
@@ -68,6 +68,7 @@
"exclamationmark.triangle.fill",
"eye",
"eye.slash",
+"face.smiling",
"film",
"folder",
"gauge.with.dots.needle.33percent",
diff --git a/apps/desktop/src/renderer/lib/prefs.ts b/apps/desktop/src/renderer/lib/prefs.ts
index 90329a0f..b8dfa95e 100644
--- a/apps/desktop/src/renderer/lib/prefs.ts
+++ b/apps/desktop/src/renderer/lib/prefs.ts
@@ -65,6 +65,9 @@ export function applyTextSize(size: number) {
const clamped = Number.isFinite(size) ? Math.min(Math.max(size, 11), 18) : DEFAULT_TEXT_SIZE
document.documentElement.style.setProperty('--scale', String(clamped / DEFAULT_TEXT_SIZE))
document.documentElement.style.setProperty('--conversation', `${clamped}px`)
+ // The chat itself reads two points larger than the chrome (Grok's desktop chat).
+ document.documentElement.style.setProperty('--chat', `${clamped + 2}px`)
+ document.documentElement.style.setProperty('--chat-scale', String((clamped + 2) / DEFAULT_TEXT_SIZE))
}
prefs.textSize.subscribe(() => applyTextSize(prefs.textSize.get()))
diff --git a/apps/desktop/src/renderer/styles/theme.css b/apps/desktop/src/renderer/styles/theme.css
index 582e83ae..b73c68f6 100644
--- a/apps/desktop/src/renderer/styles/theme.css
+++ b/apps/desktop/src/renderer/styles/theme.css
@@ -22,12 +22,19 @@
--removed: #c62828;
/* Floating menus and account panel. */
--panel: #fafafa;
+ /* The Mac chat's bubbles (a step stronger than the iPhone's). */
+ --chat-agent: #eeeeee;
+ --chat-user: #e2e2e2;
+ /* Floating transcript controls (chevrons, Jump to latest, inspector actions). */
+ --chat-button: #eeeeee;
/* Grok's frosted floating surfaces (title pill, call bar). */
--frosted: rgba(244, 244, 244, 0.82);
/* The Mac text preference: conversation size / 12 pt scales the chrome too. */
--scale: 1;
--conversation: 12px;
+ /* Markdown headings and code follow the conversation's own text size. */
+ --md-scale: var(--scale);
/* Grok Bot's motion. */
--ease: cubic-bezier(0.25, 0.1, 0.25, 1);
@@ -64,6 +71,9 @@
--added: #8fd18b;
--removed: #f0a7a7;
--panel: #1b1b1b;
+ --chat-agent: #262626;
+ --chat-user: #545454;
+ --chat-button: #303030;
--frosted: rgba(35, 35, 35, 0.82);
}
}
diff --git a/apps/desktop/src/renderer/views/BotRow.tsx b/apps/desktop/src/renderer/views/BotRow.tsx
index 3c046ef3..de308293 100644
--- a/apps/desktop/src/renderer/views/BotRow.tsx
+++ b/apps/desktop/src/renderer/views/BotRow.tsx
@@ -44,6 +44,12 @@ export const BotRow = memo(function BotRow({ bot, store, compact, usingComputer,
)
})
+/** `lineLimit(1)`: the first line, with an ellipsis when there is more. */
+const firstLine = (text: string) => {
+ const nl = text.indexOf('\n')
+ return nl < 0 ? text : `${text.slice(0, nl)}…`
+}
+
const line: React.CSSProperties = { ...font('compactSecondary'), whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', minWidth: 0 }
/** Live activity while working, otherwise the last message (Grok Bot row behavior). */
@@ -64,6 +70,6 @@ function Preview({ bot, store }: { bot: Bot; store: BotStore }) {
</span>
)
}
- if (bot.status === 'error') return <span style={{ ...line, color: 'var(--danger)' }}>{bot.lastMessage ?? 'Something went wrong'}</span>
- return <span style={{ ...line, color: 'var(--secondary)' }}>{bot.lastMessage ?? `${store.backendName(bot.backend)} · ${folderName(bot)}`}</span>
+ if (bot.status === 'error') return <span style={{ ...line, color: 'var(--danger)' }}>{firstLine(bot.lastMessage ?? 'Something went wrong')}</span>
+ return <span style={{ ...line, color: 'var(--secondary)' }}>{firstLine(bot.lastMessage ?? `${store.backendName(bot.backend)} · ${folderName(bot)}`)}</span>
}
diff --git a/apps/desktop/src/renderer/views/ChatWindow.tsx b/apps/desktop/src/renderer/views/ChatWindow.tsx
index b777356e..f1e15d1e 100644
--- a/apps/desktop/src/renderer/views/ChatWindow.tsx
+++ b/apps/desktop/src/renderer/views/ChatWindow.tsx
@@ -214,6 +214,30 @@ function ChatSplitView() {
}),
)
+ // Screenshot/UI checks (development builds): open a screen at launch.
+ const debugOpened = useRef(false)
+ useEffect(() => {
+ const target = window.codync.debugOpen
+ if (!target || debugOpened.current) return
+ if (target === 'compose' || target === 'group') {
+ if (!onlineStores.length) return
+ debugOpened.current = true
+ compose(target === 'group')
+ } else if (target === 'plugins') {
+ if (!app.local) return
+ debugOpened.current = true
+ setMarketplace(app.local.computer.id)
+ } else if (target === 'computers') {
+ debugOpened.current = true
+ setSettings('computers')
+ } else {
+ const item = app.roster.find((i) => i.bot.name === target)
+ if (!item) return
+ debugOpened.current = true
+ app.select(item.ref)
+ }
+ })
+
const newItems = (): MenuItem[] => [
{ title: 'New chat', icon: 'square.and.pencil', action: () => compose() },
{ title: 'New group chat', icon: 'person.2', action: () => compose(true) },
diff --git a/apps/desktop/src/renderer/views/thread/ChatRows.tsx b/apps/desktop/src/renderer/views/thread/ChatRows.tsx
index 9d6bd6ce..71e70923 100644
--- a/apps/desktop/src/renderer/views/thread/ChatRows.tsx
+++ b/apps/desktop/src/renderer/views/thread/ChatRows.tsx
@@ -1,9 +1,9 @@
-import { memo, useEffect, useState } from 'react'
+import { memo, useEffect, useRef, useState } from 'react'
import { isGroup, isWorking, needsInput, type Bot, type Entry, type ThreadSummary } from '@shared/models'
import { BotAvatar } from '../../components/Avatar'
import { IconButton } from '../../components/Controls'
import { Icon } from '../../components/Icon'
-import { AnchoredMenu, ReactionStrip, useContextMenu, type MenuItem, type ReactionPick } from '../../components/Overlay'
+import { AnchoredMenu, useContextMenu, type MenuItem, type ReactionPick } from '../../components/Overlay'
import { ThinkingOrb } from '../../components/ThinkingOrb'
import { font, px } from '../../lib/fonts'
import { avatarColor } from '../../lib/theme'
@@ -126,35 +126,38 @@ function Bubble({ className, items, reactions, children }: { className: string;
)
}
+const fullDate = new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' })
+
export function UserBubble({ entry, botWorking, reply }: { entry: Entry; botWorking: boolean; reply?: () => void }) {
const store = useStore()
const [hovering, setHovering] = useState(false)
const status = entry.data.status
const copy = () => entry.data.text && window.codync.app.copy(entry.data.text)
return (
- <div className="message user" onMouseEnter={() => setHovering(true)} onMouseLeave={() => setHovering(false)}>
- {entry.data.attachments?.length ? <AttachmentList attachments={entry.data.attachments} botId={entry.botId} /> : null}
- {entry.data.text ? (
- <Bubble
- className="bubble user selectable"
- reactions={reactionPick(store, entry)}
- items={() => [
- { title: 'Copy', icon: 'square.on.square', action: copy },
- ...(reply ? [{ title: 'Reply in thread', icon: 'arrowshape.turn.up.left', action: reply }] : []),
- ]}
- >
- {entry.data.text}
- </Bubble>
- ) : null}
- <div className="message-footer">
- {hovering && (!status || status === 'sent') ? <MessageActions reactions={reactionPick(store, entry)} reply={reply} copy={copy} /> : null}
- <UserStatus entry={entry} botWorking={botWorking} />
+ <div className="message user" title={fullDate.format(entry.createdAt)} onMouseEnter={() => setHovering(true)} onMouseLeave={() => setHovering(false)}>
+ <div className="message-body">
+ {entry.data.attachments?.length ? <AttachmentList attachments={entry.data.attachments} botId={entry.botId} /> : null}
+ {entry.data.text ? (
+ <Bubble
+ className="bubble user selectable"
+ reactions={reactionPick(store, entry)}
+ items={() => [
+ { title: 'Copy', icon: 'square.on.square', action: copy },
+ ...(reply ? [{ title: 'Reply in thread', icon: 'arrowshape.turn.up.left', action: reply }] : []),
+ ]}
+ >
+ {entry.data.text}
+ </Bubble>
+ ) : null}
+ {status && status !== 'sent' ? <UserStatus entry={entry} botWorking={botWorking} hovering={hovering} /> : null}
+ {/* Beside the bubble, inside its hover region: showing them never changes the height. */}
+ <MessageActions className="leading" visible={hovering} reactions={reactionPick(store, entry)} reply={reply} copy={copy} />
</div>
</div>
)
}
-function UserStatus({ entry, botWorking }: { entry: Entry; botWorking: boolean }) {
+function UserStatus({ entry, botWorking, hovering }: { entry: Entry; botWorking: boolean; hovering: boolean }) {
const store = useStore()
const caption = { ...font('caption2'), color: 'var(--tertiary)' }
switch (entry.data.status) {
@@ -188,7 +191,7 @@ function UserStatus({ entry, botWorking }: { entry: Entry; botWorking: boolean }
case 'delivering':
return <span style={caption}>Delivered to the computer</span>
default:
- return <span style={{ ...font(10), color: 'var(--tertiary)' }}>{relativeTime.time(entry.createdAt)}</span>
+ return <span style={{ ...font(10), color: 'var(--tertiary)', opacity: hovering ? 1 : 0, transition: 'opacity var(--hover)' }}>{relativeTime.time(entry.createdAt)}</span>
}
}
@@ -197,21 +200,20 @@ export function AgentBubble({ entry, openTrace, reply }: { entry: Entry; openTra
const [hovering, setHovering] = useState(false)
const copy = () => entry.data.text && window.codync.app.copy(entry.data.text)
return (
- <div className="message agent" onMouseEnter={() => setHovering(true)} onMouseLeave={() => setHovering(false)}>
- <Bubble
- className="bubble agent"
- reactions={reactionPick(store, entry)}
- items={() => [
- { title: 'Copy', icon: 'square.on.square', action: copy },
- ...(reply ? [{ title: 'Reply in thread', icon: 'arrowshape.turn.up.left', action: reply }] : []),
- { title: 'Show what it did', icon: 'list.bullet', action: openTrace },
- ]}
- >
- <MarkdownText text={entry.data.text ?? ''} streaming={entry.data.final === false} />
- </Bubble>
- <div className="message-footer" style={{ paddingLeft: 12 }}>
- <span style={{ ...font(10), color: 'var(--tertiary)' }}>{relativeTime.time(entry.createdAt)}</span>
- {hovering ? <MessageActions reactions={reactionPick(store, entry)} reply={reply} trace={openTrace} copy={copy} /> : null}
+ <div className="message agent" title={fullDate.format(entry.createdAt)} onMouseEnter={() => setHovering(true)} onMouseLeave={() => setHovering(false)}>
+ <div className="message-body">
+ <Bubble
+ className="bubble agent"
+ reactions={reactionPick(store, entry)}
+ items={() => [
+ { title: 'Copy', icon: 'square.on.square', action: copy },
+ ...(reply ? [{ title: 'Reply in thread', icon: 'arrowshape.turn.up.left', action: reply }] : []),
+ { title: 'Show what it did', icon: 'list.bullet', action: openTrace },
+ ]}
+ >
+ <MarkdownText text={entry.data.text ?? ''} streaming={entry.data.final === false} />
+ </Bubble>
+ <MessageActions className="trailing" visible={hovering} reactions={reactionPick(store, entry)} reply={reply} trace={openTrace} copy={copy} />
</div>
</div>
)
@@ -311,18 +313,35 @@ export function ReactionsRow({ entry }: { entry: Entry }) {
)
}
-/**
- * A message's quick actions, in its footer beside the time while the pointer is over it:
- * reactions, reply in thread, what it did, copy.
- */
-function MessageActions({ reactions, reply, trace, copy }: { reactions: ReactionPick; reply?: () => void; trace?: () => void; copy: () => void }) {
+/** Compact actions beside the bubble: a reaction strip, reply in thread, and more (copy, what it did). */
+function MessageActions({ visible, className, reactions, reply, trace, copy }: {
+ visible: boolean
+ className: string
+ reactions: ReactionPick
+ reply?: () => void
+ trace?: () => void
+ copy: () => void
+}) {
+ const [menu, setMenu] = useState<'reactions' | 'more' | null>(null)
+ const smile = useRef<HTMLButtonElement>(null)
+ const more = useRef<HTMLButtonElement>(null)
+ const shown = visible || menu !== null
return (
- <div className="message-actions">
- <ReactionStrip pick={reactions} />
- <div style={{ width: 1, height: 12, background: 'rgba(var(--text-rgb), 0.12)', margin: '0 4px' }} />
+ <div className={`message-actions ${className}`} style={{ opacity: shown ? 1 : 0, pointerEvents: shown ? 'auto' : 'none' }} aria-hidden={!shown}>
+ <button ref={smile} className="message-action" title="Add reaction" aria-label="Add reaction" onClick={() => setMenu('reactions')}>
+ <Icon name="face.smiling" size={14} />
+ </button>
{reply ? <IconButton title="Reply in thread" icon="arrowshape.turn.up.left" size={26} onClick={reply} /> : null}
- {trace ? <IconButton title="Show what it did" icon="list.bullet" size={26} onClick={trace} /> : null}
- <IconButton title="Copy" icon="square.on.square" size={26} onClick={copy} />
+ <button ref={more} className="message-action" title="More message actions" aria-label="More message actions" onClick={() => setMenu('more')}>
+ <Icon name="ellipsis" size={14} />
+ </button>
+ <AnchoredMenu open={menu === 'reactions'} onClose={() => setMenu(null)} anchor={smile} items={() => []} reactions={reactions} />
+ <AnchoredMenu
+ open={menu === 'more'}
+ onClose={() => setMenu(null)}
+ anchor={more}
+ items={() => [{ title: 'Copy', icon: 'square.on.square', action: copy }, ...(trace ? [{ title: 'Show what it did', icon: 'list.bullet', action: trace }] : [])]}
+ />
</div>
)
}
diff --git a/apps/desktop/src/renderer/views/thread/Composer.tsx b/apps/desktop/src/renderer/views/thread/Composer.tsx
index 2c95d7dd..e4625d59 100644
--- a/apps/desktop/src/renderer/views/thread/Composer.tsx
+++ b/apps/desktop/src/renderer/views/thread/Composer.tsx
@@ -89,7 +89,7 @@ export function Composer({ botId, thread = null, onCall, onInterrupt }: {
setFiles([])
}
- const trailing: Trailing = onInterrupt && !draft && !files.length ? 'interrupt' : working && !draft ? 'stop' : onCall && !draft && !files.length ? 'call' : 'send'
+ const trailing: Trailing = onInterrupt && !draft && !files.length ? 'interrupt' : working && !draft && !files.length ? 'stop' : onCall && !draft && !files.length ? 'call' : 'send'
const [symbol, label, size] = ({
interrupt: ['stop.fill', 'Interrupt', 12],
stop: ['stop.fill', 'Stop', 12],
@@ -123,11 +123,6 @@ export function Composer({ botId, thread = null, onCall, onInterrupt }: {
void Promise.all([...e.dataTransfer.files].map(async (f) => ({ name: f.name, data: new Uint8Array(await f.arrayBuffer()) }))).then(append)
}}
>
- {canAttach ? (
- <button className="press composer-add" aria-label="Add files" title="Add files" onClick={() => void window.codync.app.pickFiles().then(append)}>
- <Icon name="plus" size={13} weight="medium" color="var(--text)" />
- </button>
- ) : null}
<div className="composer-surface">
{files.length ? (
<div className="file-chips">
@@ -143,6 +138,12 @@ export function Composer({ botId, thread = null, onCall, onInterrupt }: {
</div>
) : null}
<div className="composer-box">
+ {/* One capsule: attachments, the field, and send / stop / call. */}
+ {canAttach ? (
+ <button className="press composer-add" aria-label="Add files" title="Add files" onClick={() => void window.codync.app.pickFiles().then(append)}>
+ <Icon name="plus" size={13} weight="medium" color="var(--text)" />
+ </button>
+ ) : null}
<textarea
ref={field}
rows={1}
@@ -175,7 +176,7 @@ export function Composer({ botId, thread = null, onCall, onInterrupt }: {
disabled={!enabled}
aria-label={label}
title={label}
- style={{ background: fill, color: ink, width: trailing === 'call' ? 28 * 1.35 : 28 }}
+ style={{ background: fill, color: ink }}
onClick={() => {
if (trailing === 'interrupt') onInterrupt?.()
else if (trailing === 'stop') store.stop(botId)
diff --git a/apps/desktop/src/renderer/views/thread/DetailsPanel.tsx b/apps/desktop/src/renderer/views/thread/DetailsPanel.tsx
index 27f96fe6..4dce0710 100644
--- a/apps/desktop/src/renderer/views/thread/DetailsPanel.tsx
+++ b/apps/desktop/src/renderer/views/thread/DetailsPanel.tsx
@@ -9,6 +9,7 @@ import { useStore } from '../../store/context'
import { BotSettingsPanel } from '../bots/BotEditorView'
import { ComputerBadge } from '../ComputerBadge'
import { RoutinesView } from '../routines/RoutinesView'
+import { MacChatButton } from './MacChatButton'
const isMac = window.codync.platform === 'darwin'
@@ -82,13 +83,9 @@ function PanelTitle({ children }: { children: ReactNode }) {
return <span style={{ ...font(15, 'semibold'), color: 'var(--text)', paddingLeft: 4 }}>{children}</span>
}
-/** A round action in the panel's header, frosted like the chat's title pill (Grok's style). */
+/** A single circular surface, shared with the floating transcript controls. */
function RoundButton({ label, symbol, action }: { label: string; symbol: string; action: () => void }) {
- return (
- <button className="press round-button" onClick={action} aria-label={label} title={label}>
- <Icon name={symbol} size={13} weight="medium" color="var(--text)" />
- </button>
- )
+ return <MacChatButton title={label} icon={symbol} direction={symbol === 'chevron.right.2' ? [1, 0] : [0, 0]} onClick={action} />
}
/** A group's bots; clicking one opens its own chat. */
diff --git a/apps/desktop/src/renderer/views/thread/MacChatButton.tsx b/apps/desktop/src/renderer/views/thread/MacChatButton.tsx
new file mode 100644
index 00000000..2bb38c4d
--- /dev/null
+++ b/apps/desktop/src/renderer/views/thread/MacChatButton.tsx
@@ -0,0 +1,26 @@
+import { Icon } from '../../components/Icon'
+
+/**
+ * The chat's one circular surface (floating chevrons, inspector actions, Jump to latest):
+ * a directional arrow nudges toward `direction` on hover and press; pressing scales to 94%.
+ */
+export function MacChatButton({ title, icon, onClick, direction = [0, 0], size = 32, className }: {
+ title: string
+ icon: string
+ onClick: () => void
+ direction?: [number, number]
+ size?: number
+ className?: string
+}) {
+ return (
+ <button
+ className={`mac-chat-button ${className ?? ''}`}
+ title={title}
+ aria-label={title}
+ onClick={onClick}
+ style={{ width: size, height: size, ['--dx' as string]: direction[0], ['--dy' as string]: direction[1] }}
+ >
+ <Icon name={icon} size={size / 2} weight="medium" />
+ </button>
+ )
+}
diff --git a/apps/desktop/src/renderer/views/thread/Markdown.tsx b/apps/desktop/src/renderer/views/thread/Markdown.tsx
index 26568de3..a7716755 100644
--- a/apps/desktop/src/renderer/views/thread/Markdown.tsx
+++ b/apps/desktop/src/renderer/views/thread/Markdown.tsx
@@ -1,24 +1,42 @@
import { memo, type ReactNode } from 'react'
-import { px } from '../../lib/fonts'
-// The Mac's Markdown renderer (kit MarkdownText.swift): paragraphs, headings, lists, quotes and
-// fenced code; inline styling like `AttributedString(markdown:)` (inline only, whitespace kept).
+// Block-level Markdown as replies use it (kit MarkdownBlocks): paragraphs, headings, nested
+// lists, quotes, rules, tables and fenced code; inline styling like `AttributedString(markdown:)`.
-type Block =
+export type Block =
| { kind: 'paragraph'; text: string }
| { kind: 'heading'; text: string; level: number }
- | { kind: 'bullet'; text: string; marker: string }
+ | { kind: 'bullet'; text: string; marker: string; depth: number }
| { kind: 'quote'; text: string }
| { kind: 'code'; text: string; language: string }
+ | { kind: 'table'; header: string[]; rows: string[][] }
+ | { kind: 'rule' }
+
+const isTableRule = (line: string) => line.includes('-') && [...line].every((c) => '|-: '.includes(c))
+const cells = (line: string) => {
+ let row = line
+ if (row.startsWith('|')) row = row.slice(1)
+ if (row.endsWith('|')) row = row.slice(0, -1)
+ return row.split('|').map((c) => c.trim())
+}
export function parseMarkdown(source: string): Block[] {
const blocks: Block[] = []
let paragraph: string[] = []
+ let table: string[] = []
let code: string[] | null = null
let language = ''
const flush = () => {
- if (paragraph.length) blocks.push({ kind: 'paragraph', text: paragraph.join('\n') })
- paragraph = []
+ if (paragraph.length) {
+ blocks.push({ kind: 'paragraph', text: paragraph.join('\n') })
+ paragraph = []
+ }
+ if (table.length) {
+ // A header and its `|---|` line make a table; anything less stays text.
+ if (table.length >= 2 && isTableRule(table[1]!)) blocks.push({ kind: 'table', header: cells(table[0]!), rows: table.slice(2).map(cells) })
+ else blocks.push({ kind: 'paragraph', text: table.join('\n') })
+ table = []
+ }
}
for (const raw of source.split('\n')) {
const line = raw.trim()
@@ -37,39 +55,80 @@ export function parseMarkdown(source: string): Block[] {
code.push(raw)
continue
}
+ if (line.startsWith('|')) {
+ if (paragraph.length) flush()
+ table.push(line)
+ continue
+ }
+ if (table.length) flush()
+ const depth = Math.min(Math.floor((/^[ \t]*/.exec(raw)?.[0].length ?? 0) / 2), 3)
const heading = /^(#+) (.*)$/.exec(line)
const ordered = /^(\d+\.) (.*)$/.exec(line)
if (!line) flush()
- else if (heading) {
+ else if (line === '---' || line === '***' || line === '___') {
+ flush()
+ blocks.push({ kind: 'rule' })
+ } else if (heading) {
flush()
blocks.push({ kind: 'heading', text: heading[2]!.trim(), level: heading[1]!.length })
- } else if (line.startsWith('- ') || line.startsWith('* ') || line.startsWith('• ')) {
+ } else if (/^[-*+•] /.test(line)) {
flush()
- blocks.push({ kind: 'bullet', text: line.slice(2), marker: '•' })
+ blocks.push({ kind: 'bullet', text: line.slice(2), marker: depth > 0 ? '◦' : '•', depth })
} else if (ordered) {
flush()
- blocks.push({ kind: 'bullet', text: ordered[2]!, marker: ordered[1]! })
- } else if (line.startsWith('> ')) {
+ blocks.push({ kind: 'bullet', text: ordered[2]!, marker: ordered[1]!, depth })
+ } else if (line.startsWith('>')) {
flush()
- blocks.push({ kind: 'quote', text: line.slice(2) })
+ blocks.push({ kind: 'quote', text: line.slice(1).trim() })
} else paragraph.push(raw)
}
- if (code) blocks.push({ kind: 'code', text: code.join('\n'), language })
+ if (code) blocks.push({ kind: 'code', text: (code as string[]).join('\n'), language })
flush()
return blocks
}
-/** Inline Markdown: `code`, **bold**, *italic*, ~~strike~~, [links](url). */
+/** 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
+}
+
+/** Inline Markdown: `code` (tinted), **bold**, *italic*, ~~strike~~, [links](url). */
export function inline(text: string, key = 'i'): ReactNode[] {
const out: ReactNode[] = []
// Code spans first: nothing inside them is styled.
- const parts = text.split(/(`[^`\n]+`)/)
- parts.forEach((part, i) => {
- if (part.startsWith('`') && part.endsWith('`') && part.length > 2) {
- out.push(<code key={`${key}${i}`} style={{ fontFamily: 'var(--mono)', fontSize: '0.92em' }}>{part.slice(1, -1)}</code>)
- } else if (part) {
- out.push(...emphasis(part, `${key}${i}-`))
- }
+ text.split(/(`[^`\n]+`)/).forEach((part, i) => {
+ if (part.length > 2 && part.startsWith('`') && part.endsWith('`')) {
+ out.push(
+ <code key={`${key}${i}`} style={{ fontFamily: 'var(--mono)', background: 'rgba(var(--text-rgb), 0.08)' }}>
+ {part.slice(1, -1)}
+ </code>,
+ )
+ } else if (part) out.push(...emphasis(part, `${key}${i}-`))
})
return out
}
@@ -103,34 +162,72 @@ function emphasis(text: string, key: string): ReactNode[] {
}
const headingSize = (level: number) => (level === 1 ? 15 : level === 2 ? 13 : 11)
+/**
+ * SwiftUI's `.lineSpacing(4 * scale)`: four points between lines on top of the font's own, none
+ * above the first or below the last (the negative margins take the half-leading back).
+ */
+const lineHeight = 'calc(1.2em + 4px * var(--md-scale))'
+const spaced: React.CSSProperties = { lineHeight, margin: 'calc(-2px * var(--md-scale)) 0' }
+const text: React.CSSProperties = { color: 'var(--text)', whiteSpace: 'pre-wrap', overflowWrap: 'anywhere', ...spaced }
+
+const MarkdownBlock = memo(function MarkdownBlock({ block }: { block: Block }) {
+ switch (block.kind) {
+ case 'paragraph':
+ return <div style={{ ...text, fontSize: 'var(--conversation)' }}>{inline(block.text)}</div>
+ case 'heading':
+ return (
+ <div style={{ ...text, fontSize: `calc(${headingSize(block.level)}px * var(--md-scale))`, fontWeight: block.level === 2 ? 600 : 700 }}>
+ {inline(block.text)}
+ </div>
+ )
+ case 'bullet':
+ return (
+ <div style={{ display: 'flex', alignItems: 'baseline', gap: 6, fontSize: 'var(--conversation)', paddingLeft: block.depth * 16, ...spaced }}>
+ <span style={{ color: 'var(--secondary)', fontVariantNumeric: 'tabular-nums', flex: 'none' }}>{block.marker}</span>
+ <span style={{ color: 'var(--text)', whiteSpace: 'pre-wrap', overflowWrap: 'anywhere', minWidth: 0 }}>{inline(block.text)}</span>
+ </div>
+ )
+ case 'rule':
+ return <div style={{ height: 1, background: 'var(--border)', margin: '4px 0' }} />
+ case 'table': {
+ const columns = Math.max(block.header.length, ...block.rows.map((r) => r.length))
+ const cols = Array.from({ length: columns }, (_, i) => i)
+ return (
+ <div style={{ overflowX: 'auto' }}>
+ <div style={{ display: 'grid', gridTemplateColumns: `repeat(${columns}, max-content)`, columnGap: 16, rowGap: 7, fontSize: 'var(--conversation)', color: 'var(--text)', padding: '2px 0', width: 'max-content', lineHeight }}>
+ {cols.map((i) => (
+ <span key={`h${i}`} style={{ fontWeight: 600 }}>{inline(block.header[i] ?? '', `h${i}`)}</span>
+ ))}
+ {block.rows.map((row, r) => [
+ <div key={`l${r}`} style={{ gridColumn: `1 / span ${columns}`, height: 1, background: 'var(--border)' }} />,
+ ...cols.map((i) => <span key={`${r}-${i}`}>{inline(row[i] ?? '', `${r}-${i}`)}</span>),
+ ])}
+ </div>
+ </div>
+ )
+ }
+ case 'quote':
+ return <div style={{ ...text, fontSize: 'var(--conversation)', color: 'var(--secondary)', paddingLeft: 10, boxShadow: 'inset 3px 0 0 var(--border)' }}>{inline(block.text)}</div>
+ case 'code':
+ return (
+ <div style={{ background: 'var(--code-background)', borderRadius: 8, overflowX: 'auto' }}>
+ <pre style={{ margin: 0, padding: 10, fontFamily: 'var(--mono)', fontSize: 'calc(10px * var(--md-scale))', color: 'var(--text)', width: 'max-content', lineHeight }}>{block.text}</pre>
+ </div>
+ )
+ }
+}, (a, b) => JSON.stringify(a.block) === JSON.stringify(b.block))
-export const MarkdownText = memo(function MarkdownText({ text }: { text: string; streaming?: boolean }) {
- const blocks = parseMarkdown(text)
+/**
+ * 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)
return (
- <div className="markdown selectable" style={{ display: 'flex', flexDirection: 'column', gap: 8, minWidth: 0 }}>
- {blocks.map((b, i) => {
- switch (b.kind) {
- case 'paragraph':
- return <div key={i} style={{ fontSize: 'var(--conversation)', color: 'var(--text)', whiteSpace: 'pre-wrap', overflowWrap: 'anywhere' }}>{inline(b.text)}</div>
- case 'heading':
- return <div key={i} style={{ fontSize: px(headingSize(b.level)), fontWeight: b.level === 2 ? 600 : 700, color: 'var(--text)' }}>{inline(b.text)}</div>
- case 'bullet':
- return (
- <div key={i} style={{ display: 'flex', alignItems: 'baseline', gap: 6, fontSize: 'var(--conversation)' }}>
- <span style={{ color: 'var(--secondary)', fontVariantNumeric: 'tabular-nums', flex: 'none' }}>{b.marker}</span>
- <span style={{ color: 'var(--text)', whiteSpace: 'pre-wrap', overflowWrap: 'anywhere', minWidth: 0 }}>{inline(b.text)}</span>
- </div>
- )
- case 'quote':
- return <div key={i} style={{ fontSize: 'var(--conversation)', color: 'var(--secondary)', paddingLeft: 10, boxShadow: 'inset 3px 0 0 var(--border)', whiteSpace: 'pre-wrap' }}>{inline(b.text)}</div>
- case 'code':
- return (
- <div key={i} style={{ background: 'var(--code-background)', borderRadius: 8, overflowX: 'auto' }}>
- <pre style={{ margin: 0, padding: 10, fontFamily: 'var(--mono)', fontSize: px(10), color: 'var(--text)', width: 'max-content' }}>{b.text}</pre>
- </div>
- )
- }
- })}
+ <div className="markdown selectable" style={{ display: 'flex', flexDirection: 'column', gap: 10, minWidth: 0 }}>
+ {blocks.map((b, i) => (
+ <MarkdownBlock key={i} block={b} />
+ ))}
</div>
)
})
diff --git a/apps/desktop/src/renderer/views/thread/ThreadView.tsx b/apps/desktop/src/renderer/views/thread/ThreadView.tsx
index d06653d4..0b52c143 100644
--- a/apps/desktop/src/renderer/views/thread/ThreadView.tsx
+++ b/apps/desktop/src/renderer/views/thread/ThreadView.tsx
@@ -1,9 +1,9 @@
import { useCallback, useEffect, useLayoutEffect, useRef, useState, type ReactNode } from 'react'
import { draftOf, isGroup, isWorkingIn, type Bot, type BotDraft } from '@shared/models'
import { BotAvatar, GroupAvatar } from '../../components/Avatar'
-import { IconButton, Spinner } from '../../components/Controls'
+import { Spinner } from '../../components/Controls'
import { Icon } from '../../components/Icon'
-import { Dialog, Sheet } from '../../components/Overlay'
+import { Sheet } from '../../components/Overlay'
import { font } from '../../lib/fonts'
import { useStore } from '../../store/context'
import { UpdateNeededCard } from '../UpdateNeededCard'
@@ -16,9 +16,10 @@ import { TraceView } from './TraceView'
import { useReading } from './reading'
import { GroupEditorView } from '../bots/GroupEditorView'
import { BotTemplateView } from '../bots/BotTemplateView'
-import { RoutinesView } from '../routines/RoutinesView'
import { CallView } from '../call/CallView'
+import { MacChatButton } from './MacChatButton'
import './thread.css'
+import './chat-controls.css'
const WIDE = 680
@@ -34,8 +35,6 @@ export function ThreadView({ botId }: { botId: string }) {
const [openThread, setOpenThread] = useState<string | null>(null)
const [editingGroup, setEditingGroup] = useState(false)
const [templateDraft, setTemplateDraft] = useState<BotDraft | null>(null)
- const [confirmNewSession, setConfirmNewSession] = useState(false)
- const [confirmDelete, setConfirmDelete] = useState<Bot | null>(null)
const [showSettings, setShowSettings] = useState(true)
const [editingDetails, setEditingDetails] = useState(false)
const [compactDetails, setCompactDetails] = useState(false)
@@ -44,8 +43,8 @@ export function ThreadView({ botId }: { botId: string }) {
const interruptCall = useRef<(() => void) | null>(null)
const [routineId, setRoutineId] = useState<string | null>(null)
const [routineRequest, setRoutineRequest] = useState(0)
- const [showRoutines, setShowRoutines] = useState(false)
const root = useRef<HTMLDivElement>(null)
+ const dock = useRef<HTMLDivElement>(null)
const [width, setWidth] = useState(800)
useReading(store, botId, null)
@@ -54,14 +53,30 @@ export function ThreadView({ botId }: { botId: string }) {
if (!el) return
const observer = new ResizeObserver(([e]) => setWidth(e!.contentRect.width))
observer.observe(el)
- return () => observer.disconnect()
+ // The composer floats over the transcript; its height becomes the transcript's bottom padding.
+ const docked = new ResizeObserver(([e]) => el.style.setProperty('--composer-height', `${Math.ceil(e!.borderBoxSize[0]!.blockSize)}px`))
+ if (dock.current) docked.observe(dock.current)
+ return () => {
+ observer.disconnect()
+ docked.disconnect()
+ }
}, [])
const wide = width >= WIDE
- const toggleDetails = useCallback(() => {
- if (!wide) setCompactDetails((c) => !c)
- else setShowSettings((s) => !s)
+ // A compact Details presentation dismisses once the window is wide enough for the inspector.
+ useEffect(() => {
+ if (wide) setCompactDetails(false)
}, [wide])
+ const toggleDetails = useCallback(() => {
+ if (!wide) {
+ setOpenThread(null)
+ setCompactDetails((c) => !c)
+ } else if (openThread) {
+ // The thread occupies the inspector slot: << shows details instead of toggling behind it.
+ setOpenThread(null)
+ setShowSettings(true)
+ } else setShowSettings((s) => !s)
+ }, [wide, openThread])
useEffect(
() =>
@@ -110,10 +125,8 @@ export function ThreadView({ botId }: { botId: string }) {
<TopFade />
<div className="top-chrome-row">
<span style={{ flex: 1 }} />
- {!showSettings || !wide ? (
- <span className="frosted-circle">
- <IconButton title="Conversation details" icon="chevron.left.2" onClick={toggleDetails} />
- </span>
+ {(!showSettings || openThread || !wide) && !compactDetails ? (
+ <MacChatButton title="Conversation details" icon="chevron.left.2" direction={[-1, 0]} onClick={toggleDetails} />
) : null}
</div>
<button className="title-pill" onClick={toggleDetails} aria-label="View conversation details" title="View conversation details">
@@ -125,7 +138,8 @@ export function ThreadView({ botId }: { botId: string }) {
</button>
</div>
<Transcript botId={botId} openTrace={openTrace} openThread={openThreadOn} openRoutine={presentRoutine} />
- <div className="composer-dock">
+ <div className="composer-dock" ref={dock}>
+ <div className="composer-fade" />
{store.mismatch ? (
<div style={{ padding: '0 16px 8px' }}>
<UpdateNeededCard />
@@ -167,25 +181,6 @@ export function ThreadView({ botId }: { botId: string }) {
<Sheet open={editingGroup} onClose={() => setEditingGroup(false)} width={420} height={560}>
<GroupEditorView group={bot} />
</Sheet>
- <Sheet open={showRoutines} onClose={() => setShowRoutines(false)} width={440} height={580}>
- <div style={{ overflowY: 'auto', padding: 20 }}>
- <RoutinesView botId={botId} initialId={routineId} onClose={() => setShowRoutines(false)} />
- </div>
- </Sheet>
- <Dialog
- open={confirmNewSession}
- title="Start a new session?"
- message="The conversation stays here, but the agent starts with a fresh context."
- actions={[{ title: 'New session', action: () => store.newSession(botId) }]}
- onClose={() => setConfirmNewSession(false)}
- />
- <Dialog
- open={confirmDelete !== null}
- title={`Delete ${confirmDelete?.name ?? 'bot'}?`}
- message={confirmDelete && isGroup(confirmDelete) ? 'Its bots and their own chats stay.' : 'Files it changed on your computer stay as they are.'}
- actions={confirmDelete ? [{ title: 'Delete bot and its conversation', destructive: true, action: () => store.delete(confirmDelete) }] : []}
- onClose={() => setConfirmDelete(null)}
- />
</div>
)
}
@@ -233,78 +228,130 @@ function ConnectionSubtitle() {
}
/** The messages: every loaded message, brought to the newest as it changes while the reader is at the bottom. */
+const PAGE = 40
+
function Transcript({ botId, openTrace, openThread, openRoutine }: { botId: string; openTrace: () => void; openThread: (e: { id: string }) => void; openRoutine: (id: string | null) => void }) {
const store = useStore()
const bot = store.bots.get(botId) ?? null
const thread = store.chat(botId)
const live = !!bot && isWorkingIn(bot, botId, null) && !store.isOffline
- const items = buildChat(thread, live)
+ const all = buildChat(thread, live, true)
+ // The newest 40 items first; older pages come in near the top.
+ const [firstShown, setFirstShown] = useState<string | null>(null)
+ const [loadingEarlier, setLoadingEarlier] = useState(false)
+ const found = firstShown ? all.findIndex((i) => i.id === firstShown) : -1
+ const start = found >= 0 ? found : Math.max(0, all.length - PAGE)
+ const items = all.slice(start)
+ const more = start > 0 || (!store.historyComplete.has(botId) && thread.length >= 50)
+ // Following the newest message, or reading history: scrolling up releases the bottom,
+ // arriving back at the end (or Jump to latest) restores it. Content growth alone never changes it.
+ const [following, setFollowing] = useState(true)
+ const followingRef = useRef(true)
+ followingRef.current = following
const scroller = useRef<HTMLDivElement>(null)
- const atBottom = useRef(true)
- const seen = useRef<Set<string> | null>(null)
+ const lastScrollTop = useRef(0)
+ const keepPlace = useRef<number | null>(null)
const last = items[items.length - 1]
- // New items (after the first render) slide up from the bottom.
- const fresh = new Set<string>()
- if (seen.current) for (const item of items) if (!seen.current.has(item.id)) fresh.add(item.id)
+ const toBottom = (smooth = false) => {
+ const el = scroller.current
+ if (el) el.scrollTo({ top: el.scrollHeight, behavior: smooth ? 'smooth' : 'auto' })
+ }
+
useEffect(() => {
- seen.current = new Set(items.map((i) => i.id))
- })
+ if (!firstShown && items[0]) setFirstShown(items[0].id)
+ }, [firstShown, items])
- const toBottom = (smooth: boolean) => {
+ const showEarlier = async () => {
+ if (loadingEarlier) return
+ setLoadingEarlier(true)
const el = scroller.current
- if (el) el.scrollTo({ top: el.scrollHeight, behavior: smooth ? 'smooth' : 'auto' })
+ keepPlace.current = el ? el.scrollHeight - el.scrollTop : null
+ let list = all
+ let at = start
+ if (at === 0) {
+ const anchor = list[0]?.id
+ await store.loadOlder(botId)
+ list = buildChat(store.chat(botId), live, true)
+ at = anchor ? Math.max(0, list.findIndex((i) => i.id === anchor)) : 0
+ }
+ if (at > 0) setFirstShown(list[Math.max(0, at - PAGE)]!.id)
+ setLoadingEarlier(false)
}
- useLayoutEffect(() => toBottom(false), [])
- const lastText = last?.kind === 'entry' ? last.entry.data.text : undefined
- const lastIsUser = last?.kind === 'entry' && last.entry.kind === 'user'
+ // Earlier messages going in above keep the reader's place; a follower stays at the bottom.
useLayoutEffect(() => {
- if (atBottom.current || lastIsUser) toBottom(true)
+ const el = scroller.current
+ if (!el) return
+ if (keepPlace.current !== null && !followingRef.current) {
+ el.scrollTop = el.scrollHeight - keepPlace.current
+ keepPlace.current = null
+ } else if (followingRef.current) toBottom()
+ })
+
+ // A message the user sends brings the chat back to the newest.
+ const lastIsUser = last?.kind === 'entry' && last.entry.kind === 'user'
+ useEffect(() => {
+ if (lastIsUser) setFollowing(true)
}, [last?.id, lastIsUser])
- useLayoutEffect(() => {
- if (atBottom.current) toBottom(false)
- }, [lastText, live])
- // The text size changes the layout: stay at the bottom if the reader was there.
+ // Rows that grow after layout (images, the text size) keep a follower at the bottom.
useEffect(() => {
const el = scroller.current
if (!el) return
const observer = new ResizeObserver(() => {
- if (atBottom.current) toBottom(false)
+ if (followingRef.current) toBottom()
})
observer.observe(el.firstElementChild!)
+ observer.observe(el)
return () => observer.disconnect()
}, [])
return (
- <div
- className="transcript"
- ref={scroller}
- onScroll={(e) => {
- const el = e.currentTarget
- atBottom.current = el.scrollHeight - el.scrollTop - el.clientHeight < 48
- }}
- >
- <div className="transcript-content">
- {!store.historyComplete.has(botId) && thread.length >= 50 ? (
- <button className="load-earlier" onClick={() => void store.loadOlder(botId)}>
- Load earlier messages
- </button>
- ) : null}
- {items.length === 0 && bot ? <div style={{ paddingTop: 40 }}>{isGroup(bot) ? <GroupIntroCard group={bot} /> : <IntroCard bot={bot} />}</div> : null}
- {items.map((item) => (
- <div key={item.id} className={fresh.has(item.id) && item.id === last?.id ? 'enter' : undefined}>
- <Row item={item} chat={bot} openTrace={openTrace} openThread={openThread} openRoutine={openRoutine} />
- </div>
- ))}
- {bot && live ? (
- <div style={{ paddingTop: 6 }}>
- <WorkingIndicator bot={bot} thinking={store.currentThinking(botId, null)} />
- </div>
- ) : null}
- <div style={{ height: 8 }} />
+ <div className="transcript-frame">
+ <div
+ className="transcript"
+ ref={scroller}
+ onScroll={(e) => {
+ const el = e.currentTarget
+ const atEnd = el.scrollHeight - el.scrollTop - el.clientHeight < 8
+ if (el.scrollTop < lastScrollTop.current - 1 && !atEnd) setFollowing(false)
+ else if (atEnd) setFollowing(true)
+ lastScrollTop.current = el.scrollTop
+ if (more && el.scrollTop < 200 && !loadingEarlier) void showEarlier()
+ }}
+ >
+ <div className="transcript-content">
+ {more ? (
+ <button className="load-earlier" disabled={loadingEarlier} onClick={() => void showEarlier()}>
+ {loadingEarlier ? <Spinner size={14} /> : 'Load earlier messages'}
+ </button>
+ ) : 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} />
+ ))}
+ {bot && live ? (
+ <div style={{ paddingTop: 6 }}>
+ <WorkingIndicator bot={bot} thinking={store.currentThinking(botId, null)} />
+ </div>
+ ) : null}
+ <div style={{ height: 8 }} />
+ </div>
</div>
+ {!following && items.length ? (
+ <div className="jump-to-latest" style={{ bottom: 'calc(var(--composer-height, 70px) + 10px)' }}>
+ <MacChatButton
+ title="Jump to latest"
+ icon="arrow.down"
+ direction={[0, 1]}
+ onClick={() => {
+ setFollowing(true)
+ toBottom(true)
+ }}
+ />
+ </div>
+ ) : null}
</div>
)
}
diff --git a/apps/desktop/src/renderer/views/thread/chat-controls.css b/apps/desktop/src/renderer/views/thread/chat-controls.css
new file mode 100644
index 00000000..429e1e51
--- /dev/null
+++ b/apps/desktop/src/renderer/views/thread/chat-controls.css
@@ -0,0 +1,87 @@
+.mac-chat-button {
+ border-radius: 50%;
+ background: var(--chat-button);
+ color: var(--secondary);
+ display: grid;
+ place-items: center;
+ flex: none;
+ position: relative;
+ overflow: hidden;
+ transition: transform var(--morph), color var(--hover);
+}
+.mac-chat-button::after {
+ content: '';
+ position: absolute;
+ inset: 0;
+ border-radius: 50%;
+ background: rgba(var(--text-rgb), 0);
+ transition: background-color var(--hover);
+}
+.mac-chat-button > * {
+ transition: translate var(--morph);
+}
+.mac-chat-button:hover {
+ color: var(--text);
+}
+.mac-chat-button:hover::after {
+ background: rgba(var(--text-rgb), 0.06);
+}
+.mac-chat-button:hover > * {
+ translate: calc(var(--dx) * 1px) calc(var(--dy) * 1px);
+}
+.mac-chat-button:active {
+ transform: scale(0.94);
+ transition: transform var(--press);
+}
+.mac-chat-button:active::after {
+ background: rgba(var(--text-rgb), 0.12);
+}
+.mac-chat-button:active > * {
+ translate: calc(var(--dx) * 1.5px) calc(var(--dy) * 1.5px);
+}
+@media (prefers-reduced-motion: reduce) {
+ .mac-chat-button:hover > *,
+ .mac-chat-button:active > * {
+ translate: none;
+ }
+ .mac-chat-button:active {
+ transform: none;
+ }
+}
+
+/* The floating composer: messages pass underneath it through a material/gradient fade. */
+.composer-dock {
+ position: absolute;
+ left: 0;
+ right: 0;
+ bottom: 0;
+ z-index: 4;
+}
+.composer-fade {
+ position: absolute;
+ z-index: -1;
+ left: 0;
+ right: 0;
+ top: -24px;
+ bottom: 0;
+ pointer-events: none;
+ backdrop-filter: blur(20px);
+ -webkit-mask-image: linear-gradient(to top, #000 40%, transparent);
+ mask-image: linear-gradient(to top, #000 40%, transparent);
+ background: linear-gradient(to top, color-mix(in srgb, var(--background) 90%, transparent) 0%, color-mix(in srgb, var(--background) 45%, transparent) 40%, transparent 100%);
+}
+.jump-to-latest {
+ position: absolute;
+ left: 50%;
+ z-index: 5;
+ transform: translateX(-50%);
+ border-radius: 50%;
+ box-shadow: 0 3px 20px rgba(0, 0, 0, 0.12);
+ animation: jump-in var(--morph) both;
+}
+@keyframes jump-in {
+ from {
+ opacity: 0;
+ translate: 0 6px;
+ }
+}
diff --git a/apps/desktop/src/renderer/views/thread/chat-items.ts b/apps/desktop/src/renderer/views/thread/chat-items.ts
index d24405d3..46e9389b 100644
--- a/apps/desktop/src/renderer/views/thread/chat-items.ts
+++ b/apps/desktop/src/renderer/views/thread/chat-items.ts
@@ -9,15 +9,21 @@ export type ChatItem =
* 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.
*/
-export function buildChat(entries: Entry[], streaming = false): ChatItem[] {
+export function buildChat(entries: Entry[], streaming = false, steady = false): 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 && lastEntry && lastEntry.kind === 'agent' && lastEntry.data.final === false ? lastEntry.id : null
+ 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
- const id = e.kind === 'user' && e.data.clientNonce ? `user-${e.data.clientNonce}` : e.id
+ 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 (lastDate === null || e.createdAt - lastDate > 3_600_000) {
out.push({ id: `sep-${id}`, kind: 'separator', date: e.createdAt })
lastAuthor = null
@@ -31,6 +37,16 @@ export function buildChat(entries: Entry[], streaming = false): ChatItem[] {
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
+ }
+ return null
+}
+
const time = new Intl.DateTimeFormat(undefined, { hour: 'numeric', minute: '2-digit' })
const monthDay = new Intl.DateTimeFormat(undefined, { month: 'short', day: 'numeric' })
const weekday = new Intl.DateTimeFormat(undefined, { weekday: 'long' })
diff --git a/apps/desktop/src/renderer/views/thread/thread.css b/apps/desktop/src/renderer/views/thread/thread.css
index e4f3c02c..f23a3f5a 100644
--- a/apps/desktop/src/renderer/views/thread/thread.css
+++ b/apps/desktop/src/renderer/views/thread/thread.css
@@ -4,6 +4,9 @@
overflow: hidden;
}
.conversation {
+ /* The chat reads two points larger than the chrome (ConversationTypography + 2). */
+ --conversation: var(--chat);
+ --md-scale: var(--chat-scale);
flex: 1;
min-width: 0;
height: 100%;
@@ -62,7 +65,7 @@
align-items: center;
gap: 2px;
padding: 9px 16px 9px 10px;
- background: var(--background);
+ background: var(--surface);
border-radius: 999px;
box-shadow: 0 4px 32px rgba(0, 0, 0, 0.12);
max-width: 60%;
@@ -87,25 +90,21 @@
flex: none;
}
+.transcript-frame {
+ position: absolute;
+ inset: 0;
+}
.transcript {
- flex: 1;
+ height: 100%;
overflow-y: auto;
overflow-anchor: none;
}
.transcript-content {
+ container-type: inline-size;
max-width: 820px;
margin: 0 auto;
- /* The floating title pill sits over the top of the list. */
- padding: 72px 16px 0;
-}
-.transcript-content > .enter {
- animation: message-in var(--conversation-motion) both;
-}
-@keyframes message-in {
- from {
- opacity: 0;
- transform: translateY(24px);
- }
+ /* The floating title pill and composer sit over the list; messages pass underneath. */
+ padding: 72px 16px var(--composer-height, 70px);
}
.load-earlier {
display: block;
@@ -132,7 +131,6 @@
.message {
display: flex;
flex-direction: column;
- gap: 4px;
width: 100%;
}
.message.user {
@@ -141,7 +139,25 @@
}
.message.agent {
align-items: flex-start;
- padding-right: 64px;
+}
+.message-body {
+ position: relative;
+ display: flex;
+ flex-direction: column;
+ gap: 4px;
+ min-width: 0;
+ max-width: 100%;
+}
+/* The reserved 88 pt beside a bubble holds its actions. */
+.message.user .message-body {
+ align-items: flex-end;
+ margin-left: 88px;
+ max-width: calc(100% - 88px);
+}
+.message.agent .message-body {
+ align-items: flex-start;
+ max-width: max(80px, min((100cqw + 32px) * 0.8 - 32px, 100cqw - 88px));
+ margin-right: 88px;
}
.bubble {
padding: 8px 12px;
@@ -150,30 +166,38 @@
min-width: 0;
}
.bubble.user {
- background: var(--bubble-user);
+ background: var(--chat-user);
color: var(--text);
font-size: var(--conversation);
white-space: pre-wrap;
overflow-wrap: anywhere;
}
.bubble.agent {
- background: var(--bubble-agent);
-}
-.message-footer {
- display: flex;
- align-items: center;
- gap: 6px;
- min-height: 26px;
+ background: var(--chat-agent);
}
.message-actions {
+ position: absolute;
+ bottom: 0;
display: flex;
align-items: center;
- animation: fade-in var(--fade) both;
+ gap: 2px;
+ transition: opacity var(--hover);
}
-@keyframes fade-in {
- from {
- opacity: 0;
- }
+.message-actions.leading {
+ right: calc(100% + 6px);
+}
+.message-actions.trailing {
+ left: calc(100% + 6px);
+}
+.message-action {
+ width: 26px;
+ height: 26px;
+ display: grid;
+ place-items: center;
+ color: var(--secondary);
+}
+.message-action:hover {
+ color: var(--text);
}
.reaction-chip {
padding: 3px 8px;
@@ -231,15 +255,15 @@
width: 100%;
}
.composer-add {
- /* The one-line field's height. */
- width: calc(max(round(up, calc(var(--conversation) * 1.25), 1px) + 14px, 28px) + 8px);
- height: calc(max(round(up, calc(var(--conversation) * 1.25), 1px) + 14px, 28px) + 8px);
+ width: 28px;
+ height: 28px;
border-radius: 50%;
background: var(--bubble-user);
box-shadow: 0 2px 20px rgba(0, 0, 0, 0.06);
display: grid;
place-items: center;
flex: none;
+ margin-bottom: calc(max(0px, (round(up, calc(var(--conversation) * 1.25), 1px) + 14px - 28px) / 2));
}
.composer-surface {
flex: 1;
@@ -254,7 +278,7 @@
display: flex;
align-items: flex-end;
gap: 8px;
- padding: 4px 6px 4px 14px;
+ padding: 4px 6px 4px 8px;
}
.composer-box textarea {
flex: 1;
@@ -267,13 +291,14 @@
cursor: text;
}
.composer-send {
+ width: 28px;
height: 28px;
border-radius: 999px;
display: grid;
place-items: center;
flex: none;
margin-bottom: calc(max(0px, (round(up, calc(var(--conversation) * 1.25), 1px) + 14px - 28px) / 2));
- transition: width var(--morph), background-color var(--morph), color var(--morph), transform var(--press);
+ transition: background-color var(--morph), color var(--morph), transform var(--press);
}
.symbol-swap {
animation: symbol-in var(--morph) both;
@@ -321,7 +346,7 @@
height: 100%;
display: flex;
flex: none;
- animation: panel-slide var(--layout) both;
+ animation: panel-slide var(--morph) both;
overflow: hidden;
}
.side-panel-border {
@@ -332,7 +357,7 @@
@keyframes panel-slide {
from {
opacity: 0;
- transform: translateX(40px);
+ transform: translateX(20px);
}
}
.panel-slide.from-trailing {
diff --git a/apps/desktop/src/shared/ipc.ts b/apps/desktop/src/shared/ipc.ts
index 409eb98b..2795dd1c 100644
--- a/apps/desktop/src/shared/ipc.ts
+++ b/apps/desktop/src/shared/ipc.ts
@@ -105,6 +105,8 @@ export interface CodyncBridge {
appVersion: string
/** The computer's name ("Kevin's MacBook Pro"). */
computerName: string
+ /** Screenshot/UI checks: CODYNC_DEBUG_OPEN=compose | group | plugins | computers | <bot name>. */
+ debugOpen: string | null
host: {
snapshot(): Promise<HostSnapshot>
onChange(cb: (s: HostSnapshot) => void): () => void