diff --git a/apps/desktop/src/settings/DesktopClientSettings.test.ts b/apps/desktop/src/settings/DesktopClientSettings.test.ts index 2338a3c238..c62f893117 100644 --- a/apps/desktop/src/settings/DesktopClientSettings.test.ts +++ b/apps/desktop/src/settings/DesktopClientSettings.test.ts @@ -66,6 +66,7 @@ const clientSettings: ClientSettings = { ariMergeSoundEnabled: false, ariMergeShout: "ship-it", ariThreadFlagsEnabled: true, + ariThreadFlagSectionsEnabled: true, ariRelayShelfEnabled: true, ariLibraryLinksInAppEnabled: true, threadDetailsUsageEnabled: false, diff --git a/apps/web/src/components/Sidebar.logic.ts b/apps/web/src/components/Sidebar.logic.ts index 0f93fad148..397593f4d9 100644 --- a/apps/web/src/components/Sidebar.logic.ts +++ b/apps/web/src/components/Sidebar.logic.ts @@ -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"; @@ -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}`; diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index 971b90588e..2daac3cba4 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -35,6 +35,7 @@ import { } from "@t3tools/client-runtime/state/thread-settled"; import { THREAD_FLAGS, + groupThreadsByFlag, matchesThreadFlagFilter, threadFlagOf, type ThreadFlagFilter, @@ -292,6 +293,11 @@ import { SidebarSectionHeader, SidebarSectionPlaceholder, } from "./sidebar/SidebarListMarkers"; +import { + SidebarFlagSectionHeader, + flagRailClassName, + sidebarFlagSectionMarker, +} from "./sidebar/SidebarFlagSectionHeader"; function sameSidebarProviderEntries( left: ReadonlyMap, @@ -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. @@ -438,6 +446,7 @@ function useSidebarThreads(input: { readonly projectScopeKey: string | null; readonly scopedProjectKeys: ReadonlySet | null; readonly flagFilter: ThreadFlagFilter | null; + readonly flagSectionsEnabled: boolean; readonly serverConfigs: ReadonlyMap; readonly connectedEnvironmentIds: readonly EnvironmentId[]; readonly optimisticDrop: SidebarOptimisticDrop | null; @@ -453,6 +462,7 @@ function useSidebarThreads(input: { projectScopeKey, scopedProjectKeys, flagFilter, + flagSectionsEnabled, serverConfigs, connectedEnvironmentIds, optimisticDrop, @@ -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}`, }); @@ -670,6 +682,7 @@ function partitionSidebarThreads(input: SidebarThreadPartitionInput) { workingShelfEnabled, relayShelfEnabled, sortActiveBySend, + groupActiveByFlag, } = input; const preciseNow = new Date().toISOString(); const visible = filterSidebarV2VisibleThreads( @@ -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 @@ -1078,6 +1097,10 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve const threadSearchInputRef = useRef(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(null); const [searchHighlightKey, setSearchHighlightKey] = useState(null); const connectedEnvironmentIds = useConnectedEnvironmentIds(); @@ -1405,6 +1428,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve projectScopeKey, scopedProjectKeys, flagFilter: flagsEnabled ? flagFilter : null, + flagSectionsEnabled, serverConfigs, connectedEnvironmentIds, optimisticDrop, @@ -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[], @@ -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")); @@ -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 ( + sidebarFlagSectionMarker(candidate.flag) === item.marker, + ); + if (group) { + items.push( + , + ); + } + break; + } case "pinned-header": items.push( + updateSettings({ ariThreadFlagSectionsEnabled: Boolean(checked) }) + } + aria-label={gt("Flag sections")} + /> + } + /> + ); +} + function RelayShelfRow() { const gt = useGT(); const searchableSetting = useSearchableSetting(); @@ -266,6 +291,7 @@ export function AriSettings() { + diff --git a/apps/web/src/components/settings/settingsSearch.ts b/apps/web/src/components/settings/settingsSearch.ts index 4b3fbab423..70b22809e6 100644 --- a/apps/web/src/components/settings/settingsSearch.ts +++ b/apps/web/src/components/settings/settingsSearch.ts @@ -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"), diff --git a/apps/web/src/components/sidebar/SidebarFlagSectionHeader.tsx b/apps/web/src/components/sidebar/SidebarFlagSectionHeader.tsx new file mode 100644 index 0000000000..08c415336b --- /dev/null +++ b/apps/web/src/components/sidebar/SidebarFlagSectionHeader.tsx @@ -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 = { + 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 ( + +
+ {Icon ? ( + + ) : null} + + {THREAD_FLAG_SECTION_LABELS[flag ?? "none"]} + + + + {count} + +
+
+ ); +} diff --git a/apps/web/src/components/sidebar/SidebarListMarkers.tsx b/apps/web/src/components/sidebar/SidebarListMarkers.tsx index c7ddcfe69a..dcb487df41 100644 --- a/apps/web/src/components/sidebar/SidebarListMarkers.tsx +++ b/apps/web/src/components/sidebar/SidebarListMarkers.tsx @@ -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; diff --git a/apps/web/src/components/sidebar/SidebarThreadRow.tsx b/apps/web/src/components/sidebar/SidebarThreadRow.tsx index 9621b56141..8bac20d425 100644 --- a/apps/web/src/components/sidebar/SidebarThreadRow.tsx +++ b/apps/web/src/components/sidebar/SidebarThreadRow.tsx @@ -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 @@ -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", )} > diff --git a/docs/user/ari.md b/docs/user/ari.md index f4bac6e5f9..274e845e00 100644 --- a/docs/user/ari.md +++ b/docs/user/ari.md @@ -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. diff --git a/packages/client-runtime/src/state/threadFlags.test.ts b/packages/client-runtime/src/state/threadFlags.test.ts index e49b36297e..f6120098a7 100644 --- a/packages/client-runtime/src/state/threadFlags.test.ts +++ b/packages/client-runtime/src/state/threadFlags.test.ts @@ -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([ @@ -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]); + }); +}); diff --git a/packages/client-runtime/src/state/threadFlags.ts b/packages/client-runtime/src/state/threadFlags.ts index dab82e7c94..19aeabfbdb 100644 --- a/packages/client-runtime/src/state/threadFlags.ts +++ b/packages/client-runtime/src/state/threadFlags.ts @@ -26,3 +26,44 @@ export function matchesThreadFlagFilter( const flag = threadFlagOf(tags); return filter === "any" ? flag !== null : flag === filter; } + +/** Sidebar order of the flag sections. Unflagged threads come after them. */ +const THREAD_FLAG_SECTION_ORDER = [ + "urgent", + "working", + "later", +] as const satisfies ReadonlyArray; + +/** Section headers. "In progress" because the sidebar's "Working" shelf means an agent is running. */ +export const THREAD_FLAG_SECTION_LABELS: Record = { + urgent: "Urgent", + working: "In progress", + later: "Later", + none: "Other", +}; + +export interface ThreadFlagGroup { + readonly flag: ThreadFlag | null; + readonly threads: T[]; +} + +/** + * Splits threads into flag sections, in section order, keeping each thread's + * order within its section. Empty sections are left out. + */ +export function groupThreadsByFlag( + threads: ReadonlyArray, + tagsOf: (thread: T) => ReadonlyArray | undefined, +): ThreadFlagGroup[] { + const byFlag = new Map(); + for (const thread of threads) { + const flag = threadFlagOf(tagsOf(thread)); + const group = byFlag.get(flag); + if (group) group.push(thread); + else byFlag.set(flag, [thread]); + } + return [...THREAD_FLAG_SECTION_ORDER, null].flatMap((flag) => { + const group = byFlag.get(flag); + return group ? [{ flag, threads: group }] : []; + }); +} diff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.ts index 0983fb105f..9669317715 100644 --- a/packages/contracts/src/settings.ts +++ b/packages/contracts/src/settings.ts @@ -542,6 +542,10 @@ export const ClientSettingsSchema = Schema.Struct({ ariMergeSoundEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))), ariMergeShout: AriMergeShout.pipe(Schema.withDecodingDefault(Effect.succeed("ship-it"))), ariThreadFlagsEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))), + // Sidebar flag sections and colour rails; only applies while ariThreadFlagsEnabled is on. + ariThreadFlagSectionsEnabled: Schema.Boolean.pipe( + Schema.withDecodingDefault(Effect.succeed(true)), + ), ariRelayShelfEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))), ariLibraryLinksInAppEnabled: Schema.Boolean.pipe( Schema.withDecodingDefault(Effect.succeed(true)), @@ -2125,6 +2129,7 @@ export const ClientSettingsPatch = Schema.Struct({ ariMergeSoundEnabled: Schema.optionalKey(Schema.Boolean), ariMergeShout: Schema.optionalKey(AriMergeShout), ariThreadFlagsEnabled: Schema.optionalKey(Schema.Boolean), + ariThreadFlagSectionsEnabled: Schema.optionalKey(Schema.Boolean), ariRelayShelfEnabled: Schema.optionalKey(Schema.Boolean), ariLibraryLinksInAppEnabled: Schema.optionalKey(Schema.Boolean), toolCallVisibility: Schema.optionalKey(ToolCallVisibility),