Skip to content

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.

fix(society): route specialist mentions through internal messaging

rubenluetke10-beep3504d931ee7e
diff --git a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx
index a65774e2b9..80d37823a5 100644
--- a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx
@@ -76,6 +76,9 @@ const CHAT_MEASURE = "mx-auto w-full max-w-[820px]";
/** The line appended to a message that names an agent; Jarvis delegates on it. */
const DELEGATE_MARK = "[to jarvis]";
+/** Specialist mentions identify teammates; they do not change the chat's recipient. */
+const MENTION_MARK = "[agent mentions]";
+
/** The line a message adds when it names a capability: pin those tools for the turn. */
const TOOL_PIN_MARK = "[tools:";
@@ -813,11 +816,12 @@ function ProposalCard({ item }: { item: NoticeItem }) {
);
}
-/** What the person typed, without the delegation line the composer added. */
+/** What the person typed, without the routing hints the composer added. */
function visibleUserText(text: string): string {
return text
.split("\n")
.filter((line) => !line.trimStart().startsWith(DELEGATE_MARK))
+ .filter((line) => !line.trimStart().startsWith(MENTION_MARK))
.filter((line) => !line.trimStart().startsWith(TOOL_PIN_MARK))
.join("\n")
.trimEnd();
@@ -972,9 +976,20 @@ export function Composer({ agent, mentionable, busy, sessionId, cwd, provider, s
const text = draftText;
if (!text || busy || modelSaving) return;
const named = mentionsInText(text, catalog);
- const lines = named.agents.map(
- (a) => `${DELEGATE_MARK} ${t("society.chat.delegate_line").replace("{0}", a.name).replace("{1}", a.agentId)}`,
- );
+ const lines: string[] = [];
+ if (named.agents.length > 0 && surface === "society") {
+ const teammates = named.agents.map((a) => `${JSON.stringify(a.name)} (id ${JSON.stringify(a.agentId)})`).join(", ");
+ lines.push(
+ `${MENTION_MARK} Current sender: the user. Current recipient: ${JSON.stringify(agent.name)} (id ${JSON.stringify(agent.agentId)}). ` +
+ `Mentioned teammates: ${teammates}. For teammate contact requested by the user, use society_message_agent; ` +
+ "use kind 'query' when asking for information. If a work assignment is needed, contact Jarvis or an orchestrator with that tool. " +
+ "Reply to the user here. An @mention or prose addressed to a teammate does not deliver a message.",
+ );
+ } else if (surface === "jarvis") {
+ lines.push(...named.agents.map(
+ (a) => `${DELEGATE_MARK} ${t("society.chat.delegate_line").replace("{0}", a.name).replace("{1}", a.agentId)}`,
+ ));
+ }
if (named.pinIds.length > 0) lines.push(`${TOOL_PIN_MARK} ${named.pinIds.join(", ")}]`);
const hint = lines.join("\n");
setValue("");
diff --git a/jarvis/ui/web/frontend/src/components/society/chat/mentionChoices.test.tsx b/jarvis/ui/web/frontend/src/components/society/chat/mentionChoices.test.tsx
index 445a633a56..1a2da62d73 100644
--- a/jarvis/ui/web/frontend/src/components/society/chat/mentionChoices.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/chat/mentionChoices.test.tsx
@@ -4,7 +4,10 @@ import { Composer, UserBubble } from "./AgentChatPanel";
import { pinnedMessageChoices, withoutChoiceTokens } from "./mentionChoices";
import type { SocietyAgent } from "../data";
-vi.mock("@/i18n", () => ({ useT: () => (key: string) => key }));
+vi.mock("@/i18n", async () => {
+ const { default: en } = await import("@/i18n/locales/en.json");
+ return { useT: () => (key: string) => key === "society.chat.delegate_line" ? en.society.chat.delegate_line : key };
+});
// Model controls have their own suite; this exercises selection and pin delivery.
vi.mock("./AgentModelPicker", () => ({ AgentModelPicker: () => null }));
vi.mock("../data", async (original) => ({
@@ -88,3 +91,71 @@ it("collapses server pins but keeps specific MCP tool selections distinct", () =
const specific = pinnedMessageChoices("Use @github/read\n\n[tools: mcp:github/read]");
expect(specific[0].id).toBe("mcp:github/read");
});
+
+const gmailAgent = { agentId: "gmail-agent", name: "Gmail-Agent", tier: "specialist" } as SocietyAgent;
+const teammates = [
+ { agentId: "linear", name: "LinearAgent", tier: "specialist", title: "Tickets", description: "Read tickets", palette: { primary: "#333", secondary: "#555", accent: "#777" } },
+ { agentId: "drive", name: "DriveAgent", tier: "specialist", title: "Files", description: "Manage files", palette: { primary: "#333", secondary: "#555", accent: "#777" } },
+] as SocietyAgent[];
+
+async function sendDraft(text: string, surface: "society" | "jarvis" = "society") {
+ const send = vi.fn(async (_text: string) => {});
+ render(
+ <Composer
+ agent={surface === "society" ? gmailAgent : { ...gmailAgent, agentId: "jarvis", name: "Jarvis", tier: "lead" }}
+ mentionable={teammates}
+ busy={false}
+ sessionId={surface === "society" ? "society:gmail-agent" : "jarvis-chat"}
+ cwd=""
+ provider="openai"
+ surface={surface}
+ onSend={send}
+ onCancel={async () => {}}
+ />,
+ );
+ const input = screen.getByRole("textbox");
+ input.textContent = text;
+ fireEvent.input(input);
+ fireEvent.click(screen.getByRole("button", { name: "society.chat.send" }));
+ await waitFor(() => expect(send).toHaveBeenCalledOnce());
+ return String(send.mock.calls[0][0]);
+}
+
+it("keeps a user's teammate request in the specialist chat and uses internal messaging", async () => {
+ const draft = "Ask @LinearAgent about current tickets and coordinate with @DriveAgent @gmail";
+ const sent = await sendDraft(draft);
+ expect(sent.startsWith(`${draft}\n\n`)).toBe(true);
+ expect(sent).not.toContain("[to jarvis]");
+ expect(sent).not.toContain("delegate-to-agent");
+ expect(sent).toContain("Current sender: the user.");
+ expect(sent).toContain('Current recipient: "Gmail-Agent" (id "gmail-agent")');
+ expect(sent).toContain('"LinearAgent" (id "linear")');
+ expect(sent).toContain('"DriveAgent" (id "drive")');
+ expect(sent).toContain("society_message_agent");
+ expect(sent).toContain("Reply to the user here.");
+ expect(sent).toContain("does not deliver a message");
+ expect(sent).toContain("[tools: plugin:gmail]");
+ cleanup();
+ render(<UserBubble item={{ type: "user", id: "new", tsMs: 1, text: sent, attachments: [] }} />);
+ expect(screen.getByText(/Ask @LinearAgent about current tickets and coordinate with @DriveAgent/)).toBeTruthy();
+ expect(screen.queryByText(/Current sender:/)).toBeNull();
+});
+
+it("keeps delegation available when the same mentions are sent to Jarvis", async () => {
+ const sent = await sendDraft("Ask @LinearAgent and @DriveAgent", "jarvis");
+ expect(sent.match(/\[to jarvis\]/g)).toHaveLength(2);
+ expect(sent).toContain("agent 'LinearAgent' (id linear) with delegate-to-agent");
+ expect(sent).toContain("agent 'DriveAgent' (id drive) with delegate-to-agent");
+ expect(sent).not.toContain("[agent mentions]");
+});
+
+it("leaves ordinary user text and unknown mentions unchanged", async () => {
+ const draft = "Explain this @UnknownAgent reference";
+ expect(await sendDraft(draft)).toBe(draft);
+});
+
+it("keeps existing saved delegation hints out of the user bubble", () => {
+ render(<UserBubble item={{ type: "user", id: "old", tsMs: 1, text: "Ask @LinearAgent\n\n[to jarvis] Hand this to LinearAgent", attachments: [] }} />);
+ expect(screen.getByText("Ask @LinearAgent")).toBeTruthy();
+ expect(screen.queryByText(/Hand this to/)).toBeNull();
+});