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.

fix(desktop): retain composer drafts between conversations

Sean Ferguson69cce92ef23b
diff --git a/apps/desktop/package.json b/apps/desktop/package.json
index 042803f2..e6c041cf 100644
--- a/apps/desktop/package.json
+++ b/apps/desktop/package.json
@@ -15,7 +15,7 @@
"dev": "node tools/account-config.mjs dev && electron-vite dev",
"build": "electron-vite build",
"typecheck": "tsc --noEmit -p tsconfig.json",
- "test": "node --test --experimental-strip-types src/shared/*.test.ts src/renderer/views/thread/*.test.ts",
+ "test": "node --test --experimental-strip-types src/shared/*.test.ts src/renderer/store/*.test.ts src/renderer/views/thread/*.test.ts",
"icons": "swift tools/export-symbols.swift",
"dist:mac:dev": "node tools/account-config.mjs dev && node tools/native-host.mjs dev && node tools/native-screen.mjs && electron-vite build && CSC_NAME=\"Pokai Lee (6KFK5J2LB4)\" electron-builder --mac",
"dist:mac:main": "node tools/account-config.mjs main && node tools/native-host.mjs main && node tools/native-screen.mjs && electron-vite build && electron-builder --mac",
diff --git a/apps/desktop/src/renderer/store/bot-store.ts b/apps/desktop/src/renderer/store/bot-store.ts
index d1739e69..0f453637 100644
--- a/apps/desktop/src/renderer/store/bot-store.ts
+++ b/apps/desktop/src/renderer/store/bot-store.ts
@@ -17,6 +17,7 @@ import {
} from '@shared/models'
import { HostClient, HostError, type HostEvent, type HostRoute, type HostTransport } from '../client/host-client'
import { Observable } from '../lib/observable'
+import { ComposerDrafts } from './composer-drafts'
export type Connection =
| { kind: 'unpaired' }
@@ -65,6 +66,8 @@ export class BotStore extends Observable {
cloud: CloudStatus | null = null
historyComplete = new Set<string>()
routineDrafts = new Map<string, string>()
+ private composerDrafts = new ComposerDrafts()
+ subscribeComposerDrafts = this.composerDrafts.subscribe
lastError: string | null = null
/** A kit view selected a bot on this store (new chat, editor); the account picks it up. */
selection: string | null = null
@@ -205,6 +208,7 @@ export class BotStore extends Observable {
retire() {
this.retired = true
+ this.composerDrafts.clear()
this.stopTransport()
if (this.saveTimer) clearTimeout(this.saveTimer)
this.onRosterChanged = null
@@ -365,6 +369,7 @@ export class BotStore extends Observable {
case 'botDeleted':
this.bots.delete(event.id)
this.entries.delete(event.id)
+ this.composerDrafts.deleteBot(event.id)
this.bump(event.rev)
if (this.selection === event.id) this.selection = null
this.onRosterChanged?.()
@@ -407,6 +412,7 @@ export class BotStore extends Observable {
private resetMirror() {
this.bots = new Map()
+ this.composerDrafts.clear()
const kept = new Map<string, Entry[]>()
for (const [id, list] of this.entries) {
const local = list.filter((e) => e.id.startsWith('local-'))
@@ -522,6 +528,22 @@ export class BotStore extends Observable {
})
}
+ composerDraft(botId: string, thread: string | null = null) {
+ return this.composerDrafts.get(botId, thread)
+ }
+
+ setComposerDraft(text: string, botId: string, thread: string | null = null) {
+ if (!this.retired) this.composerDrafts.set(botId, thread, text)
+ }
+
+ sendComposerDraft(botId: string, thread: string | null = null, files: OutgoingFile[] = []) {
+ if (this.retired) return false
+ const text = this.composerDrafts.take(botId, thread, files.length > 0)
+ if (text === null) return false
+ this.send(text, botId, thread, files)
+ return true
+ }
+
send(text: string, botId: string, thread: string | null = null, files: OutgoingFile[] = [], nonce: string = crypto.randomUUID()) {
const trimmed = text.trim()
if ((!trimmed && !files.length) || this.retired) return
@@ -732,6 +754,7 @@ export class BotStore extends Observable {
delete(bot: Bot) {
this.bots.delete(bot.id)
this.entries.delete(bot.id)
+ this.composerDrafts.deleteBot(bot.id)
this.onRosterChanged?.()
this.changed()
this.perform((c) => c.call('deleteBot', { botId: bot.id }), true)
diff --git a/apps/desktop/src/renderer/store/composer-drafts.test.ts b/apps/desktop/src/renderer/store/composer-drafts.test.ts
new file mode 100644
index 00000000..29936906
--- /dev/null
+++ b/apps/desktop/src/renderer/store/composer-drafts.test.ts
@@ -0,0 +1,69 @@
+import assert from 'node:assert/strict'
+import { test } from 'node:test'
+import { ComposerDrafts } from './composer-drafts.ts'
+
+test('switching bots, threads and computers restores each exact draft', () => {
+ const first = new ComposerDrafts()
+ const second = new ComposerDrafts()
+ const multiline = 'Unfinished message\n with spacing and @mention '
+ first.set('bot', null, multiline)
+ first.set('other', null, 'Another bot')
+ first.set('bot', 'thread', 'Thread reply')
+ second.set('bot', null, 'Another computer')
+ assert.equal(first.get('bot'), multiline)
+ assert.equal(first.get('other'), 'Another bot')
+ assert.equal(first.get('bot', 'thread'), 'Thread reply')
+ assert.equal(first.get('bot', 'another-thread'), '')
+ assert.equal(second.get('bot'), 'Another computer')
+})
+
+test('sending consumes only that destination and cannot clear a later draft', async () => {
+ const drafts = new ComposerDrafts()
+ drafts.set('bot', null, 'Message being sent')
+ drafts.set('bot', 'thread', 'Unsent reply')
+ drafts.set('other', null, 'Unsent message')
+ const sent = drafts.take('bot', null)
+ assert.equal(sent, 'Message being sent')
+ assert.equal(drafts.get('bot'), '')
+ drafts.set('bot', null, 'Next unfinished message')
+ await Promise.resolve(sent)
+ assert.equal(drafts.get('bot'), 'Next unfinished message')
+ assert.equal(drafts.get('bot', 'thread'), 'Unsent reply')
+ assert.equal(drafts.get('other'), 'Unsent message')
+})
+
+test('blank text is retained unless there are attachments to send', () => {
+ const drafts = new ComposerDrafts()
+ drafts.set('bot', null, ' \n ')
+ assert.equal(drafts.take('bot', null), null)
+ assert.equal(drafts.get('bot'), ' \n ')
+ assert.equal(drafts.take('bot', null, true), ' \n ')
+ assert.equal(drafts.get('bot'), '')
+ assert.equal(drafts.take('bot', null, true), '')
+})
+
+test('deleting a bot clears its chat and thread drafts; retiring a computer clears all', () => {
+ const drafts = new ComposerDrafts()
+ drafts.set('bot', null, 'Chat')
+ drafts.set('bot', 'thread', 'Reply')
+ drafts.set('other', null, 'Other chat')
+ drafts.deleteBot('bot')
+ assert.equal(drafts.get('bot'), '')
+ assert.equal(drafts.get('bot', 'thread'), '')
+ assert.equal(drafts.get('other'), 'Other chat')
+ drafts.clear()
+ assert.equal(drafts.get('other'), '')
+})
+
+test('mounted composers see edits and clears immediately, without retaining old subscriptions', () => {
+ const drafts = new ComposerDrafts()
+ const seen: string[] = []
+ const unsubscribe = drafts.subscribe(() => seen.push(drafts.get('bot')))
+ drafts.set('bot', null, 'Typing')
+ drafts.set('bot', null, 'Typing')
+ drafts.take('bot', null)
+ assert.deepEqual(seen, ['Typing', ''])
+ unsubscribe()
+ drafts.set('bot', null, 'Later')
+ assert.deepEqual(seen, ['Typing', ''])
+})
diff --git a/apps/desktop/src/renderer/store/composer-drafts.ts b/apps/desktop/src/renderer/store/composer-drafts.ts
new file mode 100644
index 00000000..09ff835a
--- /dev/null
+++ b/apps/desktop/src/renderer/store/composer-drafts.ts
@@ -0,0 +1,49 @@
+/** Unsent text belongs to a conversation, independently of its mounted composer. */
+export class ComposerDrafts {
+ private bots = new Map<string, Map<string | null, string>>()
+ private listeners = new Set<() => void>()
+
+ subscribe = (listener: () => void) => {
+ this.listeners.add(listener)
+ return () => { this.listeners.delete(listener) }
+ }
+
+ get(botId: string, thread: string | null = null): string {
+ return this.bots.get(botId)?.get(thread) ?? ''
+ }
+
+ set(botId: string, thread: string | null, text: string) {
+ if (this.get(botId, thread) === text) return
+ const threads = this.bots.get(botId) ?? new Map<string | null, string>()
+ if (text) {
+ threads.set(thread, text)
+ this.bots.set(botId, threads)
+ } else {
+ threads.delete(thread)
+ if (!threads.size) this.bots.delete(botId)
+ }
+ this.changed()
+ }
+
+ /** Transfer a draft to a send; asynchronous delivery never owns the next draft. */
+ take(botId: string, thread: string | null, hasFiles = false): string | null {
+ const text = this.get(botId, thread)
+ if (!text.trim() && !hasFiles) return null
+ this.set(botId, thread, '')
+ return text
+ }
+
+ deleteBot(botId: string) {
+ if (this.bots.delete(botId)) this.changed()
+ }
+
+ clear() {
+ if (!this.bots.size) return
+ this.bots.clear()
+ this.changed()
+ }
+
+ private changed() {
+ for (const listener of [...this.listeners]) listener()
+ }
+}
diff --git a/apps/desktop/src/renderer/views/thread/Composer.tsx b/apps/desktop/src/renderer/views/thread/Composer.tsx
index a3eeb0ce..a683b82e 100644
--- a/apps/desktop/src/renderer/views/thread/Composer.tsx
+++ b/apps/desktop/src/renderer/views/thread/Composer.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useLayoutEffect, useRef, useState } from 'react'
+import { useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from 'react'
import { isGroup, isWorkingIn, type Bot } from '@shared/models'
import { BotAvatar } from '../../components/Avatar'
import { Icon } from '../../components/Icon'
@@ -23,7 +23,8 @@ export function Composer({ botId, thread = null, onCall, onInterrupt }: {
}) {
const store = useStore()
const bot = store.bots.get(botId) ?? null
- const [draft, setDraft] = useState('')
+ const draft = useSyncExternalStore(store.subscribeComposerDrafts, () => store.composerDraft(botId, thread))
+ const setDraft = (text: string) => store.setComposerDraft(text, botId, thread)
const [files, setFiles] = useState<OutgoingFile[]>([])
const field = useRef<HTMLTextAreaElement>(null)
const working = !!bot && isWorkingIn(bot, botId, thread)
@@ -37,7 +38,8 @@ export function Composer({ botId, thread = null, onCall, onInterrupt }: {
const routineDraft = store.routineDrafts.get(botId)
useEffect(() => {
if (thread || routineDraft === undefined) return
- setDraft((d) => (d ? `${d}\n${routineDraft}` : routineDraft))
+ const current = store.composerDraft(botId, thread)
+ store.setComposerDraft(current ? `${current}\n${routineDraft}` : routineDraft, botId, thread)
store.consumeRoutineDraft(botId)
field.current?.focus()
}, [routineDraft, thread, botId, store])
@@ -84,9 +86,7 @@ export function Composer({ botId, thread = null, onCall, onInterrupt }: {
const submit = () => {
if (!canSend) return
- store.send(draft, botId, thread, files)
- setDraft('')
- setFiles([])
+ if (store.sendComposerDraft(botId, thread, files)) setFiles([])
}
const trailing: Trailing = onInterrupt && !draft && !files.length ? 'interrupt' : working && !draft && !files.length ? 'stop' : onCall && !draft && !files.length ? 'call' : 'send'
diff --git a/docs/architecture/desktop-app.md b/docs/architecture/desktop-app.md
index b62d916c..2153d6fe 100644
--- a/docs/architecture/desktop-app.md
+++ b/docs/architecture/desktop-app.md
@@ -30,6 +30,13 @@ The iPhone app stays native SwiftUI; its package moved from `kit/` into `apps/io
The renderer owns all state; closing the window hides it, so the menu bar keeps its data.
HTTP to the host leaves from the main process (the loopback API has no CORS).
+Unsent composer text is retained in each computer’s `BotStore`, separately for every bot
+and reply thread. Switching conversations or closing a reply panel restores the exact text.
+Submitting clears only that conversation’s draft; completion or failure of the send does
+not clear a newer draft. Drafts last for the window’s session and are cleared when the
+computer is removed, its host identity changes, or the bot is deleted. iOS and the TUI
+already retain drafts per conversation; the shared desktop behavior covers macOS and Linux.
+
## Platform notes
- **Icons**: SF Symbols may only ship in apps for Apple platforms, so the masks are generated