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): find teammates before their first direct message (#8435)

gbirman567af200e9a6
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index 31c9220c04..db09d39316 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -99,6 +99,7 @@ ownership. Cancel, logout, and the ten-minute timeout retire pending callbacks.
- Mobile dock customization shares the navigation island’s measured capacity; persist ordering per user with `mobile-dock-order.ts`, preserve gated destinations, and keep Search and More fixed. Reorder handles drag without a hold delay; the rest of each row scrolls.
- Share sidebar and mobile dock unread presence through `components/app/use-navigation-unread.ts`; keep badges reactive to read/done changes and avoid fetching extra pages for counts.
- 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.
- Keep mobile search sessions, result order, loaded rows, and scroll state with their Search history entry; preserve order before opening a result so viewedAt updates cannot move it on Back. Refresh row data in place and append later pages. Scope saved rows and scroll measurements to their account and reset result adapters/scrollers on account changes. Query/category changes rerank; a fresh dock search supplies a new session ID in Search's route state, including when reusing a native pane.
- Keep Quick Access cache availability reactive to the GraphQL rollout flag; it can arrive after the provider mounts, and email has no legacy source fallback.
- Virtualize mobile name results like desktop Command Menu; local Quick Access sources are unbounded, and mounting them all stalls iOS keyboard focus during layout. Load additional search pages near the scroll end instead of reserving a paging bar.
diff --git a/apps/web/src/features/command/contact-items.ts b/apps/web/src/features/command/contact-items.ts
index 4dbeea6b88..30c1c0ff80 100644
--- a/apps/web/src/features/command/contact-items.ts
+++ b/apps/web/src/features/command/contact-items.ts
@@ -8,6 +8,7 @@ import {
toCrmContactItem,
} from '@core/context/quickAccess/crm-contacts';
import type { CrmContactEntity } from '@entity';
+import type { CommandMenuItem } from './useCommandItems';
function directMessagesByUser(
directMessages: readonly QuickAccessItem[],
@@ -25,6 +26,38 @@ function directMessagesByUser(
return byUser;
}
+/** Resolve person matches to one conversation row, retaining names and emails. */
+export function mergeCommandPeople<T extends CommandMenuItem>(
+ items: readonly T[],
+ directMessages: readonly QuickAccessItem[],
+ viewerId: string | undefined
+): (T | EntityItem)[] {
+ const conversations = directMessagesByUser(directMessages, viewerId);
+ const merged = new Map<string, T | EntityItem>();
+ for (const item of items) {
+ if (item.kind === 'user' && item.id === viewerId) continue;
+ const conversation =
+ item.kind === 'user' ? conversations.get(item.id) : undefined;
+ const resolved = conversation
+ ? {
+ ...conversation,
+ searchText: `${conversation.searchText} | ${item.searchText}`,
+ }
+ : item;
+ const previous = merged.get(resolved.id);
+ merged.set(
+ resolved.id,
+ previous
+ ? {
+ ...resolved,
+ searchText: `${previous.searchText} | ${resolved.searchText}`,
+ }
+ : resolved
+ );
+ }
+ return [...merged.values()];
+}
+
/**
* One People row per discovered contact email. A contact who is a Macro user
* becomes that person's direct message: the existing conversation when the
@@ -37,19 +70,15 @@ export function contactCommandItems(options: {
directMessages: readonly QuickAccessItem[];
viewerId: string | undefined;
}): (EntityItem | UserItem)[] {
- const conversations = directMessagesByUser(
- options.directMessages,
- options.viewerId
- );
- return resolveContactPeople(
+ const matches = resolveContactPeople(
options.contacts.map(toCrmContactItem),
options.users
).map(({ contact, user }) => {
if (!user) return contact;
- const conversation = conversations.get(user.id) ?? user;
return {
- ...conversation,
- searchText: `${conversation.searchText} | ${contact.searchText}`,
+ ...user,
+ searchText: `${user.searchText} | ${contact.searchText}`,
};
});
+ return mergeCommandPeople(matches, options.directMessages, options.viewerId);
}
diff --git a/apps/web/src/features/command/queries/entity-search.ts b/apps/web/src/features/command/queries/entity-search.ts
index 43b0290d40..ce84eab00c 100644
--- a/apps/web/src/features/command/queries/entity-search.ts
+++ b/apps/web/src/features/command/queries/entity-search.ts
@@ -7,7 +7,7 @@ import { exclude } from '@core/context/quickAccess/types';
import { useUserId } from '@core/context/user';
import { isTransientRequestError } from '@core/util/request-error';
import { type Accessor, createMemo } from 'solid-js';
-import { contactCommandItems } from '../contact-items';
+import { contactCommandItems, mergeCommandPeople } from '../contact-items';
import {
type ProjectCommandItem,
useProjectCommandItems,
@@ -59,14 +59,18 @@ export function useEntitySearch(
const quickAccess = useQuickAccess();
const searchActive = options.enabled;
const scopedSearchTerm = () => (searchActive() ? query() : '');
+ const hasQuery = createMemo(() => scopedSearchTerm().trim().length > 0);
const activeList = createMemo(() => {
if (!searchActive()) return;
const category = categoryFilter();
- const buckets =
+ let buckets =
category === 'commands'
? undefined
: QUICK_ACCESS_BUCKETS_BY_CATEGORY[category];
if (!buckets) return;
+ if ((category === 'all' || category === 'dms') && hasQuery()) {
+ buckets = [...buckets, 'person'];
+ }
return quickAccess.useList({
buckets: options.excludeEmails
? buckets.filter((bucket) => bucket !== 'email')
@@ -80,27 +84,23 @@ export function useEntitySearch(
(categoryFilter() === 'all' || categoryFilter() === 'projects');
const projects = useProjectCommandItems(scopedSearchTerm, projectEnabled);
const contactsActive = () =>
- searchActive() &&
- CONTACT_CATEGORIES.has(categoryFilter()) &&
- query().trim().length > 0;
+ searchActive() && CONTACT_CATEGORIES.has(categoryFilter()) && hasQuery();
const contacts = options?.contactDiscovery?.(
scopedSearchTerm,
contactsActive
);
- const contactPeople = contacts
- ? {
- users: quickAccess.useList('person').items,
- directMessages: quickAccess.useList('dm').items,
- viewerId: useUserId(),
- }
- : undefined;
+ const people = {
+ users: quickAccess.useList('person').items,
+ directMessages: quickAccess.useList('dm').items,
+ viewerId: useUserId(),
+ };
const contactItems = createMemo((): EntitySearchItem[] =>
- contacts && contactPeople && contactsActive()
+ contacts && contactsActive()
? contactCommandItems({
contacts: contacts.contacts(),
- users: contactPeople.users(),
- directMessages: contactPeople.directMessages(),
- viewerId: contactPeople.viewerId(),
+ users: people.users(),
+ directMessages: people.directMessages(),
+ viewerId: people.viewerId(),
})
: []
);
@@ -115,11 +115,17 @@ export function useEntitySearch(
// A contact's row keeps its CRM name searchable, so it replaces the same
// conversation listed under its own name.
const contactIds = contactItemIds();
- if (contactIds.size === 0) return items;
- return [
+ const discovered = [
...items.filter((item) => !contactIds.has(item.id)),
...contactItems(),
];
+ return CONTACT_CATEGORIES.has(categoryFilter()) && query().trim()
+ ? mergeCommandPeople(
+ discovered,
+ people.directMessages(),
+ people.viewerId()
+ )
+ : discovered;
};
const rankItems = <T extends CommandMenuItem>(
diff --git a/apps/web/src/features/command/useCommandItems.contacts.test.ts b/apps/web/src/features/command/useCommandItems.contacts.test.ts
index 7ea178c930..49a7dba444 100644
--- a/apps/web/src/features/command/useCommandItems.contacts.test.ts
+++ b/apps/web/src/features/command/useCommandItems.contacts.test.ts
@@ -1,8 +1,10 @@
+import { searchQuickAccessItems } from '@core/context/quickAccess/entity-search';
import type {
Bucket,
EntityItem,
QuickAccessItem,
QuickAccessList,
+ QuickAccessListOptions,
UserItem,
} from '@core/context/quickAccess/types';
import type { CrmContactEntity } from '@entity';
@@ -34,9 +36,16 @@ vi.mock('@app/constants/hotkeys', () => ({
}));
vi.mock('@core/context/quickAccess', () => ({
useQuickAccess: () => ({
- useList: (first: Bucket | { buckets: readonly Bucket[] }) => {
- const key = typeof first === 'string' ? first : 'category';
- const items = () => mocks.lists[key]?.() ?? [];
+ useList: (first: Bucket | QuickAccessListOptions) => {
+ const items = () => {
+ if (typeof first === 'string') return mocks.lists[first]?.() ?? [];
+ if (first.enabled && !first.enabled()) return [];
+ const buckets = Array.isArray(first.buckets) ? first.buckets : [];
+ return searchQuickAccessItems(
+ buckets.flatMap((bucket) => mocks.lists[bucket]?.() ?? []),
+ first.searchTerm?.() ?? ''
+ );
+ };
return {
items,
totalCount: () => items().length,
@@ -51,9 +60,6 @@ vi.mock('@core/context/quickAccess', () => ({
usesSearchProjection: () => false,
}),
}));
-vi.mock('@core/context/quickAccess/types', () => ({
- exclude: () => ['dm', 'note'],
-}));
vi.mock('@core/hotkey/getCommands', () => ({
getActiveCommandsFromScope: () => [],
}));
@@ -121,7 +127,7 @@ afterEach(() => {
mocks.lists = {};
});
-function setup(initialCategory: CategoryFilter = 'dms') {
+function setup(initialCategory: CategoryFilter = 'dms', crmEnabled = true) {
return createRoot((cleanup) => {
dispose = cleanup;
const [query, setQuery] = createSignal('');
@@ -131,26 +137,30 @@ function setup(initialCategory: CategoryFilter = 'dms') {
const [dms, setDms] = createSignal<EntityItem[]>([]);
const [hasMore, setHasMore] = createSignal(false);
const [loading, setLoading] = createSignal(false);
- mocks.lists = { person: users, dm: dms, category: dms };
+ mocks.lists = { person: users, dm: dms };
const discovery = {
search: undefined as Accessor<string> | undefined,
active: undefined as Accessor<boolean> | undefined,
loadMore: vi.fn(async () => {}),
};
+ const contactDiscovery = (
+ search: Accessor<string>,
+ active: Accessor<boolean>
+ ): CommandContactSource => {
+ discovery.search = search;
+ discovery.active = active;
+ return {
+ contacts: () => (active() ? contacts() : []),
+ isLoading: loading,
+ hasMore,
+ isLoadingMore: () => false,
+ error: () => undefined,
+ loadMore: discovery.loadMore,
+ };
+ };
const result = useCommandItems(query, category, {
searchActive: () => true,
- contactDiscovery: (search, active): CommandContactSource => {
- discovery.search = search;
- discovery.active = active;
- return {
- contacts: () => (active() ? contacts() : []),
- isLoading: loading,
- hasMore,
- isLoadingMore: () => false,
- error: () => undefined,
- loadMore: discovery.loadMore,
- };
- },
+ contactDiscovery: crmEnabled ? contactDiscovery : undefined,
});
return {
result,
@@ -168,6 +178,75 @@ function setup(initialCategory: CategoryFilter = 'dms') {
}
describe('command menu contact discovery', () => {
+ it.each(['all', 'dms'] as const)(
+ 'finds a teammate without a DM or CRM contact in %s, including with CRM disabled',
+ (category) => {
+ const t = setup(category, false);
+ const gabriel = user('[email protected]', 'Gabriel Birman');
+ t.setUsers([gabriel, user('[email protected]', 'Valentina')]);
+ expect(t.ids()).toEqual([]);
+
+ t.setQuery('Gabriel');
+ expect(t.ids()).toEqual([`search:${category}:Gabriel`, gabriel.id]);
+ t.setQuery('[email protected]');
+ expect(t.ids()).toEqual([
+ `search:${category}:[email protected]`,
+ gabriel.id,
+ ]);
+
+ t.setQuery('');
+ expect(t.ids()).toEqual([]);
+ t.setQuery('Gabriel');
+ t.setCategory('channels');
+ expect(t.ids()).not.toContain(gabriel.id);
+ }
+ );
+
+ it('keeps a teammate separate from group DMs and excludes the viewer', () => {
+ const t = setup('dms', false);
+ const gabriel = user('[email protected]', 'Gabriel Birman');
+ const viewer = user('[email protected]', 'Gabriel Viewer');
+ const group = directMessage('group-gabriel', 'Gabriel group', gabriel.id);
+ if (group.data.type !== 'channel') throw new Error('Expected channel');
+ group.data.participantIds = [VIEWER, gabriel.id, 'macro|[email protected]'];
+ t.setUsers([gabriel, viewer]);
+ t.setDms([group]);
+ t.setQuery('Gabriel');
+ expect(t.ids()).toContain(gabriel.id);
+ expect(t.ids()).toContain(group.id);
+ expect(t.ids()).not.toContain(viewer.id);
+ });
+
+ it.each(['all', 'dms'] as const)(
+ 'replaces a matching person with their DM when it arrives in %s',
+ (category) => {
+ const t = setup(category);
+ const gabriel = user('[email protected]', 'Gabriel Birman');
+ t.setUsers([gabriel]);
+ t.setQuery('Gabriel');
+ t.setContacts([
+ contact('crm-gabriel', 'Gabriel External', '[email protected]'),
+ ]);
+ expect(t.ids()).toEqual([
+ `search:${category}:Gabriel`,
+ gabriel.id,
+ 'crm-gabriel',
+ ]);
+
+ const dm = directMessage('dm-gabriel', 'Gabriel Birman', gabriel.id);
+ t.setDms([dm]);
+ expect(t.ids()).toEqual([
+ `search:${category}:Gabriel`,
+ dm.id,
+ 'crm-gabriel',
+ ]);
+
+ t.setQuery('[email protected]');
+ t.setContacts([]);
+ expect(t.ids()).toEqual([`search:${category}:[email protected]`, dm.id]);
+ }
+ );
+
it('lists contacts beyond the cached seed under People for a typed query', () => {
const t = setup('dms');
t.setContacts([
@@ -252,7 +331,6 @@ describe('command menu contact discovery', () => {
const asher = user('[email protected]', 'Asher Smith');
const dm = directMessage('dm-asher', 'Asher Smith', asher.id);
// People already lists the conversation; only the CRM name matches.
- mocks.lists.category = () => [dm];
t.setUsers([asher]);
t.setDms([dm]);
t.setContacts([
diff --git a/apps/web/src/features/command/useCommandItems.test.ts b/apps/web/src/features/command/useCommandItems.test.ts
index 09ab083be6..b41e64c2fe 100644
--- a/apps/web/src/features/command/useCommandItems.test.ts
+++ b/apps/web/src/features/command/useCommandItems.test.ts
@@ -37,7 +37,8 @@ vi.mock('@app/constants/hotkeys', () => ({
vi.mock('@core/context/quickAccess', () => ({
exclude: () => ['note', 'channel'],
useQuickAccess: () => ({
- useList: (options: QuickAccessListOptions) => {
+ useList: (options: Bucket | QuickAccessListOptions) => {
+ if (typeof options === 'string') return { items: () => [] };
mocks.requestedBuckets = [...options.buckets];
if (!mocks.list) throw new Error('Missing test list');
return mocks.list;
diff --git a/docs/agent-guide/media/command/teammate-desktop.png b/docs/agent-guide/media/command/teammate-desktop.png
new file mode 100644
index 0000000000..eababeffc7
Binary files /dev/null and b/docs/agent-guide/media/command/teammate-desktop.png differ
diff --git a/docs/agent-guide/media/command/teammate-mobile.png b/docs/agent-guide/media/command/teammate-mobile.png
new file mode 100644
index 0000000000..c9af29dd5d
Binary files /dev/null and b/docs/agent-guide/media/command/teammate-mobile.png differ
diff --git a/docs/agent-guide/navigation.md b/docs/agent-guide/navigation.md
index 5ab6107869..4b4d5f3954 100644
--- a/docs/agent-guide/navigation.md
+++ b/docs/agent-guide/navigation.md
@@ -841,7 +841,23 @@ notifications. External contacts insert a link to their original CRM record;
they do not invite or notify that email address. Assignee and other user-only
pickers continue to list Macro users only.
-Cmd+K **People** and a typed **All** query also find CRM contacts, using the same
+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
+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.
+
+Browser examples: [desktop](media/command/teammate-desktop.png) and
+[mobile](media/command/teammate-mobile.png), using a known-user fixture with no DM
+or CRM record and an intercepted DM request. These captures used a bundle-only
+guard for the unrelated disabled grouped-Soup startup crash in
+`create-grouped-soup-live-query.ts`; unmodified app startup remains unverified.
+
+With CRM enabled, Cmd+K **People** and a typed **All** query also find CRM contacts, using the same
accessible-team search, hidden-record exclusions, and full-email collapsing as
mentions. Cached contacts appear at once; the server search starts about 250 ms
after typing stops and pages 100 contacts at a time, so contacts beyond the first
diff --git a/docs/agent-guide/search.md b/docs/agent-guide/search.md
index 4eb575da77..0449ada790 100644
--- a/docs/agent-guide/search.md
+++ b/docs/agent-guide/search.md
@@ -15,6 +15,10 @@ own Search history entry, including while another entry is in front. Projects re
Categories filter entities directly,
independently of view tabs, mailbox selections, and saved facets. Commands and
creation shortcuts are excluded. Empty queries show recent entities.
+Typed **All** and **People** name searches also find known teammates before their
+first DM, with or without CRM. Existing one-to-one DMs replace person rows while
+preserving name/email matches; selecting a person opens their DM. Verify both
+categories with a teammate who has no conversation or CRM record.
On phones, name-result icons and avatars are scaled to 150% (16px artwork
becomes 24px), preserving row height and text alignment.