From da03e096e21e92fba4edc333415260d469d99fd1 Mon Sep 17 00:00:00 2001 From: Badcuban <108198679+badcuban@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:03:43 -0500 Subject: [PATCH] feat(web): say what a lead chat is, and offer one when a thread starts others The crown never said what it meant, and making a lead was only in the thread menu. The Lead tab and the header's Lead chat chip now open a card that explains a lead and offers to stop using it; the sidebar's thread card says so too. The menu item carries a second line (Electron's sublabel on macOS, the web menu everywhere). The first time a thread in a project with no lead starts threads of its own, a line under its tabs offers to make it the lead; taking it or closing it keeps it away from that project. --- apps/desktop/src/electron/ElectronMenu.ts | 6 + apps/server/src/guide/topics.ts | 4 +- .../components/ChatView.sidebar.browser.tsx | 94 +++++++++++ apps/web/src/components/chat/ChatHeader.tsx | 25 ++- apps/web/src/components/chat/FamilyTabs.tsx | 70 +++++--- .../web/src/components/chat/LeadChatHints.tsx | 157 ++++++++++++++++++ .../components/sidebar/ThreadHoverCard.tsx | 12 ++ apps/web/src/components/threadMenu.logic.ts | 6 +- apps/web/src/contextMenuFallback.ts | 15 ++ apps/web/src/leadChat.ts | 11 ++ docs/design/lead-chat.md | 23 +++ packages/contracts/src/ipc.ts | 4 + 12 files changed, 393 insertions(+), 34 deletions(-) create mode 100644 apps/web/src/components/chat/LeadChatHints.tsx diff --git a/apps/desktop/src/electron/ElectronMenu.ts b/apps/desktop/src/electron/ElectronMenu.ts index e7e158401..6d2d1f95f 100644 --- a/apps/desktop/src/electron/ElectronMenu.ts +++ b/apps/desktop/src/electron/ElectronMenu.ts @@ -49,6 +49,9 @@ function normalizeContextMenuItems(source: readonly ContextMenuItem[]): ContextM const normalizedItem: ContextMenuItem = { id: sourceItem.id, label: sourceItem.label, + ...(typeof sourceItem.sublabel === "string" && sourceItem.sublabel.length > 0 + ? { sublabel: sourceItem.sublabel } + : {}), destructive: sourceItem.destructive === true, disabled: sourceItem.disabled === true, ...(sourceItem.separatorBefore === true ? { separatorBefore: true } : {}), @@ -102,6 +105,9 @@ export const layer = Layer.sync(ElectronMenu, () => { const itemOption: Electron.MenuItemConstructorOptions = { label: item.label, enabled: !item.disabled, + // Shown under the label on macOS 14.4 and later, and as the item's + // hover text on any Mac; other systems leave it out. + ...(item.sublabel !== undefined ? { sublabel: item.sublabel, toolTip: item.sublabel } : {}), }; if (item.children && item.children.length > 0) { itemOption.submenu = buildTemplate(item.children, complete); diff --git a/apps/server/src/guide/topics.ts b/apps/server/src/guide/topics.ts index 155a5b322..821d2291e 100644 --- a/apps/server/src/guide/topics.ts +++ b/apps/server/src/guide/topics.ts @@ -120,7 +120,7 @@ A project's lead chat is a thread set up to coordinate the project; see the lead ], body: `Each project can have one lead chat: a thread you drop work into (a bug, a stack trace, a list of tasks). Its agent answers small questions itself and starts threads for new work. Those threads show under the lead in the sidebar and report back to it, and it tells you what finished and what needs you. -Any thread can be the lead. Use "Make this the lead chat" in a thread's menu (right-click its row, or click the title above the chat), or the command palette. The project's menu in the project picker has Open lead chat, or New lead chat, which starts a thread in the project folder and makes it the lead. "Go to lead chat" in the command palette opens it. +Any thread can be the lead. The first time a thread in a project with no lead starts threads of its own, a line under its tabs offers to make it the lead; close it and it doesn't come back for that project. Or use "Make this the lead chat" in a thread's menu (right-click its row, or click the title above the chat), or the command palette. The project's menu in the project picker has Open lead chat, or New lead chat, which starts a thread in the project folder and makes it the lead. "Go to lead chat" in the command palette opens it. The lead can also pass a message to a thread you started by hand in the project. That is one-way: the thread works on it and answers there, not back in the lead, and it can't start threads of its own for it until you write there. The lead can't pass work into a room, a thread another thread still owns, or one you stopped. A pass never runs with more access than the lead had. @@ -128,7 +128,7 @@ When an agent asks to start several threads, the card has a checkbox per thread, Only one thread leads a project; making another the lead replaces it. "Stop using as lead chat" turns it back into an ordinary thread, and the threads it started stay with it. Archiving or deleting the lead ends it. A lead can't move to another computer, and each computer keeps its own lead for a project. -The lead's row sits at the top of the sidebar with a crown, says Lead where the project name goes, and never wraps up on its own. {place:archived.autoArchive} leaves it alone, as it does a pinned thread. The chat shows a Lead chat label beside the title, or, once it has started threads, the family tabs with the lead first. +The lead's row sits at the top of the sidebar with a crown, says Lead where the project name goes, and never wraps up on its own. {place:archived.autoArchive} leaves it alone, as it does a pinned thread. The chat shows a Lead chat label beside the title, or, once it has started threads, the family tabs with the lead first. Hovering the label or the Lead tab, or tapping it, says what a lead does and offers Stop using as lead chat. The Threads tab in the right sidebar shows the project's threads on every computer you can see, grouped as Needs you, Ready for review, Working, Landing, Idle and Done. Open it from the sidebar's list of panels or its + menu, on any thread of the project. A thread you wrapped up goes under Done (for 7 days, closed until you open it) unless its pull request is still open, which keeps it under Ready for review or Landing. Ready for review says what the pull request waits on, as the Pull requests page does. Click a row to open the thread, or right-click it for the thread's menu. The top line counts what needs you and what's working, with a Lead chat link when you're on another thread. diff --git a/apps/web/src/components/ChatView.sidebar.browser.tsx b/apps/web/src/components/ChatView.sidebar.browser.tsx index 5befa3279..f6aaf4ee7 100644 --- a/apps/web/src/components/ChatView.sidebar.browser.tsx +++ b/apps/web/src/components/ChatView.sidebar.browser.tsx @@ -464,6 +464,100 @@ describe("ChatView (full app): sidebar", () => { } }); + /** + * The open thread with one thread it started, on a computer that keeps a + * lead chat, and no lead yet (or `lead` as the lead). + */ + const mountFamily = async (lead: ThreadId | null) => { + window.localStorage.removeItem( + `threadlines:lead-chat-suggestion-dismissed:v1:${LOCAL_ENVIRONMENT_ID}:${PROJECT_ID}`, + ); + const childId = "thread-lead-child" as ThreadId; + const withChild = addThreadToSnapshot( + createSnapshotForTargetUser({ + targetMessageId: "msg-user-lead-family" as MessageId, + targetText: "lead family", + }), + childId, + ); + const capabilities = { repositoryIdentity: true, projectLead: true }; + return mountChatView({ + viewport: DEFAULT_VIEWPORT, + snapshot: { + ...withChild, + projects: withChild.projects.map((project) => ({ ...project, leadThreadId: lead })), + threads: withChild.threads.map((thread) => + thread.id === childId + ? { ...thread, title: "Fix tests", parentThreadId: THREAD_ID, attachedToParent: true } + : thread, + ), + }, + configureFixture: (nextFixture) => { + nextFixture.serverConfig = { + ...nextFixture.serverConfig, + environment: { ...nextFixture.serverConfig.environment, capabilities }, + }; + nextFixture.welcome = { + ...nextFixture.welcome, + environment: { ...nextFixture.welcome.environment, capabilities }, + }; + }, + }); + }; + const leadSetsSent = () => + wsRequests.flatMap((request) => + request._tag === ORCHESTRATION_WS_METHODS.dispatchCommand && + request.type === "project.lead.set" + ? [request.threadId] + : [], + ); + + it("offers a thread running other threads as the lead, once, and says what a lead is", async () => { + const mounted = await mountFamily(null); + try { + const suggestion = page.getByTestId("lead-chat-suggestion"); + await expect + .element(suggestion) + .toMatchTextContent(/This thread is running other threads\. Make it the lead chat/u); + await page.getByTestId("lead-chat-suggestion-make").click(); + await vi.waitFor(() => expect(leadSetsSent()).toEqual([THREAD_ID])); + await expect.element(suggestion).not.toBeInTheDocument(); + + // Once it leads, its tab is the crown, and a press on it says what that means. + const [project] = toShellSnapshot(fixture.snapshot).projects; + rpcHarness.emitStreamValue(ORCHESTRATION_WS_METHODS.subscribeShell, { + kind: "project-upserted", + sequence: fixture.snapshot.snapshotSequence + 1, + project: { ...project!, leadThreadId: THREAD_ID }, + }); + const leadTab = page.getByRole("tab", { name: `Lead: ${THREAD_TITLE}` }); + await expect.element(leadTab).toBeVisible(); + await leadTab.click(); + const card = page.getByTestId("lead-chat-card"); + await expect.element(card).toMatchTextContent(/Drop work here\./u); + await card.getByTestId("lead-chat-card-stop").click(); + await vi.waitFor(() => expect(leadSetsSent()).toEqual([THREAD_ID, null])); + } finally { + await mounted.cleanup(); + } + }); + + it("keeps the lead suggestion away from a project once it is closed", async () => { + const mounted = await mountFamily(null); + try { + await page.getByTestId("lead-chat-suggestion-dismiss").click(); + await expect.element(page.getByTestId("lead-chat-suggestion")).not.toBeInTheDocument(); + expect( + window.localStorage.getItem( + `threadlines:lead-chat-suggestion-dismissed:v1:${LOCAL_ENVIRONMENT_ID}:${PROJECT_ID}`, + ), + ).toBe("true"); + expect(leadSetsSent()).toEqual([]); + } finally { + await mounted.cleanup(); + } + }); + // The server says it made the thread a moment before this app hears of it, // as a real one does: "New lead chat" must open it once it is here, and // stay there (the thread page goes home for a thread it does not know). diff --git a/apps/web/src/components/chat/ChatHeader.tsx b/apps/web/src/components/chat/ChatHeader.tsx index 99afabd4c..6b70afa2b 100644 --- a/apps/web/src/components/chat/ChatHeader.tsx +++ b/apps/web/src/components/chat/ChatHeader.tsx @@ -42,6 +42,7 @@ import { useComputerLabel } from "../sidebar/linkedComputers"; import { useTitleBarHeaderRef } from "../sidebar/titleBarSlot"; import { outsideOriginDescription } from "../../environments/outsideAgents/outsideAgents.logic"; import { OutsideOriginMark } from "../outsideAgents/AssistantMark"; +import { LeadChatCard } from "./LeadChatHints"; export interface ForkHeaderContext { readonly sourceThreadId: ThreadId; @@ -428,13 +429,23 @@ export const ChatHeader = memo(function ChatHeader({ {parentContext ? ( ) : null} - {isLeadChat ? ( - - - - + {isLeadChat && activeThreadRef !== null ? ( + ( + + )} + /> ) : null} {outsideOrigin ? : null} {activeProjectName && !isGitRepo && sourceControlAvailable && ( diff --git a/apps/web/src/components/chat/FamilyTabs.tsx b/apps/web/src/components/chat/FamilyTabs.tsx index 716de5da5..0e3af6a64 100644 --- a/apps/web/src/components/chat/FamilyTabs.tsx +++ b/apps/web/src/components/chat/FamilyTabs.tsx @@ -26,6 +26,7 @@ import { requestIdleThreadDetailPrewarm } from "../../environments/runtime/servi import { cn } from "../../lib/utils"; import { buildThreadRouteParams } from "../../threadRoutes"; import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu"; +import { LeadChatCard, LeadChatSuggestion } from "./LeadChatHints"; import { type FamilyTab, type FamilyTabs as FamilyTabsModel, @@ -157,30 +158,44 @@ const FamilyTabRow = memo(function FamilyTabRow({ overflowPx: OVERFLOW_PX, }); + // The parent, open and not leading yet, may be offered as the lead (LeadChatSuggestion). + const parentTab = family.tabs[0]; + const suggestLead = + parentTab !== undefined && + parentTab.kind === "parent" && + !parentTab.lead && + parentTab.threadRef !== null && + parentTab.key === family.openKey + ? parentTab.threadRef + : null; + return ( -
- {shown.map((tab) => ( - - ))} - {hidden.length > 0 ?
+ <> +
+ {shown.map((tab) => ( + + ))} + {hidden.length > 0 ?
+ {suggestLead !== null ? : null} + ); }); @@ -221,7 +236,7 @@ const FamilyTabButton = memo(function FamilyTabButton({ : tab.statusWord !== null ? `${tab.title}, ${tab.statusWord}` : tab.title; - return ( + const tabButton = (showLeadCard: (() => void) | null) => ( ); + return tab.kind === "parent" && tab.lead && tab.threadRef !== null ? ( + + ) : ( + tabButton(null) + ); }); /** "+N": the tabs that don't fit, with their status; amber while one needs the user. */ diff --git a/apps/web/src/components/chat/LeadChatHints.tsx b/apps/web/src/components/chat/LeadChatHints.tsx new file mode 100644 index 000000000..89ec6f488 --- /dev/null +++ b/apps/web/src/components/chat/LeadChatHints.tsx @@ -0,0 +1,157 @@ +/** + * What tells a user what a lead chat is (docs/design/lead-chat.md, "Saying + * what a lead is"): the crown's card, which explains a lead where its crown + * shows, and the suggestion under the family tabs, which offers one the first + * time a thread in a project with no lead starts threads of its own. + * Nothing here makes a lead without the user asking. + */ +import { scopedProjectKey, scopeProjectRef } from "@threadlines/client-runtime"; +import type { ScopedThreadRef } from "@threadlines/contracts"; +import * as Schema from "effect/Schema"; +import { CrownIcon, XIcon } from "lucide-react"; +import { type ReactElement, useCallback, useState } from "react"; + +import { useLocalStorage } from "../../hooks/useLocalStorage"; +import { LEAD_CHAT_EXPLANATION, readLeadMenuState, setProjectLead } from "../../leadChat"; +import { useComputerConfig } from "../../newThreadDefaults"; +import { selectSidebarThreadSummaryByRef, useStore } from "../../store"; +import { Button } from "../ui/button"; +import { PreviewCard, PreviewCardPopup, PreviewCardTrigger } from "../ui/previewCard"; + +/** How long the pointer rests on a crown before its card opens: tabs are crossed often. */ +const LEAD_CARD_DELAY_MS = 400; + +/** The thread's project, while the thread is in view. */ +function useThreadProject(threadRef: ScopedThreadRef) { + return useStore((state) => selectSidebarThreadSummaryByRef(state, threadRef)?.projectId ?? null); +} + +/** + * The crown's card: what a lead chat does, and the way out. Opens on hover, + * and on a press of the trigger (`renderTrigger` gets `showCard` for that), + * which is how a phone, which never hovers, reaches it. + */ +export function LeadChatCard({ + threadRef, + renderTrigger, +}: { + threadRef: ScopedThreadRef; + renderTrigger: (showCard: () => void) => ReactElement; +}) { + const [open, setOpen] = useState(false); + const projectId = useThreadProject(threadRef); + const showCard = useCallback(() => setOpen(true), []); + return ( + + + +
+
+

{LEAD_CHAT_EXPLANATION}

+ {projectId !== null ? ( + + ) : null} +
+
+ ); +} + +/** One key per project, so two windows closing it for different projects can't undo each other. */ +const leadSuggestionDismissedKey = (projectKey: string | null) => + `threadlines:lead-chat-suggestion-dismissed:v1:${projectKey ?? ""}`; + +/** + * The line under the family tabs that offers to make their parent the lead + * chat: shown on the parent, while its project has no lead and it could be + * one. Closing it (or taking it) keeps it away from that project on this + * device for good. + */ +export function LeadChatSuggestion({ parentRef }: { parentRef: ScopedThreadRef }) { + const projectId = useThreadProject(parentRef); + const projectKey = + projectId === null + ? null + : scopedProjectKey(scopeProjectRef(parentRef.environmentId, projectId)); + const [dismissed, setDismissed] = useLocalStorage( + leadSuggestionDismissedKey(projectKey), + false, + Schema.Boolean, + ); + // The computer's settings can refuse a lead ("Agents can start threads" + // off); they live outside the thread store, so a change there redraws this. + useComputerConfig(parentRef.environmentId); + // Only a project with no lead, and only a thread that could lead it now. + const offered = useStore((state) => { + const thread = selectSidebarThreadSummaryByRef(state, parentRef); + if (thread === undefined || thread === null) return false; + const lead = readLeadMenuState(state, thread); + return lead?.kind === "make" && lead.replacingTitle === null && lead.refusal === null; + }); + if (!offered || projectKey === null || projectId === null || dismissed) { + return null; + } + const dismiss = () => setDismissed(true); + return ( +
+
+ ); +} diff --git a/apps/web/src/components/sidebar/ThreadHoverCard.tsx b/apps/web/src/components/sidebar/ThreadHoverCard.tsx index 537ed59e1..54a8706a8 100644 --- a/apps/web/src/components/sidebar/ThreadHoverCard.tsx +++ b/apps/web/src/components/sidebar/ThreadHoverCard.tsx @@ -11,6 +11,7 @@ import { CircleDashedIcon, CloudIcon, CornerDownRightIcon, + CrownIcon, GitBranchIcon, GitForkIcon, MonitorIcon, @@ -29,6 +30,7 @@ import { import { usePrimaryEnvironmentId } from "../../environments/primary"; import { useServerProviders } from "../../rpc/serverState"; import { selectProjectByRef, useStore } from "../../store"; +import { LEAD_MENU_SUBLABEL, projectLeadRef } from "../../leadChat"; import { useThreadTitle } from "../../hooks/useThreadTitle"; import { lendingThreadId } from "../../worktreeOrigin"; import { useGitStatus } from "../../lib/gitStatusState"; @@ -207,6 +209,11 @@ function ThreadHoverCardContent({ thread, status, lineage }: ThreadHoverCardPayl [thread.environmentId, thread.id], ); const loadedThread = useStore(useMemo(() => createThreadSelectorByRef(threadRef), [threadRef])); + // Its project's lead chat: the card says what that means, as the crown can't. + const isLead = useStore( + (state) => + backingProject !== undefined && projectLeadRef(state, backingProject)?.threadId === thread.id, + ); const primaryEnvironmentId = usePrimaryEnvironmentId(); const isRemote = primaryEnvironmentId !== null && thread.environmentId !== primaryEnvironmentId; @@ -289,6 +296,11 @@ function ThreadHoverCardContent({ thread, status, lineage }: ThreadHoverCardPayl {awaitedTasks ? : null} + {isLead ? ( + }> + Lead chat. {LEAD_MENU_SUBLABEL}. + + ) : null} {lineage?.startedBy ? ( }> Started by {lineage.startedBy} diff --git a/apps/web/src/components/threadMenu.logic.ts b/apps/web/src/components/threadMenu.logic.ts index 83cb800b4..fa2373660 100644 --- a/apps/web/src/components/threadMenu.logic.ts +++ b/apps/web/src/components/threadMenu.logic.ts @@ -1,6 +1,6 @@ import type { ContextMenuItem } from "@threadlines/contracts"; -import { leadMenuLabel, type LeadMenuState } from "../leadChat"; +import { LEAD_MENU_SUBLABEL, leadMenuLabel, type LeadMenuState } from "../leadChat"; /** Everything a thread's menu can do. Every surface that offers it offers the same. */ export type ThreadMenuAction = @@ -96,6 +96,10 @@ export function describeThreadMenu(facts: ThreadMenuFacts): ContextMenuItem( const label = document.createElement("span"); label.className = "min-w-0 flex-1 truncate"; label.textContent = item.label; + if (item.sublabel !== undefined) { + // A second, quieter line under the label. + label.className = "flex min-w-0 flex-1 flex-col"; + label.textContent = ""; + const text = document.createElement("span"); + text.className = "truncate"; + text.textContent = item.label; + const sublabel = document.createElement("span"); + sublabel.className = `truncate text-muted-foreground ${coarse ? "text-xs" : "text-[10px]"}`; + sublabel.textContent = item.sublabel; + label.append(text, sublabel); + // Named by its label alone, as before; the second line describes it. + button.setAttribute("aria-label", item.label); + button.setAttribute("aria-description", item.sublabel); + } button.appendChild(label); if (hasChildren) { diff --git a/apps/web/src/leadChat.ts b/apps/web/src/leadChat.ts index 369a3a727..7182fbfba 100644 --- a/apps/web/src/leadChat.ts +++ b/apps/web/src/leadChat.ts @@ -146,6 +146,17 @@ export function readLeadMenuState( }; } +/** + * What a lead chat does, in the words the app uses wherever it explains one + * (the crown's card on the family tabs and the header, the sidebar's thread + * card). Matches the app guide's lead chat topic. + */ +export const LEAD_CHAT_EXPLANATION = + "Drop work here. Its agent answers small things itself and starts threads for bigger ones, which report back here. It stays at the top of the sidebar and doesn't wrap up on its own."; + +/** The line under "Make this the lead chat" in a thread's menu. */ +export const LEAD_MENU_SUBLABEL = "Stays on top and hands out work to new threads"; + /** The menu words for a lead state. */ export function leadMenuLabel(state: LeadMenuState): string { if (state.kind === "stop") return "Stop using as lead chat"; diff --git a/docs/design/lead-chat.md b/docs/design/lead-chat.md index 9cbcaec66..085d279a0 100644 --- a/docs/design/lead-chat.md +++ b/docs/design/lead-chat.md @@ -111,6 +111,29 @@ Words below are the on-screen words. Copy follows the repo's copy rules (no em d - Nothing is lost when a lead stops being one: it becomes an ordinary thread, and the threads it started stay its family. +### Saying what a lead is + +A user meets the crown long before they read about it, so the app explains a lead +where it shows one, and offers one at the moment a thread starts coordinating. It +never makes a lead by itself. One set of words (`LEAD_CHAT_EXPLANATION` and +`LEAD_MENU_SUBLABEL` in `apps/web/src/leadChat.ts`) is used everywhere. + +- **The crown's card.** Hovering the Lead tab on the family row, or the header's + "Lead chat" chip, opens a card: what a lead does, and "Stop using as lead chat". A + press on the open lead's tab or on the chip opens it too, which is how a phone gets + it. The sidebar's thread card gains a "Lead chat" line on the lead's row. +- **The menu item.** "Make this the lead chat" carries a second line, "Stays on top + and hands out work to new threads". The web menu draws it; the desktop's native menu + shows it under the label on macOS 14.4 and later (Electron's `sublabel`), as the + item's hover text on any Mac (`toolTip`), and leaves it out on Windows and Linux. +- **The suggestion.** Under the family tabs, on the parent, while its project has no + lead and the parent could lead it now (no refusal): "This thread is running other + threads. Make it the lead chat and it stays on top and hands out new work by + itself." with Make lead chat and a close button. Taking it or closing it keeps it + away from that project on this device for good (one localStorage key per project, so + two windows can't undo each other's). A project with a lead + never shows it. + ### Sidebar - The lead's row carries a lead glyph before its title and "Lead" in place of the diff --git a/packages/contracts/src/ipc.ts b/packages/contracts/src/ipc.ts index 558babb7d..f859e4fd6 100644 --- a/packages/contracts/src/ipc.ts +++ b/packages/contracts/src/ipc.ts @@ -299,6 +299,8 @@ import type { export interface ContextMenuItem { id: T; label: string; + /** A short second line under the label (a native menu shows it on macOS only). */ + sublabel?: string; destructive?: boolean; disabled?: boolean; /** Starts a new group: a divider above it (none at the top of the menu). */ @@ -309,6 +311,7 @@ export interface ContextMenuItem { export interface ContextMenuItemSchemaType { readonly id: string; readonly label: string; + readonly sublabel?: string; readonly destructive?: boolean; readonly disabled?: boolean; readonly separatorBefore?: boolean; @@ -318,6 +321,7 @@ export interface ContextMenuItemSchemaType { export const ContextMenuItemSchema: Schema.Codec = Schema.Struct({ id: Schema.String, label: Schema.String, + sublabel: Schema.optionalKey(Schema.String), destructive: Schema.optionalKey(Schema.Boolean), disabled: Schema.optionalKey(Schema.Boolean), separatorBefore: Schema.optionalKey(Schema.Boolean),