diff --git a/docs/buzz-help.md b/docs/buzz-help.md index bb2699f505..cf354e7100 100644 --- a/docs/buzz-help.md +++ b/docs/buzz-help.md @@ -1454,6 +1454,13 @@ even when no session is connected; it asks you to confirm first. Full access req On desktop, **Connect [agent name]** may appear inside a DM with an old agent you own that is available to import from this computer. It preselects compatible saved harness, provider and model choices, and preserves saved effort settings. Choose another harness if the old type is unavailable or does not support inline connection setup; settings that were not saved use the selected type’s defaults. Review the inline controls; **Connect** stays disabled until the harness has a resolved model and provider, including usable defaults. If a saved Codex model is unavailable, choose another model or harness to continue. Complete installation or sign-in if prompted, stop the agent in old Buzz, then choose **Connect**. Your agent keeps its identity and conversation. This does not resend earlier messages. The same private card can appear in a channel or thread after you send a new mention of an eligible agent you own while that conversation is open, if that agent is still a member of the channel. Loading older mentions does not show cards, and known-archived agents are excluded. Only you see it, once per agent in the loaded conversation. Choose the **X** in the card’s top-right corner to hide that agent’s card in this conversation; the dismissal survives reopening and reloads. After connecting, **Ask the agent to respond** explicitly queues a follow-up addressed only to that agent in the original message’s thread; it does not automatically replay your request. If no prompt appears, use **Agents → New agent → Import an agent**. +## Choosing a channel for a workflow + +When creating a workflow, direct-message choices use participant names when available. Search +matches the displayed participant name. When no participant name is available, Buzz shows a short +public-key prefix. A direct message with yourself is labeled **Notes to self**. +These labels only help identify the conversation you select. + ## Deleting an agent’s workflow In **Workflows → Owner → All channel workflows**, open the workflow’s actions diff --git a/src/bundled/channels/useChannelLabels.ts b/src/bundled/channels/useChannelLabels.ts index 21e0e6489a..baedbcd63f 100644 --- a/src/bundled/channels/useChannelLabels.ts +++ b/src/bundled/channels/useChannelLabels.ts @@ -6,11 +6,12 @@ import type { ProfileQueries } from "../../features/relay/profile-directory"; import { selectProfiles } from "../../features/relay/profile-selection"; import { sortParticipantNames } from "../../features/identity-names/participant-order"; -/** Visible labels share the session's bounded profile directory, not per-row fetches. */ +/** Share bounded profiles, not per-row fetches; pickers may widen the name scope. */ export function useChannelLabels( roster: readonly ChannelSummary[], queries: ProfileQueries, names?: IdentityNameView, + nameCandidates?: readonly string[], ) { const resolveName = useIdentityNames(names); const channels = useMemo( @@ -63,6 +64,7 @@ export function useChannelLabels( channel: ChannelSummary; profiles: typeof profiles; resolveName: typeof resolveName; + nameCandidates: typeof nameCandidates; } >(), ); @@ -75,7 +77,8 @@ export function useChannelLabels( const previous = labelled.current.get(channel); if ( previous?.profiles === profiles && - previous.resolveName === resolveName + previous.resolveName === resolveName && + previous.nameCandidates === nameCandidates ) return previous.channel; const name = channel.participants.length @@ -84,7 +87,7 @@ export function useChannelLabels( resolveName( id, profiles.get(id)?.name ?? id.slice(0, 10), - channel.participants, + nameCandidates ?? channel.participants, ), ), ).join(", ") @@ -96,10 +99,11 @@ export function useChannelLabels( channel: result, profiles, resolveName, + nameCandidates, }); return result; }), - [channels, profiles, resolveName], + [channels, profiles, resolveName, nameCandidates], ); return { channels: labelledChannels, profiles }; } diff --git a/src/bundled/workflows/WorkflowChannelPicker.test.tsx b/src/bundled/workflows/WorkflowChannelPicker.test.tsx index 8bfc248ede..4986dbb0f5 100644 --- a/src/bundled/workflows/WorkflowChannelPicker.test.tsx +++ b/src/bundled/workflows/WorkflowChannelPicker.test.tsx @@ -1,13 +1,297 @@ // @vitest-environment jsdom import "@testing-library/jest-dom/vitest"; -import { cleanup, render, screen } from "@testing-library/react"; +import { act, cleanup, render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { afterEach, expect, it, vi } from "vitest"; -import type { ChannelSummary } from "../../features/relay/contracts"; +import type { ChannelSummary, Profile } from "../../features/relay/contracts"; +import type { IdentityNameView } from "../../features/identity-names/service"; +import type { ProfileQueries } from "../../features/relay/profile-directory"; import { WorkflowChannelPicker } from "./WorkflowChannelPicker"; afterEach(cleanup); +type TestProfileQueries = ProfileQueries & { + setSnapshot(profiles: ReadonlyMap): void; +}; + +function profileQueries( + initial: ReadonlyMap = new Map(), + ensure: ProfileQueries["ensure"] = async () => {}, +): TestProfileQueries { + let profiles = initial; + const listeners = new Set<() => void>(); + return { + snapshot: () => profiles, + subscribe(listener: () => void) { + listeners.add(listener); + return () => listeners.delete(listener); + }, + ensure: vi.fn(ensure), + setSnapshot(next: ReadonlyMap) { + profiles = next; + for (const listener of listeners) listener(); + }, + } as unknown as TestProfileQueries; +} + +it("shows and selects a DM by its participant label without changing its ID", async () => { + const user = userEvent.setup(); + const onSelect = vi.fn(); + const alice = "a".repeat(64); + render( + , + ); + + const input = screen.getByRole("combobox", { name: "Choose a channel" }); + await user.click(input); + const option = await screen.findByRole("option", { name: "Alice" }); + expect(option).toBeVisible(); + await user.click(option); + + expect(input).toHaveValue("Alice"); + expect(onSelect).toHaveBeenCalledExactlyOnceWith("dm-id"); +}); + +it("searches for a DM by its participant label", async () => { + const user = userEvent.setup(); + const onSelect = vi.fn(); + const alice = "a".repeat(64); + render( + , + ); + + const input = screen.getByRole("combobox", { name: "Choose a channel" }); + await user.type(input, "Alice"); + const option = await screen.findByRole("option", { name: "Alice" }); + expect(option).toHaveAttribute("data-highlighted"); + await user.keyboard("{Enter}"); + + expect(onSelect).toHaveBeenCalledExactlyOnceWith("dm-id"); +}); + +it("uses the shared identity name when it differs from the profile name", async () => { + const user = userEvent.setup(); + const participant = "d".repeat(64); + const names = { + resolve: (id: string, fallback?: string) => + id === participant ? "Friendly Name" : fallback, + snapshot: () => 0, + subscribe: () => () => {}, + } as unknown as IdentityNameView; + const onSelect = vi.fn(); + render( + , + ); + + const input = screen.getByRole("combobox", { name: "Choose a channel" }); + await user.type(input, "Friendly Name"); + expect( + await screen.findByRole("option", { name: "Friendly Name" }), + ).toHaveAttribute("data-highlighted"); + await user.keyboard("{Enter}"); + + expect(onSelect).toHaveBeenCalledExactlyOnceWith("named-dm-id"); +}); + +it("disambiguates and searches DM names across all eligible choices", async () => { + const user = userEvent.setup(); + const first = "a".repeat(64); + const second = "b".repeat(64); + const names = { + resolve: ( + id: string, + fallback?: string, + candidates?: readonly string[], + ) => { + if (id === first || id === second) { + const other = id === first ? second : first; + return candidates?.includes(other) + ? `Alex · ${id.slice(-4)}` + : (fallback ?? "Alex"); + } + return fallback; + }, + snapshot: () => 0, + subscribe: () => () => {}, + } as unknown as IdentityNameView; + const onSelect = vi.fn(); + + render( + , + ); + + const input = screen.getByRole("combobox", { name: "Choose a channel" }); + expect( + await screen.findByRole("option", { name: "Alex · aaaa" }), + ).toBeVisible(); + expect( + await screen.findByRole("option", { name: "Alex · bbbb" }), + ).toBeVisible(); + + await user.type(input, "Alex · bbbb"); + expect( + await screen.findByRole("option", { name: "Alex · bbbb" }), + ).toHaveAttribute("data-highlighted"); + await user.keyboard("{Enter}"); + + expect(input).toHaveValue("Alex · bbbb"); + expect(onSelect).toHaveBeenCalledExactlyOnceWith("second-dm-id"); +}); + +it("shows fallbacks during profile loading and keeps them searchable", async () => { + const user = userEvent.setup(); + const missing = "c".repeat(64); + let releaseFetch!: () => void; + let startFetch!: () => void; + const pendingFetch = new Promise((resolve) => { + releaseFetch = resolve; + }); + const fetchStarted = new Promise((resolve) => { + startFetch = resolve; + }); + const queries = profileQueries(new Map(), async () => { + startFetch(); + await pendingFetch; + }); + const onSelect = vi.fn(); + try { + render( + , + ); + + await fetchStarted; + expect( + await screen.findByRole("option", { name: missing.slice(0, 10) }), + ).toBeVisible(); + expect(screen.getByRole("option", { name: "Notes to self" })).toBeVisible(); + expect(screen.getByRole("option", { name: "hidden-stream" })).toBeVisible(); + + const input = screen.getByRole("combobox", { name: "Choose a channel" }); + await user.type(input, missing.slice(0, 10)); + expect( + await screen.findByRole("option", { name: missing.slice(0, 10) }), + ).toHaveAttribute("data-highlighted"); + await user.clear(input); + + releaseFetch(); + await pendingFetch; + expect( + await screen.findByRole("option", { name: missing.slice(0, 10) }), + ).toBeVisible(); + await user.type(input, missing.slice(0, 10)); + expect( + await screen.findByRole("option", { name: missing.slice(0, 10) }), + ).toHaveAttribute("data-highlighted"); + await user.clear(input); + + act(() => queries.setSnapshot(new Map([[missing, { name: "Casey" }]]))); + expect(await screen.findByRole("option", { name: "Casey" })).toBeVisible(); + + await user.type(input, "Notes to self"); + expect( + await screen.findByRole("option", { name: "Notes to self" }), + ).toHaveAttribute("data-highlighted"); + await user.clear(input); + + await user.type(input, "Casey"); + expect( + await screen.findByRole("option", { name: "Casey" }), + ).toHaveAttribute("data-highlighted"); + await user.keyboard("{Enter}"); + expect(input).toHaveValue("Casey"); + expect(onSelect).toHaveBeenCalledExactlyOnceWith("missing-profile-dm"); + } finally { + releaseFetch(); + await pendingFetch; + } +}); + it("picks the first matching channel with Enter, without an arrow key", async () => { const user = userEvent.setup(); const onSelect = vi.fn(); @@ -19,6 +303,7 @@ it("picks the first matching channel with Enter, without an arrow key", async () channel("2", "design-reviews"), channel("3", "design"), ]} + profiles={profileQueries()} onSelect={onSelect} />, ); @@ -40,6 +325,7 @@ it("ranks an exact name before a longer one that contains it", async () => { { id: "1", name: "dev-general" }, { id: "2", name: "general" }, ]} + profiles={profileQueries()} onSelect={onSelect} />, ); @@ -58,6 +344,7 @@ it("does not pick a channel with Enter before anything is typed", async () => { render( , ); diff --git a/src/bundled/workflows/WorkflowChannelPicker.tsx b/src/bundled/workflows/WorkflowChannelPicker.tsx index 4a88fc1f1c..52eeaaaac9 100644 --- a/src/bundled/workflows/WorkflowChannelPicker.tsx +++ b/src/bundled/workflows/WorkflowChannelPicker.tsx @@ -3,32 +3,69 @@ import type { ChannelSummary } from "../../features/relay/contracts"; import { matchName } from "../../features/search/match"; import { Combobox } from "../../shared/design-system/ui/Combobox"; import { channelIcon } from "../../features/channels/channel-icon"; +import { useChannelLabels } from "../channels/useChannelLabels"; +import type { ProfileQueries } from "../../features/relay/profile-directory"; +import type { IdentityNameView } from "../../features/identity-names/service"; export function WorkflowChannelPicker({ channels, + profiles, + names, onSelect, }: { channels: readonly ChannelSummary[]; + profiles: ProfileQueries; + names?: IdentityNameView; onSelect: (id: string) => void; }) { const [typed, setTyped] = useState(""); + const nameCandidates = useMemo( + () => + [ + ...new Set( + channels.flatMap((channel) => + channel.channelType === "dm" ? (channel.participants ?? []) : [], + ), + ), + ].sort(), + [channels], + ); + const labelled = useChannelLabels( + channels, + profiles, + names, + nameCandidates, + ).channels; + // useChannelLabels owns DM naming, but its visibility rules are for channel + // lists; keep the workflow picker's existing eligible set unchanged. + const choices = useMemo(() => { + const labels = new Map( + labelled.map((channel) => [channel.id, channel.name]), + ); + return channels.map((channel) => { + const name = labels.get(channel.id); + return name === undefined || name === channel.name + ? channel + : { ...channel, name }; + }); + }, [channels, labelled]); // Order matches as the other pickers do, so Enter on the highlighted first // row picks an exact name before a longer one that contains it. const matches = useMemo(() => { const needle = typed.trim().toLowerCase(); - if (!needle) return channels; - return channels + if (!needle) return choices; + return choices .flatMap((channel) => { const rank = matchName(channel.name, needle)?.rank; return rank === undefined ? [] : [{ channel, rank }]; }) .sort((a, b) => a.rank - b.rank) .map(({ channel }) => channel); - }, [channels, typed]); + }, [choices, typed]); return (
channel.name} diff --git a/src/bundled/workflows/WorkflowsPage.tsx b/src/bundled/workflows/WorkflowsPage.tsx index 0c05df3ff5..a34932e6e3 100644 --- a/src/bundled/workflows/WorkflowsPage.tsx +++ b/src/bundled/workflows/WorkflowsPage.tsx @@ -359,6 +359,8 @@ export function WorkflowCommunity({ scope={ { setCreateOpen(false); openChannel(id, "new");