fix(web): plans stop hijacking the UI, fold into chat instead (#5558)

Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
Theo BrowneandClaude Fable 5 authored and GitHub committed 2026-08-07 00:16:14 -07:00
1 parent 4a07c1ca9d
commit a8cd2ad2eb
30 files changed
+619 -768

No files matched your search

@@ -13,7 +13,6 @@ import * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
import * as DesktopClientSettings from "./DesktopClientSettings.ts";
const clientSettings: ClientSettings = {
autoOpenPlanSidebar: false,
confirmThreadArchive: true,
confirmThreadDelete: false,
dismissedProviderUpdateNotificationKeys: [],
@@ -51,6 +51,7 @@ import { OrchestrationEngineLive } from "../src/orchestration/Layers/Orchestrati
import { OrchestrationProjectionPipelineLive } from "../src/orchestration/Layers/ProjectionPipeline.ts";
import { OrchestrationProjectionSnapshotQueryLive } from "../src/orchestration/Layers/ProjectionSnapshotQuery.ts";
import * as ThreadBackgroundLiveness from "../src/orchestration/ThreadBackgroundLiveness.ts";
import * as ThreadPlanProgress from "../src/orchestration/ThreadPlanProgress.ts";
import { RuntimeReceiptBusTest } from "../src/orchestration/Layers/RuntimeReceiptBus.ts";
import { OrchestrationReactorLive } from "../src/orchestration/Layers/OrchestrationReactor.ts";
import { ProviderCommandReactorLive } from "../src/orchestration/Layers/ProviderCommandReactor.ts";
@@ -310,7 +311,10 @@ export const makeOrchestrationIntegrationHarness = (
checkpointStoreLayer,
providerLayer,
RuntimeReceiptBusTest,
).pipe(Layer.provideMerge(ThreadBackgroundLiveness.layer));
).pipe(
Layer.provideMerge(ThreadBackgroundLiveness.layer),
Layer.provideMerge(ThreadPlanProgress.layer),
);
const serverSettingsLayer = ServerSettingsService.layerTest();
const runtimeIngestionLayer = ProviderRuntimeIngestionLive.pipe(
Layer.provideMerge(runtimeServicesLayer),
@@ -40,6 +40,7 @@ import { OrchestrationEngineLive } from "./OrchestrationEngine.ts";
import { OrchestrationProjectionPipelineLive } from "./ProjectionPipeline.ts";
import { OrchestrationProjectionSnapshotQueryLive } from "./ProjectionSnapshotQuery.ts";
import * as ThreadBackgroundLiveness from "../ThreadBackgroundLiveness.ts";
import * as ThreadPlanProgress from "../ThreadPlanProgress.ts";
import { RuntimeReceiptBusLive } from "./RuntimeReceiptBus.ts";
import { OrchestrationEventStoreLive } from "../../persistence/Layers/OrchestrationEventStore.ts";
import { OrchestrationCommandReceiptRepositoryLive } from "../../persistence/Layers/OrchestrationCommandReceipts.ts";
@@ -296,6 +297,7 @@ describe("CheckpointReactor", () => {
const orchestrationLayer = OrchestrationEngineLive.pipe(
Layer.provide(OrchestrationProjectionSnapshotQueryLive),
Layer.provide(ThreadBackgroundLiveness.layer),
Layer.provide(ThreadPlanProgress.layer),
Layer.provide(OrchestrationProjectionPipelineLive),
Layer.provide(OrchestrationEventStoreLive),
Layer.provide(OrchestrationCommandReceiptRepositoryLive),
@@ -304,6 +306,7 @@ describe("CheckpointReactor", () => {
);
const projectionSnapshotLayer = OrchestrationProjectionSnapshotQueryLive.pipe(
Layer.provide(ThreadBackgroundLiveness.layer),
Layer.provide(ThreadPlanProgress.layer),
Layer.provide(RepositoryIdentityResolver.layer),
Layer.provide(SqlitePersistenceMemory),
);
@@ -32,6 +32,7 @@ import { OrchestrationEngineLive } from "./OrchestrationEngine.ts";
import { OrchestrationProjectionPipelineLive } from "./ProjectionPipeline.ts";
import { OrchestrationProjectionSnapshotQueryLive } from "./ProjectionSnapshotQuery.ts";
import * as ThreadBackgroundLiveness from "../ThreadBackgroundLiveness.ts";
import * as ThreadPlanProgress from "../ThreadPlanProgress.ts";
import { OrchestrationEngineService } from "../Services/OrchestrationEngine.ts";
import {
OrchestrationProjectionPipeline,
@@ -57,6 +58,7 @@ async function createOrchestrationSystem() {
OrchestrationProjectionSnapshotQueryLive,
).pipe(
Layer.provide(ThreadBackgroundLiveness.layer),
Layer.provide(ThreadPlanProgress.layer),
Layer.provide(OrchestrationEventStoreLive),
Layer.provide(OrchestrationCommandReceiptRepositoryLive),
Layer.provide(RepositoryIdentityResolver.layer),
@@ -820,6 +822,7 @@ describe("OrchestrationEngine", () => {
OrchestrationEngineLive.pipe(
Layer.provide(OrchestrationProjectionSnapshotQueryLive),
Layer.provide(ThreadBackgroundLiveness.layer),
Layer.provide(ThreadPlanProgress.layer),
Layer.provide(OrchestrationProjectionPipelineLive),
Layer.provide(Layer.succeed(OrchestrationEventStore, flakyStore)),
Layer.provide(OrchestrationCommandReceiptRepositoryLive),
@@ -926,6 +929,7 @@ describe("OrchestrationEngine", () => {
OrchestrationEngineLive.pipe(
Layer.provide(OrchestrationProjectionSnapshotQueryLive),
Layer.provide(ThreadBackgroundLiveness.layer),
Layer.provide(ThreadPlanProgress.layer),
Layer.provide(Layer.succeed(OrchestrationProjectionPipeline, flakyProjectionPipeline)),
Layer.provide(OrchestrationEventStoreLive),
Layer.provide(OrchestrationCommandReceiptRepositoryLive),
@@ -1070,6 +1074,7 @@ describe("OrchestrationEngine", () => {
OrchestrationEngineLive.pipe(
Layer.provide(OrchestrationProjectionSnapshotQueryLive),
Layer.provide(ThreadBackgroundLiveness.layer),
Layer.provide(ThreadPlanProgress.layer),
Layer.provide(Layer.succeed(OrchestrationProjectionPipeline, flakyProjectionPipeline)),
Layer.provide(Layer.succeed(OrchestrationEventStore, nonTransactionalStore)),
Layer.provide(OrchestrationCommandReceiptRepositoryLive),
@@ -32,6 +32,7 @@ import {
} from "./ProjectionPipeline.ts";
import { OrchestrationProjectionSnapshotQueryLive } from "./ProjectionSnapshotQuery.ts";
import * as ThreadBackgroundLiveness from "../ThreadBackgroundLiveness.ts";
import * as ThreadPlanProgress from "../ThreadPlanProgress.ts";
import { OrchestrationEngineService } from "../Services/OrchestrationEngine.ts";
import { OrchestrationProjectionPipeline } from "../Services/ProjectionPipeline.ts";
import { ServerConfig } from "../../config.ts";
@@ -2673,6 +2674,7 @@ const engineLayer = it.layer(
OrchestrationEngineLive.pipe(
Layer.provide(OrchestrationProjectionSnapshotQueryLive),
Layer.provide(ThreadBackgroundLiveness.layer),
Layer.provide(ThreadPlanProgress.layer),
Layer.provide(OrchestrationProjectionPipelineLive),
Layer.provide(OrchestrationEventStoreLive),
Layer.provide(OrchestrationCommandReceiptRepositoryLive),
@@ -18,6 +18,7 @@ import * as RepositoryIdentityResolver from "../../project/RepositoryIdentityRes
import { ORCHESTRATION_PROJECTOR_NAMES } from "./ProjectionPipeline.ts";
import { OrchestrationProjectionSnapshotQueryLive } from "./ProjectionSnapshotQuery.ts";
import * as ThreadBackgroundLiveness from "../ThreadBackgroundLiveness.ts";
import * as ThreadPlanProgress from "../ThreadPlanProgress.ts";
import { ProjectionSnapshotQuery } from "../Services/ProjectionSnapshotQuery.ts";
import { encodeThreadDetailPageCursor } from "../threadDetailCursor.ts";
@@ -30,6 +31,7 @@ const asCheckpointRef = (value: string): CheckpointRef => CheckpointRef.make(val
const projectionSnapshotLayer = it.layer(
OrchestrationProjectionSnapshotQueryLive.pipe(
Layer.provide(ThreadBackgroundLiveness.layer),
Layer.provide(ThreadPlanProgress.layer),
Layer.provideMerge(RepositoryIdentityResolver.layer),
Layer.provideMerge(SqlitePersistenceMemory),
Layer.provideMerge(NodeServices.layer),
@@ -447,6 +449,7 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
hasPendingUserInput: false,
hasActionableProposedPlan: false,
backgroundLiveness: null,
planProgress: null,
},
]);
@@ -1830,6 +1833,7 @@ it.effect(
const resolveCalls: string[] = [];
const layer = OrchestrationProjectionSnapshotQueryLive.pipe(
Layer.provide(ThreadBackgroundLiveness.layer),
Layer.provide(ThreadPlanProgress.layer),
Layer.provideMerge(
Layer.succeed(RepositoryIdentityResolver.RepositoryIdentityResolver, {
resolve: (cwd: string) =>
@@ -44,6 +44,7 @@ import {
} from "../../persistence/Errors.ts";
import { ProjectionCheckpoint } from "../../persistence/Services/ProjectionCheckpoints.ts";
import { ThreadBackgroundLivenessService } from "../ThreadBackgroundLiveness.ts";
import { ThreadPlanProgressService } from "../ThreadPlanProgress.ts";
import { ProjectionProject } from "../../persistence/Services/ProjectionProjects.ts";
import { ProjectionState } from "../../persistence/Services/ProjectionState.ts";
import { ProjectionThreadActivity } from "../../persistence/Services/ProjectionThreadActivities.ts";
@@ -344,6 +345,7 @@ function toPersistenceSqlOrDecodeError(sqlOperation: string, decodeOperation: st
const makeProjectionSnapshotQuery = Effect.gen(function* () {
const threadBackgroundLiveness = yield* ThreadBackgroundLivenessService;
const threadPlanProgress = yield* ThreadPlanProgressService;
const sql = yield* SqlClient.SqlClient;
const repositoryIdentityResolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
const repositoryIdentityResolutionConcurrency = 4;
@@ -1908,6 +1910,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
backgroundLiveness: threadBackgroundLiveness.getThreadBackgroundLiveness(
row.threadId,
),
planProgress: threadPlanProgress.getThreadPlanProgress(row.threadId),
} satisfies OrchestrationThreadShell)
: Result.failVoid,
),
@@ -2051,6 +2054,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
backgroundLiveness: threadBackgroundLiveness.getThreadBackgroundLiveness(
row.threadId,
),
planProgress: threadPlanProgress.getThreadPlanProgress(row.threadId),
}),
),
updatedAt: updatedAt ?? "1970-01-01T00:00:00.000Z",
@@ -2326,6 +2330,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
backgroundLiveness: threadBackgroundLiveness.getThreadBackgroundLiveness(
threadRow.value.threadId,
),
planProgress: threadPlanProgress.getThreadPlanProgress(threadRow.value.threadId),
} satisfies OrchestrationThreadShell);
});
@@ -49,6 +49,7 @@ import { OrchestrationEngineLive } from "./OrchestrationEngine.ts";
import { OrchestrationProjectionPipelineLive } from "./ProjectionPipeline.ts";
import { OrchestrationProjectionSnapshotQueryLive } from "./ProjectionSnapshotQuery.ts";
import * as ThreadBackgroundLiveness from "../ThreadBackgroundLiveness.ts";
import * as ThreadPlanProgress from "../ThreadPlanProgress.ts";
import {
providerErrorLabel,
providerErrorLabelFromInstanceHint,
@@ -347,6 +348,7 @@ describe("ProviderCommandReactor", () => {
const orchestrationLayer = OrchestrationEngineLive.pipe(
Layer.provide(OrchestrationProjectionSnapshotQueryLive),
Layer.provide(ThreadBackgroundLiveness.layer),
Layer.provide(ThreadPlanProgress.layer),
Layer.provide(OrchestrationProjectionPipelineLive),
Layer.provide(OrchestrationEventStoreLive),
Layer.provide(OrchestrationCommandReceiptRepositoryLive),
@@ -355,6 +357,7 @@ describe("ProviderCommandReactor", () => {
);
const projectionSnapshotLayer = OrchestrationProjectionSnapshotQueryLive.pipe(
Layer.provide(ThreadBackgroundLiveness.layer),
Layer.provide(ThreadPlanProgress.layer),
Layer.provide(RepositoryIdentityResolver.layer),
Layer.provide(SqlitePersistenceMemory),
);
@@ -45,6 +45,7 @@ import { OrchestrationEngineLive } from "./OrchestrationEngine.ts";
import { OrchestrationProjectionPipelineLive } from "./ProjectionPipeline.ts";
import { OrchestrationProjectionSnapshotQueryLive } from "./ProjectionSnapshotQuery.ts";
import * as ThreadBackgroundLiveness from "../ThreadBackgroundLiveness.ts";
import * as ThreadPlanProgress from "../ThreadPlanProgress.ts";
import { ProviderRuntimeIngestionLive } from "./ProviderRuntimeIngestion.ts";
import { OrchestrationEngineService } from "../Services/OrchestrationEngine.ts";
import { ProviderRuntimeIngestionService } from "../Services/ProviderRuntimeIngestion.ts";
@@ -241,6 +242,7 @@ describe("ProviderRuntimeIngestion", () => {
// Single shared liveness instance across ingestion (writer), the
// engine, and the snapshot query (reader).
Layer.provideMerge(ThreadBackgroundLiveness.layer),
Layer.provideMerge(ThreadPlanProgress.layer),
Layer.provideMerge(SqlitePersistenceMemory),
Layer.provideMerge(Layer.succeed(ProviderService, provider.service)),
Layer.provideMerge(makeTestServerSettingsLayer(options?.serverSettings)),
@@ -35,6 +35,7 @@ import { ProjectionTurnRepositoryLive } from "../../persistence/Layers/Projectio
import { isGitRepository } from "../../git/Utils.ts";
import { OrchestrationEngineService } from "../Services/OrchestrationEngine.ts";
import { ThreadBackgroundLivenessService } from "../ThreadBackgroundLiveness.ts";
import { ThreadPlanProgressService } from "../ThreadPlanProgress.ts";
import { ProjectionSnapshotQuery } from "../Services/ProjectionSnapshotQuery.ts";
import {
ProviderRuntimeIngestionService,
@@ -867,6 +868,7 @@ export function runtimeEventToActivities(
const make = Effect.gen(function* () {
const threadBackgroundLiveness = yield* ThreadBackgroundLivenessService;
const threadPlanProgress = yield* ThreadPlanProgressService;
const crypto = yield* Crypto.Crypto;
const orchestrationEngine = yield* OrchestrationEngineService;
const projectionSnapshotQuery = yield* ProjectionSnapshotQuery;
@@ -1935,6 +1937,21 @@ const make = Effect.gen(function* () {
yield* rememberTaskDescription(thread.id, event.payload.taskId, description);
}
}
// Working-indicator plan progress: current step while the turn runs,
// cleared on settle so a finished plan never lingers as stale UI.
// Events carrying a turn id that conflicts with the active turn are
// stale (superseded turn) and must neither overwrite nor clear the
// active turn's progress; session.exited always clears.
if (event.type === "session.exited") {
threadPlanProgress.clearThreadPlanProgress(thread.id);
} else if (!conflictsWithActiveTurn) {
if (event.type === "turn.plan.updated") {
threadPlanProgress.recordPlanProgress(thread.id, event.payload.plan);
} else if (event.type === "turn.completed" || event.type === "turn.aborted") {
threadPlanProgress.clearThreadPlanProgress(thread.id);
}
}
// Sidebar background liveness: fed from the same lifecycle stream,
// read by the shell query at mapping time (no persistence).
switch (event.type) {
@@ -0,0 +1,44 @@
import { describe, expect, it } from "vite-plus/test";
import * as ThreadPlanProgress from "./ThreadPlanProgress.ts";
describe("ThreadPlanProgress", () => {
it("tracks the in-progress step and clears when the plan completes", () => {
const progress = ThreadPlanProgress.make();
const threadId = "t-plan-1";
progress.recordPlanProgress(threadId, [
{ step: "Audit failure paths", status: "completed" },
{ step: "Implement the fix", status: "inProgress" },
{ step: "Run targeted tests", status: "pending" },
]);
expect(progress.getThreadPlanProgress(threadId)).toEqual({
step: "Implement the fix",
completedSteps: 1,
totalSteps: 3,
});
progress.recordPlanProgress(threadId, [
{ step: "Audit failure paths", status: "completed" },
{ step: "Implement the fix", status: "completed" },
{ step: "Run targeted tests", status: "completed" },
]);
expect(progress.getThreadPlanProgress(threadId)).toBeNull();
});
it("falls back to the first non-completed step when nothing is in progress", () => {
const progress = ThreadPlanProgress.make();
const threadId = "t-plan-2";
progress.recordPlanProgress(threadId, [
{ step: "First", status: "pending" },
{ step: "Second", status: "pending" },
]);
expect(progress.getThreadPlanProgress(threadId)?.step).toBe("First");
});
it("clearThreadPlanProgress removes the entry (turn settled / session died)", () => {
const progress = ThreadPlanProgress.make();
const threadId = "t-plan-3";
progress.recordPlanProgress(threadId, [{ step: "Only step", status: "inProgress" }]);
progress.clearThreadPlanProgress(threadId);
expect(progress.getThreadPlanProgress(threadId)).toBeNull();
});
});
@@ -0,0 +1,76 @@
/**
* ThreadPlanProgressService - in-memory per-thread plan progress for the
* Working indicators (sidebar rows, in-chat working line).
*
* Plans are a progress annotation, not a surface of their own: the useful
* kernel of a turn.plan.updated event is "which step is the agent on right
* now". Ingestion records the current step here and the shell query reads it
* at mapping time — no persistence, no migration (same pattern as
* ThreadBackgroundLivenessService). Cleared when the turn settles or the
* session dies, so a finished plan never lingers as stale UI.
*
* @module ThreadPlanProgressService
*/
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
export interface ThreadPlanProgress {
readonly step: string;
readonly completedSteps: number;
readonly totalSteps: number;
}
interface PlanStepInput {
readonly step: string;
readonly status: string;
}
export class ThreadPlanProgressService extends Context.Service<
ThreadPlanProgressService,
{
/**
* Feed one turn.plan.updated payload. An all-completed plan clears the
* entry (the turn is wrapping up; nothing is "in progress" anymore).
*/
readonly recordPlanProgress: (threadId: string, plan: ReadonlyArray<PlanStepInput>) => void;
/** Turn settled or session died: the working indicator reverts to plain. */
readonly clearThreadPlanProgress: (threadId: string) => void;
readonly getThreadPlanProgress: (threadId: string) => ThreadPlanProgress | null;
}
>()("t3/orchestration/ThreadPlanProgress/ThreadPlanProgressService") {}
export function make(): ThreadPlanProgressService["Service"] {
const progressByThreadId = new Map<string, ThreadPlanProgress>();
return {
recordPlanProgress: (threadId, plan) => {
const totalSteps = plan.length;
const completedSteps = plan.filter((step) => step.status === "completed").length;
// Current step: the in-progress one, else the first pending one (a
// plan that was just written has no in-progress step yet).
const current =
plan.find((step) => step.status === "inProgress") ??
plan.find((step) => step.status !== "completed");
if (totalSteps === 0 || completedSteps === totalSteps || current === undefined) {
progressByThreadId.delete(threadId);
return;
}
progressByThreadId.set(threadId, {
step: current.step,
completedSteps,
totalSteps,
});
},
clearThreadPlanProgress: (threadId) => {
progressByThreadId.delete(threadId);
},
getThreadPlanProgress: (threadId) => progressByThreadId.get(threadId) ?? null,
};
}
export const layer = Layer.effect(ThreadPlanProgressService, Effect.sync(make));
@@ -6,6 +6,7 @@ import { OrchestrationEngineLive } from "./Layers/OrchestrationEngine.ts";
import { OrchestrationProjectionPipelineLive } from "./Layers/ProjectionPipeline.ts";
import { OrchestrationProjectionSnapshotQueryLive } from "./Layers/ProjectionSnapshotQuery.ts";
import * as ThreadBackgroundLiveness from "./ThreadBackgroundLiveness.ts";
import * as ThreadPlanProgress from "./ThreadPlanProgress.ts";
export const OrchestrationEventInfrastructureLayerLive = Layer.mergeAll(
OrchestrationEventStoreLive,
@@ -20,10 +21,14 @@ export const OrchestrationInfrastructureLayerLive = Layer.mergeAll(
OrchestrationProjectionSnapshotQueryLive,
OrchestrationEventInfrastructureLayerLive,
OrchestrationProjectionPipelineLayerLive,
// Shared background-liveness registry: written by runtime ingestion,
// read by the snapshot query. provideMerge feeds the same instance to
// the snapshot query here and re-exports it for runtime ingestion.
).pipe(Layer.provideMerge(ThreadBackgroundLiveness.layer));
// Shared background-liveness and plan-progress registries: written by
// runtime ingestion, read by the snapshot query. provideMerge feeds the
// same instance to the snapshot query here and re-exports it for runtime
// ingestion.
).pipe(
Layer.provideMerge(ThreadBackgroundLiveness.layer),
Layer.provideMerge(ThreadPlanProgress.layer),
);
export const OrchestrationLayerLive = Layer.mergeAll(
OrchestrationInfrastructureLayerLive,
+38 -169
View File
@@ -85,7 +85,7 @@ import {
deriveTimelineEntries,
deriveActiveWorkStartedAt,
deriveActivePlanState,
findSidebarProposedPlan,
deriveTurnPlans,
findLatestProposedPlan,
deriveWorkLogEntries,
hasActionableProposedPlan,
@@ -121,11 +121,6 @@ import { useTurnDiffSummaries } from "../hooks/useTurnDiffSummaries";
import { isCommandPaletteOpen } from "../commandPaletteBus";
import { buildTemporaryWorktreeBranchName } from "@t3tools/shared/git";
import { useMediaQuery } from "../hooks/useMediaQuery";
import {
clearPlanSidebarDismissal,
dismissPlanSidebarForTurn,
isPlanSidebarDismissedForTurn,
} from "../planSidebarDismissal";
import { RIGHT_PANEL_INLINE_LAYOUT_MEDIA_QUERY } from "../rightPanelLayout";
import {
selectActiveRightPanel,
@@ -157,7 +152,6 @@ import {
import { DiffWorkerPoolProvider } from "./DiffWorkerPoolProvider";
import { BranchToolbar } from "./BranchToolbar";
import { resolveShortcutCommand, shortcutLabelForCommand } from "../keybindings";
import PlanSidebar from "./PlanSidebar";
import ThreadTerminalDrawer from "./ThreadTerminalDrawer";
import {
AlarmClockIcon,
@@ -234,7 +228,6 @@ import {
useProject,
useProjects,
useThread,
useThreadProposedPlans,
useThreadRefs,
useThreadShell,
} from "../state/entities";
@@ -451,8 +444,6 @@ type EnvironmentUnavailableState = {
readonly connection: EnvironmentConnectionPresentation;
};
type ThreadPlanCatalogEntry = Pick<Thread, "id" | "proposedPlans">;
function eventPathContainsSelector(event: Event, selector: string): boolean {
const path = event.composedPath();
if (path.length === 0 && event.target) {
@@ -1271,7 +1262,6 @@ function ChatViewContent(props: ChatViewProps) {
(store) => store.setStickyModelSelection,
);
const timestampFormat = settings.timestampFormat;
const autoOpenPlanSidebar = settings.autoOpenPlanSidebar;
const navigate = useNavigate();
const { resolvedTheme } = useTheme();
// Granular store selectors — avoid subscribing to prompt changes.
@@ -1341,10 +1331,7 @@ function ChatViewContent(props: ChatViewProps) {
>({});
const [pendingUserInputQuestionIndexByRequestId, setPendingUserInputQuestionIndexByRequestId] =
useState<Record<string, number>>({});
const shouldUsePlanSidebarSheet = useMediaQuery(RIGHT_PANEL_INLINE_LAYOUT_MEDIA_QUERY);
// When set, the thread-change reset effect will open the sidebar instead of closing it.
// Used by "Implement in a new thread" to carry the sidebar-open intent across navigation.
const planSidebarOpenOnNextThreadRef = useRef(false);
const shouldUseRightPanelSheet = useMediaQuery(RIGHT_PANEL_INLINE_LAYOUT_MEDIA_QUERY);
const [terminalFocusRequestId, setTerminalFocusRequestId] = useState(0);
const [pullRequestDialogState, setPullRequestDialogState] =
useState<PullRequestDialogState | null>(null);
@@ -1577,10 +1564,10 @@ function ChatViewContent(props: ChatViewProps) {
);
const previewPanelOpen = activeRightPanelKind === "preview" && isPreviewSupportedInRuntime();
const rightPanelOpen = rightPanelState.isOpen;
const canMaximizeRightPanel = rightPanelOpen && !shouldUsePlanSidebarSheet;
const canMaximizeRightPanel = rightPanelOpen && !shouldUseRightPanelSheet;
const rightPanelMaximized =
canMaximizeRightPanel && maximizedRightPanelThreadKey === routeThreadKey;
const inlineRightPanelOwnsTitleBar = rightPanelOpen && !shouldUsePlanSidebarSheet;
const inlineRightPanelOwnsTitleBar = rightPanelOpen && !shouldUseRightPanelSheet;
useEffect(() => {
if (!activeThreadRef) return;
@@ -1607,36 +1594,11 @@ function ChatViewContent(props: ChatViewProps) {
previewPanelOpen,
]);
const planSidebarOpen = activeRightPanelKind === "plan";
const existingOpenTerminalThreadKeys = useMemo(() => {
const existingThreadKeys = new Set<string>([...serverThreadKeys, ...draftThreadKeys]);
return openTerminalThreadKeys.filter((nextThreadKey) => existingThreadKeys.has(nextThreadKey));
}, [draftThreadKeys, openTerminalThreadKeys, serverThreadKeys]);
const activeLatestTurn = activeThread?.latestTurn ?? null;
const sourcePlanThreadRef = useMemo(() => {
const sourceThreadId = activeLatestTurn?.sourceProposedPlan?.threadId;
if (!activeThread || !sourceThreadId || sourceThreadId === activeThread.id) {
return null;
}
return scopeThreadRef(activeThread.environmentId, sourceThreadId);
}, [activeLatestTurn?.sourceProposedPlan?.threadId, activeThread]);
const sourceThreadProposedPlans = useThreadProposedPlans(sourcePlanThreadRef);
const threadPlanCatalog = useMemo<ThreadPlanCatalogEntry[]>(() => {
if (!activeThread) {
return [];
}
const entries: ThreadPlanCatalogEntry[] = [
{ id: activeThread.id, proposedPlans: activeThread.proposedPlans },
];
if (sourcePlanThreadRef) {
entries.push({
id: sourcePlanThreadRef.threadId,
proposedPlans: sourceThreadProposedPlans,
});
}
return entries;
}, [activeThread, sourcePlanThreadRef, sourceThreadProposedPlans]);
useEffect(() => {
setMountedTerminalThreadKeys((currentThreadIds) => {
const nextThreadIds = reconcileMountedTerminalThreadIds({
@@ -2086,6 +2048,7 @@ function ChatViewContent(props: ChatViewProps) {
const phase = derivePhase(activeThread?.session ?? null);
const threadActivities = activeThread?.activities ?? EMPTY_ACTIVITIES;
const workLogEntries = useMemo(() => deriveWorkLogEntries(threadActivities), [threadActivities]);
const turnPlans = useMemo(() => deriveTurnPlans(threadActivities), [threadActivities]);
// Native subagent fold: memoized by activity-list identity, shared by the
// Agents surface, live strip, and workflow cards. v2Projection is null
// until orchestration-v2 lands (source precedence lives in the derive).
@@ -2148,21 +2111,25 @@ function ChatViewContent(props: ChatViewProps) {
activeLatestTurn?.turnId ?? null,
);
}, [activeLatestTurn?.turnId, activeThread?.proposedPlans, latestTurnSettled]);
const sidebarProposedPlan = useMemo(
() =>
findSidebarProposedPlan({
threads: threadPlanCatalog,
latestTurn: activeLatestTurn,
latestTurnSettled,
threadId: activeThread?.id ?? null,
}),
[activeLatestTurn, activeThread?.id, latestTurnSettled, threadPlanCatalog],
);
const activePlan = useMemo(
() => deriveActivePlanState(threadActivities, activeLatestTurn?.turnId ?? undefined),
[activeLatestTurn?.turnId, threadActivities],
);
const planSidebarLabel = sidebarProposedPlan || interactionMode === "plan" ? "Plan" : "Tasks";
// Current step for the in-chat working row: only for the running turn's own
// plan (deriveActivePlanState falls back to older turns' plans, which must
// not label fresh work). Falls back to the first pending step so an
// all-pending freshly written plan labels the row, matching the chip and
// the server's planProgress.
const workingStepLabel = useMemo(() => {
if (!activePlan || activePlan.turnId !== (activeLatestTurn?.turnId ?? null)) {
return null;
}
return (
activePlan.steps.find((step) => step.status === "inProgress")?.step ??
activePlan.steps.find((step) => step.status === "pending")?.step ??
null
);
}, [activeLatestTurn?.turnId, activePlan]);
const showPlanFollowUpPrompt =
pendingUserInputs.length === 0 &&
interactionMode === "plan" &&
@@ -2431,8 +2398,13 @@ function ChatViewContent(props: ChatViewProps) {
}, [attachmentPreviewHandoffByMessageId, displayServerMessages, optimisticUserMessages]);
const timelineEntries = useMemo(
() =>
deriveTimelineEntries(timelineMessages, activeThread?.proposedPlans ?? [], workLogEntries),
[activeThread?.proposedPlans, timelineMessages, workLogEntries],
deriveTimelineEntries(
timelineMessages,
activeThread?.proposedPlans ?? [],
workLogEntries,
turnPlans,
),
[activeThread?.proposedPlans, timelineMessages, turnPlans, workLogEntries],
);
const [dockedDraftHeroThreadKey, setDockedDraftHeroThreadKey] = useState<string | null>(null);
const draftHeroDockRequested =
@@ -3142,47 +3114,15 @@ function ChatViewContent(props: ChatViewProps) {
const toggleInteractionMode = useCallback(() => {
handleInteractionModeChange(interactionMode === "plan" ? "default" : "plan");
}, [handleInteractionModeChange, interactionMode]);
const dismissPlanSidebarForCurrentTurn = useCallback(() => {
if (!activeThreadKey) return;
dismissPlanSidebarForTurn(
activeThreadKey,
activePlan?.turnId ?? sidebarProposedPlan?.turnId ?? "__dismissed__",
);
}, [activeThreadKey, activePlan?.turnId, sidebarProposedPlan?.turnId]);
const togglePlanSidebar = useCallback(() => {
if (!activeThreadRef) return;
if (planSidebarOpen) {
dismissPlanSidebarForCurrentTurn();
} else if (activeThreadKey) {
clearPlanSidebarDismissal(activeThreadKey);
}
useRightPanelStore.getState().toggle(activeThreadRef, "plan");
}, [activeThreadKey, activeThreadRef, dismissPlanSidebarForCurrentTurn, planSidebarOpen]);
const closePlanSidebar = useCallback(() => {
if (!activeThreadRef) return;
setMaximizedRightPanelThreadKey(null);
useRightPanelStore.getState().close(activeThreadRef);
dismissPlanSidebarForCurrentTurn();
}, [activeThreadRef, dismissPlanSidebarForCurrentTurn]);
const createBrowserSurface = useCallback(() => {
if (!activeThreadRef) return;
void addBrowserSurface({ threadRef: activeThreadRef, openPreview });
}, [activeThreadRef, openPreview]);
const addDiffSurface = useCallback(() => {
if (!activeThreadRef || !isServerThread || !isGitRepo) return;
if (planSidebarOpen) {
dismissPlanSidebarForCurrentTurn();
}
useRightPanelStore.getState().open(activeThreadRef, "diff");
onDiffPanelOpen?.();
}, [
activeThreadRef,
dismissPlanSidebarForCurrentTurn,
isGitRepo,
isServerThread,
onDiffPanelOpen,
planSidebarOpen,
]);
}, [activeThreadRef, isGitRepo, isServerThread, onDiffPanelOpen]);
const addFilesSurface = useCallback(() => {
if (!activeThreadRef || !activeProject) return;
useRightPanelStore.getState().open(activeThreadRef, "files");
@@ -3318,11 +3258,6 @@ function ChatViewContent(props: ChatViewProps) {
const activateRightPanelSurface = useCallback(
(surface: RightPanelSurface) => {
if (!activeThreadRef) return;
if (surface.kind === "plan") {
clearPlanSidebarDismissal(scopedThreadKey(activeThreadRef));
} else if (planSidebarOpen) {
dismissPlanSidebarForCurrentTurn();
}
useRightPanelStore.getState().activateSurface(activeThreadRef, surface.id);
if (surface.kind === "preview" && surface.resourceId) {
setActivePreviewTab(activeThreadRef, surface.resourceId);
@@ -3334,20 +3269,16 @@ function ChatViewContent(props: ChatViewProps) {
onDiffPanelOpen?.();
}
},
[activeThreadRef, diffOpen, dismissPlanSidebarForCurrentTurn, onDiffPanelOpen, planSidebarOpen],
[activeThreadRef, diffOpen, onDiffPanelOpen],
);
const toggleRightPanel = useCallback(() => {
if (!activeThreadRef) return;
if (rightPanelOpen) {
if (planSidebarOpen) {
closePlanSidebar();
} else {
closePreviewPanel();
}
closePreviewPanel();
return;
}
useRightPanelStore.getState().toggleVisibility(activeThreadRef);
}, [activeThreadRef, closePlanSidebar, closePreviewPanel, planSidebarOpen, rightPanelOpen]);
}, [activeThreadRef, closePreviewPanel, rightPanelOpen]);
const toggleRightPanelMaximized = useCallback(() => {
if (!canMaximizeRightPanel) return;
setMaximizedRightPanelThreadKey((threadKey) =>
@@ -3357,10 +3288,6 @@ function ChatViewContent(props: ChatViewProps) {
const cleanupRightPanelSurfaces = useCallback(
(surfaces: readonly RightPanelSurface[]) => {
if (!activeThreadRef) return;
if (surfaces.some((surface) => surface.kind === "plan")) {
dismissPlanSidebarForCurrentTurn();
}
for (const surface of surfaces) {
if (surface.kind === "preview" && surface.resourceId) {
void closePreviewSession({
@@ -3386,7 +3313,6 @@ function ChatViewContent(props: ChatViewProps) {
activePreviewState.sessions,
closePreview,
closeTerminalMutation,
dismissPlanSidebarForCurrentTurn,
storeCloseTerminal,
],
);
@@ -3976,37 +3902,9 @@ function ChatViewContent(props: ChatViewProps) {
activeTimelineAnchorIndexRef.current = null;
showScrollDebouncer.current.cancel();
setShowScrollToBottom(false);
if (planSidebarOpenOnNextThreadRef.current) {
planSidebarOpenOnNextThreadRef.current = false;
if (activeThreadRef) {
clearPlanSidebarDismissal(scopedThreadKey(activeThreadRef));
useRightPanelStore.getState().open(activeThreadRef, "plan");
}
}
// activeThreadRef resets transitively with the active thread.
}, [activeThread?.id]);
// Auto-open the plan sidebar when plan/todo steps arrive for the current turn.
// Don't auto-open for plans carried over from a previous turn (the user can open manually).
useEffect(() => {
if (!autoOpenPlanSidebar) return;
if (!activePlan) return;
if (planSidebarOpen) return;
const latestTurnId = activeLatestTurn?.turnId ?? null;
if (latestTurnId && activePlan.turnId !== latestTurnId) return;
const turnKey = activePlan.turnId ?? sidebarProposedPlan?.turnId ?? "__dismissed__";
if (!activeThreadRef) return;
if (isPlanSidebarDismissedForTurn(scopedThreadKey(activeThreadRef), turnKey)) return;
useRightPanelStore.getState().open(activeThreadRef, "plan");
}, [
activePlan,
activeLatestTurn?.turnId,
activeThreadRef,
autoOpenPlanSidebar,
planSidebarOpen,
sidebarProposedPlan?.turnId,
]);
useEffect(() => {
setIsRevertingCheckpoint(false);
}, [activeThread?.id]);
@@ -5556,15 +5454,6 @@ function ChatViewContent(props: ChatViewProps) {
if (failure === null) {
acknowledgeActiveThreadWoke();
// Optimistically open the plan sidebar when implementing (not refining).
// "default" mode here means the agent is executing the plan, which produces
// step-tracking activities that the sidebar will display.
if (nextInteractionMode === "default" && autoOpenPlanSidebar) {
if (activeThreadRef) {
clearPlanSidebarDismissal(scopedThreadKey(activeThreadRef));
useRightPanelStore.getState().open(activeThreadRef, "plan");
}
}
sendInFlightRef.current = false;
return;
}
@@ -5597,7 +5486,6 @@ function ChatViewContent(props: ChatViewProps) {
setComposerDraftInteractionMode,
setThreadError,
startThreadTurn,
autoOpenPlanSidebar,
environmentId,
composerRef,
],
@@ -5700,8 +5588,6 @@ function ChatViewContent(props: ChatViewProps) {
}
if (failure === null) {
// Signal that the plan sidebar should open on the new thread when enabled.
planSidebarOpenOnNextThreadRef.current = autoOpenPlanSidebar;
const navigateResult = await settlePromise(() =>
navigate({
to: "/$environmentId/$threadId",
@@ -5758,7 +5644,6 @@ function ChatViewContent(props: ChatViewProps) {
resetLocalDispatch,
runtimeMode,
startThreadTurn,
autoOpenPlanSidebar,
environmentId,
composerRef,
]);
@@ -5950,12 +5835,12 @@ function ChatViewContent(props: ChatViewProps) {
<div
className={cn(
"workspace-titlebar-controls z-50 gap-1 [-webkit-app-region:no-drag]",
rightPanelOpen && !shouldUsePlanSidebarSheet
rightPanelOpen && !shouldUseRightPanelSheet
? "right-2 wco:right-[var(--workspace-controls-right)]"
: "mr-px",
)}
>
{rightPanelOpen && !shouldUsePlanSidebarSheet ? (
{rightPanelOpen && !shouldUseRightPanelSheet ? (
<RightPanelMaximizeControl
maximized={rightPanelMaximized}
onToggle={toggleRightPanelMaximized}
@@ -6005,18 +5890,6 @@ function ChatViewContent(props: ChatViewProps) {
initialGitScope={initialDiffPanelGitScope}
/>
</Suspense>
) : activeRightPanelSurface?.kind === "plan" ? (
<PlanSidebar
activePlan={activePlan}
activeProposedPlan={sidebarProposedPlan}
label={planSidebarLabel}
environmentId={environmentId}
threadRef={activeThreadRef}
markdownCwd={gitCwd ?? undefined}
workspaceRoot={activeWorkspaceRoot}
timestampFormat={timestampFormat}
mode="embedded"
/>
) : activeRightPanelSurface?.kind === "agents" ? (
<AgentsPanel
model={agentPanelModel}
@@ -6050,7 +5923,7 @@ function ChatViewContent(props: ChatViewProps) {
return (
<div className="relative flex min-h-0 min-w-0 flex-1 overflow-hidden bg-background">
{rightPanelOpen && !shouldUsePlanSidebarSheet ? panelLayoutControls : null}
{rightPanelOpen && !shouldUseRightPanelSheet ? panelLayoutControls : null}
<div
className={cn(
"flex min-h-0 min-w-0 flex-col overflow-x-hidden",
@@ -6122,6 +5995,7 @@ function ChatViewContent(props: ChatViewProps) {
onOpenAgents={addAgentsSurface}
key={activeThread.id}
isWorking={isWorking}
workingStepLabel={workingStepLabel}
activeTurnInProgress={isWorking || !latestTurnSettled}
activeTurnStartedAt={activeWorkStartedAt}
listRef={legendListRef}
@@ -6264,10 +6138,6 @@ function ChatViewContent(props: ChatViewProps) {
respondingRequestIds={respondingRequestIds}
showPlanFollowUpPrompt={showPlanFollowUpPrompt}
activeProposedPlan={activeProposedPlan}
activePlan={activePlan as { turnId?: TurnId } | null}
sidebarProposedPlan={sidebarProposedPlan as { turnId?: TurnId } | null}
planSidebarLabel={planSidebarLabel}
planSidebarOpen={planSidebarOpen}
runtimeMode={runtimeMode}
interactionMode={interactionMode}
lockedProvider={lockedProvider}
@@ -6305,7 +6175,6 @@ function ChatViewContent(props: ChatViewProps) {
toggleInteractionMode={toggleInteractionMode}
handleRuntimeModeChange={handleRuntimeModeChange}
handleInteractionModeChange={handleInteractionModeChange}
togglePlanSidebar={togglePlanSidebar}
focusComposer={focusComposer}
scheduleComposerFocus={scheduleComposerFocus}
setThreadError={setThreadError}
@@ -6440,7 +6309,7 @@ function ChatViewContent(props: ChatViewProps) {
))}
</div>
{!shouldUsePlanSidebarSheet && rightPanelOpen && activeThreadRef ? (
{!shouldUseRightPanelSheet && rightPanelOpen && activeThreadRef ? (
<RightPanelTabs
mode="inline"
maximized={rightPanelMaximized}
@@ -6467,8 +6336,8 @@ function ChatViewContent(props: ChatViewProps) {
{rightPanelContent}
</RightPanelTabs>
) : null}
{shouldUsePlanSidebarSheet && rightPanelOpen && activeThreadRef ? (
<RightPanelSheet open onClose={planSidebarOpen ? closePlanSidebar : closePreviewPanel}>
{shouldUseRightPanelSheet && rightPanelOpen && activeThreadRef ? (
<RightPanelSheet open onClose={closePreviewPanel}>
<RightPanelTabs
mode="sheet"
layoutControls={panelToggleControls}
-284
View File
@@ -1,284 +0,0 @@
import { memo, useState, useCallback } from "react";
import {
isAtomCommandInterrupted,
squashAtomCommandFailure,
} from "@t3tools/client-runtime/state/runtime";
import type { EnvironmentId, ScopedThreadRef } from "@t3tools/contracts";
import { type TimestampFormat } from "@t3tools/contracts/settings";
import { Badge } from "./ui/badge";
import { Button } from "./ui/button";
import { ScrollArea } from "./ui/scroll-area";
import ChatMarkdown from "./ChatMarkdown";
import {
CheckIcon,
ChevronDownIcon,
ChevronRightIcon,
EllipsisIcon,
LoaderIcon,
} from "lucide-react";
import { cn } from "~/lib/utils";
import type { ActivePlanState } from "../session-logic";
import type { LatestProposedPlanState } from "../session-logic";
import { formatTimestamp } from "../timestampFormat";
import {
proposedPlanTitle,
buildProposedPlanMarkdownFilename,
normalizePlanMarkdownForExport,
downloadPlanAsTextFile,
stripDisplayedPlanMarkdown,
} from "../proposedPlan";
import { Menu, MenuItem, MenuPopup, MenuTrigger } from "./ui/menu";
import { projectEnvironment } from "~/state/projects";
import { stackedThreadToast, toastManager } from "./ui/toast";
import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";
import { useAtomCommand } from "~/state/use-atom-command";
function stepStatusIcon(status: string): React.ReactNode {
if (status === "completed") {
return (
<span className="flex size-5 shrink-0 items-center justify-center rounded-full bg-success/10 text-success-foreground">
<CheckIcon className="size-3" />
</span>
);
}
if (status === "inProgress") {
return (
<span className="flex size-5 shrink-0 items-center justify-center rounded-full bg-primary/10 text-primary">
<LoaderIcon className="size-3 animate-spin" />
</span>
);
}
return (
<span className="flex size-5 shrink-0 items-center justify-center rounded-full border border-border/60 bg-muted/30">
<span className="size-1.5 rounded-full bg-muted-foreground/30" />
</span>
);
}
interface PlanSidebarProps {
activePlan: ActivePlanState | null;
activeProposedPlan: LatestProposedPlanState | null;
label?: string;
environmentId: EnvironmentId;
threadRef?: ScopedThreadRef | undefined;
markdownCwd: string | undefined;
workspaceRoot: string | undefined;
timestampFormat: TimestampFormat;
mode?: "sheet" | "sidebar" | "embedded";
}
const PlanSidebar = memo(function PlanSidebar({
activePlan,
activeProposedPlan,
label = "Plan",
environmentId,
threadRef,
markdownCwd,
workspaceRoot,
timestampFormat,
mode = "sidebar",
}: PlanSidebarProps) {
const [proposedPlanExpanded, setProposedPlanExpanded] = useState(false);
const [isSavingToWorkspace, setIsSavingToWorkspace] = useState(false);
const writeProjectFile = useAtomCommand(projectEnvironment.writeFile, {
reportFailure: false,
});
const { copyToClipboard, isCopied } = useCopyToClipboard({ target: "plan" });
const planMarkdown = activeProposedPlan?.planMarkdown ?? null;
const displayedPlanMarkdown = planMarkdown ? stripDisplayedPlanMarkdown(planMarkdown) : null;
const planTitle = planMarkdown ? proposedPlanTitle(planMarkdown) : null;
const handleCopyPlan = useCallback(() => {
if (!planMarkdown) return;
copyToClipboard(planMarkdown);
}, [planMarkdown, copyToClipboard]);
const handleDownload = useCallback(() => {
if (!planMarkdown) return;
const filename = buildProposedPlanMarkdownFilename(planMarkdown);
downloadPlanAsTextFile(filename, normalizePlanMarkdownForExport(planMarkdown));
}, [planMarkdown]);
const handleSaveToWorkspace = useCallback(() => {
if (!workspaceRoot || !planMarkdown) return;
const filename = buildProposedPlanMarkdownFilename(planMarkdown);
setIsSavingToWorkspace(true);
void (async () => {
const result = await writeProjectFile({
environmentId,
input: {
cwd: workspaceRoot,
relativePath: filename,
contents: normalizePlanMarkdownForExport(planMarkdown),
},
});
setIsSavingToWorkspace(false);
if (result._tag === "Success") {
toastManager.add({
type: "success",
title: "Plan saved",
description: result.value.relativePath,
});
return;
}
if (!isAtomCommandInterrupted(result)) {
const error = squashAtomCommandFailure(result);
toastManager.add(
stackedThreadToast({
type: "error",
title: "Could not save plan",
description: error instanceof Error ? error.message : "An error occurred.",
}),
);
}
})();
}, [environmentId, planMarkdown, workspaceRoot, writeProjectFile]);
return (
<div
className={cn(
"flex min-h-0 flex-col bg-card/50",
mode === "sidebar"
? "h-full w-[340px] shrink-0 border-l border-border/70"
: "h-full w-full",
)}
>
{/* Header */}
<div className="flex h-12 shrink-0 items-center justify-between border-b border-border/60 px-3">
<div className="flex items-center gap-2">
<Badge
variant="info"
size="sm"
className="rounded-md px-1.5 py-0 font-semibold tracking-wide uppercase"
>
{label}
</Badge>
{activePlan ? (
<span className="text-[11px] text-muted-foreground/60 tabular-nums">
{formatTimestamp(activePlan.createdAt, timestampFormat)}
</span>
) : null}
</div>
<div className="flex items-center gap-1">
{planMarkdown ? (
<Menu>
<MenuTrigger
render={
<Button
size="icon-xs"
variant="ghost"
className="text-muted-foreground/50 hover:text-foreground/70"
aria-label="Plan actions"
/>
}
>
<EllipsisIcon className="size-3.5" />
</MenuTrigger>
<MenuPopup align="end">
<MenuItem onClick={handleCopyPlan}>
{isCopied ? "Copied!" : "Copy to clipboard"}
</MenuItem>
<MenuItem onClick={handleDownload}>Download as markdown</MenuItem>
<MenuItem
onClick={handleSaveToWorkspace}
disabled={!workspaceRoot || isSavingToWorkspace}
>
Save to workspace
</MenuItem>
</MenuPopup>
</Menu>
) : null}
</div>
</div>
{/* Content */}
<ScrollArea className="min-h-0 flex-1">
<div className="p-3 space-y-4">
{/* Explanation */}
{activePlan?.explanation ? (
<p className="text-[13px] leading-relaxed text-muted-foreground/80">
{activePlan.explanation}
</p>
) : null}
{/* Plan Steps */}
{activePlan && activePlan.steps.length > 0 ? (
<div className="space-y-1">
<p className="mb-2 text-[10px] font-semibold tracking-widest text-muted-foreground/40 uppercase">
Steps
</p>
{activePlan.steps.map((step) => (
<div
key={`${step.status}:${step.step}`}
className={cn(
"flex items-center gap-2.5 rounded-lg px-2.5 py-2 transition-colors duration-200",
step.status === "inProgress" && "bg-blue-500/5",
step.status === "completed" && "bg-emerald-500/5",
)}
>
{stepStatusIcon(step.status)}
<p
className={cn(
"text-[13px] leading-snug",
step.status === "completed"
? "text-muted-foreground/50 line-through decoration-muted-foreground/20"
: step.status === "inProgress"
? "text-foreground/90"
: "text-muted-foreground/70",
)}
>
{step.step}
</p>
</div>
))}
</div>
) : null}
{/* Proposed Plan Markdown */}
{planMarkdown ? (
<div className="space-y-2">
<button
type="button"
className="group flex w-full items-center gap-1.5 text-left"
onClick={() => setProposedPlanExpanded((v) => !v)}
>
{proposedPlanExpanded ? (
<ChevronDownIcon className="size-3 shrink-0 text-muted-foreground/40 transition-transform" />
) : (
<ChevronRightIcon className="size-3 shrink-0 text-muted-foreground/40 transition-transform" />
)}
<span className="text-[10px] font-semibold tracking-widest text-muted-foreground/40 uppercase group-hover:text-muted-foreground/60">
{planTitle ?? "Full Plan"}
</span>
</button>
{proposedPlanExpanded ? (
<div className="rounded-lg border border-border/50 bg-background/50 p-3">
<ChatMarkdown
text={displayedPlanMarkdown ?? ""}
cwd={markdownCwd}
threadRef={threadRef}
isStreaming={false}
/>
</div>
) : null}
</div>
) : null}
{/* Empty state */}
{!activePlan && !planMarkdown ? (
<div className="flex flex-col items-center justify-center py-12 text-center">
<p className="text-[13px] text-muted-foreground/40">No active plan yet.</p>
<p className="mt-1 text-[11px] text-muted-foreground/30">
Plans will appear here when generated.
</p>
</div>
) : null}
</div>
</ScrollArea>
</div>
);
});
export default PlanSidebar;
export type { PlanSidebarProps };
+1 -5
View File
@@ -1,6 +1,6 @@
import type { ContextMenuItem, PreviewSessionSnapshot } from "@t3tools/contracts";
import { getTerminalLabel } from "@t3tools/shared/terminalLabels";
import { Bot, ClipboardList, FileDiff, Files, Globe2, Plus, TerminalSquare, X } from "lucide-react";
import { Bot, FileDiff, Files, Globe2, Plus, TerminalSquare, X } from "lucide-react";
import {
type MouseEvent as ReactMouseEvent,
type ReactElement,
@@ -213,8 +213,6 @@ function surfaceTitle(
terminalLabelsById.get(surface.activeTerminalId) ??
getTerminalLabel(surface.activeTerminalId)
);
case "plan":
return "Plan";
case "agents":
return "Agents";
case "preview": {
@@ -276,8 +274,6 @@ function SurfaceIcon({
);
case "terminal":
return <TerminalSquare className="size-3 shrink-0" />;
case "plan":
return <ClipboardList className="size-3 shrink-0" />;
case "agents":
return <Bot className="size-3 shrink-0" />;
}
+12 -1
View File
@@ -1098,7 +1098,18 @@ const SidebarV2Row = memo(function SidebarV2Row(props: {
) : null}
</div>
<div className="mt-0.5 flex min-w-0 items-center gap-1.5 text-xs text-muted-foreground/75">
{thread.branch ? (
{/* While working, the current plan step outranks the branch:
it's the one line that says what the thread is doing. */}
{status === "working" && thread.planProgress ? (
<span className="min-w-0 flex-1 truncate whitespace-nowrap">
{thread.planProgress.step}
{/* Completed count, matching the transcript chip's n/m. */}
<span className="text-muted-foreground/50 tabular-nums">
{" "}
{thread.planProgress.completedSteps}/{thread.planProgress.totalSteps}
</span>
</span>
) : thread.branch ? (
<span className="min-w-0 flex-1 truncate whitespace-nowrap">{thread.branch}</span>
) : (
<span className="flex-1" />
@@ -10,7 +10,6 @@ import type {
ScopedThreadRef,
ServerProvider,
ThreadId,
TurnId,
} from "@t3tools/contracts";
import {
ProviderDriverKind,
@@ -195,7 +194,6 @@ import { toastManager } from "../ui/toast";
import {
BotIcon,
CircleAlertIcon,
ListTodoIcon,
PencilRulerIcon,
type LucideIcon,
LockIcon,
@@ -300,12 +298,8 @@ const ComposerFooterModeControls = memo(function ComposerFooterModeControls(prop
showInteractionModeToggle: boolean;
interactionMode: ProviderInteractionMode;
runtimeMode: RuntimeMode;
showPlanToggle: boolean;
planSidebarLabel: string;
planSidebarOpen: boolean;
onToggleInteractionMode: () => void;
onRuntimeModeChange: (mode: RuntimeMode) => void;
onTogglePlanSidebar: () => void;
}) {
const runtimeModeOption = runtimeModeConfig[props.runtimeMode];
const RuntimeModeIcon = runtimeModeOption.icon;
@@ -313,9 +307,6 @@ const ComposerFooterModeControls = memo(function ComposerFooterModeControls(prop
props.interactionMode === "plan"
? "Plan mode — click to return to normal build mode"
: "Default mode — click to enter plan mode";
const planSidebarTooltip = props.planSidebarOpen
? `Hide ${props.planSidebarLabel.toLowerCase()} sidebar`
: `Show ${props.planSidebarLabel.toLowerCase()} sidebar`;
const interactionModeToggle = props.showInteractionModeToggle ? (
<>
@@ -391,36 +382,6 @@ const ComposerFooterModeControls = memo(function ComposerFooterModeControls(prop
</Tooltip>
{interactionModeToggle}
{props.showPlanToggle ? (
<>
<Separator orientation="vertical" className="mx-0.5 hidden h-4 sm:block" />
<Tooltip>
<TooltipTrigger
render={
<ComposerControl
className={cn(
"shrink-0 whitespace-nowrap",
props.planSidebarOpen
? "bg-blue-500/10 text-blue-400 hover:bg-blue-500/15 hover:text-blue-300"
: "text-muted-foreground/70 hover:text-foreground/80",
)}
type="button"
onClick={props.onTogglePlanSidebar}
aria-label={planSidebarTooltip}
/>
}
>
<ComposerControlIcon
icon={ListTodoIcon}
className={props.planSidebarOpen ? "text-current opacity-100" : undefined}
/>
<span className="sr-only sm:not-sr-only">{props.planSidebarLabel}</span>
</TooltipTrigger>
<TooltipPopup side="top">{planSidebarTooltip}</TooltipPopup>
</Tooltip>
</>
) : null}
</>
);
});
@@ -576,10 +537,6 @@ export interface ChatComposerProps {
// Plan
showPlanFollowUpPrompt: boolean;
activeProposedPlan: Thread["proposedPlans"][number] | null;
activePlan: { turnId?: TurnId } | null;
sidebarProposedPlan: { turnId?: TurnId } | null;
planSidebarLabel: string;
planSidebarOpen: boolean;
// Mode
runtimeMode: RuntimeMode;
@@ -632,7 +589,6 @@ export interface ChatComposerProps {
toggleInteractionMode: () => void;
handleRuntimeModeChange: (mode: RuntimeMode) => void;
handleInteractionModeChange: (mode: ProviderInteractionMode) => void;
togglePlanSidebar: () => void;
focusComposer: () => void;
scheduleComposerFocus: () => void;
@@ -675,10 +631,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
respondingRequestIds,
showPlanFollowUpPrompt,
activeProposedPlan,
activePlan,
sidebarProposedPlan,
planSidebarLabel,
planSidebarOpen,
runtimeMode,
interactionMode,
lockedProvider,
@@ -709,7 +661,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
toggleInteractionMode,
handleRuntimeModeChange,
handleInteractionModeChange,
togglePlanSidebar,
focusComposer,
scheduleComposerFocus,
setThreadError,
@@ -1180,7 +1131,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
isComposerCollapsedMobile && !isComposerApprovalState && pendingUserInputs.length === 0;
const composerFooterHasWideActions = showPlanFollowUpPrompt || activePendingProgress !== null;
const showPlanSidebarToggle = Boolean(activePlan || sidebarProposedPlan || planSidebarOpen);
const composerFooterActionLayoutKey = useMemo(() => {
if (activePendingProgress) {
return `pending:${activePendingProgress.questionIndex}:${activePendingProgress.isLastQuestion}:${activePendingIsResponding}`;
@@ -3187,15 +3137,11 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
{isComposerFooterCompact ? (
<CompactComposerControlsMenu
activePlan={showPlanSidebarToggle}
interactionMode={interactionMode}
planSidebarLabel={planSidebarLabel}
planSidebarOpen={planSidebarOpen}
runtimeMode={runtimeMode}
showInteractionModeToggle={composerProviderControls.showInteractionModeToggle}
traitsMenuContent={providerTraitsMenuContent}
onToggleInteractionMode={toggleInteractionMode}
onTogglePlanSidebar={togglePlanSidebar}
onRuntimeModeChange={handleRuntimeModeChange}
/>
) : (
@@ -3210,12 +3156,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
showInteractionModeToggle={composerProviderControls.showInteractionModeToggle}
interactionMode={interactionMode}
runtimeMode={runtimeMode}
showPlanToggle={showPlanSidebarToggle}
planSidebarLabel={planSidebarLabel}
planSidebarOpen={planSidebarOpen}
onToggleInteractionMode={toggleInteractionMode}
onRuntimeModeChange={handleRuntimeModeChange}
onTogglePlanSidebar={togglePlanSidebar}
/>
</>
)}
@@ -1,10 +1,9 @@
import { ProviderInteractionMode, RuntimeMode } from "@t3tools/contracts";
import { memo, type ReactNode } from "react";
import { EllipsisIcon, ListTodoIcon } from "lucide-react";
import { EllipsisIcon } from "lucide-react";
import { Button } from "../ui/button";
import {
Menu,
MenuItem,
MenuPopup,
MenuRadioGroup,
MenuRadioItem,
@@ -13,15 +12,11 @@ import {
} from "../ui/menu";
export const CompactComposerControlsMenu = memo(function CompactComposerControlsMenu(props: {
activePlan: boolean;
interactionMode: ProviderInteractionMode;
planSidebarLabel: string;
planSidebarOpen: boolean;
runtimeMode: RuntimeMode;
showInteractionModeToggle: boolean;
traitsMenuContent?: ReactNode;
onToggleInteractionMode: () => void;
onTogglePlanSidebar: () => void;
onRuntimeModeChange: (mode: RuntimeMode) => void;
}) {
return (
@@ -74,17 +69,6 @@ export const CompactComposerControlsMenu = memo(function CompactComposerControls
<MenuRadioItem value="auto">Auto</MenuRadioItem>
<MenuRadioItem value="full-access">Full access</MenuRadioItem>
</MenuRadioGroup>
{props.activePlan ? (
<>
<MenuDivider />
<MenuItem onClick={props.onTogglePlanSidebar}>
<ListTodoIcon className="size-4 shrink-0" />
{props.planSidebarOpen
? `Hide ${props.planSidebarLabel.toLowerCase()} sidebar`
: `Show ${props.planSidebarLabel.toLowerCase()} sidebar`}
</MenuItem>
</>
) : null}
</MenuPopup>
</Menu>
);
@@ -4,6 +4,7 @@ import {
workEntryIndicatesToolNeutralStatus,
workLogEntryIsToolLike,
type TimelineEntry,
type TurnPlanEntry,
type WorkLogEntry,
} from "../../session-logic";
import { type ChatMessage, type ProposedPlan, type TurnDiffSummary } from "../../types";
@@ -201,6 +202,12 @@ export type MessagesTimelineRow =
createdAt: string;
proposedPlan: ProposedPlan;
}
| {
kind: "turn-plan";
id: string;
createdAt: string;
turnPlan: TurnPlanEntry;
}
| { kind: "working"; id: string; createdAt: string | null };
export interface StableMessagesTimelineRowsState {
@@ -576,6 +583,16 @@ export function deriveMessagesTimelineRows(input: {
continue;
}
if (timelineEntry.kind === "turn-plan") {
nextRows.push({
kind: "turn-plan",
id: timelineEntry.id,
createdAt: timelineEntry.createdAt,
turnPlan: timelineEntry.turnPlan,
});
continue;
}
const assistantTurnStillInProgress =
timelineEntry.message.role === "assistant" &&
unsettledTurnId !== null &&
@@ -659,6 +676,13 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean
case "proposed-plan":
return a.proposedPlan === (b as typeof a).proposedPlan;
case "turn-plan": {
const bp = b as typeof a;
// Plans rewrite in place: compare the snapshot's identity fields so an
// unchanged plan keeps its row reference (virtualization stability).
return a.createdAt === bp.createdAt && a.turnPlan.plan === bp.turnPlan.plan;
}
case "work":
return Equal.equals(a.groupedEntries, (b as typeof a).groupedEntries);
@@ -152,6 +152,8 @@ interface TimelineRowActivityState {
isRevertingCheckpoint: boolean;
activeTurnInProgress: boolean;
latestTurnId: TurnId | null;
/** Current plan step label for the working row, when the turn has a plan. */
workingStepLabel: string | null;
}
const TimelineRowCtx = createContext<TimelineRowSharedState>(null!);
@@ -196,6 +198,7 @@ interface MessagesTimelineProps {
agentPanelModel?: AgentPanelModel;
onOpenAgents?: () => void;
isWorking: boolean;
workingStepLabel?: string | null;
activeTurnInProgress: boolean;
activeTurnStartedAt: string | null;
listRef: React.RefObject<LegendListRef | null>;
@@ -240,6 +243,7 @@ interface MessagesTimelineProps {
export const MessagesTimeline = memo(function MessagesTimeline({
isWorking,
workingStepLabel = null,
activeTurnInProgress,
activeTurnStartedAt,
agentPanelModel = EMPTY_AGENT_PANEL_MODEL,
@@ -508,8 +512,9 @@ export const MessagesTimeline = memo(function MessagesTimeline({
isRevertingCheckpoint,
activeTurnInProgress,
latestTurnId: latestTurn?.turnId ?? null,
workingStepLabel,
}),
[activeTurnInProgress, isRevertingCheckpoint, isWorking, latestTurn?.turnId],
[activeTurnInProgress, isRevertingCheckpoint, isWorking, latestTurn?.turnId, workingStepLabel],
);
// Stable renderItem — no closure deps. Row components read shared state
@@ -911,7 +916,8 @@ const TimelineRowContent = memo(function TimelineRowContent({ row }: { row: Time
// they sit closer to the work that follows them.
(row.kind === "message" && row.message.role === "assistant" && !row.showAssistantMeta) ||
row.kind === "work" ||
row.kind === "work-toggle"
row.kind === "work-toggle" ||
row.kind === "turn-plan"
? "pb-2"
: "pb-4",
row.kind === "message" && row.message.role === "assistant" ? "group/assistant" : null,
@@ -929,6 +935,7 @@ const TimelineRowContent = memo(function TimelineRowContent({ row }: { row: Time
<AssistantTimelineRow row={row} />
) : null}
{row.kind === "proposed-plan" ? <ProposedPlanTimelineRow row={row} /> : null}
{row.kind === "turn-plan" ? <TurnPlanTimelineRow row={row} /> : null}
{row.kind === "working" ? <WorkingTimelineRow row={row} /> : null}
</div>
);
@@ -1159,16 +1166,117 @@ function ProposedPlanTimelineRow({
);
}
/**
* Inline folded plan chip: one row per turn that produced plan/todo steps.
* Collapsed by default — a segment bar plus the in-progress step label —
* and expands in place to the full step list. Replaces the old plan sidebar.
*/
const TurnPlanTimelineRow = memo(function TurnPlanTimelineRow({
row,
}: {
row: Extract<TimelineRow, { kind: "turn-plan" }>;
}) {
const [expanded, setExpanded] = useState(false);
const { steps } = row.turnPlan.plan;
const completedCount = steps.filter((step) => step.status === "completed").length;
const allDone = completedCount === steps.length;
// Label priority: the in-progress step, else the next pending step (plan
// just created), else the last step (plan finished, rendered muted).
const label =
steps.find((step) => step.status === "inProgress")?.step ??
steps.find((step) => step.status === "pending")?.step ??
steps.at(-1)?.step ??
"Plan";
const Chevron = expanded ? ChevronDownIcon : ChevronRightIcon;
return (
<div className="min-w-0 px-1 py-0.5">
<button
type="button"
className="flex w-full min-w-0 cursor-pointer items-center gap-2 rounded-md px-0.5 py-0.5 text-left text-[12px] leading-5 transition-colors duration-150 hover:bg-accent/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
aria-expanded={expanded}
onClick={() => setExpanded((value) => !value)}
>
<Chevron className="size-3.5 shrink-0 text-muted-foreground/65" />
{steps.length > 1 ? (
<span aria-hidden className="flex shrink-0 items-center gap-0.5">
{steps.map((step) => (
<span
key={step.step}
className={cn(
"h-[3px] w-2.5 rounded-full",
step.status === "completed"
? "bg-success"
: step.status === "inProgress"
? "bg-primary"
: "bg-muted-foreground/25",
)}
/>
))}
</span>
) : null}
<span
className={cn(
"min-w-0 truncate",
allDone ? "text-muted-foreground/65" : "font-medium text-foreground/85",
)}
>
{label}
</span>
{steps.length > 1 ? (
<span className="shrink-0 text-muted-foreground/50 tabular-nums">
{completedCount}/{steps.length}
</span>
) : null}
</button>
{expanded ? (
<div className="mt-0.5 space-y-px pl-6">
{steps.map((step) => (
<div key={step.step} className="flex items-baseline gap-2 text-[12px] leading-5">
<span
className={cn(
"w-3 shrink-0 text-center font-mono text-[10px]",
step.status === "completed"
? "text-success"
: step.status === "inProgress"
? "text-primary"
: "text-muted-foreground/40",
)}
aria-hidden
>
{step.status === "completed" ? "✓" : step.status === "inProgress" ? "●" : "○"}
</span>
<span
className={cn(
"min-w-0",
step.status === "completed"
? "text-muted-foreground/55"
: step.status === "inProgress"
? "text-foreground/90"
: "text-muted-foreground/70",
)}
>
{step.step}
</span>
</div>
))}
</div>
) : null}
</div>
);
});
function WorkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "working" }> }) {
const { workingStepLabel } = use(TimelineRowActivityCtx);
return (
<div className="py-0.5 pl-1.5">
<div className="flex items-center gap-2 pt-1 text-[11px] text-muted-foreground/70 tabular-nums">
<div className="flex min-w-0 items-center gap-2 pt-1 text-[11px] text-muted-foreground/70 tabular-nums">
<span className="inline-flex items-center gap-[3px]">
<span className="h-1 w-1 rounded-full bg-muted-foreground/30 animate-status-pulse" />
<span className="h-1 w-1 rounded-full bg-muted-foreground/30 animate-status-pulse [animation-delay:200ms]" />
<span className="h-1 w-1 rounded-full bg-muted-foreground/30 animate-status-pulse [animation-delay:400ms]" />
</span>
<span>
<span className="shrink-0">
{row.createdAt ? (
<>
Working for <WorkingTimer createdAt={row.createdAt} />
@@ -1177,6 +1285,9 @@ function WorkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "workin
"Working..."
)}
</span>
{workingStepLabel ? (
<span className="min-w-0 truncate text-muted-foreground/55">· {workingStepLabel}</span>
) : null}
</div>
</div>
);
@@ -623,9 +623,6 @@ export function useSettingsRestore(onRestored?: () => void) {
...(settings.diffIgnoreWhitespace !== DEFAULT_UNIFIED_SETTINGS.diffIgnoreWhitespace
? ["Diff whitespace changes"]
: []),
...(settings.autoOpenPlanSidebar !== DEFAULT_UNIFIED_SETTINGS.autoOpenPlanSidebar
? ["Auto-open task panel"]
: []),
...(settings.enableAssistantStreaming !== DEFAULT_UNIFIED_SETTINGS.enableAssistantStreaming
? ["Assistant output"]
: []),
@@ -655,7 +652,6 @@ export function useSettingsRestore(onRestored?: () => void) {
[
isTextGenerationModelDirty,
isBackgroundActivityDirty,
settings.autoOpenPlanSidebar,
settings.confirmThreadArchive,
settings.confirmThreadDelete,
settings.addProjectBaseDirectory,
@@ -701,7 +697,6 @@ export function useSettingsRestore(onRestored?: () => void) {
glassOpacity: DEFAULT_UNIFIED_SETTINGS.glassOpacity,
sidebarThreadPreviewCount: DEFAULT_UNIFIED_SETTINGS.sidebarThreadPreviewCount,
sidebarProjectGroupingMode: DEFAULT_UNIFIED_SETTINGS.sidebarProjectGroupingMode,
autoOpenPlanSidebar: DEFAULT_UNIFIED_SETTINGS.autoOpenPlanSidebar,
enableAssistantStreaming: DEFAULT_UNIFIED_SETTINGS.enableAssistantStreaming,
enableProviderUpdateChecks: DEFAULT_UNIFIED_SETTINGS.enableProviderUpdateChecks,
backgroundActivity: DEFAULT_UNIFIED_SETTINGS.backgroundActivity,
@@ -1897,32 +1892,6 @@ export function GeneralSettingsPanel() {
}
/>
<SettingsRow
{...searchableSetting("auto-open-task-panel")}
description="Open the right-side plan and task panel automatically when steps appear."
resetAction={
settings.autoOpenPlanSidebar !== DEFAULT_UNIFIED_SETTINGS.autoOpenPlanSidebar ? (
<SettingResetButton
label="auto-open task panel"
onClick={() =>
updateSettings({
autoOpenPlanSidebar: DEFAULT_UNIFIED_SETTINGS.autoOpenPlanSidebar,
})
}
/>
) : null
}
control={
<Switch
checked={settings.autoOpenPlanSidebar}
onCheckedChange={(checked) =>
updateSettings({ autoOpenPlanSidebar: Boolean(checked) })
}
aria-label="Open the task panel automatically"
/>
}
/>
<SettingsRow
{...searchableSetting("new-threads")}
description="Pick the default workspace mode for newly created draft threads."
@@ -110,11 +110,6 @@ export const SETTINGS_SEARCH_ITEMS = [
title: "Provider update checks",
to: "/settings/general",
},
{
id: "auto-open-task-panel",
title: "Auto-open task panel",
to: "/settings/general",
},
{
id: "new-threads",
title: "New threads",
-21
View File
@@ -1,21 +0,0 @@
/**
* Tracks which turn's plan sidebar the user explicitly dismissed, per thread.
*
* Kept outside React state so a dismissal survives leaving and re-entering a
* thread (ChatView resets its per-thread refs on navigation). Dismissals are
* keyed by turn, so when a new turn produces fresh plan steps the sidebar
* still auto-opens.
*/
const dismissedTurnByThreadKey = new Map<string, string>();
export function dismissPlanSidebarForTurn(threadKey: string, turnKey: string): void {
dismissedTurnByThreadKey.set(threadKey, turnKey);
}
export function clearPlanSidebarDismissal(threadKey: string): void {
dismissedTurnByThreadKey.delete(threadKey);
}
export function isPlanSidebarDismissedForTurn(threadKey: string, turnKey: string): boolean {
return dismissedTurnByThreadKey.get(threadKey) === turnKey;
}
+47 -12
View File
@@ -102,6 +102,41 @@ describe("rightPanelStore", () => {
});
});
it("drops persisted plan surfaces and does not reopen an empty panel", () => {
expect(
migratePersistedRightPanelState({
byThreadKey: {
"env-1:thread-A": {
isOpen: true,
activeSurfaceId: "plan",
surfaces: [{ id: "plan", kind: "plan" }],
},
"env-1:thread-B": {
isOpen: true,
activeSurfaceId: "plan",
surfaces: [
{ id: "plan", kind: "plan" },
{ id: "diff", kind: "diff" },
],
},
},
}),
).toEqual({
byThreadKey: {
"env-1:thread-A": {
isOpen: false,
activeSurfaceId: null,
surfaces: [],
},
"env-1:thread-B": {
isOpen: true,
activeSurfaceId: "diff",
surfaces: [{ id: "diff", kind: "diff" }],
},
},
});
});
it("open sets the active panel for a thread", () => {
useRightPanelStore.getState().open(refA, "preview");
expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("preview");
@@ -109,7 +144,7 @@ describe("rightPanelStore", () => {
});
it("opening a different kind keeps both surfaces and activates the new one", () => {
useRightPanelStore.getState().open(refA, "plan");
useRightPanelStore.getState().open(refA, "agents");
useRightPanelStore.getState().open(refA, "preview");
expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("preview");
expect(
@@ -119,7 +154,7 @@ describe("rightPanelStore", () => {
it("reopening an inactive singleton activates its existing surface", () => {
useRightPanelStore.getState().open(refA, "diff");
useRightPanelStore.getState().open(refA, "plan");
useRightPanelStore.getState().open(refA, "agents");
useRightPanelStore.getState().open(refA, "diff");
expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
@@ -127,7 +162,7 @@ describe("rightPanelStore", () => {
activeSurfaceId: "diff",
surfaces: [
{ id: "diff", kind: "diff" },
{ id: "plan", kind: "plan" },
{ id: "agents", kind: "agents" },
],
});
});
@@ -207,15 +242,15 @@ describe("rightPanelStore", () => {
it("removes persisted file surfaces when their workspace no longer exists", () => {
useRightPanelStore.getState().openFile(refA, "src/index.ts");
useRightPanelStore.getState().open(refA, "plan");
useRightPanelStore.getState().open(refA, "agents");
useRightPanelStore.getState().openFile(refA, "README.md");
useRightPanelStore.getState().reconcileFileSurfaces(refA, false);
expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
isOpen: true,
activeSurfaceId: "plan",
surfaces: [{ id: "plan", kind: "plan" }],
activeSurfaceId: "agents",
surfaces: [{ id: "agents", kind: "agents" }],
});
useRightPanelStore.getState().openFile(refB, "conductor.json");
@@ -228,13 +263,13 @@ describe("rightPanelStore", () => {
});
it("close hides the panel without clearing its selected surface", () => {
useRightPanelStore.getState().open(refA, "plan");
useRightPanelStore.getState().open(refA, "agents");
useRightPanelStore.getState().close(refA);
expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBeNull();
expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
isOpen: false,
activeSurfaceId: "plan",
surfaces: [{ id: "plan", kind: "plan" }],
activeSurfaceId: "agents",
surfaces: [{ id: "agents", kind: "agents" }],
});
});
@@ -264,12 +299,12 @@ describe("rightPanelStore", () => {
it("toggle to a different kind switches active", () => {
useRightPanelStore.getState().toggle(refA, "preview");
useRightPanelStore.getState().toggle(refA, "plan");
expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("plan");
useRightPanelStore.getState().toggle(refA, "agents");
expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("agents");
});
it("removeThread clears persisted state", () => {
useRightPanelStore.getState().open(refA, "plan");
useRightPanelStore.getState().open(refA, "agents");
useRightPanelStore.getState().removeThread(refA);
expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBeNull();
});
+17 -9
View File
@@ -5,7 +5,7 @@
* surface descriptors and the active surface, while each feature continues to
* own its durable resource state. Browser surfaces point at preview tab ids,
* terminal surfaces point at terminal session ids, file surfaces point at
* workspace paths, and diff/plan/files remain singleton surfaces.
* workspace paths, and diff/files remain singleton surfaces.
*/
import { scopedThreadKey } from "@t3tools/client-runtime/environment";
import type { ScopedThreadRef } from "@t3tools/contracts";
@@ -15,7 +15,6 @@ import { createJSONStorage, persist } from "zustand/middleware";
import { resolveStorage } from "./lib/storage";
export const RIGHT_PANEL_KINDS = [
"plan",
"diff",
"files",
"file",
@@ -45,11 +44,11 @@ export type RightPanelSurface =
revealLine: number | null;
revealRequestId: number;
}
| { id: "plan"; kind: "plan" }
| { id: "agents"; kind: "agents" };
const RIGHT_PANEL_STORAGE_KEY = "t3code:right-panel-state:v2";
const RIGHT_PANEL_STORAGE_VERSION = 8;
// v9 removed the "plan" surface kind (plans render inline in the transcript).
const RIGHT_PANEL_STORAGE_VERSION = 9;
export interface ThreadRightPanelState {
isOpen: boolean;
@@ -99,8 +98,6 @@ const singletonSurface = (
return { id: "diff", kind };
case "files":
return { id: "files", kind };
case "plan":
return { id: "plan", kind };
case "agents":
return { id: "agents", kind };
}
@@ -181,6 +178,9 @@ export function migratePersistedRightPanelState(persistedState: unknown): {
threadState && typeof threadState === "object" ? threadState : null;
const surfaces = Array.isArray(validThreadState?.surfaces)
? validThreadState.surfaces.flatMap<RightPanelSurface>((surface) => {
// Dropped surface kind: plans now render inline in the
// transcript (v9).
if ((surface as { kind?: string }).kind === "plan") return [];
if (surface.kind === "file") {
const revealLine =
typeof surface.revealLine === "number" &&
@@ -229,15 +229,23 @@ export function migratePersistedRightPanelState(persistedState: unknown): {
];
})
: [];
const activeSurfaceId = surfaces.some(
const persistedActiveSurfaceId = surfaces.some(
(surface) => surface.id === validThreadState?.activeSurfaceId,
)
? (validThreadState?.activeSurfaceId ?? null)
: null;
// A migration that dropped every surface (e.g. plan-only panels
// in v9) must not reopen an empty panel.
const isOpen =
typeof validThreadState?.isOpen === "boolean"
surfaces.length > 0 &&
(typeof validThreadState?.isOpen === "boolean"
? validThreadState.isOpen
: activeSurfaceId !== null;
: persistedActiveSurfaceId !== null);
// An open panel needs an active surface: if migration dropped
// the persisted one (e.g. plan was active), fall back to the
// first survivor instead of rendering an open empty panel.
const activeSurfaceId =
persistedActiveSurfaceId ?? (isOpen ? (surfaces[0]?.id ?? null) : null);
return [threadKey, { isOpen, surfaces, activeSurfaceId }];
},
),
+90 -98
View File
@@ -11,12 +11,12 @@ import { describe, expect, it } from "vite-plus/test";
import {
deriveActiveWorkStartedAt,
deriveActivePlanState,
deriveTurnPlans,
derivePendingApprovals,
derivePendingUserInputs,
deriveTimelineEntries,
deriveWorkLogEntries,
findLatestProposedPlan,
findSidebarProposedPlan,
hasActionableProposedPlan,
isLatestTurnSettled,
workEntryIndicatesToolFailure,
@@ -410,6 +410,95 @@ describe("deriveActivePlanState", () => {
});
});
describe("deriveTurnPlans", () => {
it("keeps one entry per turn, anchored at the first snapshot with the latest steps", () => {
const activities: OrchestrationThreadActivity[] = [
makeActivity({
id: "plan-1a",
createdAt: "2026-02-23T00:00:01.000Z",
kind: "turn.plan.updated",
summary: "Plan updated",
tone: "info",
turnId: "turn-1",
payload: {
plan: [{ step: "Inspect code", status: "inProgress" }],
},
}),
makeActivity({
id: "plan-1b",
createdAt: "2026-02-23T00:00:05.000Z",
kind: "turn.plan.updated",
summary: "Plan updated",
tone: "info",
turnId: "turn-1",
payload: {
plan: [{ step: "Inspect code", status: "completed" }],
},
}),
makeActivity({
id: "plan-2a",
createdAt: "2026-02-23T00:01:00.000Z",
kind: "turn.plan.updated",
summary: "Plan updated",
tone: "info",
turnId: "turn-2",
payload: {
plan: [{ step: "Ship it", status: "pending" }],
},
}),
];
const turnPlans = deriveTurnPlans(activities);
expect(turnPlans).toHaveLength(2);
expect(turnPlans[0]).toMatchObject({
id: "turn-plan:turn-1",
createdAt: "2026-02-23T00:00:01.000Z",
turnId: "turn-1",
});
expect(turnPlans[0]?.plan.steps).toEqual([{ step: "Inspect code", status: "completed" }]);
expect(turnPlans[1]?.plan.steps).toEqual([{ step: "Ship it", status: "pending" }]);
});
it("skips activities without parseable steps", () => {
const activities: OrchestrationThreadActivity[] = [
makeActivity({
id: "plan-bad",
createdAt: "2026-02-23T00:00:01.000Z",
kind: "turn.plan.updated",
summary: "Plan updated",
tone: "info",
turnId: "turn-1",
payload: { plan: [] },
}),
];
expect(deriveTurnPlans(activities)).toEqual([]);
});
it("drops a turn's chip when a later snapshot clears the plan", () => {
const activities: OrchestrationThreadActivity[] = [
makeActivity({
id: "plan-set",
createdAt: "2026-02-23T00:00:01.000Z",
kind: "turn.plan.updated",
summary: "Plan updated",
tone: "info",
turnId: "turn-1",
payload: { plan: [{ step: "Inspect code", status: "inProgress" }] },
}),
makeActivity({
id: "plan-clear",
createdAt: "2026-02-23T00:00:02.000Z",
kind: "turn.plan.updated",
summary: "Plan updated",
tone: "info",
turnId: "turn-1",
payload: { plan: [] },
}),
];
expect(deriveTurnPlans(activities)).toEqual([]);
});
});
describe("findLatestProposedPlan", () => {
it("prefers the latest proposed plan for the active turn", () => {
expect(
@@ -515,103 +604,6 @@ describe("hasActionableProposedPlan", () => {
});
});
describe("findSidebarProposedPlan", () => {
it("prefers the running turn source proposed plan when available on the same thread", () => {
expect(
findSidebarProposedPlan({
threads: [
{
id: ThreadId.make("thread-1"),
proposedPlans: [
{
id: "plan-1",
turnId: TurnId.make("turn-plan"),
planMarkdown: "# Source plan",
implementedAt: "2026-02-23T00:00:03.000Z",
implementationThreadId: ThreadId.make("thread-2"),
createdAt: "2026-02-23T00:00:01.000Z",
updatedAt: "2026-02-23T00:00:02.000Z",
},
],
},
{
id: ThreadId.make("thread-2"),
proposedPlans: [
{
id: "plan-2",
turnId: TurnId.make("turn-other"),
planMarkdown: "# Latest elsewhere",
implementedAt: null,
implementationThreadId: null,
createdAt: "2026-02-23T00:00:04.000Z",
updatedAt: "2026-02-23T00:00:05.000Z",
},
],
},
],
latestTurn: {
turnId: TurnId.make("turn-implementation"),
sourceProposedPlan: {
threadId: ThreadId.make("thread-1"),
planId: "plan-1",
},
},
latestTurnSettled: false,
threadId: ThreadId.make("thread-1"),
}),
).toEqual({
id: "plan-1",
turnId: "turn-plan",
planMarkdown: "# Source plan",
implementedAt: "2026-02-23T00:00:03.000Z",
implementationThreadId: "thread-2",
createdAt: "2026-02-23T00:00:01.000Z",
updatedAt: "2026-02-23T00:00:02.000Z",
});
});
it("falls back to the latest proposed plan once the turn is settled", () => {
expect(
findSidebarProposedPlan({
threads: [
{
id: ThreadId.make("thread-1"),
proposedPlans: [
{
id: "plan-1",
turnId: TurnId.make("turn-plan"),
planMarkdown: "# Older",
implementedAt: null,
implementationThreadId: null,
createdAt: "2026-02-23T00:00:01.000Z",
updatedAt: "2026-02-23T00:00:02.000Z",
},
{
id: "plan-2",
turnId: TurnId.make("turn-latest"),
planMarkdown: "# Latest",
implementedAt: null,
implementationThreadId: null,
createdAt: "2026-02-23T00:00:03.000Z",
updatedAt: "2026-02-23T00:00:04.000Z",
},
],
},
],
latestTurn: {
turnId: TurnId.make("turn-implementation"),
sourceProposedPlan: {
threadId: ThreadId.make("thread-1"),
planId: "plan-1",
},
},
latestTurnSettled: true,
threadId: ThreadId.make("thread-1"),
})?.planMarkdown,
).toBe("# Latest");
});
});
describe("workEntryIndicatesToolFailure", () => {
const base = {
id: "w1",
+85 -46
View File
@@ -151,6 +151,12 @@ export type TimelineEntry =
createdAt: string;
proposedPlan: ProposedPlan;
}
| {
id: string;
kind: "turn-plan";
createdAt: string;
turnPlan: TurnPlanEntry;
}
| {
id: string;
kind: "work";
@@ -532,26 +538,10 @@ export function derivePendingUserInputs(
);
}
export function deriveActivePlanState(
activities: ReadonlyArray<OrchestrationThreadActivity>,
latestTurnId: TurnId | undefined,
): ActivePlanState | null {
const ordered = [...activities].toSorted(compareActivitiesByOrder);
const allPlanActivities = ordered.filter((activity) => activity.kind === "turn.plan.updated");
// Prefer plan from the current turn; fall back to the most recent plan from any turn
// so that TodoWrite tasks persist across follow-up messages.
const latest = Option.firstSomeOf([
...(latestTurnId
? Arr.findLast(allPlanActivities, (activity) => activity.turnId === latestTurnId)
: Option.none()),
Arr.last(allPlanActivities),
]).pipe(Option.getOrNull);
if (!latest) {
return null;
}
function planStateFromActivity(activity: OrchestrationThreadActivity): ActivePlanState | null {
const payload =
latest.payload && typeof latest.payload === "object"
? (latest.payload as Record<string, unknown>)
activity.payload && typeof activity.payload === "object"
? (activity.payload as Record<string, unknown>)
: null;
const rawPlan = payload?.plan;
if (!Array.isArray(rawPlan)) {
@@ -580,8 +570,8 @@ export function deriveActivePlanState(
return null;
}
return {
createdAt: latest.createdAt,
turnId: latest.turnId,
createdAt: activity.createdAt,
turnId: activity.turnId,
...(payload && "explanation" in payload
? { explanation: payload.explanation as string | null }
: {}),
@@ -589,6 +579,72 @@ export function deriveActivePlanState(
};
}
export function deriveActivePlanState(
activities: ReadonlyArray<OrchestrationThreadActivity>,
latestTurnId: TurnId | undefined,
): ActivePlanState | null {
const ordered = [...activities].toSorted(compareActivitiesByOrder);
const allPlanActivities = ordered.filter((activity) => activity.kind === "turn.plan.updated");
// Prefer plan from the current turn; fall back to the most recent plan from any turn
// so that TodoWrite tasks persist across follow-up messages.
const latest = Option.firstSomeOf([
...(latestTurnId
? Arr.findLast(allPlanActivities, (activity) => activity.turnId === latestTurnId)
: Option.none()),
Arr.last(allPlanActivities),
]).pipe(Option.getOrNull);
if (!latest) {
return null;
}
return planStateFromActivity(latest);
}
export interface TurnPlanEntry {
/** Stable per-turn row id (plans rewrite constantly; the row must not churn). */
id: string;
/** Anchor timestamp: the turn's FIRST plan activity, so the chip renders where planning began. */
createdAt: string;
turnId: TurnId | null;
plan: ActivePlanState;
}
/**
* One inline plan chip per turn that produced plan/todo steps: the latest
* snapshot for the turn, anchored at the first snapshot's timestamp. Turn-less
* plan activities collapse into a single chip keyed by thread order.
*/
export function deriveTurnPlans(
activities: ReadonlyArray<OrchestrationThreadActivity>,
): TurnPlanEntry[] {
const ordered = [...activities].toSorted(compareActivitiesByOrder);
const byTurn = new Map<string, TurnPlanEntry>();
for (const activity of ordered) {
if (activity.kind !== "turn.plan.updated") {
continue;
}
const plan = planStateFromActivity(activity);
const key = activity.turnId ?? "no-turn";
if (!plan) {
// A later snapshot with no steps clears the turn's plan; keeping the
// stale entry would freeze the chip on a withdrawn plan.
byTurn.delete(key);
continue;
}
const existing = byTurn.get(key);
if (existing) {
existing.plan = plan;
} else {
byTurn.set(key, {
id: `turn-plan:${key}`,
createdAt: activity.createdAt,
turnId: activity.turnId,
plan,
});
}
}
return [...byTurn.values()];
}
export function findLatestProposedPlan(
proposedPlans: ReadonlyArray<ProposedPlan>,
latestTurnId: TurnId | string | null | undefined,
@@ -619,30 +675,6 @@ export function findLatestProposedPlan(
return toLatestProposedPlanState(latestPlan);
}
export function findSidebarProposedPlan(input: {
threads: ReadonlyArray<Pick<Thread, "id" | "proposedPlans">>;
latestTurn: Pick<OrchestrationLatestTurn, "turnId" | "sourceProposedPlan"> | null;
latestTurnSettled: boolean;
threadId: ThreadId | string | null | undefined;
}): LatestProposedPlanState | null {
const activeThreadPlans =
input.threads.find((thread) => thread.id === input.threadId)?.proposedPlans ?? [];
if (!input.latestTurnSettled) {
const sourceProposedPlan = input.latestTurn?.sourceProposedPlan;
if (sourceProposedPlan) {
const sourcePlan = input.threads
.find((thread) => thread.id === sourceProposedPlan.threadId)
?.proposedPlans.find((plan) => plan.id === sourceProposedPlan.planId);
if (sourcePlan) {
return toLatestProposedPlanState(sourcePlan);
}
}
}
return findLatestProposedPlan(activeThreadPlans, input.latestTurn?.turnId ?? null);
}
export function hasActionableProposedPlan(
proposedPlan: LatestProposedPlanState | Pick<ProposedPlan, "implementedAt"> | null,
): boolean {
@@ -1542,6 +1574,7 @@ export function deriveTimelineEntries(
messages: ReadonlyArray<ChatMessage>,
proposedPlans: ReadonlyArray<ProposedPlan>,
workEntries: ReadonlyArray<WorkLogEntry>,
turnPlans: ReadonlyArray<TurnPlanEntry> = [],
): TimelineEntry[] {
const messageRows: TimelineEntry[] = messages.map((message) => ({
id: message.id,
@@ -1555,13 +1588,19 @@ export function deriveTimelineEntries(
createdAt: proposedPlan.createdAt,
proposedPlan,
}));
const turnPlanRows: TimelineEntry[] = turnPlans.map((turnPlan) => ({
id: turnPlan.id,
kind: "turn-plan",
createdAt: turnPlan.createdAt,
turnPlan,
}));
const workRows: TimelineEntry[] = workEntries.map((entry) => ({
id: entry.id,
kind: "work",
createdAt: entry.createdAt,
entry,
}));
return [...messageRows, ...proposedPlanRows, ...workRows].toSorted((a, b) =>
return [...messageRows, ...proposedPlanRows, ...turnPlanRows, ...workRows].toSorted((a, b) =>
a.createdAt.localeCompare(b.createdAt),
);
}
+14
View File
@@ -446,6 +446,20 @@ export const OrchestrationThreadShell = Schema.Struct({
* live work. Optional so old servers/clients interop; absent = none.
*/
backgroundLiveness: Schema.optional(Schema.NullOr(Schema.Literals(["working", "monitoring"]))),
/**
* Current plan step while a turn runs, for the Working indicators
* (sidebar row, in-chat working line). Cleared when the turn settles —
* never persists as stale UI. Optional so old servers/clients interop.
*/
planProgress: Schema.optional(
Schema.NullOr(
Schema.Struct({
step: TrimmedNonEmptyString,
completedSteps: NonNegativeInt,
totalSteps: NonNegativeInt,
}),
),
),
});
export type OrchestrationThreadShell = typeof OrchestrationThreadShell.Type;
-2
View File
@@ -111,7 +111,6 @@ export const FontFamilyPreference = Schema.String.check(Schema.isMaxLength(200))
export type FontFamilyPreference = typeof FontFamilyPreference.Type;
export const ClientSettingsSchema = Schema.Struct({
autoOpenPlanSidebar: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
confirmThreadArchive: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
confirmThreadDelete: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
dismissedProviderUpdateNotificationKeys: Schema.Array(TrimmedNonEmptyString).pipe(
@@ -747,7 +746,6 @@ export const ServerSettingsPatch = Schema.Struct({
export type ServerSettingsPatch = typeof ServerSettingsPatch.Type;
export const ClientSettingsPatch = Schema.Struct({
autoOpenPlanSidebar: Schema.optionalKey(Schema.Boolean),
confirmThreadArchive: Schema.optionalKey(Schema.Boolean),
confirmThreadDelete: Schema.optionalKey(Schema.Boolean),
diffIgnoreWhitespace: Schema.optionalKey(Schema.Boolean),