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 @@ -66,6 +66,7 @@ const clientSettings: ClientSettings = {
ariMergeSoundEnabled: false,
ariMergeShout: "ship-it",
ariThreadFlagsEnabled: true,
ariThreadFlagSectionsEnabled: true,
ariRelayShelfEnabled: true,
ariLibraryLinksInAppEnabled: true,
threadDetailsUsageEnabled: false,
Expand Down
7 changes: 6 additions & 1 deletion apps/web/src/components/Sidebar.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
type EnvironmentThreadShell,
} from "@t3tools/client-runtime/state/models";
import { isThreadActionable } from "@t3tools/client-runtime/state/thread-inbox";
import type { ThreadFlag } from "@t3tools/client-runtime/state/thread-flags";
import { isShownUnderParent } from "@t3tools/client-runtime/state/threads";
import { backgroundWorkHoldsCompletion } from "@t3tools/shared/orchestrationV2PendingBackgroundWork";
import { threadPullRequestSearchTerms } from "@t3tools/shared/threadPullRequests";
Expand Down Expand Up @@ -235,7 +236,11 @@ export type SidebarListMarker =
| "working-header"
| "relay-header"
| "snoozed-header"
| "settled-header";
| "settled-header"
| SidebarFlagSectionMarker;

/** Flag group headers inside the active section; they never change a row's section. */
export type SidebarFlagSectionMarker = `flag-${ThreadFlag | "none"}-header`;

