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(society): tag plugins, MCP servers and tools with @ in agent chat
rubenluetke10-beep0e2e968ee723
diff --git a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsxindex 473897b3d5..51e9075af3 100644--- a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx+++ b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx@@ -5,9 +5,9 @@** For Jarvis the column speaks to the SAME store the front page and the* voice stage use (`useAgentChatStore`, the "jarvis" surface): one history,- * whatever a person said or typed anywhere. A "@Name" in the message hands- * the task to that agent — Jarvis delegates through its router tool and- * reports back here. The reasoning trail stays readable: a centred+ * whatever a person said or typed anywhere. "@Name" hands the task to that+ * agent; "@gmail" (and the other catalog tags) pins that plugin, MCP server+ * or tool for the turn. The reasoning trail stays readable: a centred* "Thought for 4s" pill above the answer, never a second wall of text.** Jarvis' card alone also has a `Voice | Chat` switch (maintainer,@@ -48,6 +48,14 @@ import type { AgentChatSurface, ApprovalDecision } from "@/lib/agentChatApi";import { AgentSwatch } from "../AgentSwatch";import { useResolveProposal, useSocietyCapabilities, type SocietyAgent } from "../data";+import { MentionPicker } from "./MentionPicker";+import {+ buildMentionCatalog,+ filterMentions,+ mentionToken,+ mentionsInText,+ type MentionItem,+} from "./mentionItems";/** A gap this long between messages earns a fresh time stamp. */const STAMP_GAP_MS = 30 * 60_000;@@ -1051,7 +1059,9 @@ function Composer({ agent, mentionable, busy, sessionId, cwd, provider, surfaceconst [plusOpen, setPlusOpen] = useState(false);const [problem, setProblem] = useState<string | null>(null);const [mention, setMention] = useState<{ query: string; start: number } | null>(null);+ const [activeIndex, setActiveIndex] = useState(0);const textarea = useRef<HTMLTextAreaElement>(null);+ const composerRef = useRef<HTMLDivElement>(null);const fileInput = useRef<HTMLInputElement>(null);const attachments = useChatAttachments({ sessionId, cwd, provider, surface }, (message) => setProblem(message));const dictation = useComposerDictation(value, setValue);@@ -1064,56 +1074,55 @@ function Composer({ agent, mentionable, busy, sessionId, cwd, provider, surface}, []);useEffect(resize, [value, resize]);- // On the society surface "@" also completes CAPABILITIES — the connected- // plugins, CLIs and MCP tools, by their capability id. Naming one pins it- // for the turn (see `submit`), which is how a person points the agent at a- // tool without editing its focus.+ // "@" completes teammates AND the capability catalog — plugins, MCP+ // servers, CLIs, skills, Jarvis tools — on every agent card, including+ // Jarvis'. Naming one pins it for the turn (see `submit`).const capabilities = useSocietyCapabilities();- const capabilityRows = useMemo(- () => (surface === "society" ? (capabilities.data ?? []) : []),- [surface, capabilities.data],+ const catalog = useMemo(+ () => buildMentionCatalog(mentionable, capabilities.data ?? []),+ [mentionable, capabilities.data],+ );+ const matches = useMemo(+ () => (mention ? filterMentions(catalog, mention.query) : []),+ [mention, catalog],);+ useEffect(() => {+ setActiveIndex(0);+ }, [mention?.query, mention?.start]);+ useEffect(() => {+ if (activeIndex >= matches.length) setActiveIndex(Math.max(0, matches.length - 1));+ }, [matches.length, activeIndex]);+const onChange = (next: string, caret: number) => {setValue(next);- const before = next.slice(0, caret);- const m = /(?:^|\s)@([^\s@]*)$/.exec(before);- const offers = mentionable.length > 0 || capabilityRows.length > 0;- setMention(m && offers ? { query: m[1].toLowerCase(), start: caret - m[1].length - 1 } : null);+ setMention(mentionToken(next, caret));};- const matches = useMemo(() => {- if (!mention) return [] as { key: string; value: string; label: string; agent?: SocietyAgent }[];- const q = mention.query;- const agents = mentionable- .filter((a) => a.name.toLowerCase().startsWith(q))- .map((a) => ({ key: a.agentId, value: a.name, label: a.name, agent: a }));- const caps = capabilityRows- .filter((c) => c.id.toLowerCase().includes(q) || c.label.toLowerCase().startsWith(q))- .slice(0, 6)- .map((c) => ({ key: c.id, value: c.id, label: c.label, agent: undefined }));- return [...agents, ...caps].slice(0, 8);- }, [mention, mentionable, capabilityRows]);-- const insertMention = (name: string) => {+ const insertMention = (item: MentionItem) => {if (!mention) return;const el = textarea.current;const caret = el?.selectionStart ?? value.length;- const next = `${value.slice(0, mention.start)}@${name} ${value.slice(caret)}`;+ const inserted = `@${item.value} `;+ const next = `${value.slice(0, mention.start)}${inserted}${value.slice(caret)}`;setValue(next);setMention(null);- requestAnimationFrame(() => el?.focus());+ requestAnimationFrame(() => {+ if (!el) return;+ el.focus();+ const at = mention.start + inserted.length;+ el.setSelectionRange(at, at);+ });};const submit = async () => {const text = value.trim();if (!text || busy) return;- const named = mentionable.filter((a) => text.includes(`@${a.name}`));- const lines = named.map(+ 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 pinned = capabilityRows.filter((c) => text.includes(`@${c.id}`)).map((c) => c.id);- if (pinned.length > 0) lines.push(`${TOOL_PIN_MARK} ${pinned.join(", ")}]`);+ if (named.pinIds.length > 0) lines.push(`${TOOL_PIN_MARK} ${named.pinIds.join(", ")}]`);const hint = lines.join("\n");setValue("");setMention(null);@@ -1126,32 +1135,26 @@ function Composer({ agent, mentionable, busy, sessionId, cwd, provider, surface}};+ const pickerOpen = Boolean(mention) && (matches.length > 0 || (mention?.query.length ?? 0) > 0 || capabilities.isLoading);+return (<div className="shrink-0 border-t border-border px-3 pb-3 pt-2">{problem ? <p className="mb-1 px-1 text-xs text-destructive">{problem}</p> : null}<div className={CHAT_MEASURE}><ChatAttachmentStrip attachments={attachments.attachments} analyzing={attachments.analyzing} onRemove={attachments.remove} /></div>- {matches.length > 0 ? (- <ul className={cn(CHAT_MEASURE, "mb-1 flex flex-wrap gap-1 px-1")} role="listbox" aria-label={t("society.chat.mention_hint")}>- {matches.map((m) => (- <li key={m.key}>- <button- type="button"- role="option"- aria-selected={false}- onClick={() => insertMention(m.value)}- className="flex items-center gap-1.5 rounded-full border border-border px-2 py-0.5 text-xs text-foreground hover:bg-secondary"- >- {m.agent ? <AgentSwatch agent={m.agent} size={16} /> : null}- {m.label}- </button>- </li>- ))}- </ul>- ) : null}<DictationStatus onStop={dictation.stop} className={cn(CHAT_MEASURE, "mb-1.5")} />+ <MentionPicker+ anchorRef={composerRef}+ open={pickerOpen}+ items={matches}+ loading={capabilities.isLoading}+ activeIndex={activeIndex}+ onHover={setActiveIndex}+ onPick={insertMention}+ /><div+ ref={composerRef}className={cn(CHAT_MEASURE,"relative flex items-end gap-1 rounded-[22px] border border-border bg-background px-1.5 py-1",@@ -1218,12 +1221,36 @@ function Composer({ agent, mentionable, busy, sessionId, cwd, provider, surfaceonChange={(e) => onChange(e.target.value, e.target.selectionStart ?? e.target.value.length)}onPaste={attachments.onPaste}onKeyDown={(e) => {+ if (pickerOpen) {+ if (e.key === "ArrowDown") {+ e.preventDefault();+ if (matches.length) setActiveIndex((i) => (i + 1) % matches.length);+ return;+ }+ if (e.key === "ArrowUp") {+ e.preventDefault();+ if (matches.length) setActiveIndex((i) => (i - 1 + matches.length) % matches.length);+ return;+ }+ if (e.key === "Escape") {+ e.preventDefault();+ setMention(null);+ return;+ }+ if (e.key === "Tab" || (e.key === "Enter" && !e.shiftKey)) {+ const item = matches[activeIndex] ?? matches[0];+ if (item) {+ e.preventDefault();+ insertMention(item);+ return;+ }+ if (e.key === "Tab") return;+ }+ }if (e.key === "Enter" && !e.shiftKey) {e.preventDefault();- if (matches.length > 0 && mention) insertMention(matches[0].value);- else void submit();+ void submit();}- if (e.key === "Escape" && mention) setMention(null);}}className="max-h-[180px] min-h-[32px] flex-1 resize-none bg-transparent px-1 py-1.5 text-sm leading-relaxed text-foreground placeholder:text-muted-foreground focus:outline-none"/>diff --git a/jarvis/ui/web/frontend/src/components/society/chat/MentionPicker.test.tsx b/jarvis/ui/web/frontend/src/components/society/chat/MentionPicker.test.tsxnew file mode 100644index 0000000000..996768a356--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/society/chat/MentionPicker.test.tsx@@ -0,0 +1,66 @@+import { createRef } from "react";+import { cleanup, fireEvent, render, screen } from "@testing-library/react";+import { afterEach, describe, expect, it } from "vitest";++import type { Capability } from "@/components/society/data";++import { MentionPicker } from "./MentionPicker";+import { buildMentionCatalog, filterMentions } from "./mentionItems";++afterEach(cleanup);++function cap(over: Partial<Capability> & Pick<Capability, "id">): Capability {+ const kind = (over.id.split(":")[0] || "plugin") as Capability["kind"];+ return {+ kind,+ label: over.id.replace(/^[^:]+:/, ""),+ one_liner: over.one_liner ?? "Does the thing.",+ risk_tier: "monitor",+ connected: true,+ tool_name: over.id.replace(/^[^:]+:/, ""),+ ...over,+ };+}++describe("MentionPicker", () => {+ it("groups plugins and MCP servers and picks on click", () => {+ const items = filterMentions(+ buildMentionCatalog(+ [],+ [+ cap({ id: "plugin:gmail", label: "gmail", one_liner: "Read and send mail." }),+ cap({ id: "mcp:github/create_issue" }),+ cap({ id: "mcp:github/list_issues" }),+ cap({ id: "core:search-web", label: "search-web" }),+ ],+ ),+ "",+ );+ const picked: string[] = [];+ const anchor = createRef<HTMLDivElement>();+ render(+ <>+ <div ref={anchor} />+ <MentionPicker+ anchorRef={anchor}+ open+ items={items}+ loading={false}+ activeIndex={0}+ onHover={() => undefined}+ onPick={(item) => picked.push(item.value)}+ />+ </>,+ );+ expect(screen.getByTestId("mention-picker")).toBeTruthy();+ expect(screen.getByText("Plugins")).toBeTruthy();+ expect(screen.getByText("MCP servers")).toBeTruthy();+ expect(screen.getByText("Jarvis tools")).toBeTruthy();+ const gmail = screen.getAllByTestId("mention-picker-item").find((el) =>+ (el.textContent ?? "").includes("@gmail"),+ );+ expect(gmail).toBeTruthy();+ fireEvent.click(gmail!);+ expect(picked).toEqual(["gmail"]);+ });+});diff --git a/jarvis/ui/web/frontend/src/components/society/chat/MentionPicker.tsx b/jarvis/ui/web/frontend/src/components/society/chat/MentionPicker.tsxnew file mode 100644index 0000000000..bebf057079--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/society/chat/MentionPicker.tsx@@ -0,0 +1,217 @@+/**+ * The list over the society composer after "@" — agents, plugins, MCP+ * servers, CLIs, skills and Jarvis tools, grouped, with the service's mark.+ *+ * Portalled into the agent card (a Radix dialog) the way Combobox is, so a+ * click still lands: the dialog sets pointer-events none on body. Drawn+ * above the composer; the highlighted row follows the arrow keys the text+ * box receives.+ */+import { useEffect, useId, useLayoutEffect, useRef, useState, type RefObject } from "react";+import { createPortal } from "react-dom";++import { cn } from "@/lib/utils";+import { resolveToolBrand } from "@/lib/toolBrand";+import { useT } from "@/i18n";++import { AgentSwatch } from "../AgentSwatch";+import { groupMentions, type MentionGroup, type MentionItem } from "./mentionItems";++const PANEL_MAX_HEIGHT = 340;+const PANEL_MIN_WIDTH = 320;+const VIEWPORT_MARGIN = 8;++function panelHost(anchor: HTMLElement | null): HTMLElement {+ return anchor?.closest<HTMLElement>('[role="dialog"]') ?? document.body;+}++export function MentionPicker({+ anchorRef,+ open,+ items,+ loading,+ activeIndex,+ onHover,+ onPick,+}: {+ anchorRef: RefObject<HTMLElement | null>;+ open: boolean;+ items: MentionItem[];+ loading: boolean;+ activeIndex: number;+ onHover: (index: number) => void;+ onPick: (item: MentionItem) => void;+}) {+ const t = useT();+ const listId = useId();+ const listRef = useRef<HTMLDivElement | null>(null);+ const [position, setPosition] = useState<{+ left: number;+ bottom: number;+ width: number;+ maxHeight: number;+ } | null>(null);++ useLayoutEffect(() => {+ if (!open) return;+ const measure = () => {+ const anchor = anchorRef.current;+ if (!anchor) return;+ const rect = anchor.getBoundingClientRect();+ const width = Math.min(+ Math.max(rect.width, PANEL_MIN_WIDTH),+ window.innerWidth - 2 * VIEWPORT_MARGIN,+ );+ const left = Math.min(+ Math.max(VIEWPORT_MARGIN, rect.left),+ Math.max(VIEWPORT_MARGIN, window.innerWidth - width - VIEWPORT_MARGIN),+ );+ setPosition({+ left,+ bottom: window.innerHeight - rect.top + 6,+ width,+ maxHeight: Math.max(140, Math.min(PANEL_MAX_HEIGHT, rect.top - VIEWPORT_MARGIN - 6)),+ });+ };+ measure();+ window.addEventListener("scroll", measure, true);+ window.addEventListener("resize", measure);+ return () => {+ window.removeEventListener("scroll", measure, true);+ window.removeEventListener("resize", measure);+ };+ }, [open, anchorRef, items.length]);++ useEffect(() => {+ if (!open) return;+ const row = listRef.current?.querySelector<HTMLElement>(`[data-index="${activeIndex}"]`);+ if (row && typeof row.scrollIntoView === "function") row.scrollIntoView({ block: "nearest" });+ }, [open, activeIndex]);++ if (!open || !position) return null;++ const runs = groupMentions(items);+ let runningIndex = 0;+ const host = panelHost(anchorRef.current);++ return createPortal(+ <div+ data-testid="mention-picker"+ data-combobox-panel=""+ role="listbox"+ id={listId}+ aria-label={t("society.chat.mention_hint")}+ ref={listRef}+ style={{+ left: position.left,+ bottom: position.bottom,+ width: position.width,+ maxHeight: position.maxHeight,+ }}+ onMouseDown={(ev) => ev.preventDefault()}+ className="pointer-events-auto fixed z-[70] flex flex-col overflow-y-auto rounded-xl border border-border-strong bg-popover p-1 text-sm shadow-float"+ >+ {items.length === 0 ? (+ <div className="px-3 py-2 text-xs text-muted-foreground" data-testid="mention-picker-empty">+ {loading ? t("society.chat.mention_loading") : t("society.chat.mention_empty")}+ </div>+ ) : (+ runs.map((run) => (+ <div key={run.group} role="group" aria-label={groupLabel(run.group, t)}>+ <div className="px-2 pb-0.5 pt-1.5 text-micro font-semibold text-muted-foreground">+ {groupLabel(run.group, t)}+ </div>+ {run.items.map((item) => {+ const index = runningIndex;+ runningIndex += 1;+ const active = index === activeIndex;+ return (+ <div+ key={item.key}+ role="option"+ aria-selected={active}+ data-index={index}+ data-kind={item.kind}+ data-testid="mention-picker-item"+ onMouseEnter={() => onHover(index)}+ onClick={() => onPick(item)}+ className={cn(+ "flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5",+ active ? "bg-secondary text-foreground" : "text-foreground",+ !item.connected && "opacity-50",+ )}+ >+ <Mark item={item} />+ <span className="min-w-0 flex-1">+ <span className="flex items-baseline gap-1.5">+ <span className="font-mono text-meta">+ <span className="text-muted-foreground">@</span>+ {item.value}+ </span>+ {item.label.toLowerCase() !== item.value.toLowerCase() ? (+ <span className="truncate text-xs text-foreground">{item.label}</span>+ ) : null}+ </span>+ {item.hint ? (+ <span className="block truncate text-xs text-muted-foreground">{item.hint}</span>+ ) : null}+ </span>+ {!item.connected ? (+ <span className="shrink-0 text-micro text-muted-foreground">+ {t("society.chat.mention_disconnected")}+ </span>+ ) : item.kind === "mcp" && !item.detail && item.pinIds.length > 1 ? (+ <span className="shrink-0 font-mono text-micro text-muted-foreground">+ {item.pinIds.length}+ </span>+ ) : null}+ </div>+ );+ })}+ </div>+ ))+ )}+ </div>,+ host,+ );+}++function groupLabel(group: MentionGroup, t: (key: string) => string): string {+ switch (group) {+ case "agents":+ return t("society.chat.mention_group_agents");+ case "plugins":+ return t("society.chat.mention_group_plugins");+ case "mcp":+ return t("society.chat.mention_group_mcp");+ case "cli":+ return t("society.chat.mention_group_cli");+ case "skills":+ return t("society.chat.mention_group_skills");+ case "tools":+ return t("society.chat.mention_group_tools");+ default:+ return group;+ }+}++function Mark({ item }: { item: MentionItem }) {+ if (item.agent) {+ return <AgentSwatch agent={item.agent} size={20} className="h-5 w-5" />;+ }+ const brand = resolveToolBrand(item.toolName || item.value);+ return (+ <span+ aria-hidden+ className="inline-flex h-5 w-5 shrink-0 items-center justify-center overflow-hidden rounded-[5px] bg-secondary"+ >+ {brand.logoUrl ? (+ <img src={brand.logoUrl} alt="" className="h-full w-full object-contain p-[2px]" draggable={false} />+ ) : (+ <span className="font-mono text-[10px] font-semibold uppercase text-muted-foreground">+ {brand.monogram}+ </span>+ )}+ </span>+ );+}diff --git a/jarvis/ui/web/frontend/src/components/society/chat/mentionItems.test.ts b/jarvis/ui/web/frontend/src/components/society/chat/mentionItems.test.tsnew file mode 100644index 0000000000..c1f9bfdd31--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/society/chat/mentionItems.test.ts@@ -0,0 +1,181 @@+import { describe, expect, it } from "vitest";++import type { Capability, SocietyAgent } from "@/components/society/data";++import {+ buildMentionCatalog,+ filterMentions,+ groupMentions,+ mentionToken,+ mentionsInText,+} from "./mentionItems";++function agent(over: Partial<SocietyAgent> & Pick<SocietyAgent, "agentId" | "name">): SocietyAgent {+ return {+ title: "",+ description: "",+ tier: "specialist",+ provider: "",+ providerLabel: "",+ model: "",+ effort: "",+ figure: null,+ palette: { primary: "#000", secondary: "#000", accent: "#000" },+ grantMode: "all",+ toolGrants: [],+ focus: [],+ denies: [],+ approvalRules: { requireApproval: [], alwaysAllow: [] },+ permissionCeiling: "ask",+ dailyBudgetUsd: 0,+ checkpoint: "idle",+ state: "idle",+ lifecycle: "active",+ createdMs: 0,+ maxConcurrentRuns: 1,+ workspaceDir: "",+ wikiNamespace: "",+ chatSessionId: null,+ routines: [],+ stats: { runs: 0, totalCostUsd: 0, spentTodayUsd: 0, lastActiveMs: null },+ ...over,+ };+}++function cap(over: Partial<Capability> & Pick<Capability, "id">): Capability {+ const kind = (over.id.split(":")[0] || "plugin") as Capability["kind"];+ return {+ kind,+ label: over.id.replace(/^[^:]+:/, ""),+ one_liner: "",+ risk_tier: "monitor",+ connected: true,+ tool_name: over.id.replace(/^[^:]+:/, ""),+ ...over,+ };+}++describe("buildMentionCatalog", () => {+ it("tags a plugin as @gmail, not @plugin:gmail", () => {+ const items = buildMentionCatalog([], [cap({ id: "plugin:gmail", label: "gmail" })]);+ expect(items).toEqual([+ expect.objectContaining({+ value: "gmail",+ kind: "plugin",+ group: "plugins",+ pinIds: ["plugin:gmail"],+ detail: false,+ }),+ ]);+ });++ it("collapses an MCP server to one browse row and keeps the tools as detail", () => {+ const items = buildMentionCatalog(+ [],+ [+ cap({ id: "mcp:github/create_issue", label: "create_issue", one_liner: "Open an issue." }),+ cap({ id: "mcp:github/list_issues", label: "list_issues" }),+ cap({ id: "mcp:sentry/list_issues", label: "list_issues", tool_name: "sentry/list_issues" }),+ ],+ );+ const browse = items.filter((i) => !i.detail);+ expect(browse.map((i) => i.value).sort()).toEqual(["github", "sentry"]);+ const github = items.find((i) => i.key === "mcp-server:github")!;+ expect(github.pinIds).toEqual(["mcp:github/create_issue", "mcp:github/list_issues"]);+ expect(items.filter((i) => i.detail).map((i) => i.value)).toEqual([+ "github/create_issue",+ "github/list_issues",+ ]);+ });++ it("keeps an agent's name even when a plugin would want the same tag", () => {+ const items = buildMentionCatalog(+ [agent({ agentId: "mail-bot", name: "gmail", title: "Inbox" })],+ [cap({ id: "plugin:gmail", label: "gmail" })],+ );+ expect(items.find((i) => i.kind === "agent")?.value).toBe("gmail");+ expect(items.find((i) => i.kind === "plugin")?.value).toBe("plugin:gmail");+ });+});++describe("filterMentions", () => {+ const items = buildMentionCatalog(+ [agent({ agentId: "scout", name: "Scout", title: "Research" })],+ [+ cap({ id: "plugin:gmail", label: "gmail", one_liner: "Read and send mail.", aliases: ["mail"] }),+ cap({ id: "plugin:notion", label: "notion", connected: false }),+ cap({ id: "mcp:github/create_issue", label: "create_issue" }),+ cap({ id: "mcp:github/list_issues", label: "list_issues" }),+ cap({ id: "core:search-web", label: "search-web", one_liner: "Search the web." }),+ cap({ id: "cli:gh", label: "gh" }),+ ],+ );++ it("on a bare @ lists connected browse rows, not disconnected plugins or MCP tools", () => {+ const values = filterMentions(items, "").map((i) => i.value);+ expect(values).toEqual(["Scout", "gmail", "search-web", "gh", "github"]);+ expect(values).not.toContain("notion");+ expect(values).not.toContain("github/create_issue");+ });++ it("finds Gmail by @gmail, @mail and the catalog id", () => {+ expect(filterMentions(items, "gmail").map((i) => i.value)).toEqual(["gmail"]);+ expect(filterMentions(items, "mail").map((i) => i.value)).toEqual(["gmail"]);+ expect(filterMentions(items, "plugin:gmail").map((i) => i.value)).toEqual(["gmail"]);+ });++ it("unfolds MCP tools when the query names them, and still matches the server", () => {+ const create = filterMentions(items, "create");+ expect(create.map((i) => i.value)).toContain("github/create_issue");+ expect(filterMentions(items, "github").map((i) => i.value)[0]).toBe("github");+ });++ it("a disconnected plugin still appears once it is searched for", () => {+ expect(filterMentions(items, "notion").map((i) => i.value)).toEqual(["notion"]);+ });+});++describe("groupMentions / mentionsInText / mentionToken", () => {+ const items = buildMentionCatalog(+ [agent({ agentId: "scout", name: "Scout", title: "Research" })],+ [+ cap({ id: "plugin:gmail", label: "gmail" }),+ cap({ id: "mcp:github/create_issue" }),+ cap({ id: "mcp:github/list_issues" }),+ ],+ );++ it("groups in the picker order", () => {+ expect(groupMentions(filterMentions(items, "")).map((g) => g.group)).toEqual([+ "agents",+ "plugins",+ "mcp",+ ]);+ });++ it("pins @gmail to the plugin id and @github to every GitHub MCP tool", () => {+ const named = mentionsInText("please check @gmail and ping @github", items);+ expect(named.pinIds).toEqual([+ "plugin:gmail",+ "mcp:github/create_issue",+ "mcp:github/list_issues",+ ]);+ expect(named.agents).toEqual([]);+ });++ it("a longer MCP tag is not also the server tag", () => {+ const named = mentionsInText("open @github/create_issue", items);+ expect(named.pinIds).toEqual(["mcp:github/create_issue"]);+ });++ it("names an agent for delegation", () => {+ const named = mentionsInText("hand this to @Scout", items);+ expect(named.agents.map((a) => a.agentId)).toEqual(["scout"]);+ });++ it("opens on the @ token under the caret", () => {+ expect(mentionToken("see @gm", 7)).toEqual({ query: "gm", start: 4 });+ expect(mentionToken("see @gm next", 12)).toBeNull();+ expect(mentionToken("mail [email protected]", 10)).toBeNull();+ });+});diff --git a/jarvis/ui/web/frontend/src/components/society/chat/mentionItems.ts b/jarvis/ui/web/frontend/src/components/society/chat/mentionItems.tsnew file mode 100644index 0000000000..9b33b8fb6d--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/society/chat/mentionItems.ts@@ -0,0 +1,330 @@+/**+ * What "@" offers in a society chat: teammates, connected plugins, MCP+ * servers, CLIs, skills and Jarvis' own tools.+ *+ * The picker shows a short tag (`@gmail`, `@github`) rather than the catalog+ * id (`plugin:gmail`). Sending still pins the real capability ids so the+ * agent reaches the right hands. MCP servers collapse to one row while+ * browsing; typing a tool name unfolds the individual tools.+ */++import type { Capability, SocietyAgent } from "../data";++/** "plugin:gmail" → "gmail"; "mcp:github/create_issue" → "github/create_issue". */+function capabilityName(id: string): string {+ return id.replace(/^(plugin|cli|mcp|skill|core):/, "");+}++export type MentionKind = "agent" | "plugin" | "mcp" | "cli" | "skill" | "core";+export type MentionGroup = "agents" | "plugins" | "mcp" | "cli" | "skills" | "tools";++export interface MentionItem {+ key: string;+ kind: MentionKind;+ group: MentionGroup;+ /** What lands after `@`. */+ value: string;+ label: string;+ hint: string;+ /** Capability ids this tag pins for the turn; empty for agents. */+ pinIds: string[];+ agent?: SocietyAgent;+ connected: boolean;+ searchText: string;+ /** Individual MCP tools — hidden until the query names them. */+ detail: boolean;+ /** Registry / tool name the brand resolver reads. */+ toolName: string;+}++const GROUP_ORDER: readonly MentionGroup[] = [+ "agents",+ "plugins",+ "mcp",+ "cli",+ "skills",+ "tools",+];++const KIND_GROUP: Record<string, MentionGroup> = {+ plugin: "plugins",+ cli: "cli",+ mcp: "mcp",+ skill: "skills",+ core: "tools",+};++const BROWSE_LIMIT = 80;+const SEARCH_LIMIT = 60;++function kindOf(cap: Capability): MentionKind {+ const prefix = cap.id.split(":")[0];+ if (prefix === "plugin" || prefix === "cli" || prefix === "mcp" || prefix === "skill" || prefix === "core") {+ return prefix;+ }+ if (+ cap.kind === "plugin" ||+ cap.kind === "cli" ||+ cap.kind === "mcp" ||+ cap.kind === "skill" ||+ cap.kind === "core"+ ) {+ return cap.kind;+ }+ return "plugin";+}++function mcpServer(id: string): string {+ const rest = capabilityName(id);+ const slash = rest.indexOf("/");+ return slash === -1 ? rest : rest.slice(0, slash);+}++function takeValue(wanted: string, fallback: string, taken: Set<string>): string {+ const tryOne = (candidate: string): string | null => {+ const key = candidate.toLowerCase();+ if (!candidate || taken.has(key)) return null;+ taken.add(key);+ return candidate;+ };+ return tryOne(wanted) ?? tryOne(fallback) ?? fallback;+}++function searchBlob(parts: Array<string | undefined | null>): string {+ return parts+ .filter((p): p is string => Boolean(p && p.trim()))+ .join(" ")+ .toLowerCase();+}++function capabilityItem(+ cap: Capability,+ value: string,+ opts: {+ key: string;+ detail: boolean;+ pinIds?: string[];+ label?: string;+ hint?: string;+ toolName?: string;+ connected?: boolean;+ },+): MentionItem {+ const kind = kindOf(cap);+ const aliases = cap.aliases ?? [];+ return {+ key: opts.key,+ kind,+ group: KIND_GROUP[kind] ?? "plugins",+ value,+ label: opts.label ?? cap.label ?? value,+ hint: opts.hint ?? cap.one_liner ?? "",+ pinIds: opts.pinIds ?? [cap.id],+ connected: opts.connected ?? cap.connected,+ searchText: searchBlob([+ value,+ cap.id,+ cap.label,+ cap.one_liner,+ cap.tool_name,+ kind,+ ...aliases,+ ]),+ detail: opts.detail,+ toolName: opts.toolName ?? cap.tool_name ?? value,+ };+}++/**+ * Every taggable row: agents first (they keep their names), then one row per+ * plugin / CLI / skill / core tool, plus a collapsed MCP server and its+ * individual tools.+ */+export function buildMentionCatalog(+ agents: readonly SocietyAgent[],+ capabilities: readonly Capability[],+): MentionItem[] {+ const taken = new Set<string>();+ const items: MentionItem[] = [];++ for (const agent of agents) {+ const value = takeValue(agent.name, agent.agentId, taken);+ items.push({+ key: `agent:${agent.agentId}`,+ kind: "agent",+ group: "agents",+ value,+ label: agent.name,+ hint: agent.title,+ pinIds: [],+ agent,+ connected: true,+ searchText: searchBlob([agent.name, agent.title, agent.agentId]),+ detail: false,+ toolName: "",+ });+ }++ const mcpByServer = new Map<string, Capability[]>();+ const rest: Capability[] = [];+ for (const cap of capabilities) {+ if (kindOf(cap) === "mcp") {+ const server = mcpServer(cap.id);+ const bucket = mcpByServer.get(server);+ if (bucket) bucket.push(cap);+ else mcpByServer.set(server, [cap]);+ } else {+ rest.push(cap);+ }+ }++ for (const cap of rest) {+ const short = capabilityName(cap.id);+ const value = takeValue(short, cap.id, taken);+ items.push(+ capabilityItem(cap, value, {+ key: cap.id,+ detail: false,+ }),+ );+ }++ for (const [server, tools] of mcpByServer) {+ const connected = tools.some((c) => c.connected);+ const pinIds = tools.map((c) => c.id);+ const value = takeValue(server, `mcp:${server}`, taken);+ const representative = tools[0];+ items.push(+ capabilityItem(representative, value, {+ key: `mcp-server:${server}`,+ detail: false,+ pinIds,+ label: server,+ hint: representative.one_liner,+ toolName: server,+ connected,+ }),+ );++ if (tools.length === 1) continue;+ for (const cap of tools) {+ const short = capabilityName(cap.id);+ const toolValue = takeValue(short, cap.id, taken);+ items.push(+ capabilityItem(cap, toolValue, {+ key: cap.id,+ detail: true,+ }),+ );+ }+ }++ return items;+}++function scoreItem(item: MentionItem, q: string): number | null {+ const value = item.value.toLowerCase();+ const label = item.label.toLowerCase();+ if (value.startsWith(q) || label.startsWith(q)) return 0;+ if (value.includes(q) || label.includes(q)) return 1;+ if (item.searchText.includes(q) || item.hint.toLowerCase().includes(q)) return 2;+ return null;+}++/**+ * Empty query: the browse list (no disconnected rows, no individual MCP+ * tools). A query searches everything, disconnected included, ranked.+ */+export function filterMentions(items: readonly MentionItem[], query: string): MentionItem[] {+ const q = query.trim().toLowerCase();+ if (!q) {+ return items.filter((item) => !item.detail && item.connected).slice(0, BROWSE_LIMIT);+ }+ const ranked: { score: number; index: number; item: MentionItem }[] = [];+ items.forEach((item, index) => {+ const score = scoreItem(item, q);+ if (score === null) return;+ ranked.push({ score, index, item });+ });+ ranked.sort((a, b) => a.score - b.score || a.index - b.index);+ return ranked.slice(0, SEARCH_LIMIT).map((r) => r.item);+}++export function groupMentions(+ items: readonly MentionItem[],+): { group: MentionGroup; items: MentionItem[] }[] {+ const buckets = new Map<MentionGroup, MentionItem[]>();+ for (const item of items) {+ const bucket = buckets.get(item.group);+ if (bucket) bucket.push(item);+ else buckets.set(item.group, [item]);+ }+ return GROUP_ORDER.filter((group) => (buckets.get(group)?.length ?? 0) > 0).map((group) => ({+ group,+ items: buckets.get(group) ?? [],+ }));+}++const TOKEN_RE = /(?:^|\s)@([^\s@]+)/g;++/**+ * Agents named in `text` and the capability ids those tags pin.+ *+ * Appearance order; a more specific tag (`@github/create_issue`) suppresses+ * the server tag (`@github`) so the two are not both pinned.+ */+export function mentionsInText(+ text: string,+ items: readonly MentionItem[],+): { agents: SocietyAgent[]; pinIds: string[] } {+ const tokens = [...text.matchAll(TOKEN_RE)].map((m) => m[1]);+ if (tokens.length === 0) return { agents: [], pinIds: [] };++ const byValue = new Map<string, MentionItem[]>();+ for (const item of items) {+ const key = item.value.toLowerCase();+ const list = byValue.get(key);+ if (list) list.push(item);+ else byValue.set(key, [item]);+ }++ const seen = tokens.map((token) => token.toLowerCase());+ const used = new Set<string>();+ const agents: SocietyAgent[] = [];+ const pinIds: string[] = [];+ for (const token of tokens) {+ const lower = token.toLowerCase();+ if (used.has(lower)) continue;+ // A shorter tag sitting next to a more specific one (`@github` beside+ // `@github/create_issue`) must not also fire.+ if (+ seen.some(+ (other) => other !== lower && (other.startsWith(`${lower}/`) || other.startsWith(`${lower}:`)),+ )+ ) {+ continue;+ }+ used.add(lower);+ const hits = byValue.get(lower);+ if (!hits) continue;+ for (const item of hits) {+ if (item.agent) agents.push(item.agent);+ for (const id of item.pinIds) {+ if (!pinIds.includes(id)) pinIds.push(id);+ }+ }+ }+ return { agents, pinIds };+}++/** The `@` token the caret sits in, or null. */+export function mentionToken(+ text: string,+ caret: number,+): { query: string; start: number } | null {+ const at = Math.max(0, Math.min(caret, text.length));+ const before = text.slice(0, at);+ const m = /(?:^|\s)@([^\s@]*)$/.exec(before);+ if (!m) return null;+ return { query: m[1], start: at - m[1].length - 1 };+}diff --git a/jarvis/ui/web/frontend/src/components/society/data.ts b/jarvis/ui/web/frontend/src/components/society/data.tsindex 788854773d..0da73bfe9a 100644--- a/jarvis/ui/web/frontend/src/components/society/data.ts+++ b/jarvis/ui/web/frontend/src/components/society/data.ts@@ -299,6 +299,8 @@ export interface Capability {risk_tier: string;connected: boolean;tool_name: string;+ /** Extra words the @-picker may match (server name, aliases). */+ aliases?: string[];}async function fetchCapabilities(): Promise<Capability[]> {diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.jsonindex 4716bf7cd0..57279106a7 100644--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json@@ -5069,7 +5069,7 @@"effort_default": "auto","today": "Heute","empty_title": "Sprich mit {0}",- "empty_hint": "Tippen, sprechen oder einen anderen Agenten mit @ nennen — Jarvis gibt die Aufgabe weiter und meldet sich zurück.",+ "empty_hint": "Tippen, sprechen oder einen Agenten, ein Plugin oder ein Werkzeug mit @ markieren — z. B. @gmail.","thinking": "Denkt nach…","thought_for": "{0} nachgedacht","thinking_for": "Denkt seit {0}",@@ -5081,7 +5081,16 @@"tool_waiting": "wartet auf deine Freigabe","approve": "Erlauben","deny": "Ablehnen",- "mention_hint": "Agenten",+ "mention_hint": "Agenten, Plugins und Werkzeuge",+ "mention_loading": "Suche…",+ "mention_empty": "Nichts passt",+ "mention_disconnected": "Nicht verbunden",+ "mention_group_agents": "Agenten",+ "mention_group_plugins": "Plugins",+ "mention_group_mcp": "MCP-Server",+ "mention_group_cli": "Kommandozeile",+ "mention_group_skills": "Skills",+ "mention_group_tools": "Jarvis-Werkzeuge","result_done": "{0} ist fertig","result_blocked": "{0} kam nicht weiter","result_agent": "Ein Agent",diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.jsonindex 8dfae4fae7..379de9aec8 100644--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json@@ -5102,7 +5102,7 @@"effort_default": "auto","today": "Today","empty_title": "Talk to {0}",- "empty_hint": "Type, speak, or name another agent with @ — Jarvis hands the task over and reports back.",+ "empty_hint": "Type, speak, or tag an agent, plugin or tool with @ — e.g. @gmail.","thinking": "Thinking…","thought_for": "Thought for {0}","thinking_for": "Thinking for {0}",@@ -5114,7 +5114,16 @@"tool_waiting": "waiting for your approval","approve": "Allow","deny": "Deny",- "mention_hint": "Agents",+ "mention_hint": "Agents, plugins and tools",+ "mention_loading": "Looking…",+ "mention_empty": "Nothing matches",+ "mention_disconnected": "Not connected",+ "mention_group_agents": "Agents",+ "mention_group_plugins": "Plugins",+ "mention_group_mcp": "MCP servers",+ "mention_group_cli": "Command line",+ "mention_group_skills": "Skills",+ "mention_group_tools": "Jarvis tools","result_done": "{0} is done","result_blocked": "{0} got stuck","result_agent": "An agent",diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.jsonindex 07631b7001..3bab7e70ce 100644--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json@@ -5069,7 +5069,7 @@"effort_default": "auto","today": "Hoy","empty_title": "Habla con {0}",- "empty_hint": "Escribe, habla o nombra a otro agente con @: Jarvis le pasa la tarea e informa aquí.",+ "empty_hint": "Escribe, habla o etiqueta un agente, plugin o herramienta con @ — p. ej. @gmail.","thinking": "Pensando…","thought_for": "Pensó durante {0}","thinking_for": "Pensando desde hace {0}",@@ -5081,7 +5081,16 @@"tool_waiting": "esperando tu aprobación","approve": "Permitir","deny": "Denegar",- "mention_hint": "Agentes",+ "mention_hint": "Agentes, plugins y herramientas",+ "mention_loading": "Buscando…",+ "mention_empty": "Nada coincide",+ "mention_disconnected": "Sin conexión",+ "mention_group_agents": "Agentes",+ "mention_group_plugins": "Plugins",+ "mention_group_mcp": "Servidores MCP",+ "mention_group_cli": "Línea de comandos",+ "mention_group_skills": "Habilidades",+ "mention_group_tools": "Herramientas de Jarvis","result_done": "{0} ha terminado","result_blocked": "{0} se quedó atascado","result_agent": "Un agente",