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: 2 additions & 0 deletions apps/server/src/guide/topics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ The sliders button beside the project picker at the top of the sidebar groups th

A new thread starts either in the project folder as it is, or in a worktree of its own: a separate git checkout on a new branch, so its changes stay apart until you merge them. You pick per thread in the composer; the default is {place:threads.startIn}, and new worktrees branch from {place:threads.worktreesFrom}. A project's setup script runs once in each new worktree.

The project name in "What's next in …?" on the new-thread screen opens the list of projects to start in, and so does the arrow beside New thread on the home screen. A long list has a search box that matches project names and folders. The pin on a row keeps that project at the top. Dragging rows, or Alt+Up and Alt+Down, sets your own order, and Reset to automatic order at the bottom goes back to recent activity. Pins and this order are kept per device.

A repository can already have worktrees that Threadlines did not make (git worktree add, or another app). Right after such a repository is added as a project, the new-thread screen lists them under the message box with a checkbox each, and "Add N threads" makes a thread for every ticked one, named from its branch; nothing runs until you send a message there. After that the screen shows only a count beside the recent threads ("4 worktrees"); opening it lists them with Work here, which points the thread you are about to start at that worktree, Add as threads…, and Hide for this project. The Workspace picker under the message box lists the same worktrees under Existing worktree, and the command palette has Add existing worktrees as threads…, which also brings a hidden count back. A thread in one of these is a guest: no setup script runs, the branch is not renamed, deleting the thread never offers to delete the folder, and undoing a turn only undoes that thread's own edits. Worktrees a thread already works in are left out. The computer's server needs to be on a version that has this; with an older one none of it shows.

The agent and model a new thread starts with is {place:threads.agent}. You can switch model or agent at any time from the model button in the composer, which also holds the agent's effort. Beside it sit Build or Plan (one click switches, as does Shift+Tab in the message box) and the access level; on a narrow window they show just their icons, and on phones both live in the model button's panel instead.
Expand Down
100 changes: 46 additions & 54 deletions apps/web/src/components/NoActiveThreadState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,14 @@ import {
useStore,
} from "../store";
import { OpenSourceSupportLinks } from "./OpenSourceSupportLinks";
import { ProjectFavicon } from "./ProjectFavicon";
import { RecentThreadsList } from "./RecentThreadsList";
import { riseDelay, ThreadlinesFigure } from "./ThreadlinesFigure";
import { Button } from "./ui/button";
import { Empty, EmptyDescription, EmptyTitle } from "./ui/empty";
import { Group } from "./ui/group";
import {
Menu,
MenuGroup,
MenuGroupLabel,
MenuItem,
MenuPopup,
MenuSeparator,
MenuTrigger,
} from "./ui/menu";
import { MenuGroup, MenuItem, MenuTrigger } from "./ui/menu";
import { ProjectPickerMenu } from "./ProjectPickerMenu";
import { getProjectOrderKey } from "../logicalProject";
import { SidebarInset } from "./ui/sidebar";
import { PageTitlebar } from "./PageTitlebar";