export function sidebarMarkerId(marker: SidebarListMarker): string {
return `${SIDEBAR_MARKER_PREFIX}${marker}`;
Expand Down
67 changes: 64 additions & 3 deletions apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
} from "@t3tools/client-runtime/state/thread-settled";
import {
THREAD_FLAGS,
groupThreadsByFlag,
matchesThreadFlagFilter,
threadFlagOf,
type ThreadFlagFilter,
Expand Down Expand Up @@ -292,6 +293,11 @@ import {
SidebarSectionHeader,
SidebarSectionPlaceholder,
} from "./sidebar/SidebarListMarkers";
import {
SidebarFlagSectionHeader,
flagRailClassName,
sidebarFlagSectionMarker,
} from "./sidebar/SidebarFlagSectionHeader";

function sameSidebarProviderEntries(
left: ReadonlyMap<string, SidebarProviderEntry>,
Expand Down Expand Up @@ -378,6 +384,8 @@ interface SidebarThreadPartitionInput {
readonly relayShelfEnabled: boolean;
/** Boring mode: folders list active threads by the user's latest message. */
readonly sortActiveBySend: boolean;
/** Flag sections: flagged active threads sort ahead of unflagged ones, by flag. */
readonly groupActiveByFlag: boolean;
// Snooze wakes, the queued-turn grace and the Working shelf's exit grace depend
// on the clock, so the minute tick, the precise snooze-wake tick and the inbox
// tracker's expiry version are inputs: a new key repartitions.
Expand Down Expand Up @@ -438,6 +446,7 @@ function useSidebarThreads(input: {
readonly projectScopeKey: string | null;
readonly scopedProjectKeys: ReadonlySet<string> | null;
readonly flagFilter: ThreadFlagFilter | null;
readonly flagSectionsEnabled: boolean;
readonly serverConfigs: ReadonlyMap<EnvironmentId, EnvironmentServerConfig>;
readonly connectedEnvironmentIds: readonly EnvironmentId[];
readonly optimisticDrop: SidebarOptimisticDrop | null;
Expand All @@ -453,6 +462,7 @@ function useSidebarThreads(input: {
projectScopeKey,
scopedProjectKeys,
flagFilter,
flagSectionsEnabled,
serverConfigs,
connectedEnvironmentIds,
optimisticDrop,
Expand Down Expand Up @@ -518,6 +528,8 @@ function useSidebarThreads(input: {
workingShelfEnabled,
relayShelfEnabled,
sortActiveBySend: folderGroups !== null,
// Folders already group the active rows, so they keep their own order.
groupActiveByFlag: flagSectionsEnabled && folderGroups === null,
clockKey: `${nowMinute}:${snoozeWakeClock}:${inboxReturnsVersion}`,
});

Expand Down Expand Up @@ -670,6 +682,7 @@ function partitionSidebarThreads(input: SidebarThreadPartitionInput) {
workingShelfEnabled,
relayShelfEnabled,
sortActiveBySend,
groupActiveByFlag,
} = input;
const preciseNow = new Date().toISOString();
const visible = filterSidebarV2VisibleThreads(
Expand Down Expand Up @@ -734,11 +747,17 @@ function partitionSidebarThreads(input: SidebarThreadPartitionInput) {
}
// Availability gates dragging only; sorting must stay consistent across clients.
const sortedPinned = sortPinnedThreadsForSidebar(pinned);
const sortedActive = sortActiveBySend
const sortedActiveFlat = sortActiveBySend
? sortWorkingThreadsBySend(active)
: workingShelfEnabled
? sortInboxThreadsByReturn(active, inboxObservation.returnedAt)
: sortThreadsForSidebar(active);
// Flag groups sit inside the active section, so the active order follows them.
const sortedActive = groupActiveByFlag
? groupThreadsByFlag(sortedActiveFlat, (thread) => thread.source.tags).flatMap(
(group) => group.threads,
)
: sortedActiveFlat;
return {
pinnedThreads:
optimisticDrop?.section !== "pinned" || optimisticDrop.order === null
Expand Down Expand Up @@ -1078,6 +1097,10 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
const threadSearchInputRef = useRef<HTMLInputElement>(null);
const [threadSearchQuery, setThreadSearchQuery] = useState("");
const flagsEnabled = useClientSettings((s) => s.ariThreadFlagsEnabled);
// Flag sections and rails are an opt-out on top of thread flags.
const flagSectionsEnabled = useClientSettings(
(s) => s.ariThreadFlagsEnabled && s.ariThreadFlagSectionsEnabled,
);
const [flagFilter, setFlagFilter] = useState<ThreadFlagFilter | null>(null);
const [searchHighlightKey, setSearchHighlightKey] = useState<string | null>(null);
const connectedEnvironmentIds = useConnectedEnvironmentIds();
Expand Down Expand Up @@ -1405,6 +1428,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
projectScopeKey,
scopedProjectKeys,
flagFilter: flagsEnabled ? flagFilter : null,
flagSectionsEnabled,
serverConfigs,
connectedEnvironmentIds,
optimisticDrop,
Expand Down Expand Up @@ -2005,6 +2029,12 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
});
};
const hasProjectFolders = projectFolders !== null && projectFolders.length > 0;
// Project folders already group the active rows, so flag headers show only in the flat list.
const activeFlagGroups =
flagSectionsEnabled && projectFolders === null
? groupThreadsByFlag(activeThreads, (thread) => thread.source.tags)
: [];
const showFlagSections = activeFlagGroups.some((group) => group.flag !== null);
const sidebarListItemsFresh = ((): readonly SidebarListItem[] => {
const rowsOf = (
list: readonly EnvironmentThreadShell[],
Expand All @@ -2031,9 +2061,15 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
const pinnedRows = rowsOf(pinnedThreads, "pinned");
items.push(...pinnedRows);
items.push({ kind: "marker", marker: "pinned-divider" });
const activeRows = rowsOf(activeThreads, "active");
items.push({ kind: "marker", marker: "active-placeholder" });
items.push(...activeRows);
if (showFlagSections) {
for (const group of activeFlagGroups) {
items.push({ kind: "marker", marker: sidebarFlagSectionMarker(group.flag) });
items.push(...rowsOf(group.threads, "active"));
}
} else {
items.push(...rowsOf(activeThreads, "active"));
}
if (workingThreads.length > 0) {
items.push({ kind: "marker", marker: "working-header" });
items.push(...rowsOf(visibleWorkingThreads, "working"));
Expand Down Expand Up @@ -3529,6 +3565,11 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
: isCard
? "card"
: "slim";
// Pinned and running threads keep their place, so their rail still shows the flag.
const railFlag =
flagSectionsEnabled && rowVariant === "card"
? threadFlagOf(thread.source.tags)
: null;
return (
<SortableThreadRow
key={threadKey}
Expand Down Expand Up @@ -3561,6 +3602,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
snoozeSupported={serverConfigs.has(thread.environmentId)}
pinningSupported={serverConfigs.has(thread.environmentId)}
isPinned={thread.pinnedAt != null}
railClassName={railFlag ? flagRailClassName(railFlag) : undefined}
dropVerb={
dragState?.activeKey === threadKey
? resolveSidebarDropVerb(dragState.activeSection, dragTargetSection)
Expand Down Expand Up @@ -3678,6 +3720,25 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
continue;
}
switch (item.marker) {
case "flag-urgent-header":
case "flag-working-header":
case "flag-later-header":
case "flag-none-header": {
const group = activeFlagGroups.find(
(candidate) =>
sidebarFlagSectionMarker(candidate.flag) === item.marker,
);
if (group) {
items.push(
<SidebarFlagSectionHeader
key={item.marker}
flag={group.flag}
count={group.threads.length}
/>,
);
}
break;
}
case "pinned-header":
items.push(
<SidebarDragBoundary
Expand Down
26 changes: 26 additions & 0 deletions apps/web/src/components/settings/AriSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,31 @@ function ThreadFlagsRow() {
);
}

function ThreadFlagSectionsRow() {
const gt = useGT();
const searchableSetting = useSearchableSetting();
const settings = useScopedSettings();
const updateSettings = useUpdateScopedSettings();
return (
<SettingsRow
{...searchableSetting("ari-thread-flag-sections")}
description={gt(
"Group flagged threads under Urgent, In progress and Later headers at the top of the sidebar, with a colour rail on flagged rows. Off keeps the usual order with only the flag icon. Needs Thread flags.",
)}
control={
<Switch
checked={settings.ariThreadFlagsEnabled && settings.ariThreadFlagSectionsEnabled}
disabled={!settings.ariThreadFlagsEnabled}
onCheckedChange={(checked) =>
updateSettings({ ariThreadFlagSectionsEnabled: Boolean(checked) })
}
aria-label={gt("Flag sections")}
/>
}
/>
);
}

function RelayShelfRow() {
const gt = useGT();
const searchableSetting = useSearchableSetting();
Expand Down Expand Up @@ -266,6 +291,7 @@ export function AriSettings() {
<SettingsSection id="ari-features" title={gt("Features")}>
<MergeShoutRow />
<ThreadFlagsRow />
<ThreadFlagSectionsRow />
<RelayShelfRow />
<TeamThreadsRow />
<LibraryLinksRow />
Expand Down
8 changes: 8 additions & 0 deletions apps/web/src/components/settings/settingsSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,14 @@ export const SETTINGS_SEARCH_ITEMS = [
to: "/settings/ari",
searchTerms: ["ari livemap flag urgent later working mark sidebar icon"],
},
{
id: "ari-thread-flag-sections",
title: msg("Flag sections"),
to: "/settings/ari",
searchTerms: [
"ari livemap flag urgent later working in progress group section header rail colour color sidebar",
],
},
{
id: "ari-relay-shelf",
title: msg("Relay section"),
Expand Down
53 changes: 53 additions & 0 deletions apps/web/src/components/sidebar/SidebarFlagSectionHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {
THREAD_FLAG_SECTION_LABELS,
type ThreadFlag,
} from "@t3tools/client-runtime/state/thread-flags";

import { cn } from "~/lib/utils";
import type { SidebarFlagSectionMarker } from "../Sidebar.logic";
import { FLAG_ICONS, FLAG_ICON_CLASSES } from "./SidebarFlagFilter";
import { SortableSidebarMarker } from "./SidebarListMarkers";

const FLAG_RAIL_COLORS: Record<ThreadFlag, string> = {
urgent: "before:bg-error",
working: "before:bg-warning",
later: "before:bg-secondary-label",
};

/** A coloured bar down the left of each row in a flag section; rows touch, so it reads as one rail. */
export const flagRailClassName = (flag: ThreadFlag): string =>
cn(
"relative pl-2.5 before:absolute before:inset-y-0 before:left-1 before:w-[3px] before:content-['']",
FLAG_RAIL_COLORS[flag],
);

export const sidebarFlagSectionMarker = (flag: ThreadFlag | null): SidebarFlagSectionMarker =>
`flag-${flag ?? "none"}-header`;

/** A static header over one flag group inside the active section. */
export function SidebarFlagSectionHeader(props: { flag: ThreadFlag | null; count: number }) {
const { flag, count } = props;
const marker = sidebarFlagSectionMarker(flag);
const Icon = flag === null ? null : FLAG_ICONS[flag];
const tone = flag === null ? "text-sidebar-muted-foreground" : FLAG_ICON_CLASSES[flag];
return (
<SortableSidebarMarker
marker={marker}
data-testid={`sidebar-${marker}`}
className="relative mx-0.5 h-7"
>
<div className="flex h-7 items-center gap-1.5 px-2 text-xs font-medium">
{Icon ? (
<Icon aria-hidden className={cn("size-3 shrink-0", tone)} fill="currentColor" />
) : null}
<span className={cn("min-w-0 truncate", tone)}>
{THREAD_FLAG_SECTION_LABELS[flag ?? "none"]}
</span>
<span aria-hidden className="h-px min-w-2 flex-1 bg-sidebar-border/50" />
<span className="shrink-0 font-normal tabular-nums text-sidebar-muted-foreground">
{count}
</span>
</div>
</SortableSidebarMarker>
);
}
2 changes: 1 addition & 1 deletion apps/web/src/components/sidebar/SidebarListMarkers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from "../Sidebar.logic";
import { SIDEBAR_SORTABLE_DRAG_DISABLED } from "./SidebarThreadRow";

function SortableSidebarMarker(props: {
export function SortableSidebarMarker(props: {
marker: SidebarListMarker;
className?: string;
children?: ReactNode;
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/components/sidebar/SidebarThreadRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,8 @@ type SidebarThreadRowProps = {
snoozeWakeLabelText: string | null;
wokeAt: string | null;
isActive: boolean;
/** Extra classes on a card row's list item, such as a flag section's colour rail. */
railClassName?: string | undefined;
// Set on the active row only; scrolls it into view when a reveal is owed.
revealRef?: ((row: HTMLElement, threadKey: string) => (() => void) | undefined) | undefined;
// Unlike isActive, never true for the ancestor standing in for an open
Expand Down Expand Up @@ -1571,6 +1573,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
className={cn(
"list-none py-0.5 [content-visibility:auto] [contain-intrinsic-size:auto_78px]",
metaLineEmpty && "[contain-intrinsic-size:auto_60px]",
props.railClassName,
sortable?.isDragging && "relative z-20",
)}
>
Expand Down
6 changes: 5 additions & 1 deletion docs/user/ari.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# Ari

Settings → Ari holds the switches for the Ari features (merge shout, thread flags, the Relay section, team threads, Ari Library links) and shows the Ari CLI account and relay health on each connected server host. On mobile, open the environment in Settings to see its Ari agent host panel. Fix commands run on the named server, including when you connect remotely. Reading this information requires the `ari:read` permission; guest thread access does not include it.
Settings → Ari holds the switches for the Ari features (merge shout, thread flags, flag sections, the Relay section, team threads, Ari Library links) and shows the Ari CLI account and relay health on each connected server host. On mobile, open the environment in Settings to see its Ari agent host panel. Fix commands run on the named server, including when you connect remotely. Reading this information requires the `ari:read` permission; guest thread access does not include it.

A quiet sidebar dot appears when relay delivery needs attention or messages are held. Held messages on your current environment open the Ari relay site; other environments open their settings. Unbound held messages appear only in the hub’s account-wide list until Ari binds them to an environment. Approval and trust decisions stay on the Ari site. Held messages show senders only.

Threads containing an Ari relay marker show the sender in a badge. In the web and desktop apps, a thread that a relay message started carries the `relay` tag and a relay icon in the sidebar, and sits in a Relay section there, apart from the threads you started; threads started before this was added do not. A relay thread that waits for your approval or answer, or that failed, shows with your own threads until that is dealt with. One you write in yourself stays with your own threads, and one you pin, snooze or settle goes where those go. Settings → Ari → Relay section turns the section off; the icon stays. Folders have no Relay section. The marker is message text and can be forged; the badge, the icon and the section do not verify identity or grant permissions.

## Thread flags

Right-click a thread in the sidebar and flag it as urgent, later, or working; a flagged thread shows the flag's icon. In the web and desktop apps, flagged threads in the active list are grouped under Urgent, In progress and Later headers, above the unflagged ones under Other, and each flagged row carries a rail in the flag's colour. The headers show only while an active thread is flagged, and order within a group stays as it was. Pinned threads and threads in the Working section keep their place and show only the rail. Folders keep their own grouping and show no flag headers. Settings → Ari → Flag sections turns the grouping and the rail off and leaves the icon; Settings → Ari → Thread flags turns flags off altogether.

## Sharing a thread and handing one over

Ask your agent to send a relay question with this thread, and the teammate's agent can read your thread's transcript to answer it. The message shows a Shared thread line with the thread's title; the teammate can also read it on the Ari relay site through the conversation link.
Expand Down
27 changes: 26 additions & 1 deletion packages/client-runtime/src/state/threadFlags.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vite-plus/test";

import { matchesThreadFlagFilter } from "./threadFlags.ts";
import { groupThreadsByFlag, matchesThreadFlagFilter } from "./threadFlags.ts";

describe("matchesThreadFlagFilter", () => {
it.each([
Expand All @@ -16,3 +16,28 @@ describe("matchesThreadFlagFilter", () => {
expect(matchesThreadFlagFilter(tags, filter)).toBe(expected);
});
});

describe("groupThreadsByFlag", () => {
it("orders sections urgent, working, later, unflagged and keeps order within each", () => {
const threads = [
{ id: "a", tags: ["flag:later"] },
{ id: "b", tags: [] },
{ id: "c", tags: ["flag:urgent"] },
{ id: "d", tags: ["flag:later", "other"] },
{ id: "e", tags: undefined },
{ id: "f", tags: ["flag:working"] },
];
const groups = groupThreadsByFlag(threads, (thread) => thread.tags);
expect(groups.map((group) => [group.flag, group.threads.map((thread) => thread.id)])).toEqual([
["urgent", ["c"]],
["working", ["f"]],
["later", ["a", "d"]],
[null, ["b", "e"]],
]);
});

it("leaves out empty sections", () => {
const groups = groupThreadsByFlag([{ tags: [] }], (thread) => thread.tags);
expect(groups.map((group) => group.flag)).toEqual([null]);
});
});
Loading