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
2 changes: 1 addition & 1 deletion apps/server/src/guide/topics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Whether the thread's agent may bring in another model on its own is {place:threa
id: "agent-threads",
title: "Threads agents start",
keywords: ["child thread", "subthread", "thread_start", "spawn", "parallel", "delegate"],
body: `An agent can start threads of its own to work in parallel, and message, read or stop them. Each started thread shows under its parent in the sidebar; its final reply comes back to the parent as a message, which wakes the parent's agent. The parent and the threads it started also show as a row of tabs under the chat header, on the parent and on each of its threads: a click opens that thread, with its own message box and draft. The row lists the threads the sidebar shows under the parent; one the user made its own, or whose parent is wrapped, has no row.
body: `An agent can start threads of its own to work in parallel, and message, read or stop them. Each started thread shows under its parent in the sidebar; its final reply comes back to the parent as a message, which wakes the parent's agent. The parent and the threads it started also show as a row of tabs under the chat header, on the parent and on each of its threads: a click opens that thread, with its own message box and draft. When two or more of the threads start their titles with the same topic ("Pull Station: ..."), their tabs and their rows under the parent in the sidebar leave it out, and hovering one shows the full title. The row lists the threads the sidebar shows under the parent; one the user made its own, or whose parent is wrapped, has no row.

{place:threads.agentThreads} decides this: Off, Ask me first (a card in the chat lists the threads and you decide), or Automatic. The same setting covers agents creating or changing scheduled tasks. An agent may start at most 5 threads and send 10 messages to them per message you send.

Expand Down
84 changes: 84 additions & 0 deletions apps/web/src/components/ChatView.agents.browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,90 @@ describe("ChatView (full app): agent browser tabs and rooms", () => {
}
});

it("keeps the lead's tab whole on a crowded row, drops a shared topic, and cuts long tabs to one width", async () => {
const titles = [
"Panel Jam animation timing review",
"Panel Jam: council round two",
"Review: last three commits on main",
"Pull Station restructure: start the split",
"Pull Station: Android toolchain setup",
"Pull Station: UI polish pass after review",
];
const children = titles.map((_, index) => `thread-crowded-${index}` as ThreadId);
const base = children.reduce(
(snapshot, child) => addThreadToSnapshot(snapshot, child),
createSnapshotForTargetUser({
targetMessageId: "msg-user-crowded-family" as MessageId,
targetText: "crowded family target",
}),
);
const mounted = await mountChatView({
viewport: { ...DEFAULT_VIEWPORT, width: 1_280 },
snapshot: {
...base,
projects: base.projects.map((project) => ({ ...project, leadThreadId: THREAD_ID })),
threads: base.threads.map((thread) => {
const index = children.indexOf(thread.id);
return index === -1
? thread
: {
...thread,
title: titles[index]!,
parentThreadId: THREAD_ID,
attachedToParent: true,
createdAt: isoAt(10 + index),
};
}),
},
});
const tabs = () => [
...document.querySelectorAll<HTMLElement>('[data-testid="family-tabs"] [role="tab"]'),
];
try {
await vi.waitFor(() => expect(tabs()).toHaveLength(1 + children.length), {
timeout: 10_000,
});
const [leadTab, ...childTabs] = tabs();
const labelOf = (tab: HTMLElement) => tab.querySelector<HTMLElement>("span.truncate")!;
// A topic two threads share is dropped from their tabs, and kept in the tooltip.
expect(childTabs.map((tab) => labelOf(tab).textContent)).toEqual([
"Animation timing review",
"Council round two",
"Review: last three commits on main",
"Restructure: start the split",
"Android toolchain setup",
"UI polish pass after review",
]);
expect(childTabs.map((tab) => tab.title)).toEqual(titles);
// "Lead" is never cut...
expect(labelOf(leadTab!).textContent).toBe("Lead");
expect(labelOf(leadTab!).scrollWidth).toBeLessThanOrEqual(labelOf(leadTab!).clientWidth);
// ...and on a crowded row the cut tabs share one width, which no other tab passes.
const width = (tab: HTMLElement) => tab.getBoundingClientRect().width;
const cut = childTabs.filter((tab) => labelOf(tab).scrollWidth > labelOf(tab).clientWidth);
expect(cut.length).toBeGreaterThan(1);
const cutWidths = cut.map(width);
// Within a pixel: layout splits the row in fractions of one.
expect(Math.max(...cutWidths) - Math.min(...cutWidths)).toBeLessThan(1);
expect(childTabs.every((tab) => width(tab) < Math.max(...cutWidths) + 1)).toBe(true);

// The sidebar's rows under the lead say the same, with the full title for screen readers.
await page.getByTestId(`thread-family-${THREAD_ID}`).click();
const sidebarTitle = (child: ThreadId) =>
document.querySelector<HTMLElement>(`[data-testid="child-title-${child}"]`);
await vi.waitFor(() => expect(sidebarTitle(children[4]!)).not.toBeNull(), {
timeout: 10_000,
});
expect(sidebarTitle(children[4]!)!.querySelector(`[aria-hidden="true"]`)?.textContent).toBe(
"Android toolchain setup",
);
expect(sidebarTitle(children[4]!)!.querySelector(".sr-only")?.textContent).toBe(titles[4]);
expect(sidebarTitle(children[2]!)!.textContent).toBe(titles[2]);
} finally {
await mounted.cleanup();
}
});

