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
28 changes: 28 additions & 0 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ import {
makeThreadErrorSetter,
} from "./ChatView.logic";

const activityCollapsedThreadsSchema = Schema.NullOr(
Schema.Record(Schema.String, Schema.Boolean),
);

const EMPTY_SEEN_MESSAGES: ReadonlyArray<SeenMessage> = [];
const EMPTY_PROVIDERS: ServerProvider[] = [];
const EMPTY_PROVIDER_MODELS: ServerProvider["models"] = [];
Expand Down Expand Up @@ -1818,6 +1822,24 @@ export default function ChatView(props: ChatViewProps) {
selectThreadPanelOpen(state.threadPanelVisibilityByThreadKey, activeThreadRef, "inline"),
);
const isStandingBot = activeStanding !== null;
// A coordinator thread buries the founder under agent relays, so those collapse
// until he asks for everything. Remembered per thread; ordinary threads stay flat.
const [activityCollapsedThreads, setActivityCollapsedThreads] = useLocalStorage(
"t3code:activity-collapsed-threads",
null,
activityCollapsedThreadsSchema,
);
const activityCollapsed =
activeThreadKey === null ||
activityCollapsedThreads === null ||
activityCollapsedThreads[activeThreadKey] !== false;
const toggleActivityCollapsed = () => {
if (activeThreadKey === null) return;
setActivityCollapsedThreads((stored) => ({
...stored,
[activeThreadKey]: !activityCollapsed,
}));
};
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- folds a bot's details card (branch, worktree, PR) the first time this client shows that bot; the panel toggle reopens it and that choice persists
useEffect(() => {
if (!isStandingBot || !activeThreadRef || !activeThreadKey) return;
Expand Down Expand Up @@ -3425,6 +3447,11 @@ export default function ChatView(props: ChatViewProps) {
: {})}
{...(threadFindEnabled ? { onFindInThread: openThreadFindStable } : {})}
standing={activeStanding}
activityCollapsed={
isStandingBot && activeThreadKey !== null
? { on: activityCollapsed, onToggle: toggleActivityCollapsed }
: null
}
/>
</header>
)}
Expand Down Expand Up @@ -3482,6 +3509,7 @@ export default function ChatView(props: ChatViewProps) {
entriesInput={timelineEntriesInput}
draftEntries={isServerThread ? null : draftTimelineEntries}
activeThreadKey={activeThreadKey}
collapseActivity={isStandingBot && activityCollapsed}
syncing={threadSyncPhase !== null}
detailLoading={threadDetailLoading}
citationRequest={citationRequest}
Expand Down
47 changes: 47 additions & 0 deletions apps/web/src/components/chat/ChatHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ interface ChatHeaderProps {
onFindInThread?: ((threadRef: ScopedThreadRef) => void) | undefined;
/** A standing bot shows who it is instead of the project/thread breadcrumb. */
standing?: ThreadStanding | null | undefined;
/**
* Collapse agent, automation and system activity, or null when the thread has
* no toggle. A standing thread passes it.
*/
activityCollapsed?: { readonly on: boolean; readonly onToggle: () => void } | null | undefined;
}

function resolveRenameCommit(input: {
Expand All @@ -87,6 +92,7 @@ export const ChatHeader = memo(function ChatHeader({
onOpenProjectSettings,
onFindInThread,
standing,
activityCollapsed = null,
}: ChatHeaderProps) {
const activeProjectName = activeProject?.isScratch ? "No project" : activeProject?.title;
const activeProjectCwd = activeProject?.workspaceRoot ?? null;
Expand Down Expand Up @@ -282,6 +288,7 @@ export const ChatHeader = memo(function ChatHeader({
</span>
) : null}
<span className="flex-1" />
<ActivityViewToggle collapsed={activityCollapsed} />
{isServerThread ? <GuestShareIndicator threadRef={activeThreadRef} /> : null}
</div>
);
Expand Down Expand Up @@ -439,6 +446,46 @@ export const ChatHeader = memo(function ChatHeader({
</WorkspaceBreadcrumbItem>
</WorkspaceBreadcrumb>
{isServerThread ? <GuestShareIndicator threadRef={activeThreadRef} /> : null}
<ActivityViewToggle collapsed={activityCollapsed} />
</div>
);
});

/**
* Switches the timeline between the founder's conversation and everything that
* happened in the thread. Absent when the thread has nothing to collapse.
*/
function ActivityViewToggle({
collapsed,
}: {
collapsed: { readonly on: boolean; readonly onToggle: () => void } | null;
}) {
if (collapsed === null) return null;
const label = collapsed.on ? "Human conversation" : "All activity";
return (
<Tooltip>
<TooltipTrigger
render={
<button
type="button"
aria-pressed={collapsed.on}
onClick={collapsed.onToggle}
className={cn(
"shrink-0 cursor-pointer rounded-full border px-2 py-0.5 text-xs transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
collapsed.on
? "border-border bg-muted/60 text-foreground hover:bg-muted"
: "border-transparent text-muted-foreground hover:text-foreground",
)}
/>
}
>
{label}
</TooltipTrigger>
<TooltipPopup side="bottom">
{collapsed.on
? "Agent, automation and system updates are collapsed. Click to show everything."
: "Showing everything. Click to keep only your messages and the replies to them."}
</TooltipPopup>
</Tooltip>
);
}
183 changes: 182 additions & 1 deletion apps/web/src/components/chat/MessagesTimeline.logic.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ThreadId, type WorktreeSetupSnapshot } from "@t3tools/contracts";
import { ScheduledTaskId, ThreadId, type WorktreeSetupSnapshot } from "@t3tools/contracts";
import {
CheckpointRef,
NodeId,
Expand Down Expand Up @@ -30,6 +30,9 @@ import {
computeStableMessagesTimelineRows,
deriveMessagesTimelineRows,
filterTimelineRowsBySender,
collapseTimelineActivity,
activityUpdateSummary,
activityPillIdForEntry,
timelineTurnFoldRunIdsByEntryId,
liveAnswerPreview,
deriveMessagesTimelineRowsWithState,
Expand Down Expand Up @@ -5223,3 +5226,181 @@ describe("message senders in the timeline", () => {
expect(kameron[1]).toMatchObject({ groupedWithPrevious: false });
});
});

describe("collapsing non-human activity", () => {
const runId = RunId.make("activity-run");
const time = (second: number) => new Date(Date.UTC(2026, 0, 2, 0, 0, second)).toISOString();
const messageRow = (
id: string,
second: number,
extra: Record<string, unknown> = {},
): MessagesTimelineRow => ({
kind: "message",
id,
createdAt: time(second),
showAssistantMeta: false,
showAssistantCopyButton: false,
assistantCopyStreaming: false,
message: {
id: MessageId.make(id),
role: "user",
text: id,
runId,
createdAt: time(second),
updatedAt: time(second),
streaming: false,
...extra,
},
});
const workRow = (id: string, second: number): MessagesTimelineRow => ({
kind: "work",
id,
createdAt: time(second),
groupedEntries: [],
isExpandedToolGroup: false,
});
const person = (founder: "kameron" | "jeff") => ({
sentBy: {
sessionId: AuthSessionId.make(`session:${founder}`),
device: "laptop",
deviceType: "desktop" as const,
founder,
},
});
const rows: MessagesTimelineRow[] = [
messageRow("kameron", 0, person("kameron")),
messageRow("reply", 1, { role: "assistant" }),
messageRow("agent-1", 2, { createdBy: "agent", senderThreadId: ThreadId.make("child") }),
workRow("work-1", 3),
messageRow("agent-2", 4, { createdBy: "agent" }),
messageRow("jeff", 5, person("jeff")),
messageRow("system-1", 6, { createdBy: "system" }),
];

it("collapses the activity between human turns into one pill", () => {
const collapsed = collapseTimelineActivity(rows, new Set());
expect(collapsed.map((row) => row.id)).toEqual([
"kameron",
"reply",
"activity:reply",
"jeff",
"activity:jeff",
]);
expect(collapsed[2]).toMatchObject({
kind: "activity",
count: 3,
summary: "2 agent updates",
expanded: false,
});
expect(collapsed[4]).toMatchObject({ kind: "activity", count: 1, summary: "1 system notice" });
});

it("puts the collapsed rows back exactly when the pill expands", () => {
const expanded = collapseTimelineActivity(rows, new Set(["activity:reply"]));
expect(expanded.map((row) => row.id)).toEqual([
"kameron",
"reply",
"activity:reply",
"agent-1",
"work-1",
"agent-2",
"jeff",
"activity:jeff",
]);
expect(expanded[2]).toMatchObject({ expanded: true });
});

it("keeps a thread of only activity as one pill", () => {
const activity = rows.slice(2, 5);
expect(collapseTimelineActivity(activity, new Set()).map((row) => row.id)).toEqual([
"activity:agent-1",
]);
expect(activityUpdateSummary(activity)).toBe("2 agent updates");
});

it("names mixed activity by kind", () => {
expect(
activityUpdateSummary([
messageRow("a", 0, { createdBy: "agent" }),
messageRow("b", 1, { createdBy: "system" }),
messageRow("c", 2, { scheduledTaskId: ScheduledTaskId.make("task-1") }),
]),
).toBe("1 agent update and 1 system notice and 1 automation");
});

it("keeps a plan, a render and viewed images on screen", () => {
const plan: MessagesTimelineRow = {
kind: "proposed-plan",
id: "plan-1",
createdAt: time(7),
proposedPlan: {
id: "plan-1" as never,
runId,
planMarkdown: "Do the thing",
status: "active",
createdAt: time(7),
updatedAt: time(7),
},
};
const images: MessagesTimelineRow = {
kind: "viewed-images",
id: "images-1",
createdAt: time(8),
paths: ["shot.png"],
};
const withCards = [rows[0]!, plan, rows[2]!, images, rows[5]!];
expect(collapseTimelineActivity(withCards, new Set()).map((row) => row.id)).toEqual([
"kameron",
"plan-1",
"activity:plan-1",
"images-1",
"jeff",
]);
});

it("keeps a secret request and a link request on screen", () => {
const request = (id: string, type: "secret_request" | "link_request"): MessagesTimelineRow => ({
kind: "event",
id,
createdAt: time(9),
projectedItem: { item: { type } } as never,
});
const withRequests = [
rows[0]!,
rows[2]!,
request("secret-1", "secret_request"),
request("link-1", "link_request"),
rows[5]!,
];
expect(collapseTimelineActivity(withRequests, new Set()).map((row) => row.id)).toEqual([
"kameron",
"activity:kameron",
"secret-1",
"link-1",
"jeff",
]);
});

it("names the pill after the message it follows, so streaming rows do not rename it", () => {
const grown = [...rows.slice(0, 5), workRow("work-2", 9), ...rows.slice(5)];
expect(collapseTimelineActivity(grown, new Set()).map((row) => row.id)).toEqual(
collapseTimelineActivity(rows, new Set()).map((row) => row.id),
);
});

it("finds the pill hiding a row", () => {
expect(activityPillIdForEntry(rows, "work-1")).toBe("activity:reply");
expect(activityPillIdForEntry(rows, "system-1")).toBe("activity:jeff");
expect(activityPillIdForEntry(rows, "kameron")).toBeUndefined();
expect(activityPillIdForEntry(rows.slice(2, 5), "agent-2")).toBe("activity:agent-1");
});

it("leaves a human conversation untouched", () => {
const conversation = [rows[0]!, rows[1]!, rows[5]!];
expect(collapseTimelineActivity(conversation, new Set()).map((row) => row.id)).toEqual([
"kameron",
"reply",
"jeff",
]);
});
});
Loading
Loading