Client-only sidebar v2: back settle with archive, revert all server changes

Makes the new sidebar/thread-list testable against existing unupgraded
servers by removing every backend dependency of the settled feature:

- apps/server, contracts orchestration schemas, and client-runtime
  command/reducer plumbing revert to main baseline (no thread.settle
  commands, no settled events/fields, no migration 033)
- effectiveSettled() is now archive-based: archivedAt is the explicit
  settled signal; PR merged/closed and inactivity auto-settle keep
  working client-side. Blocked work (pending approval/input, live
  session) still never settles
- settle/unsettle actions ride threadEnvironment.archive/unarchive on
  web and mobile — UI and UX unchanged
- Archived threads stay visible as the settled tail: the live shell
  stream drops archived threads (thread.archived → thread-removed), so
  both clients merge them back from the archived shell snapshot and
  refresh it after settle/unsettle/archive actions
- Client settings (sidebarV2Enabled, sidebarAutoSettleAfterDays) are
  kept — they persist client-side only

Trade-offs vs the event-sourced model (still on t3code/sidebar-v2-mobile):
no activity-driven auto-un-settle for archived threads, and no "keep
active" override distinct from unarchiving.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
Theo BrowneandClaude Fable 5 committed 2026-07-15 21:31:50 -07:00
1 parent a2f8028f13
commit da08b588fa
50 files changed
+146 -1102

No files matched your search

