Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(command): merge people with DMs found beyond recent history (#9050)

gbirman0c03b53fb534
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index f735e06dee..db1eb1c5bb 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -248,7 +248,7 @@ the user's newest account for that app from the last fifteen minutes.
- Use `ChannelTitleIcon` for conversation breadcrumbs so DMs retain participant or agent avatars and named channels retain their pictures; suppress avatar actions inside breadcrumb buttons.
- Normalize thread-only conversation URLs in `channelsSearch` before Home, Chat, or touch views derive their message target.
- Mobile dock search owns transient category/mode state in `features/command/mobile`; reuse the shared entity source and explicit full-text adapter rather than overlaying the dock query on view tabs or saved facets. See `docs/agent-guide/search.md` at the repository root.
-- Include known Macro users in typed All/People name searches without requiring a DM or CRM contact; resolve a matching person to their existing one-to-one DM while preserving name/email matching.
+- Include known Macro users in typed All/People name searches without requiring a DM or CRM contact; resolve a matching person against both recent DMs and DMs found by the current search while preserving name/email matching.
- Key mobile name-result history ordering and scroll anchors by the other participant for one-to-one DMs, preserving a person's position when their conversation is created; keep group DMs keyed by channel.
- Keep mobile Search history lightweight: save query/category/mode, account-scoped item anchors, and at most 200 ordering IDs per mode; never save row objects or virtualizer caches. Restore from current sources with at most three additional pages, fall back when an anchor disappears, and stop restoration on user interaction or scope changes. Dock navigation starts a fresh search session; cached rows belong to the source, not history.
- Release per-history-entry state when its router entry is replaced, pruned, or closed; retain only the latest per-view session snapshot and the latest split event outside reachable Back/Forward history.
diff --git a/apps/web/src/features/command/contact-items.ts b/apps/web/src/features/command/contact-items.ts
index 8ed2596ef1..7110fe60e3 100644
--- a/apps/web/src/features/command/contact-items.ts
+++ b/apps/web/src/features/command/contact-items.ts
@@ -31,7 +31,7 @@ export function commandSearchResultKey(
}
function directMessagesByUser(
- directMessages: readonly QuickAccessItem[],
+ directMessages: readonly CommandMenuItem[],
viewerId: string | undefined
) {
const byUser = new Map<string, EntityItem>();
@@ -49,7 +49,11 @@ export function mergeCommandPeople<T extends CommandMenuItem>(
directMessages: readonly QuickAccessItem[],
viewerId: string | undefined
): (T | EntityItem)[] {
- const conversations = directMessagesByUser(directMessages, viewerId);
+ // Typed search can find DMs outside the bounded recent list.
+ const conversations = directMessagesByUser(
+ [...directMessages, ...items],
+ viewerId
+ );
const merged = new Map<string, T | EntityItem>();
for (const item of items) {
if (item.kind === 'user' && item.id === viewerId) continue;
diff --git a/apps/web/src/features/command/useCommandItems.contacts.test.ts b/apps/web/src/features/command/useCommandItems.contacts.test.ts
index 49a7dba444..898f3afae7 100644
--- a/apps/web/src/features/command/useCommandItems.contacts.test.ts
+++ b/apps/web/src/features/command/useCommandItems.contacts.test.ts
@@ -17,6 +17,7 @@ const VIEWER = 'macro|[email protected]';
const mocks = vi.hoisted(() => ({
lists: {} as Record<string, () => QuickAccessItem[]>,
+ searchDms: (): QuickAccessItem[] => [],
}));
vi.mock('@app/lib/analytics/posthog', () => ({
useFeatureFlag: () => () => ({ enabled: false, loading: false }),
@@ -42,7 +43,10 @@ vi.mock('@core/context/quickAccess', () => ({
if (first.enabled && !first.enabled()) return [];
const buckets = Array.isArray(first.buckets) ? first.buckets : [];
return searchQuickAccessItems(
- buckets.flatMap((bucket) => mocks.lists[bucket]?.() ?? []),
+ [
+ ...buckets.flatMap((bucket) => mocks.lists[bucket]?.() ?? []),
+ ...(buckets.includes('dm') ? mocks.searchDms() : []),
+ ],
first.searchTerm?.() ?? ''
);
};
@@ -125,6 +129,7 @@ let dispose: (() => void) | undefined;
afterEach(() => {
dispose?.();
mocks.lists = {};
+ mocks.searchDms = () => [];
});
function setup(initialCategory: CategoryFilter = 'dms', crmEnabled = true) {
@@ -135,9 +140,11 @@ function setup(initialCategory: CategoryFilter = 'dms', crmEnabled = true) {
const [contacts, setContacts] = createSignal<CrmContactEntity[]>([]);
const [users, setUsers] = createSignal<UserItem[]>([]);
const [dms, setDms] = createSignal<EntityItem[]>([]);
+ const [searchDms, setSearchDms] = createSignal<EntityItem[]>([]);
const [hasMore, setHasMore] = createSignal(false);
const [loading, setLoading] = createSignal(false);
mocks.lists = { person: users, dm: dms };
+ mocks.searchDms = searchDms;
const discovery = {
search: undefined as Accessor<string> | undefined,
active: undefined as Accessor<boolean> | undefined,
@@ -171,6 +178,7 @@ function setup(initialCategory: CategoryFilter = 'dms', crmEnabled = true) {
setContacts,
setUsers,
setDms,
+ setSearchDms,
setHasMore,
setLoading,
};
@@ -178,6 +186,33 @@ function setup(initialCategory: CategoryFilter = 'dms', crmEnabled = true) {
}
describe('command menu contact discovery', () => {
+ it.each(['all', 'dms'] as const)(
+ 'merges a DM found beyond the recent list with its person and CRM alias in %s',
+ (category) => {
+ const t = setup(category);
+ const person = user('[email protected]', 'Sample Person');
+ const dm = directMessage('older-dm', 'Sample Person', person.id);
+ t.setUsers([person]);
+ t.setQuery('Sample');
+ expect(t.ids()).toEqual([`search:${category}:Sample`, person.id]);
+
+ // Typed cache search finds this DM without adding it to the browse list.
+ t.setSearchDms([dm]);
+ expect(t.ids()).toEqual([`search:${category}:Sample`, dm.id]);
+ t.setContacts([
+ contact('crm-person', 'Sample CRM alias', person.data.email),
+ ]);
+ expect(t.ids()).toEqual([`search:${category}:Sample`, dm.id]);
+ const result = t.result.items().find((item) => item.id === dm.id);
+ expect(result?.searchText).toContain(person.data.email);
+ expect(result?.searchText).toContain('Sample CRM alias');
+
+ // Hydrating the browse list later must not add a second row.
+ t.setDms([dm]);
+ expect(t.ids()).toEqual([`search:${category}:Sample`, dm.id]);
+ }
+ );
+
it.each(['all', 'dms'] as const)(
'finds a teammate without a DM or CRM contact in %s, including with CRM disabled',
(category) => {
diff --git a/docs/agent-guide/media/command/deduplicated-person-desktop.png b/docs/agent-guide/media/command/deduplicated-person-desktop.png
new file mode 100644
index 0000000000..29f95898e5
Binary files /dev/null and b/docs/agent-guide/media/command/deduplicated-person-desktop.png differ
diff --git a/docs/agent-guide/media/command/deduplicated-person-mobile.png b/docs/agent-guide/media/command/deduplicated-person-mobile.png
new file mode 100644
index 0000000000..cacc28e164
Binary files /dev/null and b/docs/agent-guide/media/command/deduplicated-person-mobile.png differ
diff --git a/docs/agent-guide/navigation.md b/docs/agent-guide/navigation.md
index 41f7008128..5f35b3fbff 100644
--- a/docs/agent-guide/navigation.md
+++ b/docs/agent-guide/navigation.md
@@ -1199,11 +1199,21 @@ Typed Cmd+K **People** and **All** queries find known Macro users, including
teammates supplied by the contacts service, before their first DM and without a
CRM record or the CRM feature. Search by name or email. Selecting a person opens
their direct message; an existing one-to-one DM replaces the person row without
-losing name/email matches. Group DMs stay separate, and the viewer is excluded
+losing name/email matches, including DMs found by typed search beyond the recent
+channel list. Group DMs stay separate, and the viewer is excluded
from person results. Empty queries keep the existing recency lists. Verify a
teammate with no DM or CRM record in both categories, including with CRM disabled,
then verify that loading their DM produces one row and that Files/Channels do not
-show that person.
+show that person. Also verify a typed match whose DM is absent from the recent
+list: desktop and mobile should show one DM row, including after a same-email CRM
+contact arrives, with its alias still searchable.
+
+Duplicate-row verification: [desktop](media/command/deduplicated-person-desktop.png)
+and [phone](media/command/deduplicated-person-mobile.png) use the real command and
+mobile search views in the backend-free universal-input fixture, with a synthetic
+person and a DM available only to typed searches. All/People each show one row;
+Enter and tap select that DM through recording-only navigation adapters. These
+captures verify result composition, not a live account's cache or backend.
Browser examples: [desktop](media/command/teammate-desktop.png) and
[mobile](media/command/teammate-mobile.png), using a known-user fixture with no DM