Skip to content

Commit 65cc403

Browse files
tulsi-builderBasilBotclaude
committed
fix(agents): keep the opened-from-activity transcript to one offer
Addresses review on #1830: - Close other tabs clears the profile's detail tabs without closing the profile: the workspace marks that cleanup with keepOwner, and the auto-opened transcript only closes its panel on a real close. - The profile panel asks for the transcript once per conversation, so leaving Activity for another section and returning does not reopen it. - Only a transcript known when the conversation is shown opens by itself; one a lookup finds later never takes the reader's focus or choice. - Each opened transcript keys its view, so it starts following its latest step even after the reader scrolled up in the previous one. Co-authored-by: BasilBot <399581b6165ab01343e3a1324774b1024d76942aea563468f93c975e5ee5193c@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: tulsi <[email protected]>
1 parent 44fac11 commit 65cc403

16 files changed

Lines changed: 191 additions & 97 deletions

‎src/bundled/agents/AgentDetails.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export function AgentDetails({
9292
messageAction: (variant: "glass" | "subtle") => ReactNode;
9393
conversation?: AgentConversation | undefined;
9494
initialActivity?: boolean;
95-
initialTranscript?: boolean;
95+
initialTranscript?: (() => void) | undefined;
9696
/** Closes the panel showing the agent. */
9797
close?: () => void;
9898
communities?: CommunityReader | undefined;

‎src/bundled/agents/AgentTabs.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function AgentTabs(props: {
2727
settingsContent: ReactNode;
2828
conversation?: AgentConversation | undefined;
2929
initialActivity?: boolean | undefined;
30-
initialTranscript?: boolean | undefined;
30+
initialTranscript?: (() => void) | undefined;
3131
close?: (() => void) | undefined;
3232
onDiscard?: () => void;
3333
}) {

‎src/bundled/claude-code/tabs.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ it("opens the conversation's transcript when opened from its activity, once", as
376376
agent={agent()}
377377
save={vi.fn()}
378378
conversation={conversation}
379-
initialTranscript
379+
initialTranscript={() => undefined}
380380
/>,
381381
);
382382
const user = userEvent.setup();

‎src/bundled/claude-code/tabs.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ export function createTabs({
738738
const { open, show, back } = useOpenTranscript(
739739
conversation,
740740
label,
741-
initialTranscript ? here : undefined,
741+
initialTranscript && { initial: here, done: initialTranscript },
742742
close,
743743
);
744744
return (
@@ -812,6 +812,7 @@ export function createTabs({
812812
onBack={back}
813813
>
814814
<TranscriptView
815+
key={open.key}
815816
agent={agent}
816817
conversation={open}
817818
working={busy.get(open.key) ?? false}

‎src/bundled/codex/tabs.test.tsx‎

Lines changed: 70 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from "@testing-library/react";
1717
import { StrictMode } from "react";
1818
import userEvent from "@testing-library/user-event";
19-
import { afterEach, beforeEach, expect, it, vi } from "vitest";
19+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2020
import { pubkeyOf } from "../../features/agents/membership";
2121
import { ownerReads } from "../../features/agents/reads";
2222
import {
@@ -384,48 +384,78 @@ it("brings an open transcript's tab back, and closes it when the profile moves",
384384
expect(tab(transcript)).toHaveAttribute("aria-selected", "true");
385385
});
386386

387-
it("opened from activity, shows the transcript, and closing it closes the panel", async () => {
387+
describe("opened from activity", () => {
388388
const root = "e".repeat(64);
389-
const f = fixture({
390-
saved: {
391-
[JSON.stringify(["channel", root])]: {
392-
threadId: "kept",
393-
workspace: "/w",
394-
at: 2,
389+
const transcript = "#general · thread eeeeeeee";
390+
const opened = () => {
391+
const f = fixture({
392+
saved: {
393+
[JSON.stringify(["channel", root])]: {
394+
threadId: "kept",
395+
workspace: "/w",
396+
at: 2,
397+
},
395398
},
396-
},
399+
});
400+
const close = vi.fn();
401+
const done = vi.fn();
402+
const panel = (initialTranscript?: () => void) => (
403+
<PanelWorkspace
404+
value="profile"
405+
select={() => undefined}
406+
tabMenu={{
407+
key: "channel",
408+
closeAll: () => false,
409+
closeOthers: () => false,
410+
}}
411+
items={[
412+
{
413+
id: "profile",
414+
label: "Sol",
415+
close: () => undefined,
416+
content: (
417+
<f.tabs.ActivityTab
418+
{...f.props()}
419+
conversation={{ channelId: "channel", rootId: root }}
420+
{...(initialTranscript && { initialTranscript })}
421+
close={close}
422+
/>
423+
),
424+
},
425+
]}
426+
/>
427+
);
428+
return { close, done, panel };
429+
};
430+
431+
it("shows the transcript, and closing it closes the panel", async () => {
432+
const { close, done, panel } = opened();
433+
render(panel(done));
434+
expect(
435+
await screen.findByRole("tab", { name: transcript }),
436+
).toHaveAttribute("aria-selected", "true");
437+
expect(done).toHaveBeenCalled();
438+
await userEvent.click(
439+
screen.getByRole("button", { name: `Close ${transcript} tab` }),
440+
);
441+
expect(close).toHaveBeenCalledOnce();
442+
});
443+
444+
it("keeps the panel when the profile's other tabs are closed", async () => {
445+
const user = userEvent.setup();
446+
const { close, done, panel } = opened();
447+
render(panel(done));
448+
await screen.findByRole("tab", { name: transcript });
449+
await user.pointer({
450+
target: screen.getByRole("tab", { name: "Sol" }),
451+
keys: "[MouseRight]",
452+
});
453+
await user.click(
454+
await screen.findByRole("menuitem", { name: "Close other tabs" }),
455+
);
456+
expect(screen.queryByRole("tab", { name: transcript })).toBeNull();
457+
expect(close).not.toHaveBeenCalled();
397458
});
398-
const close = vi.fn();
399-
render(
400-
<PanelWorkspace
401-
value="profile"
402-
select={() => undefined}
403-
items={[
404-
{
405-
id: "profile",
406-
label: "Sol",
407-
close: () => undefined,
408-
content: (
409-
<f.tabs.ActivityTab
410-
{...f.props()}
411-
conversation={{ channelId: "channel", rootId: root }}
412-
initialTranscript
413-
close={close}
414-
/>
415-
),
416-
},
417-
]}
418-
/>,
419-
);
420-
const transcript = "#general · thread eeeeeeee";
421-
expect(await screen.findByRole("tab", { name: transcript })).toHaveAttribute(
422-
"aria-selected",
423-
"true",
424-
);
425-
await userEvent.click(
426-
screen.getByRole("button", { name: `Close ${transcript} tab` }),
427-
);
428-
expect(close).toHaveBeenCalledOnce();
429459
});
430460

431461
it("finds the thread's Codex session another build started", async () => {

‎src/bundled/codex/tabs.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ export function createTabs(
839839
const { open, show, back } = useOpenTranscript(
840840
conversation,
841841
label,
842-
initialTranscript ? here : undefined,
842+
initialTranscript && { initial: here, done: initialTranscript },
843843
close,
844844
);
845845
const saved = new Set(conversations.map((row) => row.key));
@@ -944,7 +944,7 @@ export function createTabs(
944944
backLabel="Back to profile"
945945
onBack={back}
946946
>
947-
<TranscriptView agent={agent} conversation={open} />
947+
<TranscriptView key={open.key} agent={agent} conversation={open} />
948948
</PanelSubview>
949949
)}
950950
</div>

‎src/bundled/goose/tabs.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ export function createTabs({
869869
const { open, show, back } = useOpenTranscript(
870870
conversation,
871871
label,
872-
initialTranscript ? here : undefined,
872+
initialTranscript && { initial: here, done: initialTranscript },
873873
close,
874874
);
875875
const rows = (recent.value ?? [])
@@ -964,6 +964,7 @@ export function createTabs({
964964
onBack={back}
965965
>
966966
<TranscriptView
967+
key={open.key}
967968
agent={agent}
968969
row={open}
969970
working={busy(open.sessionId) ? open.sessionId : undefined}

‎src/bundled/pi/tabs.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ export function createTabs({
762762
const { open, show, back } = useOpenTranscript(
763763
conversation,
764764
label,
765-
initialTranscript ? here : undefined,
765+
initialTranscript && { initial: here, done: initialTranscript },
766766
close,
767767
);
768768
const recent = places
@@ -832,6 +832,7 @@ export function createTabs({
832832
onBack={back}
833833
>
834834
<TranscriptView
835+
key={open.key}
835836
agent={agent}
836837
place={open}
837838
working={working.includes(open.conversation)}

‎src/bundled/profiles/ProfilePanel.test.tsx‎

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { stubAvatarBrowserApis } from "../../features/agents/avatar-testing";
44
stubAvatarBrowserApis();
55
import userEvent from "@testing-library/user-event";
66
import { act, cleanup, render, screen, waitFor } from "@testing-library/react";
7+
import { useEffect, useState } from "react";
78
import { afterEach, expect, it, vi } from "vitest";
89
import { createRelaySession } from "../../features/relay/session";
910
import type { RelayData } from "../../features/relay/service";
@@ -371,24 +372,29 @@ function renderAgentActivity(
371372
id: title.toLowerCase(),
372373
title,
373374
role,
374-
component: ({
375+
component: function Echo({
375376
conversation,
376377
initialTranscript,
377378
}: {
378379
conversation?: { channelId: string; rootId?: string };
379-
initialTranscript?: boolean;
380-
}) => (
381-
<>
382-
<p>Echo {title.toLowerCase()}</p>
383-
{initialTranscript && <p>Transcript first</p>}
384-
{conversation && (
385-
<p>
386-
Opened from {conversation.channelId}/
387-
{conversation.rootId ?? "channel"}
388-
</p>
389-
)}
390-
</>
391-
),
380+
initialTranscript?: () => void;
381+
}) {
382+
// Like a type's Activity tab: it acts on the request as it shows.
383+
const [first] = useState(!!initialTranscript);
384+
useEffect(() => initialTranscript?.(), [initialTranscript]);
385+
return (
386+
<>
387+
<p>Echo {title.toLowerCase()}</p>
388+
{first && <p>Transcript first</p>}
389+
{conversation && (
390+
<p>
391+
Opened from {conversation.channelId}/
392+
{conversation.rootId ?? "channel"}
393+
</p>
394+
)}
395+
</>
396+
);
397+
},
392398
})),
393399
} as unknown as RegisteredAgentType;
394400
const agent = {
@@ -476,6 +482,27 @@ it("asks the Activity tab for its transcript only when the opener knows the conv
476482
}
477483
});
478484

485+
it("asks for the transcript once, not again on returning from another section", async () => {
486+
const dispose = renderAgentActivity(
487+
[
488+
{ title: "Settings", role: "settings" },
489+
{ title: "Activity", role: "activity" },
490+
],
491+
"thread-root",
492+
true,
493+
);
494+
try {
495+
expect(screen.getByText("Transcript first")).toBeVisible();
496+
const user = userEvent.setup();
497+
await user.click(screen.getByRole("tab", { name: "Identity" }));
498+
await user.click(screen.getByRole("tab", { name: "Activity" }));
499+
expect(screen.getByText("Echo activity")).toBeVisible();
500+
expect(screen.queryByText("Transcript first")).toBeNull();
501+
} finally {
502+
dispose();
503+
}
504+
});
505+
479506
it("opens an agent's activity on its type's first tab when the type has no Activity tab", () => {
480507
const dispose = renderAgentActivity([
481508
{ title: "Settings", role: "settings" },

‎src/bundled/profiles/ProfilePanel.tsx‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ export function ProfilePanel({
7676
const activityKey = profileActivityViewKey(target);
7777
const transcript = profileActivityTranscript(target);
7878
const opening = transcript ? "transcript" : activityKey ? "activity" : "info";
79+
// Asked once per conversation: changing sections must not reopen it.
80+
const place = context ? `${context.channelId}/${context.rootId ?? ""}` : "";
81+
const [asked, setAsked] = useState<string>();
82+
const initialTranscript =
83+
transcript && asked !== place ? () => setAsked(place) : undefined;
7984
const pubkey = profilePanelKey(target) ?? activityKey;
8085
const owned = useAgent(agents, pubkey ?? "");
8186
if (!pubkey) return <p>Unsupported profile.</p>;
@@ -94,7 +99,7 @@ export function ProfilePanel({
9499
agents={agents}
95100
communities={communities}
96101
initialActivity={!!activityKey}
97-
initialTranscript={transcript}
102+
initialTranscript={initialTranscript}
98103
pubkey={pubkey}
99104
relay={relay}
100105
session={connection.session}
@@ -107,7 +112,7 @@ export function ProfilePanel({
107112
<ProfileDetails
108113
key={`${connection.scope}:${connection.generation}:${pubkey}:${opening}`}
109114
initialTab={activityKey ? "activity" : "info"}
110-
initialTranscript={transcript}
115+
initialTranscript={initialTranscript}
111116
session={connection.session}
112117
pubkey={pubkey}
113118
agentHint={profileAgentHint(target) || !!activityKey}
@@ -136,7 +141,7 @@ function OwnedAgentProfile({
136141
agents: Agents;
137142
communities: CommunityReader | undefined;
138143
initialActivity: boolean;
139-
initialTranscript: boolean;
144+
initialTranscript: (() => void) | undefined;
140145
pubkey: string;
141146
relay: RelayData;
142147
session: RelaySession;
@@ -197,7 +202,7 @@ function ProfileDetails({
197202
agents: Agents | undefined;
198203
communities: CommunityReader | undefined;
199204
initialTab: "info" | "activity";
200-
initialTranscript: boolean;
205+
initialTranscript: (() => void) | undefined;
201206
agentHint: boolean;
202207
session: RelaySession;
203208
pubkey: string;

0 commit comments

Comments
 (0)