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: single-letter @-mention search matches only prefix tags

rubenluetke10-beepe567c7ed2873
diff --git a/jarvis/agent_chat/typeahead.py b/jarvis/agent_chat/typeahead.py
index 586b981456..0bea8e85ce 100644
--- a/jarvis/agent_chat/typeahead.py
+++ b/jarvis/agent_chat/typeahead.py
@@ -617,25 +617,33 @@ def jarvis_skills() -> list[Suggestion]:
def _filter_definitions(rows: list[Suggestion], query: str) -> list[Suggestion]:
- """Prefix matches first, then substring — on the value, the label, or the hint."""
+ """Prefix matches first, then substring — on the value, the label, or the hint.
+
+ A single letter sits inside almost every description ("x" in "X-Marketing",
+ "xAI", "codex", "dropbox"), so single-character queries stay strictly
+ alphabetical: only a value or label starting with that letter may match.
+ """
if not query:
return rows
q = query.lower()
- ranked: list[tuple[int, int, Suggestion]] = []
+ single = len(q) <= 1
+ ranked: list[tuple[int, str, str, int, Suggestion]] = []
for idx, row in enumerate(rows):
value = row.value.lower()
label = row.label.lower()
if value.startswith(q) or label.startswith(q):
score = 0
+ elif single:
+ continue
elif q in value or q in label:
score = 1
elif q in row.hint.lower():
score = 2
else:
continue
- ranked.append((score, idx, row))
- ranked.sort(key=lambda t: (t[0], t[1]))
- return [row for _, _, row in ranked]
+ ranked.append((score, value, label, idx, row))
+ ranked.sort(key=lambda t: (t[0], t[1], t[2], t[3]))
+ return [row for _, _, _, _, row in ranked]
# ------------------------------------------------------------------- files
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.ts
index 0ce86f1849..8e4ae02bb7 100644
--- a/jarvis/ui/web/frontend/src/components/society/chat/mentionItems.test.ts
+++ b/jarvis/ui/web/frontend/src/components/society/chat/mentionItems.test.ts
@@ -254,6 +254,27 @@ describe("filterMentions", () => {
it("a disconnected plugin still appears once it is searched for", () => {
expect(filterMentions(items, "notion").map((i) => i.value)).toEqual(["notion"]);
});
+
+ it("a single letter only matches tags and labels starting with it", () => {
+ const catalog = buildMentionCatalog(
+ [agent({ agentId: "nala", name: "Nala", title: "X-Marketing Lead & Growth Specialist" })],
+ [
+ cap({ id: "plugin:x", label: "X (Twitter)", one_liner: "Read posts and mentions" }),
+ cap({ id: "plugin:dropbox", label: "Dropbox", one_liner: "Find files" }),
+ ],
+ [
+ { name: "codex", display_name: "Codex", installed: true, version: null, install_command: null },
+ {
+ name: "grok-build", display_name: "Grok Build",
+ description: "xAI's terminal coding agent",
+ installed: true, version: null, install_command: null,
+ },
+ ],
+ );
+ expect(filterMentions(catalog, "x").map((i) => i.value)).toEqual(["x"]);
+ expect(filterMentions(catalog, "g").map((i) => i.value)).toEqual(["grok-build"]);
+ expect(filterMentions(catalog, "d").map((i) => i.value)).toEqual(["dropbox"]);
+ });
});
describe("groupMentions / mentionsInText / mentionToken", () => {
diff --git a/jarvis/ui/web/frontend/src/components/society/chat/mentionItems.ts b/jarvis/ui/web/frontend/src/components/society/chat/mentionItems.ts
index a9d0069f1e..5a6db8a370 100644
--- a/jarvis/ui/web/frontend/src/components/society/chat/mentionItems.ts
+++ b/jarvis/ui/web/frontend/src/components/society/chat/mentionItems.ts
@@ -333,6 +333,10 @@ 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;
+ // A single letter sits inside almost every description ("x" in "X-Marketing",
+ // "xAI", "codex", "dropbox"). Keep such queries strictly alphabetical:
+ // only a tag or label starting with that letter may match.
+ if (q.length <= 1) return null;
if (value.includes(q) || label.includes(q)) return 1;
if (item.searchText.includes(q) || item.hint.toLowerCase().includes(q)) return 2;
return null;
@@ -354,7 +358,13 @@ export function filterMentions(items: readonly MentionItem[], query: string): Me
if (score === null) return;
ranked.push({ score, index, item });
});
- ranked.sort((a, b) => a.score - b.score || a.index - b.index);
+ ranked.sort(
+ (a, b) =>
+ a.score - b.score ||
+ a.item.value.localeCompare(b.item.value, undefined, { sensitivity: "base" }) ||
+ a.item.label.localeCompare(b.item.label, undefined, { sensitivity: "base" }) ||
+ a.index - b.index,
+ );
return groupMentions(ranked.map((r) => r.item)).flatMap((group) => group.items);
}
diff --git a/tests/unit/agent_chat/test_typeahead.py b/tests/unit/agent_chat/test_typeahead.py
index a0e0e3af76..27e73e05e8 100644
--- a/tests/unit/agent_chat/test_typeahead.py
+++ b/tests/unit/agent_chat/test_typeahead.py
@@ -156,6 +156,26 @@ def test_slash_query_ranks_prefix_before_substring_before_hint(account: Path, fo
assert [i["value"] for i in items] == ["commit", "autocommit", "release"]
+def test_single_letter_query_only_matches_prefix():
+ """@x lists X, not every row with an x in its name or description."""
+ rows = [
+ typeahead.Suggestion(
+ value="x", label="X (Twitter)", hint="Read posts", kind="capability", group="plugins"
+ ),
+ typeahead.Suggestion(value="codex", label="Codex", hint="", kind="agent", group="agents"),
+ typeahead.Suggestion(
+ value="Nala", label="Nala", hint="X-Marketing Lead", kind="agent", group="agents"
+ ),
+ typeahead.Suggestion(
+ value="dropbox", label="Dropbox", hint="Files", kind="capability", group="plugins"
+ ),
+ ]
+ assert [r.value for r in typeahead._filter_definitions(rows, "x")] == ["x"]
+ # Longer queries still search substrings and descriptions.
+ assert [r.value for r in typeahead._filter_definitions(rows, "code")] == ["codex"]
+ assert [r.value for r in typeahead._filter_definitions(rows, "marketing")] == ["Nala"]
+
+
# ------------------------------------------------------------- agents