Expand Down Expand Up @@ -146,53 +139,52 @@ export function NoActiveThreadState() {
</span>
</Button>
{orderedProjects.length > 1 || generalChatsRef ? (
<Menu>
<MenuTrigger
render={
<Button
aria-label="Choose where to start the new thread"
data-testid="no-thread-project-picker-trigger"
size="icon-sm"
variant="outline"
/>
}
>
<ChevronDownIcon className="size-3.5" />
</MenuTrigger>
<MenuPopup align="end">
{generalChatsRef ? (
<>
<MenuGroup>
<MenuItem
data-testid="no-thread-new-general-chat-item"
onClick={handleNewGeneralChat}
>
<MessagesSquareIcon className="size-3.5 shrink-0 text-muted-foreground/70" />
General chat
</MenuItem>
</MenuGroup>
<MenuSeparator />
</>
) : null}
<MenuGroup>
<MenuGroupLabel>New thread in…</MenuGroupLabel>
{orderedProjects.map((project) => (
<ProjectPickerMenu
align="end"
label="New thread in…"
trigger={
<MenuTrigger
render={
<Button
aria-label="Choose where to start the new thread"
data-testid="no-thread-project-picker-trigger"
size="icon-sm"
variant="outline"
/>
}
>
<ChevronDownIcon className="size-3.5" />
</MenuTrigger>
}
header={
generalChatsRef ? (
<MenuGroup>
<MenuItem
key={`${project.environmentId}:${project.id}`}
onClick={() => handleNewThreadInProject(project)}
title={project.cwd}
data-testid="no-thread-new-general-chat-item"
onClick={handleNewGeneralChat}
>
<ProjectFavicon
cwd={project.cwd}
environmentId={project.environmentId}
name={project.name}
/>
<span className="max-w-56 truncate">{project.name}</span>
<MessagesSquareIcon className="size-3.5 shrink-0 text-muted-foreground/70" />
General chat
</MenuItem>
))}
</MenuGroup>
</MenuPopup>
</Menu>
</MenuGroup>
) : undefined
}
rows={orderedProjects.map((project) => ({
key: getProjectOrderKey(project),
name: project.name,
cwd: project.cwd,
environmentId: project.environmentId,
orderKeys: [getProjectOrderKey(project)],
cwds: [project.cwd],
selected: false,
}))}
onPick={(row) => {
const project = orderedProjects.find(
(candidate) => getProjectOrderKey(candidate) === row.key,
);
if (project) handleNewThreadInProject(project);
}}
/>
) : null}
</Group>
) : (
Expand Down
151 changes: 151 additions & 0 deletions apps/web/src/components/ProjectPickerMenu.browser.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// The new-thread project menu: pins, search and drag order run through the
// real UI store and client settings, with the order applied the way
// `useHandleNewThread` applies it.
import "../index.css";

import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { EnvironmentId } from "@threadlines/contracts";
import { page, userEvent } from "vite-plus/test/browser";
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
import { render } from "vitest-browser-react";

import { updateSettings, useSettings } from "../hooks/useSettings";
import { resetTestPage } from "../lib/testPage.browser-harness";
import { pinnedProjectsFirst } from "../projectPickerOrder";
import { useUiStateStore } from "../uiStateStore";
import { ProjectPickerMenu, PROJECT_SEARCH_MIN_PROJECTS } from "./ProjectPickerMenu";
import { MenuTrigger } from "./ui/menu";

const ENVIRONMENT_ID = EnvironmentId.make("environment-local");

// Enough projects for the search line; two live in an "apis" folder.
const PROJECTS = [
{ name: "web", cwd: "/work/web" },
{ name: "gateway", cwd: "/work/apis/gateway" },
{ name: "billing", cwd: "/work/apis/billing" },
{ name: "docs", cwd: "/work/docs" },
{ name: "mobile", cwd: "/work/mobile" },
{ name: "infra", cwd: "/work/infra" },
{ name: "design", cwd: "/work/design" },
{ name: "cli", cwd: "/work/cli" },
{ name: "scratch", cwd: "/work/scratch" },
].map((project) => ({ ...project, key: `${ENVIRONMENT_ID}:${project.cwd}` }));

function Harness(props: { onPick: (key: string) => void }) {
const projectOrder = useUiStateStore((store) => store.projectOrder);
const pinnedProjectCwds = useUiStateStore((store) => store.pinnedProjectCwds);
const sortOrder = useSettings((settings) => settings.sidebarProjectSortOrder);
const ordered =
sortOrder === "manual"
? PROJECTS.toSorted((a, b) => projectOrder.indexOf(a.key) - projectOrder.indexOf(b.key))
: PROJECTS;
return (
<ProjectPickerMenu
align="start"
label="Switch project"
trigger={<MenuTrigger data-testid="picker-trigger">Projects</MenuTrigger>}
rows={pinnedProjectsFirst(ordered, pinnedProjectCwds).map((project) => ({
key: project.key,
name: project.name,
cwd: project.cwd,
environmentId: ENVIRONMENT_ID,
orderKeys: [project.key],
cwds: [project.cwd],
selected: false,
}))}
onPick={(row) => props.onPick(row.key)}
/>
);
}

function shownNames(): string[] {
return Array.from(document.querySelectorAll("[data-project-picker-row]")).map(
(row) =>
PROJECTS.find((project) => project.key === row.getAttribute("data-project-picker-row"))!.name,
);
}

function renderHarness(onPick: (key: string) => void = vi.fn()) {
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
return render(
<QueryClientProvider client={queryClient}>
<Harness onPick={onPick} />
</QueryClientProvider>,
);
}

describe("ProjectPickerMenu", () => {
beforeEach(() => {
expect(PROJECTS.length).toBeGreaterThanOrEqual(PROJECT_SEARCH_MIN_PROJECTS);
useUiStateStore.setState({
projectOrder: PROJECTS.map((project) => project.key),
pinnedProjectCwds: [],
});
updateSettings({ sidebarProjectSortOrder: "updated_at" });
});

afterEach(async () => {
await resetTestPage();
});

it("pins a project into its own group on top, and a search matches folders", async () => {
const onPick = vi.fn();
const mounted = await renderHarness(onPick);
try {
await page.getByTestId("picker-trigger").click();
await userEvent.hover(page.getByRole("menuitem", { name: "docs" }));
await page.getByRole("button", { name: "Pin docs to the top" }).click();

await expect.element(page.getByText("Pinned", { exact: true })).toBeVisible();
expect(shownNames()[0]).toBe("docs");
expect(useUiStateStore.getState().pinnedProjectCwds).toEqual(["/work/docs"]);

// Off the rows, as a hand on the keyboard is: a pointer the shrinking
// list leaves behind takes the highlight with it (Base UI's own rule).
await userEvent.hover(page.getByTestId("project-picker-search"));
// Neither name says "apis"; their folder does.
await page.getByTestId("project-picker-search").fill("apis");
await expect.poll(shownNames).toEqual(["gateway", "billing"]);
// Enter picks the first match once the search has highlighted it.
await expect
.element(page.getByRole("menuitem", { name: "gateway" }))
.toHaveAttribute("data-highlighted");
await userEvent.keyboard("{Enter}");
await expect.poll(() => onPick.mock.calls).toEqual([[PROJECTS[1]!.key]]);
} finally {
await mounted.unmount();
}
});

it("a drag puts the project where it was dropped in the user's own order, and reset brings back the automatic one", async () => {
const mounted = await renderHarness();
try {
await page.getByTestId("picker-trigger").click();
await userEvent.dragAndDrop(
page.getByRole("menuitem", { name: "mobile" }),
page.getByRole("menuitem", { name: "gateway" }),
);

// Into gateway's place; everything else stays where it was shown.
await expect
.poll(shownNames)
.toEqual([
"web",
"mobile",
"gateway",
"billing",
"docs",
"infra",
"design",
"cli",
"scratch",
]);

await page.getByTestId("project-picker-reset-order").click();
await expect.poll(shownNames).toEqual(PROJECTS.map((project) => project.name));
await expect.element(page.getByTestId("project-picker-reset-order")).not.toBeInTheDocument();
} finally {
await mounted.unmount();
}
});
});
Loading
Loading