Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
Chat: a customer's or a bot's message says who wrote it, never "You" (23c) (#746)
Oleksandr Ivanchenkodcef2f15f146
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsxindex ffc2d4f5..4fbadaa3 100644--- a/frontend/src/App.tsx+++ b/frontend/src/App.tsx@@ -2270,7 +2270,7 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({streamStore.show({ text: '', thinking: '' });}}- markLive(ctx, senderLabel(msg.sender_role, msg.sender_id, liveRef.current[ctx] || 'Bot'));+ markLive(ctx, senderLabel(msg.sender_role, msg.sender_id, liveRef.current[ctx] || 'Bot', msg.meta));}}return { ok: true, answered: saved.answered };diff --git a/frontend/src/agentConnections.ts b/frontend/src/agentConnections.tsindex ea8cfb1f..66fe3f93 100644--- a/frontend/src/agentConnections.ts+++ b/frontend/src/agentConnections.ts@@ -4,6 +4,8 @@export type BotScope = 'all' | string[];import { dateText, timeText } from './clock';+import { botOf } from './sharedFiles';+import type { BotRef } from './sharedFiles';export interface AgentConnection {id: string;@@ -253,6 +255,56 @@ export function callTime(iso: string, now = new Date(), locale?: string): stringreturn d.toDateString() === now.toDateString() ? time : `${dateText(d, { locale })}, ${time}`;}+// 23c (autonomy/others-messages-never-you/brief.md): a "user" message someone else wrote never reads "You".+// The server marks who: a Telegram customer (customers.rs, meta `from_customer`, source `telegram-customer`)+// and a bot posting through the chat API (routes.rs, meta `sent_by_bot`, plus `sent_by_bot_name` and+// `sent_by_kwant_id` from 0.9.18). The check is on these markers, never on the text.++const CUSTOMER_SOURCE = 'telegram-customer';+/** Sender ids the app itself sends for the person; never shown as a bot's name. */+const PERSON_IDS = new Set(['playerhero', 'user', 'me', 'you']);+const looksLikeId = (s: string) => s.length > 20 && !/\s/.test(s);+const str = (v: unknown) => (typeof v === 'string' ? v.trim() : '');++/**+ * Who wrote a "user" message when it isn't the person: "Ann (customer)" or "A customer" for a Telegram+ * customer; "Scout (bot)" for a bot's chat-API message (its kwant id's current name, else the name it sent,+ * else a short sender id, else "A bot"). Null for the person's own messages, a coding agent's included.+ */+export function otherSenderLabel(meta: string | null | undefined, knownBots: ReadonlyArray<BotRef> = [], senderId?: string | null): string | null {+ if (!meta) return null;+ let m: Record<string, unknown>;+ try {+ const parsed = JSON.parse(meta) as unknown;+ if (!parsed || typeof parsed !== 'object') return null;+ m = parsed as Record<string, unknown>;+ } catch {+ return null;+ }+ if ('from_customer' in m || m.source === CUSTOMER_SOURCE) {+ const name = str(m.from_customer);+ return name ? `${name} (customer)` : 'A customer';+ }+ if (m.sent_by_bot === true) {+ const byId = botOf(str(m.sent_by_kwant_id) || null, knownBots)?.name;+ const sent = str(m.sent_by_bot_name);+ const id = str(senderId);+ const bySender = id ? botOf(id, knownBots)?.name ?? (!looksLikeId(id) && !PERSON_IDS.has(id.toLowerCase()) ? id : '') : '';+ const name = byId || sent || bySender;+ return name ? `${name} (bot)` : 'A bot';+ }+ return null;+}++/** "<name>'s message" for the message menu; "your message" for the person's own. */+export const messageAbout = (other: string | null): string => (other ? `${other}'s message` : 'your message');++/** The letter an other sender's avatar shows: the name's first letter, or '' for "A customer" and "A bot". */+export function senderLetter(other: string): string {+ if (other === 'A customer' || other === 'A bot') return '';+ return Array.from(other.trim())[0]?.toUpperCase() ?? '';+}+/** "Claude Code (coding agent)" for a message a coding agent sent, else null (the person's own). */export function agentSenderLabel(meta: string | null | undefined): string | null {if (!meta) return null;diff --git a/frontend/src/components/ChatView.tsx b/frontend/src/components/ChatView.tsxindex d4cc4797..01fad9f5 100644--- a/frontend/src/components/ChatView.tsx+++ b/frontend/src/components/ChatView.tsx@@ -11,8 +11,8 @@ import { emptyTrialReplyLine, trialCardsAfter, trialOf } from '../showOnce';import { parsePick } from '../engines';import { onContinuity } from '../continuity';import { TrialWaitsCard } from './SkillsPanel';-import { agentSenderLabel } from '../agentConnections';-import { ArrowDown, ArrowUp, AtSign, Paperclip, Sparkles, ChevronDown, ChevronRight, Check, ChevronLeft, Users, Square, Settings2, Folder, GitBranch, Pencil, Pin, Monitor, CircleSlash } from 'lucide-react';+import { agentSenderLabel, messageAbout, otherSenderLabel, senderLetter } from '../agentConnections';+import { ArrowDown, ArrowUp, AtSign, Paperclip, Sparkles, ChevronDown, ChevronRight, Check, ChevronLeft, User, Users, Square, Settings2, Folder, GitBranch, Pencil, Pin, Monitor, CircleSlash } from 'lucide-react';import { ModernAvatar } from './ModernAvatar';import { WorkingAvatar } from './WorkingAvatar';import { BotHome } from './BotHome';@@ -210,6 +210,20 @@ export interface RoutingState {// One reply row geometry, shared by the live row and the finished one (16a), so a reply lands without a shift:// a 36 px avatar column from sm up, a 20 px avatar in the name line on phones, and the same bubble padding.const REPLY_AVATAR = 36;++/** 23c: someone else's "user" message (a customer, a bot's chat-API post) gets their letter, never the person's avatar. */+function SenderLetter({ name }: { name: string }) {+ const letter = senderLetter(name);+ return (+ <span+ aria-hidden="true"+ data-sender-letter={letter}+ className="w-9 h-9 shrink-0 rounded-full bg-zinc-800 border border-zinc-700/60 text-zinc-200 text-sm font-semibold inline-flex items-center justify-center select-none"+ >+ {letter || <User size={16} className="text-zinc-400" />}+ </span>+ );+}const REPLY_AVATAR_PHONE = 20;const REPLY_BUBBLE = 'px-3.5 py-3 sm:p-5 rounded-2xl text-sm leading-relaxed shadow-sm w-full';const REPLY_BUBBLE_BOT = 'bg-zinc-900/60 text-zinc-200 rounded-tl-sm border border-zinc-800/80';@@ -1759,7 +1773,9 @@ export const ChatView: React.FC<ChatViewProps> = ({? emptyTrialReplyLine(parsePick(activeKwants.find((k) => k.id === msg.sender_id || k.name === msg.sender_id)?.preferred_model).family): null;const workAhead = isUser ? null : parseWorkAhead(msg.meta);- const displayName = isUser ? agentSenderLabel(msg.meta) ?? 'You' : botDisplayName(msg.sender_id, knownBots);+ // 23c: a customer's or a bot's "user" message says who wrote it; the person (Telegram too) and a coding agent as before+ const otherSender = isUser ? otherSenderLabel(msg.meta, knownBots, msg.sender_id) : null;+ const displayName = isUser ? otherSender ?? agentSenderLabel(msg.meta) ?? 'You' : botDisplayName(msg.sender_id, knownBots);// P4: a share that now sits under its bot's reply reads as part of it, without a second header.const underReply = !isUser && filesOnly && (arranged.attached.has(msg.id) || liveShareIds.has(msg.id));const olderCopies = filesOnly ? arranged.earlier.get(msg.id) : undefined;@@ -1790,13 +1806,17 @@ export const ChatView: React.FC<ChatViewProps> = ({<span className="hidden sm:contents">{/* Laya hand-off: a reply she just routed brings the chosen bot's avatar up into the header */}<span className={routed && freshTrack.current.fresh.has(msg.id) ? 'kws-handoff inline-flex' : 'contents'}>- <ModernAvatar- role={isUser ? 'user' : title}- name={displayName}- size={REPLY_AVATAR}- kwantId={replyKwantId}- modelBadge={false}- />+ {otherSender ? (+ <SenderLetter name={otherSender} />+ ) : (+ <ModernAvatar+ role={isUser ? 'user' : title}+ name={displayName}+ size={REPLY_AVATAR}+ kwantId={replyKwantId}+ modelBadge={false}+ />+ )}</span></span>)}@@ -1805,8 +1825,8 @@ export const ChatView: React.FC<ChatViewProps> = ({{underReply ? (<span className="sr-only">Shared by {displayName}</span>) : isUser ? (- <div className="flex items-center gap-2 mb-1.5 text-[11px] text-zinc-400 font-medium max-w-full min-w-0 whitespace-nowrap">- <span className="text-zinc-200 shrink-0">{displayName}</span>+ <div className="flex items-center gap-2 mb-1.5 text-[11px] text-zinc-400 font-medium max-w-full min-w-0 whitespace-nowrap" data-sender={otherSender ? 'other' : undefined}>+ <span className={otherSender ? 'text-zinc-200 min-w-0 truncate' : 'text-zinc-200 shrink-0'}>{displayName}</span>{fromTelegram(parseMetaObject(msg.meta)) && <ViaTelegram />}</div>) : (@@ -1889,7 +1909,7 @@ export const ChatView: React.FC<ChatViewProps> = ({<div className={isUser ? 'relative w-full max-w-2xl' : 'contents'}>{isUser && (() => {// The person's message: the overflow sits in the empty gutter left of the bubble, bottom-aligned, no row- const more = continueMenu(msg, 'your message', 'end', 'hover');+ const more = continueMenu(msg, messageAbout(otherSender), 'end', 'hover');return more ? <div className="absolute right-full bottom-0 mr-1" data-message-more-gutter="">{more}</div> : null;})()}<divdiff --git a/frontend/src/reactReply.ts b/frontend/src/reactReply.tsindex 250b63fd..d930fa86 100644--- a/frontend/src/reactReply.ts+++ b/frontend/src/reactReply.ts@@ -1,6 +1,9 @@// Reactions and replies on bot messages (react-reply contract, section 3).// Pure helpers, so the toggle, the excerpt and the save-with-rollback are testable without a DOM.+import { otherSenderLabel } from './agentConnections';+import type { BotRef } from './sharedFiles';+export type Reaction = 'up' | 'down';/** What a reply points at: the server's shape, or a target that was deleted. */@@ -53,9 +56,12 @@ export function excerptOf(text: string, max = 120): string {return `${plain.slice(0, max - 1).trimEnd()}…`;}-/** Who a message or quote is from, as the chat shows it: long ids (uuids) fall back to the chat's title. */-export function senderLabel(senderRole: string | undefined, senderId: string | undefined, fallback: string): string {- if (senderRole === 'user') return 'You';+/**+ * Who a message or quote is from, as the chat shows it: long ids (uuids) fall back to the chat's title.+ * A "user" message someone else wrote (a customer, a bot's chat-API post; see `otherSenderLabel`) says who.+ */+export function senderLabel(senderRole: string | undefined, senderId: string | undefined, fallback: string, meta?: string | null, knownBots?: ReadonlyArray<BotRef>): string {+ if (senderRole === 'user') return otherSenderLabel(meta, knownBots, senderId) ?? 'You';if (!senderId) return fallback;return senderId.length > 20 ? fallback : senderId;}diff --git a/frontend/tests/continueChat.test.mjs b/frontend/tests/continueChat.test.mjsindex b0c65bb2..3acfea26 100644--- a/frontend/tests/continueChat.test.mjs+++ b/frontend/tests/continueChat.test.mjs@@ -203,7 +203,8 @@ test('ChatView puts ⋯ right after Copy, the line before the messages, and keepconst copy = src.indexOf('<CopyGhost copied=');const more = src.indexOf("continueMenu(msg, `${displayName}'s reply`, 'start')");assert.ok(copy > 0 && more > copy && more - copy < 200, '⋯ sits next to Copy');- assert.match(src, /continueMenu\(msg, 'your message', 'end', 'hover'\)/);+ // 23c: "your message" for the person, "<name>'s message" for a customer or a bot (messageAbout)+ assert.match(src, /continueMenu\(msg, messageAbout\(otherSender\), 'end', 'hover'\)/);assert.match(src, /absolute right-full bottom-0 mr-1" data-message-more-gutter/, 'the person’s ⋯ sits in the gutter, no row of its own');assert.equal(/mt-1 flex justify-end">\{more\}/.test(src), false, 'no ⋯ row under the person’s bubble');assert.ok(src.indexOf('<ContinuedLine') > 0);diff --git a/frontend/tests/othersMessagesNeverYou.test.mjs b/frontend/tests/othersMessagesNeverYou.test.mjsnew file mode 100644index 00000000..2d9218f7--- /dev/null+++ b/frontend/tests/othersMessagesNeverYou.test.mjs@@ -0,0 +1,127 @@+// 23c (autonomy/others-messages-never-you/brief.md): a "user" message someone else wrote never reads "You".+// A Telegram customer reads "Ann (customer)", a bot's chat-API message "Scout (bot)"; the person (Telegram+// too) and a coding agent stay as before. The avatar, the "...'s message" menu and the quote label follow.+import assert from 'node:assert/strict';+import test from 'node:test';+import { loadBundled } from './bundle.mjs';++globalThis.localStorage ??= { getItem: () => null, setItem: () => {}, removeItem: () => {} };++const a = await loadBundled(`export * from './src/agentConnections';`);+const rr = await loadBundled(`export * from './src/reactReply';`);+const ui = await loadBundled(`+ import React from 'react';+ import { renderToStaticMarkup } from 'react-dom/server.browser';+ import { ChatView } from './src/components/ChatView';+ export const chat = (props) => renderToStaticMarkup(React.createElement(ChatView, props));+`);++const SCOUT = { id: '0e7bf95d-cb8b-4396-a0d7-bcf14a38ab47', name: 'Scout' };+const bots = [SCOUT, { id: 'k-ada', name: 'Ada' }];+const j = (o) => JSON.stringify(o);+const customer = j({ source: 'telegram-customer', from_customer: 'Ann', customer_chat_id: 4242 });+const customerNoName = j({ source: 'telegram-customer', from_customer: '', customer_chat_id: 4242 });+const botWithId = j({ sent_by_bot: true, sent_by_bot_name: 'Old Scout', sent_by_kwant_id: SCOUT.id });+const botNameOnly = j({ sent_by_bot: true, sent_by_bot_name: 'Scout' });+const viaTelegram = j({ source: 'telegram' });+const agent = j({ from_agent: 'Claude Code' });++test('otherSenderLabel: a Telegram customer, with and without a name', () => {+ assert.equal(a.otherSenderLabel(customer, bots, 'telegram-customer:4242'), 'Ann (customer)');+ assert.equal(a.otherSenderLabel(customerNoName, bots, 'telegram-customer:4242'), 'A customer');+ assert.equal(a.otherSenderLabel(j({ from_customer: null }), bots), 'A customer', 'the marker alone is enough');+ assert.equal(a.otherSenderLabel(j({ source: 'telegram-customer' }), bots), 'A customer', 'the source alone is enough');+ assert.equal(a.otherSenderLabel(j({ from_customer: ' Ann ' }), bots), 'Ann (customer)', 'trimmed');+});++test('otherSenderLabel: a bot by kwant id (its current name), by name only, and with nothing', () => {+ assert.equal(a.otherSenderLabel(botWithId, bots, 'PlayerHero'), 'Scout (bot)', 'kwant id wins: a renamed bot shows its new name');+ assert.equal(a.otherSenderLabel(j({ sent_by_bot: true, sent_by_kwant_id: 'gone', sent_by_bot_name: 'Vega' }), bots), 'Vega (bot)', 'unknown id: the name it sent');+ assert.equal(a.otherSenderLabel(botNameOnly, bots, 'PlayerHero'), 'Scout (bot)');+ assert.equal(a.otherSenderLabel(j({ sent_by_bot: true }), bots, 'k-ada'), 'Ada (bot)', 'no name sent: the sender id, as a known bot');+ assert.equal(a.otherSenderLabel(j({ sent_by_bot: true }), bots, 'Lin'), 'Lin (bot)', 'a short sender id reads as a name');+ assert.equal(a.otherSenderLabel(j({ sent_by_bot: true }), bots, 'PlayerHero'), 'A bot', "the app's own person id is never a bot name");+ assert.equal(a.otherSenderLabel(j({ sent_by_bot: true }), bots, '4c6677dc-533e-4706-8028-4afa492d95a4'), 'A bot', 'an unknown uuid');+ assert.equal(a.otherSenderLabel(j({ sent_by_bot: true }), []), 'A bot');+ assert.equal(a.otherSenderLabel(j({ sent_by_bot: 'yes', sent_by_bot_name: 'X' }), bots), null, 'only sent_by_bot: true counts');+});++test('otherSenderLabel: the person (also via Telegram) and a coding agent are not someone else', () => {+ assert.equal(a.otherSenderLabel(null, bots, 'PlayerHero'), null);+ assert.equal(a.otherSenderLabel(undefined, bots), null);+ assert.equal(a.otherSenderLabel(j({ attachments: [] }), bots, 'PlayerHero'), null);+ assert.equal(a.otherSenderLabel(viaTelegram, bots, 'PlayerHero'), null, 'the person typing in Telegram stays "You"');+ assert.equal(a.otherSenderLabel(agent, bots, 'PlayerHero'), null, 'the coding agent keeps its own label');+ assert.equal(a.agentSenderLabel(agent), 'Claude Code (coding agent)');+ assert.equal(a.otherSenderLabel('not json', bots), null);+ assert.equal(a.otherSenderLabel('"text"', bots), null);+ assert.equal(a.otherSenderLabel('null', bots), null);+});++test('messageAbout and senderLetter', () => {+ assert.equal(a.messageAbout(null), 'your message');+ assert.equal(a.messageAbout('Ann (customer)'), "Ann (customer)'s message");+ assert.equal(a.senderLetter('Ann (customer)'), 'A');+ assert.equal(a.senderLetter('scout (bot)'), 'S');+ assert.equal(a.senderLetter('A customer'), '', 'no name: no letter (a neutral person icon instead)');+ assert.equal(a.senderLetter('A bot'), '');+});++test("reactReply senderLabel: the quote label names a customer or a bot, the person stays You", () => {+ assert.equal(rr.senderLabel('user', 'telegram-customer:4242', 'Chat', customer), 'Ann (customer)');+ assert.equal(rr.senderLabel('user', 'PlayerHero', 'Chat', botWithId, bots), 'Scout (bot)');+ assert.equal(rr.senderLabel('user', 'PlayerHero', 'Chat', j({ sent_by_bot: true })), 'A bot');+ assert.equal(rr.senderLabel('user', 'PlayerHero', 'Chat', viaTelegram), 'You');+ assert.equal(rr.senderLabel('user', 'PlayerHero', 'Chat'), 'You', 'no meta, as before');+ assert.equal(rr.senderLabel('kwant', 'Ada', 'Chat', customer), 'Ada', 'bot replies unchanged');+});++const chatProps = (messages, kwants = []) => ({+ title: 'Ada', subtitle: '', messages, streamingText: '', streamingThinking: '', isStreaming: false,+ pendingApprovals: [], onSendMessage: () => {}, onResolveApproval: () => {}, kwants, teams: [],+ onContinueFrom: () => {}, home: { kind: 'bot', bot: { id: 'k-ada', name: 'Ada', title: 'Tech lead', avatar_sprite: 'dev' } },+});+const msg = (id, meta, sender_id = 'PlayerHero') => ({ id, sender_role: 'user', sender_id, text: `text ${id}`, meta, created_at: '2026-11-16T09:00:00Z' });+const header = (html, id) => {+ const at = html.indexOf(`data-message-id="${id}"`);+ assert.ok(at >= 0, id);+ const next = html.indexOf('data-message-id="', at + 10);+ return html.slice(at, next < 0 ? undefined : next);+};++test('ChatView: the customer, the bot, the person, Telegram and the coding agent each read as who wrote it', () => {+ const html = ui.chat(chatProps([+ msg('c1', customer, 'telegram-customer:4242'),+ msg('c2', customerNoName, 'telegram-customer:4243'),+ msg('b1', botWithId),+ msg('p1', null),+ msg('t1', viaTelegram),+ msg('g1', agent),+ ], [{ id: SCOUT.id, name: 'Scout', status: 'idle' }]));+ const c1 = header(html, 'c1');+ assert.match(c1, />Ann \(customer\)</);+ assert.match(c1, /data-sender-letter="A"/, "the customer's letter, not the person's avatar");+ assert.doesNotMatch(c1, />You</);+ assert.match(header(html, 'c2'), />A customer</);+ assert.match(header(html, 'c2'), /data-sender-letter=""/);+ const b1 = header(html, 'b1');+ assert.match(b1, />Scout \(bot\)</);+ assert.match(b1, /data-sender-letter="S"/);+ assert.doesNotMatch(b1, />You</);+ for (const id of ['p1', 't1']) {+ assert.match(header(html, id), /<span class="text-zinc-200 shrink-0">You<\/span>/, id);+ assert.doesNotMatch(header(html, id), /data-sender-letter/, id);+ }+ assert.match(header(html, 't1'), /Telegram/i, 'ViaTelegram stays on the person');+ assert.match(header(html, 'g1'), /Claude Code \(coding agent\)/);+ assert.doesNotMatch(header(html, 'g1'), /data-sender-letter/);+ const you = html.match(/>You<\/span>/g) ?? [];+ assert.equal(you.length, 2, 'only the person, typed here and in Telegram');+});++test("ChatView: the message menu is the author's, never \"your message\" for someone else", () => {+ const html = ui.chat(chatProps([msg('c1', customer, 'telegram-customer:4242'), msg('p1', null)]));+ assert.match(html, /aria-label="More for Ann \(customer\)'s message"/);+ assert.doesNotMatch(header(html, 'c1'), /More for your message/);+ assert.match(header(html, 'p1'), /aria-label="More for your message"/, "the person's own menu as before");+});