Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/buzz-help.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions src/bundled/channels/useChannelLabels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -63,6 +64,7 @@ export function useChannelLabels(
channel: ChannelSummary;
profiles: typeof profiles;
resolveName: typeof resolveName;
nameCandidates: typeof nameCandidates;
}
>(),
);
Expand All @@ -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
Expand All @@ -84,7 +87,7 @@ export function useChannelLabels(
resolveName(
id,
profiles.get(id)?.name ?? id.slice(0, 10),
channel.participants,
nameCandidates ?? channel.participants,
),
),
).join(", ")
Expand All @@ -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 };
}
291 changes: 289 additions & 2 deletions src/bundled/workflows/WorkflowChannelPicker.test.tsx
Original file line number Diff line number Diff line change
@@ -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<string, Profile>): void;
};

function profileQueries(
initial: ReadonlyMap<string, Profile> = 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<string, Profile>) {
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(
<WorkflowChannelPicker
channels={[
{
id: "dm-id",
name: "private-conversation",
channelType: "dm",
participants: [alice],
},
]}
profiles={profileQueries(new Map([[alice, { name: "Alice" }]]))}
onSelect={onSelect}
/>,
);

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(
<WorkflowChannelPicker
channels={[
{
id: "dm-id",
name: "private-conversation",
channelType: "dm",
participants: [alice],
},
{ id: "channel-id", name: "general" },
]}
profiles={profileQueries(new Map([[alice, { name: "Alice" }]]))}
onSelect={onSelect}
/>,
);

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(
<WorkflowChannelPicker
channels={[
{
id: "named-dm-id",
name: "raw-dm-name",
channelType: "dm",
participants: [participant],
},
]}
profiles={profileQueries(
new Map([[participant, { name: "Profile Name" }]]),
)}
names={names}
onSelect={onSelect}
/>,
);

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(
<WorkflowChannelPicker
channels={[
{
id: "first-dm-id",
name: "raw-first-name",
channelType: "dm",
participants: [first],
},
{
id: "second-dm-id",
name: "raw-second-name",
channelType: "dm",
participants: [second],
},
]}
profiles={profileQueries(
new Map([
[first, { name: "Alex" }],
[second, { name: "Alex" }],
]),
)}
names={names}
onSelect={onSelect}
/>,
);

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<void>((resolve) => {
releaseFetch = resolve;
});
const fetchStarted = new Promise<void>((resolve) => {
startFetch = resolve;
});
const queries = profileQueries(new Map(), async () => {
startFetch();
await pendingFetch;
});
const onSelect = vi.fn();
try {
render(
<WorkflowChannelPicker
channels={
[
{
id: "missing-profile-dm",
name: "raw-dm-name",
channelType: "dm",
participants: [missing],
hidden: true,
},
{
id: "self-dm",
name: "raw-self-name",
channelType: "dm",
participants: [],
},
{
id: "hidden-channel",
name: "hidden-stream",
channelType: "stream",
hidden: true,
},
] satisfies readonly ChannelSummary[]
}
profiles={queries}
onSelect={onSelect}
/>,
);

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();
Expand All @@ -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}
/>,
);
Expand All @@ -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}
/>,
);
Expand All @@ -58,6 +344,7 @@ it("does not pick a channel with Enter before anything is typed", async () => {
render(
<WorkflowChannelPicker
channels={[{ id: "1", name: "general" }]}
profiles={profileQueries()}
onSelect={onSelect}
/>,
);
Expand Down
Loading
Loading