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
1 change: 1 addition & 0 deletions apps/desktop/src/settings/DesktopClientSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const clientSettings: ClientSettings = {
inboxSort: "recent",
inboxCustomOrder: [],
inboxGroupOrder: [],
inboxCustomGroupOrder: [],
sidebarProjectGroupingMode: "repository_path",
sidebarProjectGroupingOverrides: {
"environment-1:/tmp/project-a": "separate",
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/guide/topics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const GUIDE_TOPICS: ReadonlyArray<GuideTopic> = [
],
body: `A thread is one conversation with an agent in a project. Threads are listed in the sidebar; one that needs you, finished or failed says so there. In a narrow window the sidebar floats over the thread instead of sitting beside it: the sidebar button at the top left, or Cmd+B (Ctrl+B on Windows and Linux), opens it, and picking a thread or clicking the thread puts it away. A thread you scrolled up in opens where you left it when you come back, until Threadlines reloads; one that finished, failed or needs you since then opens at the end.

The sliders button beside the project picker at the top of the sidebar groups the list by project or computer and sorts it: recent activity, newest, oldest, title, or a custom order. In the custom order you drag rows to arrange them, or use Move up and Move down in a thread's menu, and only you move a row; new threads go to the bottom, and the same button can reset the order. Pinned threads stay above a thin line in every sort, under a project's lead chat, which comes first. When the list is grouped, drag a group's header to move the whole group, in any sort; its menu has Move up, Move down and Use automatic order. These orders are kept per device, so a phone has its own.
The sliders button beside the project picker at the top of the sidebar groups the list by project or computer and sorts it: recent activity, newest, oldest, title, or a custom order. In the custom order you drag rows to arrange them, or use Move up and Move down in a thread's menu, and only you move a row; new threads go to the bottom, a group keeps its place when its top thread goes, a new group goes last, and the same button can reset the order. Pinned threads stay above a thin line in every sort, under a project's lead chat, which comes first. When the list is grouped, drag a group's header to move the whole group, in any sort; its menu has Move up, Move down and Use automatic order. These orders are kept per device, so a phone has its own.

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.

Expand Down
44 changes: 44 additions & 0 deletions apps/web/src/components/Sidebar.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ import {
moveInInboxCustomOrder,
trimInboxCustomOrder,
orderInboxLiveRowsByGroup,
appendInboxGroupKeys,
inboxDrawnGroupOrder,
countInboxPinDividers,
moveInInboxGroupOrder,
inboxCustomOrderPeers,
Expand Down Expand Up @@ -1824,6 +1826,48 @@ describe("the inbox's sorts", () => {
]);
});

it("keeps a custom-sorted group in place when its top row goes, and puts a new group last", () => {
const groupOf = (row: { key: string; group: string }) => row.group;
const groupsOn = (rows: readonly { key: string; group: string }[]) =>
groupInboxLiveRows(rows, groupOf).map((group) => group.key);
const draw = (
rows: readonly { key: string; group: string }[],
sort: "custom" | "recent",
draggedOrder: readonly string[],
seen: readonly string[],
) =>
orderInboxLiveRowsByGroup(
rows,
groupOf,
inboxDrawnGroupOrder({ sort, draggedOrder, customSeenOrder: seen }),
).map((row) => row.key);

const first = [
{ key: "a1", group: "project:a" },
{ key: "b1", group: "project:b" },
{ key: "a2", group: "project:a" },
];
const seen = appendInboxGroupKeys([], groupsOn(first));
expect(seen).toEqual(["project:a", "project:b"]);
// a1 is wrapped, and a thread in a new project shows up.
const later = [
{ key: "b1", group: "project:b" },
{ key: "a2", group: "project:a" },
{ key: "c1", group: "project:c" },
];
const seenLater = appendInboxGroupKeys(seen, groupsOn(later));
expect(appendInboxGroupKeys(seenLater, groupsOn(later))).toBe(seenLater);
// A saved list with a repeat still takes a new group.
expect(appendInboxGroupKeys(["project:a", "project:a"], ["project:b"])).toEqual([
"project:a",
"project:b",
]);
expect(draw(later, "custom", [], seenLater)).toEqual(["a2", "b1", "c1"]);
// A dragged order still wins, and the other sorts follow each group's first row.
expect(draw(later, "custom", ["project:b"], seenLater)).toEqual(["b1", "a2", "c1"]);
expect(draw(later, "recent", [], seenLater)).toEqual(["b1", "a2", "c1"]);
});

it("counts one line for each group that has pinned and unpinned rows", () => {
const row = (group: string, pinned: boolean) => ({
group,
Expand Down
45 changes: 42 additions & 3 deletions apps/web/src/components/Sidebar.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2681,6 +2681,42 @@ export function orderInboxLiveRowsByGroup<R>(
.flatMap((group) => group.rows);
}

/**
* `order` with the keys it lacks added at the end, in the order given. The same
* array when nothing is new, so a caller can tell a change by identity.
*/
export function appendInboxGroupKeys(
order: readonly string[],
keys: readonly string[],
): readonly string[] {
const placed = new Set(order);
let grew = false;
for (const key of keys) {
if (placed.has(key)) continue;
placed.add(key);
grew = true;
}
return grew ? [...placed] : order;
}

/**
* The group order the inbox draws. In the custom sort, a group the user never
* dragged keeps the place it held when the sort first showed it, so it stays
* put when its top row is wrapped, archived or moved. In the other sorts it
* follows its first row, as {@link orderInboxLiveRowsByGroup} does.
*/
export function inboxDrawnGroupOrder(input: {
readonly sort: InboxSort;
/** The order the user dragged the headers into. */
readonly draggedOrder: readonly string[];
/** Where the custom sort first showed each group. */
readonly customSeenOrder: readonly string[];
}): readonly string[] {
return input.sort === "custom"
? appendInboxGroupKeys(input.draggedOrder, input.customSeenOrder)
: input.draggedOrder;
}

/**
* The saved group order with one header moved among the ones on screen. Every
* group on screen gets a place, so moving one never makes another jump, and a
Expand All @@ -2693,9 +2729,12 @@ export function moveInInboxGroupOrder(input: {
readonly groupKey: string;
readonly toIndex: number;
}): string[] {
const placed = new Set(input.groupOrder);
const order = [...placed, ...input.shownGroups.filter((key) => !placed.has(key))];
return tradeSavedPlaces(order, input.shownGroups, input.groupKey, input.toIndex);
return tradeSavedPlaces(
appendInboxGroupKeys(input.groupOrder, input.shownGroups),
input.shownGroups,
input.groupKey,
input.toIndex,
);
}

/**
Expand Down
72 changes: 67 additions & 5 deletions apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ import {
countInboxPinDividers,
moveInInboxGroupOrder,
orderInboxLiveRowsByGroup,
appendInboxGroupKeys,
inboxDrawnGroupOrder,
inboxCustomOrderPeers,
moveInInboxCustomOrder,
trimInboxCustomOrder,
Expand Down Expand Up @@ -175,7 +177,7 @@ import { SidebarVersionTag } from "./sidebar/SidebarVersionTag";
import { readEnvironmentApi } from "../environmentApi";
import { useRoomsEnabled } from "~/hooks/useRoomsEnabled";
import { NO_REMOTE_CHILDREN, useRemoteFamilyChildren } from "../hooks/useRemoteFamilyChildren";
import { useSettings, useUpdateSettings } from "~/hooks/useSettings";
import { useClientSettingsHydrated, useSettings, useUpdateSettings } from "~/hooks/useSettings";
import { useServerKeybindings } from "../rpc/serverState";

import {
Expand Down Expand Up @@ -613,6 +615,8 @@ export default function Sidebar() {
const inboxSort = useSettings((s) => s.inboxSort);
const inboxCustomOrder = useSettings((s) => s.inboxCustomOrder);
const inboxGroupOrder = useSettings((s) => s.inboxGroupOrder);
const savedCustomSeenGroups = useSettings((s) => s.inboxCustomGroupOrder);
const settingsHydrated = useClientSettingsHydrated();
// A family's children on computers this app can't see, as the family tabs read them too.
const remoteFamilyChildren = useRemoteFamilyChildren(nowIso);
const { updateSettings } = useUpdateSettings();
Expand Down Expand Up @@ -928,18 +932,63 @@ export default function Sidebar() {
sidebarGroupingSetting === "computer" && environmentScopeOptions.length <= 1
? "none"
: sidebarGroupingSetting;
// The custom sort remembers where it first showed each group, so a group
// keeps its place when its top row goes; a group new to it goes last.
const customSeenGroups = useMemo(
() =>
inboxSort !== "custom" || sidebarGrouping === "none"
? savedCustomSeenGroups
: appendInboxGroupKeys(
savedCustomSeenGroups,
groupInboxLiveRows(liveEntriesBySort, (row) =>
inboxLiveGroupKey(sidebarGrouping, row),
).map((group) => group.key),
),
[inboxSort, liveEntriesBySort, savedCustomSeenGroups, sidebarGrouping],
);
// Saved once the computer's threads have loaded, so a half-loaded list doesn't
// fix the first places. The last attempt is kept so a failed save isn't
// retried on every render.
const customSeenGroupsSaveAttempt = useRef<readonly string[] | null>(null);
useEffect(() => {
if (
!settingsHydrated ||
!bootstrapComplete ||
customSeenGroups === savedCustomSeenGroups ||
customSeenGroups === customSeenGroupsSaveAttempt.current
) {
return;
}
customSeenGroupsSaveAttempt.current = customSeenGroups;
updateSettings({ inboxCustomGroupOrder: customSeenGroups });
}, [
bootstrapComplete,
customSeenGroups,
savedCustomSeenGroups,
settingsHydrated,
updateSettings,
]);
// Groups the user dragged keep that order; the fold and the jump labels read
// the rows in it.
const drawnGroupOrder = useMemo(
() =>
inboxDrawnGroupOrder({
sort: inboxSort,
draggedOrder: inboxGroupOrder,
customSeenOrder: customSeenGroups,
}),
[customSeenGroups, inboxGroupOrder, inboxSort],
);
const liveEntries = useMemo(
() =>
sidebarGrouping === "none"
? liveEntriesBySort
: orderInboxLiveRowsByGroup(
liveEntriesBySort,
(row) => inboxLiveGroupKey(sidebarGrouping, row),
inboxGroupOrder,
drawnGroupOrder,
),
[inboxGroupOrder, liveEntriesBySort, sidebarGrouping],
[drawnGroupOrder, liveEntriesBySort, sidebarGrouping],
);
// What a closed Wrapped shelf keeps under its header: the thread open in
// the chat, and the wrapped thread it sits under. The live list's fill
Expand Down Expand Up @@ -1301,7 +1350,11 @@ export default function Sidebar() {
"Reset your custom order?\n\nThreads go back to most recent first. You can't undo this.",
);
if (confirmed) {
updateSettings({ inboxCustomOrder: seedInboxCustomOrder(inboxThreads, "recent") });
// Groups take their places afresh from the reset rows.
updateSettings({
inboxCustomOrder: seedInboxCustomOrder(inboxThreads, "recent"),
inboxCustomGroupOrder: [],
});
}
}, [inboxThreads, updateSettings]);
// The scope menu is memoized; these change with the inbox's threads, which
Expand All @@ -1318,6 +1371,7 @@ export default function Sidebar() {
liveEntries,
inboxCustomOrder,
inboxGroupOrder,
customSeenGroups,
inboxThreads,
sidebarThreads,
sidebarGrouping,
Expand Down Expand Up @@ -1375,16 +1429,24 @@ export default function Sidebar() {
describeInboxGroupMenu({
canMoveUp: index > 0,
canMoveDown: index < before.shownGroups.length - 1,
hasSavedOrder: before.inboxGroupOrder.some((key) => key.startsWith(kind)),
// In the custom sort, remembered places count too: resetting takes
// them afresh from where each group's first row stands now.
hasSavedOrder: [
...before.inboxGroupOrder,
...(inboxSortRef.current === "custom" ? before.customSeenGroups : []),
].some((key) => key.startsWith(kind)),
}),
position,
);
// From wherever it is by the time the item is picked.
const source = inboxMoveSourceRef.current;
const current = source.shownGroups.indexOf(groupKey);
if (clicked === "reset") {
// The custom sort's remembered places go too, so it takes them afresh
// from where each group's first row stands now.
updateSettings({
inboxGroupOrder: source.inboxGroupOrder.filter((key) => !key.startsWith(kind)),
inboxCustomGroupOrder: source.customSeenGroups.filter((key) => !key.startsWith(kind)),
});
} else if (clicked === "move-up" || clicked === "move-down") {
const toIndex = current + (clicked === "move-up" ? -1 : 1);
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/localApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ describe("wsApi", () => {
inboxSort: "recent" as const,
inboxCustomOrder: [],
inboxGroupOrder: [],
inboxCustomGroupOrder: [],
sidebarProjectGroupingMode: "repository_path" as const,
sidebarProjectGroupingOverrides: {
"environment-local:/tmp/project": "separate" as const,
Expand Down Expand Up @@ -941,6 +942,7 @@ describe("wsApi", () => {
inboxSort: "recent" as const,
inboxCustomOrder: [],
inboxGroupOrder: [],
inboxCustomGroupOrder: [],
sidebarProjectGroupingMode: "repository_path" as const,
sidebarProjectGroupingOverrides: {
"environment-local:/tmp/project": "separate" as const,
Expand Down
7 changes: 7 additions & 0 deletions packages/contracts/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ export const ClientSettingsSchema = Schema.Struct({
// The order the user dragged the inbox's project and computer headers into,
// as group keys. Empty: each group sits where its first row would.
inboxGroupOrder: Schema.Array(Schema.String).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
// Where each group stood when the custom sort first showed it, as group keys.
// The custom sort places groups the user never dragged by this, so a group
// stays put when its top row goes away; the other sorts ignore it.
inboxCustomGroupOrder: Schema.Array(Schema.String).pipe(
Schema.withDecodingDefault(Effect.succeed([])),
),
sidebarProjectGroupingMode: SidebarProjectGroupingMode.pipe(
Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_PROJECT_GROUPING_MODE)),
),
Expand Down Expand Up @@ -1404,6 +1410,7 @@ export const ClientSettingsPatch = Schema.Struct({
inboxSort: Schema.optionalKey(InboxSort),
inboxCustomOrder: Schema.optionalKey(Schema.Array(Schema.String)),
inboxGroupOrder: Schema.optionalKey(Schema.Array(Schema.String)),
inboxCustomGroupOrder: Schema.optionalKey(Schema.Array(Schema.String)),
sidebarProjectGroupingMode: Schema.optionalKey(SidebarProjectGroupingMode),
sidebarProjectGroupingOverrides: Schema.optionalKey(
Schema.Record(TrimmedNonEmptyString, SidebarProjectGroupingMode),
Expand Down
Loading