Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
feat(chat): fold agent-to-agent messages to one line with expand
rubenluetke10-beep9139df9c74d7
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/AgentTimeline.tsx b/jarvis/ui/web/frontend/src/components/agentchat/AgentTimeline.tsxindex 0ebfd9b69c..45ac85813e 100644--- a/jarvis/ui/web/frontend/src/components/agentchat/AgentTimeline.tsx+++ b/jarvis/ui/web/frontend/src/components/agentchat/AgentTimeline.tsx@@ -1,4 +1,4 @@-import { InternalMessageBubble } from "./InternalMessageBubble";+import { InternalMessageBubble, type InternalParticipant } from "./InternalMessageBubble";import {memo,useEffect,@@ -91,18 +91,31 @@ export function AgentTimeline({assistantName,providerLabel,onDecide,+ recipientName,+ agentsById,}: {items: TimelineItem[];assistantName: string;providerLabel: (providerId: string) => string;onDecide: (approvalId: string, decision: ApprovalDecision) => void;+ /** Who an internal agent message was sent to — the chat owner (defaults to the assistant). */+ recipientName?: string;+ /** Sender faces by agent id, where the caller has a roster. */+ agentsById?: Record<string, InternalParticipant>;}) {const t = useT();return (<>{items.map((item) => {if (item.type === "internal") {- return <InternalMessageBubble key={item.id} item={item} />;+ return (+ <InternalMessageBubble+ key={item.id}+ item={item}+ sender={agentsById?.[item.message.sender_id] ?? null}+ recipientName={recipientName ?? assistantName}+ />+ );}if (item.type === "user") {return (diff --git a/jarvis/ui/web/frontend/src/components/agentchat/InternalMessageBubble.test.tsx b/jarvis/ui/web/frontend/src/components/agentchat/InternalMessageBubble.test.tsxindex 260061b931..1d1cb48639 100644--- a/jarvis/ui/web/frontend/src/components/agentchat/InternalMessageBubble.test.tsx+++ b/jarvis/ui/web/frontend/src/components/agentchat/InternalMessageBubble.test.tsx@@ -1,9 +1,9 @@-import { cleanup, render, screen } from "@testing-library/react";+import { cleanup, fireEvent, render, screen } from "@testing-library/react";import { afterEach, expect, it, vi } from "vitest";import en from "@/i18n/locales/en.json";import de from "@/i18n/locales/de.json";import es from "@/i18n/locales/es.json";-import { InternalMessageBubble } from "./InternalMessageBubble";+import { InternalMessageBubble, internalNeedsFold, internalPreview } from "./InternalMessageBubble";import { EMPTY_TIMELINE, reduceEvent, reduceEvents } from "./reduce";import type { AgentChatEvent } from "@/lib/agentChatApi";@@ -63,3 +63,46 @@ it("shows agent authors and a terminal failure without changing the message", ()expect(screen.getByText("Failed")).toBeTruthy();expect(screen.getByText("The recipient is paused")).toBeTruthy();});++it("folds a long message to one sentence and unfolds it on click", () => {+ locale.strings = en.agent_chat;+ const long = "First sentence here. Second sentence follows with details. Third one too.";+ const timeline = reduceEvent(EMPTY_TIMELINE, {+ ...incoming,+ payload: { ...incoming.payload, message_id: "m-long", text: long },+ });+ const item = timeline.items[0];+ if (item.type !== "internal") throw new Error("Expected an internal message");+ render(<InternalMessageBubble item={item} recipientName="Scout" />);+ const card = screen.getByTestId("agent-message-internal");+ expect(card.getAttribute("data-state")).toBe("folded");+ // Only the first sentence shows; the rest stays hidden until the click.+ expect(screen.getByTestId("agent-message-internal-preview").textContent).toContain("First sentence here.");+ expect(screen.queryByTestId("agent-message-internal-full")).toBeNull();+ expect(screen.getByText("Scout")).toBeTruthy();++ fireEvent.click(screen.getByTestId("agent-message-internal-toggle"));+ expect(card.getAttribute("data-state")).toBe("open");+ expect(screen.getByTestId("agent-message-internal-full").textContent).toContain("Third one too.");++ fireEvent.click(screen.getByTestId("agent-message-internal-toggle"));+ expect(card.getAttribute("data-state")).toBe("folded");+});++it("shows a short message whole with no toggle", () => {+ locale.strings = en.agent_chat;+ const timeline = reduceEvent(EMPTY_TIMELINE, incoming);+ const item = timeline.items[0];+ if (item.type !== "internal") throw new Error("Expected an internal message");+ render(<InternalMessageBubble item={item} recipientName="Scout" />);+ expect(screen.getByTestId("agent-message-internal").getAttribute("data-state")).toBe("whole");+ expect(screen.getByTestId("agent-message-internal-toggle").hasAttribute("disabled")).toBe(true);+ expect(screen.getByTestId("agent-message-internal-full").textContent).toContain("A test message");+});++it("derives a one-sentence preview", () => {+ expect(internalPreview("Hello world. More follows.")).toBe("Hello world.");+ expect(internalPreview("Short")).toBe("Short");+ expect(internalNeedsFold("Short")).toBe(false);+ expect(internalNeedsFold("First. Second.")).toBe(true);+});diff --git a/jarvis/ui/web/frontend/src/components/agentchat/InternalMessageBubble.tsx b/jarvis/ui/web/frontend/src/components/agentchat/InternalMessageBubble.tsxindex 3a4785dee7..aa9d1b6286 100644--- a/jarvis/ui/web/frontend/src/components/agentchat/InternalMessageBubble.tsx+++ b/jarvis/ui/web/frontend/src/components/agentchat/InternalMessageBubble.tsx@@ -1,19 +1,189 @@-import type { InternalMessageItem } from "./reduce";+import { useState } from "react";+import { ArrowRight, ChevronDown, MessagesSquare } from "lucide-react";++import { AgentSwatch } from "@/components/society/AgentSwatch";+import type { FigureRecipe } from "@/components/society/figures/figureRecipe";import { useT } from "@/i18n";+import { cn } from "@/lib/utils";++import type { InternalMessageItem } from "./reduce";++/** Enough of a roster row to paint a face; the full SocietyAgent also fits. */+export interface InternalParticipant {+ name: string;+ figure: FigureRecipe | null;+ palette: { primary: string; secondary: string; accent: string };+}++/**+ * One sentence, at most — what a collapsed agent-to-agent message shows.+ * Markdown marks, code fences and line breaks are flattened so the row reads+ * as a sentence, never as a wall.+ */+export function internalPreview(text: string, max = 140): string {+ const flat = text+ .replace(/```[\s\S]*?```/g, " ")+ .replace(/[`*_#>~|]+/g, "")+ .replace(/\s+/g, " ")+ .trim();+ if (!flat) return "";+ const first = flat.split(/(?<=[.!?…])\s/)[0] ?? flat;+ const sentence = first.trim();+ if (sentence.length <= max) return sentence;+ return `${sentence.slice(0, Math.max(0, max - 1)).trimEnd()}…`;+}++/** A collapsed message needs a fold only when the preview hides something. */+export function internalNeedsFold(text: string): boolean {+ const trimmed = text.trim();+ if (!trimmed) return false;+ return internalPreview(trimmed) !== trimmed.replace(/\s+/g, " ").trim();+}++function Initials({ name, size = 20 }: { name: string; size?: number }) {+ const letter = name.trim().charAt(0).toUpperCase() || "?";+ return (+ <span+ aria-hidden+ className="inline-flex shrink-0 items-center justify-center rounded-full border border-border bg-secondary font-medium text-muted-foreground"+ style={{ width: size, height: size, fontSize: size * 0.5 }}+ >+ {letter}+ </span>+ );+}-/** Shared by the lead's timeline and the society's canonical agent chat. */-export function InternalMessageBubble({ item }: { item: InternalMessageItem }) {+function Face({ who, size = 20 }: { who?: InternalParticipant | null; size?: number }) {+ if (!who) return null;+ if (who.figure || who.palette) {+ try {+ return <AgentSwatch agent={who} size={size} />;+ } catch {+ return <Initials name={who.name} size={size} />;+ }+ }+ return <Initials name={who.name} size={size} />;+}++/**+ * An agent-to-agent message, folded by default.+ *+ * Agent chats fill with long internal turns; showing each one whole buries+ * the conversation. The card therefore reads as one compact row — sender+ * face + name, arrow, recipient face + name, one-sentence preview, delivery+ * state — and a click unfolds the whole message. Short (single-sentence)+ * messages show whole with no toggle.+ *+ * Shared by the lead's timeline and the society's canonical agent chat.+ */+export function InternalMessageBubble({+ item,+ sender,+ recipient,+ recipientName,+}: {+ item: InternalMessageItem;+ sender?: InternalParticipant | null;+ recipient?: InternalParticipant | null;+ recipientName?: string;+}) {const t = useT();+ const [open, setOpen] = useState(false);+ const text = item.message.text.trim();+ const preview = internalPreview(text);+ const foldable = internalNeedsFold(text);+ const shown = !foldable || open;++ const senderName = sender?.name || item.message.sender_name;+ const toName = recipient?.name || recipientName || "";+ const status = item.message.status;+ const statusLabel = t(`agent_chat.delivery_${status}`);+ const statusTone =+ status === "failed"+ ? "text-destructive"+ : status === "delivered"+ ? "text-success"+ : "text-muted-foreground";+return (- <div data-testid="agent-message-internal" data-message-id={item.id}- className="max-w-[85%] self-start rounded-lg border border-border bg-card px-4 py-3 text-reading">- <div className="mb-1 flex flex-wrap items-center gap-2 text-sm text-muted-foreground">- <span className="font-medium text-foreground">{item.message.sender_name}</span>- <span>{t("agent_chat.internal_message")}</span>- <span aria-live="polite">{t(`agent_chat.delivery_${item.message.status}`)}</span>+ <div+ data-testid="agent-message-internal"+ data-message-id={item.id}+ data-state={!foldable ? "whole" : open ? "open" : "folded"}+ className="max-w-[85%] self-start overflow-hidden rounded-xl border border-border bg-card"+ >+ <button+ type="button"+ onClick={() => foldable && setOpen((v) => !v)}+ aria-expanded={foldable ? open : undefined}+ aria-label={+ foldable+ ? open+ ? t("agent_chat.internal_collapse")+ : t("agent_chat.internal_expand")+ : undefined+ }+ data-testid="agent-message-internal-toggle"+ disabled={!foldable}+ className={cn(+ "flex w-full items-center gap-1.5 px-3 py-2 text-left",+ foldable && "cursor-pointer hover:bg-secondary/50",+ !foldable && "cursor-default",+ )}+ >+ <MessagesSquare className="h-3.5 w-3.5 shrink-0 text-muted-foreground" aria-hidden />+ <Face who={sender ?? { name: senderName, figure: null, palette: { primary: "#888", secondary: "#555", accent: "#aaa" } }} />+ <span className="truncate text-xs font-medium text-foreground">{senderName}</span>+ {toName ? (+ <>+ <ArrowRight className="h-3 w-3 shrink-0 text-muted-foreground" aria-hidden />+ <Face who={recipient ?? { name: toName, figure: null, palette: { primary: "#888", secondary: "#555", accent: "#aaa" } }} />+ <span className="truncate text-xs text-muted-foreground">{toName}</span>+ </>+ ) : null}+ <span className="ml-auto flex shrink-0 items-center gap-1.5">+ <span+ className={cn(+ "hidden rounded-full border border-border px-1.5 py-px text-[10px] sm:inline",+ "text-muted-foreground",+ )}+ >+ {t("agent_chat.internal_message")}+ </span>+ <span className={cn("flex items-center gap-1 text-[11px]", statusTone)} aria-live="polite">+ <span+ aria-hidden+ className={cn(+ "h-1.5 w-1.5 rounded-full",+ status === "failed" ? "bg-destructive" : status === "delivered" ? "bg-success" : "bg-muted-foreground",+ )}+ />+ {statusLabel}+ </span>+ {foldable ? (+ <ChevronDown+ className={cn("h-3.5 w-3.5 text-muted-foreground transition-transform", open && "rotate-180")}+ aria-hidden+ />+ ) : null}+ </span>+ </button>+ <div className="px-3 pb-2.5 pl-[30px]">+ {shown ? (+ <div data-testid="agent-message-internal-full" className="whitespace-pre-wrap text-sm leading-relaxed text-foreground [overflow-wrap:anywhere]">+ {text}+ </div>+ ) : (+ <p+ data-testid="agent-message-internal-preview"+ className="truncate text-xs leading-relaxed text-muted-foreground"+ title={text}+ >+ {preview}+ </p>+ )}+ {item.message.error ? <div className="mt-1 text-xs text-destructive">{item.message.error}</div> : null}</div>- <div className="whitespace-pre-wrap">{item.message.text}</div>- {item.message.error && <div className="text-destructive">{item.message.error}</div>}</div>);}diff --git a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsxindex f6d20aee89..002dbdc280 100644--- a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx+++ b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx@@ -203,7 +203,7 @@ function SpecialistChat({ agent, roster }: AgentChatPanelProps) {{agent.model ? <span className="truncate font-mono">{agent.model}</span> : null}{agent.effort ? <span className="ml-auto rounded-full border border-border px-2 py-0.5">{agent.effort}</span> : null}</div>- <Transcript key={sessionId ?? agent.agentId} items={visibleItems} agent={agent} busy={sessionReady && busy} onDecide={decide} />+ <Transcript key={sessionId ?? agent.agentId} items={visibleItems} agent={agent} roster={roster} busy={sessionReady && busy} onDecide={decide} />{lastError && sessionReady ? (<p role="alert" className="px-4 pb-1 text-xs text-destructive">{lastError}@@ -313,7 +313,7 @@ function JarvisChat({ agent, roster }: AgentChatPanelProps) {<RotateCcw className="h-3.5 w-3.5" aria-hidden /></button></div>- <Transcript items={items} agent={agent} busy={busy} onDecide={decide} />+ <Transcript items={items} agent={agent} roster={roster} busy={busy} onDecide={decide} />{lastError ? (<p role="alert" className="px-4 pb-1 text-xs text-destructive">{lastError}@@ -552,11 +552,13 @@ function EffortPicker() {function Transcript({items,agent,+ roster,busy,onDecide,}: {items: TimelineItem[];agent: SocietyAgent;+ roster: SocietyAgent[];busy: boolean;onDecide: (approvalId: string, decision: ApprovalDecision) => Promise<void>;}) {@@ -588,7 +590,11 @@ function Transcript({<div key={item.id} className="flex flex-col gap-2">{stamp ? <TimeStamp ms={stamp} /> : null}{item.type === "internal" ? (- <InternalMessageBubble item={item} />+ <InternalMessageBubble+ item={item}+ sender={roster.find((a) => a.agentId === item.message.sender_id) ?? null}+ recipient={agent}+ />) : item.type === "user" ? (<UserBubble item={item} />) : item.type === "turn" ? (diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.jsonindex bbe1880e51..1cc16e48ba 100644--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json@@ -603,6 +603,8 @@},"agent_chat": {"internal_message": "Interne Nachricht",+ "internal_expand": "Ganze Nachricht zeigen",+ "internal_collapse": "Weniger anzeigen","delivery_queued": "Eingereiht","delivery_delivered": "Zugestellt","delivery_failed": "Fehlgeschlagen",diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.jsonindex ebf762fd25..6d1ccf5097 100644--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json@@ -603,6 +603,8 @@},"agent_chat": {"internal_message": "Internal message",+ "internal_expand": "Show the full message",+ "internal_collapse": "Show less","delivery_queued": "Queued","delivery_delivered": "Delivered","delivery_failed": "Failed",diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.jsonindex a18d66dfd1..812bbfdc87 100644--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json@@ -603,6 +603,8 @@},"agent_chat": {"internal_message": "Mensaje interno",+ "internal_expand": "Mostrar el mensaje completo",+ "internal_collapse": "Mostrar menos","delivery_queued": "En cola","delivery_delivered": "Entregado","delivery_failed": "Error",