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
78 changes: 25 additions & 53 deletions apps/web/src/components/Sidebar.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ describe("hasUnseenCompletion", () => {
it("returns true when a thread completed after its last visit", () => {
expect(
hasUnseenCompletion({
hasActionableProposedPlan: false,
hasPendingApprovals: false,
hasPendingUserInput: false,
interactionMode: "default",
latestTurn: makeLatestTurn(),
lastVisitedAt: "2026-03-09T10:04:00.000Z",
proposedPlans: [],
session: null,
}),
).toBe(true);
Expand Down Expand Up @@ -322,17 +324,14 @@ describe("getVisibleSidebarThreadIds", () => {
expect(
getVisibleSidebarThreadIds([
{
renderedThreads: [
{ id: ThreadId.makeUnsafe("thread-12") },
{ id: ThreadId.makeUnsafe("thread-11") },
{ id: ThreadId.makeUnsafe("thread-10") },
renderedThreadIds: [
ThreadId.makeUnsafe("thread-12"),
ThreadId.makeUnsafe("thread-11"),
ThreadId.makeUnsafe("thread-10"),
],
},
{
renderedThreads: [
{ id: ThreadId.makeUnsafe("thread-8") },
{ id: ThreadId.makeUnsafe("thread-6") },
],
renderedThreadIds: [ThreadId.makeUnsafe("thread-8"), ThreadId.makeUnsafe("thread-6")],
},
]),
).toEqual([
Expand All @@ -349,17 +348,14 @@ describe("getVisibleSidebarThreadIds", () => {
getVisibleSidebarThreadIds([
{
shouldShowThreadPanel: false,
renderedThreads: [
{ id: ThreadId.makeUnsafe("thread-hidden-2") },
{ id: ThreadId.makeUnsafe("thread-hidden-1") },
renderedThreadIds: [
ThreadId.makeUnsafe("thread-hidden-2"),
ThreadId.makeUnsafe("thread-hidden-1"),
],
},
{
shouldShowThreadPanel: true,
renderedThreads: [
{ id: ThreadId.makeUnsafe("thread-12") },
{ id: ThreadId.makeUnsafe("thread-11") },
],
renderedThreadIds: [ThreadId.makeUnsafe("thread-12"), ThreadId.makeUnsafe("thread-11")],
},
]),
).toEqual([ThreadId.makeUnsafe("thread-12"), ThreadId.makeUnsafe("thread-11")]);
Expand Down Expand Up @@ -400,10 +396,12 @@ describe("isContextMenuPointerDown", () => {

describe("resolveThreadStatusPill", () => {
const baseThread = {
hasActionableProposedPlan: false,
hasPendingApprovals: false,
hasPendingUserInput: false,
interactionMode: "plan" as const,
latestTurn: null,
lastVisitedAt: undefined,
proposedPlans: [],
session: {
provider: "codex" as const,
status: "running" as const,
Expand All @@ -416,19 +414,22 @@ describe("resolveThreadStatusPill", () => {
it("shows pending approval before all other statuses", () => {
expect(
resolveThreadStatusPill({
thread: baseThread,
hasPendingApprovals: true,
hasPendingUserInput: true,
thread: {
...baseThread,
hasPendingApprovals: true,
hasPendingUserInput: true,
},
}),
).toMatchObject({ label: "Pending Approval", pulse: false });
});

it("shows awaiting input when plan mode is blocked on user answers", () => {
expect(
resolveThreadStatusPill({
thread: baseThread,
hasPendingApprovals: false,
hasPendingUserInput: true,
thread: {
...baseThread,
hasPendingUserInput: true,
},
}),
).toMatchObject({ label: "Awaiting Input", pulse: false });
});
Expand All @@ -437,8 +438,6 @@ describe("resolveThreadStatusPill", () => {
expect(
resolveThreadStatusPill({
thread: baseThread,
hasPendingApprovals: false,
hasPendingUserInput: false,
}),
).toMatchObject({ label: "Working", pulse: true });
});
Expand All @@ -448,26 +447,14 @@ describe("resolveThreadStatusPill", () => {
resolveThreadStatusPill({
thread: {
...baseThread,
hasActionableProposedPlan: true,
latestTurn: makeLatestTurn(),
proposedPlans: [
{
id: "plan-1" as never,
turnId: "turn-1" as never,
createdAt: "2026-03-09T10:00:00.000Z",
updatedAt: "2026-03-09T10:05:00.000Z",
planMarkdown: "# Plan",
implementedAt: null,
implementationThreadId: null,
},
],
session: {
...baseThread.session,
status: "ready",
orchestrationStatus: "ready",
},
},
hasPendingApprovals: false,
hasPendingUserInput: false,
}),
).toMatchObject({ label: "Plan Ready", pulse: false });
});
Expand All @@ -478,25 +465,12 @@ describe("resolveThreadStatusPill", () => {
thread: {
...baseThread,
latestTurn: makeLatestTurn(),
proposedPlans: [
{
id: "plan-1" as never,
turnId: "turn-1" as never,
createdAt: "2026-03-09T10:00:00.000Z",
updatedAt: "2026-03-09T10:05:00.000Z",
planMarkdown: "# Plan",
implementedAt: "2026-03-09T10:06:00.000Z",
implementationThreadId: "thread-implement" as never,
},
],
session: {
...baseThread.session,
status: "ready",
orchestrationStatus: "ready",
},
},
hasPendingApprovals: false,
hasPendingUserInput: false,
}),
).toMatchObject({ label: "Completed", pulse: false });
});
Expand All @@ -515,8 +489,6 @@ describe("resolveThreadStatusPill", () => {
orchestrationStatus: "ready",
},
},
hasPendingApprovals: false,
hasPendingUserInput: false,
}),
).toMatchObject({ label: "Completed", pulse: false });
});
Expand Down
39 changes: 16 additions & 23 deletions apps/web/src/components/Sidebar.logic.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import * as React from "react";
import type { SidebarProjectSortOrder, SidebarThreadSortOrder } from "@t3tools/contracts/settings";
import type { Thread } from "../types";
import type { SidebarThreadSummary, Thread } from "../types";
import { cn } from "../lib/utils";
import {
findLatestProposedPlan,
hasActionableProposedPlan,
isLatestTurnSettled,
} from "../session-logic";
import { isLatestTurnSettled } from "../session-logic";

export const THREAD_SELECTION_SAFE_SELECTOR = "[data-thread-item], [data-thread-selection-safe]";
export const THREAD_JUMP_HINT_SHOW_DELAY_MS = 100;
Expand Down Expand Up @@ -47,8 +43,13 @@ const THREAD_STATUS_PRIORITY: Record<ThreadStatusPill["label"], number> = {
};

type ThreadStatusInput = Pick<
Thread,
"interactionMode" | "latestTurn" | "proposedPlans" | "session"
SidebarThreadSummary,
| "hasActionableProposedPlan"
| "hasPendingApprovals"
| "hasPendingUserInput"
| "interactionMode"
| "latestTurn"
| "session"
> & {
lastVisitedAt?: string | undefined;
};
Expand Down Expand Up @@ -232,15 +233,11 @@ export function orderItemsByPreferredIds<TItem, TId>(input: {
export function getVisibleSidebarThreadIds<TThreadId>(
renderedProjects: readonly {
shouldShowThreadPanel?: boolean;
renderedThreads: readonly {
id: TThreadId;
}[];
renderedThreadIds: readonly TThreadId[];
}[],
): TThreadId[] {
return renderedProjects.flatMap((renderedProject) =>
renderedProject.shouldShowThreadPanel === false
? []
: renderedProject.renderedThreads.map((thread) => thread.id),
renderedProject.shouldShowThreadPanel === false ? [] : renderedProject.renderedThreadIds,
);
}

Expand Down Expand Up @@ -313,12 +310,10 @@ export function resolveThreadRowClassName(input: {

export function resolveThreadStatusPill(input: {
thread: ThreadStatusInput;
hasPendingApprovals: boolean;
hasPendingUserInput: boolean;
}): ThreadStatusPill | null {
const { hasPendingApprovals, hasPendingUserInput, thread } = input;
const { thread } = input;

if (hasPendingApprovals) {
if (thread.hasPendingApprovals) {
return {
label: "Pending Approval",
colorClass: "text-amber-600 dark:text-amber-300/90",
Expand All @@ -327,7 +322,7 @@ export function resolveThreadStatusPill(input: {
};
}

if (hasPendingUserInput) {
if (thread.hasPendingUserInput) {
return {
label: "Awaiting Input",
colorClass: "text-indigo-600 dark:text-indigo-300/90",
Expand Down Expand Up @@ -355,12 +350,10 @@ export function resolveThreadStatusPill(input: {
}

const hasPlanReadyPrompt =
!hasPendingUserInput &&
!thread.hasPendingUserInput &&
thread.interactionMode === "plan" &&
isLatestTurnSettled(thread.latestTurn, thread.session) &&
hasActionableProposedPlan(
findLatestProposedPlan(thread.proposedPlans, thread.latestTurn?.turnId ?? null),
);
thread.hasActionableProposedPlan;
if (hasPlanReadyPrompt) {
return {
label: "Plan Ready",
Expand Down
Loading
Loading