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.
Rust acpagent-client-protocolai-agentsai-assistantclaudeclaude-codecodexcoding-agentscursorgeminigemini-cligrok-bot-alternativeiosiphonelinuxmacosmcpopen-sourcerustself-hosted
feat(desktop): parse chat markdown like the Mac app
leepokai1055636cd138
diff --git a/.github/workflows/release-desktop.yml b/.github/workflows/release-desktop.ymlindex 4ffe9871..760294b8 100644--- a/.github/workflows/release-desktop.yml+++ b/.github/workflows/release-desktop.yml@@ -162,8 +162,8 @@ jobs:strategy:matrix:include:- - { os: ubuntu-24.04, arch: x64, name: linux-x86_64, target: x86_64-unknown-linux-musl }- - { os: ubuntu-24.04-arm, arch: arm64, name: linux-arm64, target: aarch64-unknown-linux-musl }+ - { os: ubuntu-24.04, arch: x64, name: linux-x86_64 }+ - { os: ubuntu-24.04-arm, arch: arm64, name: linux-arm64 }runs-on: ${{ matrix.os }}steps:- uses: actions/checkout@v4@@ -172,16 +172,8 @@ jobs:node-version: 24cache: npmcache-dependency-path: apps/desktop/package-lock.json- - name: Install Rust (rust-toolchain.toml)- run: rustup toolchain install- - run: rustup target add ${{ matrix.target }} && sudo apt-get update && sudo apt-get install -y musl-tools rpm- - name: Host- env:- CFLAGS_aarch64_unknown_linux_musl: -mno-outline-atomics- run: |- cargo build --release --manifest-path host/Cargo.toml --target ${{ matrix.target }}- mkdir -p apps/desktop/build/native- cp host/target/${{ matrix.target }}/release/codync-host apps/desktop/build/native/+ # The Linux app uses the installed codync-host (codync-host-linux-*.tar.gz, host.yml).+ - run: sudo apt-get update && sudo apt-get install -y rpm- name: Buildworking-directory: apps/desktoprun: |diff --git a/apps/desktop/electron-builder.yml b/apps/desktop/electron-builder.ymlindex 75bede17..feac8edd 100644--- a/apps/desktop/electron-builder.yml+++ b/apps/desktop/electron-builder.yml@@ -13,8 +13,6 @@ files:- out/**- package.jsonextraResources:- - from: build/native/codync-host- to: codync-host- from: resources/account-config.jsonto: account-config.json- from: resources/tray@@ -42,7 +40,11 @@ mac:extendInfo:NSMicrophoneUsageDescription: Talk to your bots in a voice call.NSSpeechRecognitionUsageDescription: Your words are transcribed on this Mac and sent to your bot as a message.+ # The host ships inside the Mac app; Linux uses the installed codync-host (an AppImage's+ # mount path changes every launch, so a service can't point into it).extraResources:+ - from: build/native/codync-host+ to: codync-host- from: build/native/codync-speechto: codync-speechextraFiles:diff --git a/apps/desktop/package.json b/apps/desktop/package.jsonindex c6f29a33..696ef427 100644--- a/apps/desktop/package.json+++ b/apps/desktop/package.json@@ -11,7 +11,7 @@"dev": "electron-vite dev","build": "electron-vite build","typecheck": "tsc --noEmit -p tsconfig.json",- "test": "node --test --experimental-strip-types src/**/*.test.ts",+ "test": "node --test --experimental-strip-types src/shared/*.test.ts src/renderer/views/thread/*.test.ts","icons": "swift tools/export-symbols.swift","dist:mac": "electron-vite build && electron-builder --mac","dist:linux": "electron-vite build && electron-builder --linux"diff --git a/apps/desktop/resources/icon.svg b/apps/desktop/resources/icon.svgnew file mode 100644index 00000000..b0bc6aa6--- /dev/null+++ b/apps/desktop/resources/icon.svg@@ -0,0 +1 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256"><rect width="256" height="256" rx="57.6" fill="#000"/><g fill="#fff"><circle cx="68.27" cy="48.36" r="7.17"/><circle cx="88.18" cy="48.36" r="7.17"/><circle cx="108.09" cy="48.36" r="7.17"/><circle cx="128.00" cy="48.36" r="7.17"/><circle cx="147.91" cy="48.36" r="7.13"/><circle cx="167.82" cy="48.36" r="6.92"/><circle cx="187.73" cy="48.36" r="6.70"/><circle cx="48.36" cy="68.27" r="7.17"/><circle cx="68.27" cy="68.27" r="7.17"/><circle cx="88.18" cy="68.27" r="7.17"/><circle cx="108.09" cy="68.27" r="7.17"/><circle cx="128.00" cy="68.27" r="7.06"/><circle cx="147.91" cy="68.27" r="6.85"/><circle cx="167.82" cy="68.27" r="6.63"/><circle cx="187.73" cy="68.27" r="6.42"/><circle cx="207.64" cy="68.27" r="6.20"/><circle cx="48.36" cy="88.18" r="7.17"/><circle cx="68.27" cy="88.18" r="7.17"/><circle cx="88.18" cy="88.18" r="7.17"/><circle cx="108.09" cy="88.18" r="6.99"/><circle cx="128.00" cy="88.18" r="6.77"/><circle cx="147.91" cy="88.18" r="6.56"/><circle cx="167.82" cy="88.18" r="6.34"/><circle cx="187.73" cy="88.18" r="6.13"/><circle cx="207.64" cy="88.18" r="5.91"/><circle cx="48.36" cy="108.09" r="7.17"/><circle cx="68.27" cy="108.09" r="7.13"/><circle cx="88.18" cy="108.09" r="6.92"/><circle cx="128.00" cy="108.09" r="6.49"/><circle cx="167.82" cy="108.09" r="6.06"/><circle cx="187.73" cy="108.09" r="5.84"/><circle cx="207.64" cy="108.09" r="5.63"/><circle cx="48.36" cy="128.00" r="7.06"/><circle cx="68.27" cy="128.00" r="6.85"/><circle cx="88.18" cy="128.00" r="6.63"/><circle cx="128.00" cy="128.00" r="6.20"/><circle cx="167.82" cy="128.00" r="5.77"/><circle cx="187.73" cy="128.00" r="5.56"/><circle cx="207.64" cy="128.00" r="5.34"/><circle cx="48.36" cy="147.91" r="6.77"/><circle cx="68.27" cy="147.91" r="6.56"/><circle cx="88.18" cy="147.91" r="6.34"/><circle cx="108.09" cy="147.91" r="6.13"/><circle cx="128.00" cy="147.91" r="5.91"/><circle cx="147.91" cy="147.91" r="5.70"/><circle cx="167.82" cy="147.91" r="5.48"/><circle cx="187.73" cy="147.91" r="5.27"/><circle cx="207.64" cy="147.91" r="5.05"/><circle cx="48.36" cy="167.82" r="6.49"/><circle cx="68.27" cy="167.82" r="6.27"/><circle cx="88.18" cy="167.82" r="6.06"/><circle cx="108.09" cy="167.82" r="5.84"/><circle cx="128.00" cy="167.82" r="5.63"/><circle cx="147.91" cy="167.82" r="5.41"/><circle cx="167.82" cy="167.82" r="5.20"/><circle cx="187.73" cy="167.82" r="4.98"/><circle cx="207.64" cy="167.82" r="4.77"/><circle cx="48.36" cy="187.73" r="6.20"/><circle cx="68.27" cy="187.73" r="5.99"/><circle cx="88.18" cy="187.73" r="5.77"/><circle cx="108.09" cy="187.73" r="5.56"/><circle cx="128.00" cy="187.73" r="5.34"/><circle cx="147.91" cy="187.73" r="5.13"/><circle cx="167.82" cy="187.73" r="4.91"/><circle cx="187.73" cy="187.73" r="4.70"/><circle cx="207.64" cy="187.73" r="4.48"/><circle cx="68.27" cy="207.64" r="5.70"/><circle cx="88.18" cy="207.64" r="5.48"/><circle cx="108.09" cy="207.64" r="5.27"/><circle cx="128.00" cy="207.64" r="5.05"/><circle cx="147.91" cy="207.64" r="4.84"/><circle cx="167.82" cy="207.64" r="4.62"/><circle cx="187.73" cy="207.64" r="4.41"/></g></svg>\ No newline at end of filediff --git a/apps/desktop/src/main/host-controller.ts b/apps/desktop/src/main/host-controller.tsindex 24085962..412178d2 100644--- a/apps/desktop/src/main/host-controller.ts+++ b/apps/desktop/src/main/host-controller.ts@@ -65,8 +65,9 @@ export class HostController extends EventEmitter {get binary(): string | null {const candidates = [- app.isPackaged ? join(process.resourcesPath, 'codync-host') : null,+ app.isPackaged && isMac ? join(process.resourcesPath, 'codync-host') : null,process.env.CODYNC_HOST_BIN ?? null,+ join(homedir(), '.local/bin/codync-host'),'/opt/homebrew/bin/codync-host','/usr/local/bin/codync-host','/usr/bin/codync-host',diff --git a/apps/desktop/src/renderer/views/thread/Markdown.tsx b/apps/desktop/src/renderer/views/thread/Markdown.tsxindex a7716755..5015ddd0 100644--- a/apps/desktop/src/renderer/views/thread/Markdown.tsx+++ b/apps/desktop/src/renderer/views/thread/Markdown.tsx@@ -1,121 +1,8 @@import { memo, type ReactNode } from 'react'+import { parseStreaming, type Block } from './markdown-blocks.ts'-// Block-level Markdown as replies use it (kit MarkdownBlocks): paragraphs, headings, nested-// lists, quotes, rules, tables and fenced code; inline styling like `AttributedString(markdown:)`.--export type Block =- | { kind: 'paragraph'; text: string }- | { kind: 'heading'; text: string; level: number }- | { 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 (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()- if (line.startsWith('```')) {- if (code) {- blocks.push({ kind: 'code', text: code.join('\n'), language })- code = null- } else {- flush()- code = []- language = line.slice(3)- }- continue- }- if (code) {- 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 (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 (/^[-*+•] /.test(line)) {- flush()- 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]!, depth })- } else if (line.startsWith('>')) {- flush()- blocks.push({ kind: 'quote', text: line.slice(1).trim() })- } else paragraph.push(raw)- }- if (code) blocks.push({ kind: 'code', text: (code as string[]).join('\n'), language })- 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-}+// The Mac's Markdown for messages: the blocks from `markdown-blocks.ts`, with inline styling like+// `AttributedString(markdown:)`./** Inline Markdown: `code` (tinted), **bold**, *italic*, ~~strike~~, [links](url). */export function inline(text: string, key = 'i'): ReactNode[] {diff --git a/apps/desktop/src/renderer/views/thread/markdown-blocks.test.ts b/apps/desktop/src/renderer/views/thread/markdown-blocks.test.tsnew file mode 100644index 00000000..2af9abe8--- /dev/null+++ b/apps/desktop/src/renderer/views/thread/markdown-blocks.test.ts@@ -0,0 +1,29 @@+import assert from 'node:assert/strict'+import { test } from 'node:test'+import { heal, parseMarkdown, parseStreaming } 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')+ assert.deepEqual(blocks, [+ { kind: 'heading', text: 'Title', level: 1 },+ { kind: 'bullet', text: 'one', marker: '•', depth: 0 },+ { kind: 'bullet', text: 'two', marker: '◦', depth: 1 },+ { kind: 'bullet', text: 'first', marker: '1.', depth: 0 },+ { kind: 'rule' },+ { kind: 'table', header: ['A', 'B'], rows: [['1', '2']] },+ { kind: 'code', text: 'x = 1', language: 'js' },+ { kind: 'quote', text: 'quoted' },+ ])+})++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.tsnew file mode 100644index 00000000..6186681c--- /dev/null+++ b/apps/desktop/src/renderer/views/thread/markdown-blocks.ts@@ -0,0 +1,117 @@+// Block-level Markdown as replies use it (kit MarkdownBlocks): paragraphs, headings, nested+// lists, quotes, rules, tables and fenced code. Pure parsing, tested on its own.++export type Block =+ | { kind: 'paragraph'; text: string }+ | { kind: 'heading'; text: string; level: number }+ | { 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 (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()+ if (line.startsWith('```')) {+ if (code) {+ blocks.push({ kind: 'code', text: code.join('\n'), language })+ code = null+ } else {+ flush()+ code = []+ language = line.slice(3)+ }+ continue+ }+ if (code) {+ 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 (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 (/^[-*+•] /.test(line)) {+ flush()+ 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]!, depth })+ } else if (line.startsWith('>')) {+ flush()+ blocks.push({ kind: 'quote', text: line.slice(1).trim() })+ } else paragraph.push(raw)+ }+ if (code) blocks.push({ kind: 'code', text: (code as string[]).join('\n'), language })+ 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/shared/compat.test.ts b/apps/desktop/src/shared/compat.test.tsnew file mode 100644index 00000000..ed97ee46--- /dev/null+++ b/apps/desktop/src/shared/compat.test.ts@@ -0,0 +1,18 @@+import assert from 'node:assert/strict'+import { test } from 'node:test'+import { checkVersions, isBelow, parseVersion } from './compat.ts'++test('versions parse like the host and the iPhone app', () => {+ assert.deepEqual(parseVersion('v2.6'), [2, 6, 0])+ assert.deepEqual(parseVersion('2.6.3-beta+1'), [2, 6, 3])+ assert.equal(parseVersion('2.x'), null)+ assert.equal(isBelow('2.6.3', '2.7.0'), true)+ assert.equal(isBelow('2.10.0', '2.9.9'), false)+ assert.equal(isBelow('garbage', '9.9.9'), false)+})++test('the side that must update', () => {+ assert.deepEqual(checkVersions('2.6.0', '2.7.0', '2.7.0'), { kind: 'updateApp', minimum: '2.7.0' })+ assert.deepEqual(checkVersions('2.7.0', '2.2.0', null), { kind: 'updateHost', version: '2.2.0', minimum: '2.3.0' })+ assert.equal(checkVersions('2.7.0', '2.7.0', '2.3.0'), null)+})