it("names the thread that started this one, in the header and on its request", async () => {
const base = createSnapshotForTargetUser({
targetMessageId: "msg-user-started-by" as MessageId,
Expand Down
24 changes: 23 additions & 1 deletion apps/web/src/components/Sidebar.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1937,10 +1937,15 @@ describe("child thread families", () => {
deliveredAt?: string;
seenAt?: string;
wrappedByUser?: boolean;
title?: string;
} = {},
): Entry => ({
threadKey: id,
thread: { id: ThreadId.make(id), createdAt: options.createdAt ?? "2026-10-01T00:00:00.000Z" },
thread: {
id: ThreadId.make(id),
createdAt: options.createdAt ?? "2026-10-01T00:00:00.000Z",
title: options.title ?? id,
},
status: options.status ?? null,
isDone: options.done ?? false,
settledAt: options.settledAt ?? options.createdAt ?? "2026-10-01T00:00:00.000Z",
Expand Down Expand Up @@ -1969,6 +1974,22 @@ describe("child thread families", () => {
sortDone: (heads) => [...heads],
});

it("shortens a family's titles over every child, drawn or folded, as the tabs do", () => {
const entries = [
entry("lead"),
entry("android", { parent: "lead", title: "Pull Station: Android toolchain" }),
entry("polish", { parent: "lead", title: "Pull Station: UI polish pass" }),
entry("notes", { parent: "lead", title: "Write release notes" }),
];
// Folded, no child is drawn, but the labels stay what they are when open.
const [folded] = sections(entries).live;
expect(folded!.shownChildren).toEqual([]);
expect(Object.fromEntries(folded!.childShortTitles)).toEqual({
android: "Android toolchain",
polish: "UI polish pass",
});
});

it("takes one seat per family and lists exactly the rows it draws", () => {
// Children never stand as live rows of their own while their parent is
// live; a family folds as one row, and the keyboard walks what is drawn.
Expand Down Expand Up @@ -2310,6 +2331,7 @@ describe("families across computers", () => {
thread: {
id: ThreadId.make(id),
createdAt: "2026-10-21T09:00:00.000Z",
title: id,
environmentId,
parentThreadId: options.childOf === undefined ? null : ThreadId.make(options.childOf),
attachedToParent: options.childOf !== undefined,
Expand Down
29 changes: 28 additions & 1 deletion apps/web/src/components/Sidebar.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type { SidebarThreadSummary, Thread } from "../types";
import { isLatestTurnSettled, isWaitingOnBackgroundTasks } from "../session-logic";
import { startOfLocalDayMs } from "../timestampFormat";
import { nextCheckBack } from "./chat/checkBacks";
import { shortFamilyTitles } from "./familyTitles.logic";
import { isHandedBackCompletion } from "@threadlines/shared/childThreads";
import {
hasUnseenCompletion as hasUnseenCompletionSince,
Expand Down Expand Up @@ -1606,7 +1607,7 @@ export interface InboxFamilyExit extends InboxFamilyStatus {
/** What the family rules read about each inbox thread. */
export interface InboxFamilyEntry extends InboxFamilyExit {
readonly threadKey: string;
readonly thread: Pick<SidebarThreadSummary, "id" | "createdAt">;
readonly thread: Pick<SidebarThreadSummary, "id" | "createdAt" | "title">;
readonly seenAt: string | undefined;
readonly wrappedByUser: boolean;
}
Expand Down Expand Up @@ -1701,6 +1702,12 @@ export interface InboxLiveRow<E extends InboxFamilyEntry> {
readonly remoteChildren: readonly InboxRemoteChild[];
/** The ones drawn: all while open, else only those that need the user. */
readonly shownRemoteChildren: readonly InboxRemoteChild[];
/**
* What a child's row shows where its title shares a topic with its
* siblings' (`shortFamilyTitles`, as the family tabs do), by thread key.
* A child missing here shows its title.
*/
readonly childShortTitles: ReadonlyMap<string, string>;
/** A live child whose parent is wrapped stands on its own, naming the parent. */
readonly wrappedParent: E | null;
/**
Expand Down Expand Up @@ -1737,6 +1744,25 @@ export interface InboxDoneRow<E extends InboxFamilyEntry> {
readonly startedBy: E | null;
}

const NO_SHORT_TITLES: ReadonlyMap<string, string> = new Map();

/** A family's shortened child titles by thread key, over every member, drawn or folded. */
function childShortTitlesOf(
children: readonly InboxFamilyEntry[],
remoteChildren: readonly InboxRemoteChild[],
): ReadonlyMap<string, string> {
const members = [
...children.map((child) => ({ key: child.threadKey, title: child.thread.title })),
...remoteChildren.map((child) => ({ key: child.threadKey, title: child.title })),
];
if (members.length < 2) return NO_SHORT_TITLES;
const short = shortFamilyTitles(members.map((member) => member.title));
const changed = members.flatMap((member, index) =>
short[index] === member.title ? [] : [[member.key, short[index]!] as const],
);
return changed.length === 0 ? NO_SHORT_TITLES : new Map(changed);
}

const NEEDS_YOU_NOW: ReadonlySet<ThreadStatusPill["label"]> = new Set([
"Pending Approval",
"Awaiting Input",
Expand Down Expand Up @@ -1995,6 +2021,7 @@ export function buildInboxSections<E extends InboxFamilyEntry>(input: {
shownChildren,
remoteChildren,
shownRemoteChildren,
childShortTitles: childShortTitlesOf(children, remoteChildren),
wrappedParent,
scopedOutParent,
};
Expand Down
10 changes: 9 additions & 1 deletion apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2153,7 +2153,13 @@ export default function Sidebar() {
) : null}
{section.rows.map(
(
{ entry, shownChildren, shownRemoteChildren, wrappedParent },
{
entry,
shownChildren,
shownRemoteChildren,
childShortTitles,
wrappedParent,
},
rowIndex,
) => (
<React.Fragment key={entry.threadKey}>
Expand Down Expand Up @@ -2218,6 +2224,7 @@ export default function Sidebar() {
<InboxChildRow
key={child.threadKey}
thread={child.thread}
shortTitle={childShortTitles.get(child.threadKey)}
status={child.status}
isDone={child.isDone}
doneAt={child.doneAt}
Expand Down Expand Up @@ -2257,6 +2264,7 @@ export default function Sidebar() {
<InboxRemoteChildRow
key={child.threadKey}
child={child}
shortTitle={childShortTitles.get(child.threadKey)}
onSetDone={setRemoteChildDone}
/>
))}
Expand Down
28 changes: 15 additions & 13 deletions apps/web/src/components/chat/FamilyTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,12 @@ const FamilyTabButton = memo(function FamilyTabButton({
[openMenu],
);
const touchHold = useTouchHoldMenu<HTMLButtonElement>({ open: openMenu, onContextMenu });
const label =
tab.kind === "parent" && tab.lead
? `Lead: ${tab.title}`
: tab.statusWord !== null
? `${tab.title}, ${tab.statusWord}`
: tab.title;
const isLeadTab = tab.kind === "parent" && tab.lead;
const label = isLeadTab
? `Lead: ${tab.title}`
: tab.statusWord !== null
? `${tab.title}, ${tab.statusWord}`
: tab.title;
const tabButton = (showLeadCard: (() => void) | null) => (
<button
ref={buttonRef}
Expand All @@ -249,9 +249,13 @@ const FamilyTabButton = memo(function FamilyTabButton({
disabled={tab.threadRef === null}
className={cn(
"flex h-6 items-center gap-1.5 rounded-md px-2 text-xs transition-colors focus-ring",
// As wide as its title up to a cap, packed to the left like the right
// panel's strip; tabs only shrink (toward the fit's floor) when crowded.
fill ? "min-w-0 max-w-50 shrink" : "shrink-0",
// As wide as its title up to a 200px cap, packed to the left. When the
// row is crowded, every tab starts from the same 200px basis, so the
// longest titles give way first and all end up the same width (toward
// the fit's floor). Sizing from the title instead would squeeze each
// tab by its full title length and crush the short ones. The lead's
// crown and "Lead" never shrink: cut, they say nothing.
!fill || isLeadTab ? "shrink-0" : "min-w-0 max-w-max grow-0 shrink basis-50",
active
? "bg-accent text-foreground"
: "text-muted-foreground hover:text-foreground disabled:hover:text-muted-foreground",
Expand All @@ -278,12 +282,10 @@ const FamilyTabButton = memo(function FamilyTabButton({
)}
/>
)}
<span className="min-w-0 truncate">
{tab.kind === "parent" && tab.lead ? "Lead" : tab.title}
</span>
<span className="min-w-0 truncate">{isLeadTab ? "Lead" : tab.shortTitle}</span>
</button>
);
return tab.kind === "parent" && tab.lead && tab.threadRef !== null ? (
return isLeadTab && tab.threadRef !== null ? (
<LeadChatCard threadRef={tab.threadRef} renderTrigger={tabButton} />
) : (
tabButton(null)
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/chat/familyTabs.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ describe("fitting the row", () => {
threadRef: null,
kind: "child",
title: key,
shortTitle: key,
lead: false,
dotClass: null,
statusWord: null,
Expand Down
15 changes: 13 additions & 2 deletions apps/web/src/components/chat/familyTabs.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
isNeedsUserStatus,
liveFamilyOf,
} from "../Sidebar.logic";
import { shortFamilyTitles } from "../familyTitles.logic";

/** One tab on the row. */
export interface FamilyTab {
Expand All @@ -28,6 +29,11 @@ export interface FamilyTab {
readonly threadRef: ScopedThreadRef | null;
readonly kind: "parent" | "child";
readonly title: string;
/**
* What the tab itself shows: the title, less a topic it shares with other
* threads on the row (`shortFamilyTitles`, the sidebar's rule too). The tooltip keeps the title.
*/
readonly shortTitle: string;
/** The parent is its project's lead chat: its tab is the flag and "Lead". */
readonly lead: boolean;
/** A child's status dot class and word; null for the parent or a quiet child. */
Expand Down Expand Up @@ -100,6 +106,7 @@ export function familyTabsOf<E extends FamilyTabEntry>(input: {
threadRef: scopeThreadRef(child.thread.environmentId, child.thread.id),
kind: "child",
title: child.thread.title,
shortTitle: child.thread.title,
lead: false,
dotClass: child.isDone ? null : (child.status?.dotClass ?? null),
statusWord: child.isDone ? null : inboxStatusWord(child.status),
Expand All @@ -113,6 +120,7 @@ export function familyTabsOf<E extends FamilyTabEntry>(input: {
threadRef: null,
kind: "child",
title: child.title,
shortTitle: child.title,
lead: false,
dotClass: child.isDone ? null : (child.status?.dotClass ?? null),
statusWord: child.isDone ? null : inboxStatusWord(child.status),
Expand All @@ -121,6 +129,8 @@ export function familyTabsOf<E extends FamilyTabEntry>(input: {
computerLabel: child.computerLabel,
inbox: null,
});
const children = [...family.children.map(childTab), ...family.remoteChildren.map(remoteTab)];
const shortTitles = shortFamilyTitles(children.map((tab) => tab.title));
return {
familyKey: parent.threadKey,
openKey: input.openKey,
Expand All @@ -130,6 +140,7 @@ export function familyTabsOf<E extends FamilyTabEntry>(input: {
threadRef: scopeThreadRef(parent.thread.environmentId, parent.thread.id),
kind: "parent",
title: parent.thread.title,
shortTitle: parent.thread.title,
lead: parent.isLead === true,
dotClass: null,
statusWord: null,
Expand All @@ -138,8 +149,7 @@ export function familyTabsOf<E extends FamilyTabEntry>(input: {
computerLabel: null,
inbox: { isDone: parent.isDone, canMarkDone: parent.canMarkDone === true },
},
...family.children.map(childTab),
...family.remoteChildren.map(remoteTab),
...children.map((tab, index) => ({ ...tab, shortTitle: shortTitles[index]! })),
],
};
}
Expand All @@ -157,6 +167,7 @@ export function sameFamilyTabs(left: FamilyTabs | null, right: FamilyTabs | null
return (
tab.key === other.key &&
tab.title === other.title &&
tab.shortTitle === other.shortTitle &&
tab.lead === other.lead &&
tab.dotClass === other.dotClass &&
tab.statusWord === other.statusWord &&
Expand Down
Loading
Loading