@@ -42,8 +42,6 @@ function makeThread(overrides: Partial<Thread> = {}): Thread {
createdAt: now,
updatedAt: now,
archivedAt: null,
settledOverride: null,
settledAt: null,
deletedAt: null,
latestTurn: null,
branch: null,
@@ -45,8 +45,6 @@ export function buildLocalDraftThread(
createdAt: draftThread.createdAt,
updatedAt: draftThread.createdAt,
archivedAt: null,
settledOverride: null,
settledAt: null,
deletedAt: null,
latestTurn: null,
branch: draftThread.branch,
@@ -24,8 +24,6 @@ function makeThread(overrides: Partial<Thread> = {}): Thread {
proposedPlans: [],
createdAt: "2026-03-01T00:00:00.000Z",
archivedAt: null,
settledOverride: null,
settledAt: null,
deletedAt: null,
updatedAt: "2026-03-01T00:00:00.000Z",
latestTurn: null,
@@ -910,8 +910,6 @@ function makeThread(overrides: Partial<Thread> = {}): Thread {
proposedPlans: [],
createdAt: "2026-03-09T10:00:00.000Z",
archivedAt: null,
settledOverride: null,
settledAt: null,
deletedAt: null,
updatedAt: "2026-03-09T10:00:00.000Z",
latestTurn: null,
+39 -6
View File
@@ -43,6 +43,10 @@ import { readLocalApi } from "../localApi";
import { useUiStateStore } from "../uiStateStore";
import { useThreadSelectionStore } from "../threadSelectionStore";
import { useThreadActions } from "../hooks/useThreadActions";
import {
refreshArchivedThreadsForEnvironment,
useArchivedThreadSnapshots,
} from "../lib/archivedThreadsState";
import { useHandleNewThread } from "../hooks/useHandleNewThread";
import { useOpenAddProjectCommandPalette } from "../commandPaletteContext";
import { onOpenNewThreadPicker } from "../newThreadPickerBus";
@@ -702,14 +706,37 @@ export default function SidebarV2() {
}
}, [projectScopeKey, projects]);
// Archived threads ARE the settled tail in the client-only settled model,
// but the live shell stream drops a thread the moment it is archived
// (thread.archived → thread-removed). Merge them back in from the archived
// snapshot query; live shells win on the (brief) overlap.
const archivedEnvironmentIds = useMemo(
() => environments.map((environment) => environment.environmentId),
[environments],
);
const { snapshots: archivedSnapshots } = useArchivedThreadSnapshots(archivedEnvironmentIds);
const allThreads = useMemo(() => {
const liveKeys = new Set(
threads.map((thread) => scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id))),
);
const archived = archivedSnapshots.flatMap(({ environmentId, snapshot }) =>
snapshot.threads
.map((thread) => ({ ...thread, environmentId }))
.filter(
(thread) =>
!liveKeys.has(scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id))),
),
);
return [...threads, ...archived];
}, [archivedSnapshots, threads]);
const { activeThreads, settledThreads } = useMemo(() => {
const now = `${nowMinute}:00.000Z`;
const visible = threads.filter(
const visible = allThreads.filter(
(thread) =>
thread.archivedAt === null &&
(scopedProject === null ||
(thread.environmentId === scopedProject.environmentId &&
thread.projectId === scopedProject.id)),
scopedProject === null ||
(thread.environmentId === scopedProject.environmentId &&
thread.projectId === scopedProject.id),
);
const active: EnvironmentThreadShell[] = [];
const settled: EnvironmentThreadShell[] = [];
@@ -730,7 +757,7 @@ export default function SidebarV2() {
Date.parse(left.latestUserMessageAt ?? left.updatedAt),
),
};
}, [autoSettleAfterDays, changeRequestStateByKey, nowMinute, scopedProject, threads]);
}, [allThreads, autoSettleAfterDays, changeRequestStateByKey, nowMinute, scopedProject]);
const orderedThreads = useMemo(
() => [...activeThreads, ...settledThreads],
@@ -877,7 +904,11 @@ export default function SidebarV2() {
description: error instanceof Error ? error.message : "An error occurred.",
}),
);
return;
}
// Settle = archive: the shell stream drops the thread, so pull the
// archived snapshot immediately to keep it visible as a settled row.
refreshArchivedThreadsForEnvironment(threadRef.environmentId);
})();
},
[settleThread],
@@ -895,7 +926,9 @@ export default function SidebarV2() {
description: error instanceof Error ? error.message : "An error occurred.",
}),
);
return;
}
refreshArchivedThreadsForEnvironment(threadRef.environmentId);
})();
},
[unsettleThread],
+6 -4
View File
@@ -54,10 +54,12 @@ export function useThreadActions() {
const deleteThreadMutation = useAtomCommand(threadEnvironment.delete, {
reportFailure: false,
});
const settleThreadMutation = useAtomCommand(threadEnvironment.settle, {
// Client-only settled model: settle/unsettle ride the pre-existing archive
// lifecycle so no server upgrade is required. See threadSettled.ts.
const settleThreadMutation = useAtomCommand(threadEnvironment.archive, {
reportFailure: false,
});
const unsettleThreadMutation = useAtomCommand(threadEnvironment.unsettle, {
const unsettleThreadMutation = useAtomCommand(threadEnvironment.unarchive, {
reportFailure: false,
});
const stopThreadSession = useAtomCommand(threadEnvironment.stopSession);
@@ -416,7 +418,7 @@ export function useThreadActions() {
const stillOrphaned =
getOrphanedWorktreePathForThread(currentThreads, threadRef.threadId) ===
orphanedWorktreePath;
const stillSettled = currentShell?.settledOverride === "settled";
const stillSettled = currentShell?.archivedAt != null;
if (!stillOrphaned || !stillSettled) {
toastManager.add(
stackedThreadToast({
@@ -485,7 +487,7 @@ export function useThreadActions() {
(target: ScopedThreadRef) =>
unsettleThreadMutation({
environmentId: target.environmentId,
input: { threadId: target.threadId, reason: "user" },
input: { threadId: target.threadId },
}),
[unsettleThreadMutation],
);
-2
View File
@@ -26,8 +26,6 @@ function makeThread(overrides: Partial<Thread> = {}): Thread {
proposedPlans: [],
createdAt: "2026-03-09T10:00:00.000Z",
archivedAt: null,
settledOverride: null,
settledAt: null,
deletedAt: null,
updatedAt: "2026-03-09T10:00:00.000Z",
latestTurn: null,
-2
View File
@@ -30,8 +30,6 @@ function makeThread(overrides: Partial<Thread> = {}): Thread {
createdAt: "2026-02-13T00:00:00.000Z",
updatedAt: "2026-02-13T00:00:00.000Z",
archivedAt: null,
settledOverride: null,
settledAt: null,
deletedAt: null,
latestTurn: null,
branch: null,