fix: make thread auto-settling opt-in (#8321)

This commit is contained in:
shivam authored and GitHub committed 2026-08-29 03:58:48 +05:30
1 parent cb49e5d720
commit 0bbecfabf1
25 files changed
+569 -232

No files matched your search

@@ -39,7 +39,7 @@ const clientSettings: ClientSettings = {
showSkillsInSlashMenu: false,
providerModelPreferences: {},
sidebarAutoSettleAfterDays: 3,
sidebarAutoSettleOnMerge: true,
sidebarAutoSettleMode: "change-request",
sidebarProjectGroupingMode: "repository_path",
sidebarProjectGroupingOverrides: {
"environment-1:/tmp/project-a": "separate",
+8
View File
@@ -51,6 +51,7 @@ import {
import { NewTaskFlowProvider } from "./features/threads/new-task-flow-provider";
import { NewTaskRouteScreen } from "./features/threads/NewTaskRouteScreen";
import { SettingsAppearanceRouteScreen } from "./features/settings/SettingsAppearanceRouteScreen";
import { SettingsAutoSettleRouteScreen } from "./features/settings/SettingsAutoSettleRouteScreen";
import { SettingsClientStorageRouteScreen } from "./features/settings/SettingsClientStorageRouteScreen";
import { SettingsAuthRouteScreen } from "./features/settings/SettingsAuthRouteScreen";
import { SettingsEnvironmentsRouteScreen } from "./features/settings/SettingsEnvironmentsRouteScreen";
@@ -177,6 +178,13 @@ const SettingsContentStack = createNativeStackNavigator({
title: "Appearance",
},
}),
SettingsAutoSettle: createNativeStackScreen({
screen: SettingsAutoSettleRouteScreen,
linking: "thread-settling",
options: {
title: "Thread Settling",
},
}),
SettingsProjectGrouping: createNativeStackScreen({
screen: SettingsProjectGroupingRouteScreen,
linking: "project-grouping",
+8 -5
View File
@@ -30,6 +30,7 @@ import type { WorkspaceEnvironment, WorkspaceState } from "../../state/workspace
import type { SavedRemoteConnection } from "../../lib/connection";
import { scopedProjectKey } from "../../lib/scopedEntities";
import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
import { resolveMobileAutoSettlePreferences } from "../../persistence/mobile-preferences";
import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
import { useThreadSearch } from "../../state/queries";
import { useThreadListV2Enabled } from "../threads/use-thread-list-v2-enabled";
@@ -208,9 +209,9 @@ export function HomeScreen(props: HomeScreenProps) {
>(() => new Map());
const preferencesResult = useAtomValue(mobilePreferencesAtom);
const threadListV2Enabled = useThreadListV2Enabled();
const autoSettleOnMerge =
!AsyncResult.isSuccess(preferencesResult) ||
preferencesResult.value.autoSettleOnMerge !== false;
const autoSettlePreferences = resolveMobileAutoSettlePreferences(
AsyncResult.isSuccess(preferencesResult) ? preferencesResult.value : {},
);
const savePreferences = useAtomSet(updateMobilePreferencesAtom);
const openSwipeableRef = useRef<SwipeableMethods | null>(null);
const listRef = useRef<LegendListRef | null>(null);
@@ -678,7 +679,8 @@ export function HomeScreen(props: HomeScreenProps) {
searchQuery: props.searchQuery,
matchedThreadKeys,
changeRequestByKey,
autoSettleOnMerge,
autoSettleAfterDays: autoSettlePreferences.autoSettleAfterDays,
autoSettleMode: autoSettlePreferences.autoSettleMode,
settlementEnvironmentIds,
snoozeEnvironmentIds,
settledLimit: settledVisibleCount,
@@ -690,7 +692,8 @@ export function HomeScreen(props: HomeScreenProps) {
});
}, [
changeRequestByKey,
autoSettleOnMerge,
autoSettlePreferences.autoSettleAfterDays,
autoSettlePreferences.autoSettleMode,
nowMinute,
snoozeWakeTick,
snoozedShelfExpanded,
@@ -0,0 +1,173 @@
import { useAtomSet, useAtomValue } from "@effect/atom-react";
import { useNavigation } from "@react-navigation/native";
import {
MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
type SidebarAutoSettleMode,
} from "@t3tools/contracts";
import { AsyncResult } from "effect/unstable/reactivity";
import { Platform, Pressable, ScrollView, View } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { AndroidScreenHeader } from "../../components/AndroidScreenHeader";
import { AppText as Text } from "../../components/AppText";
import { SymbolView } from "../../components/AppSymbol";
import { useUniwindTheme } from "../../lib/useUniwindTheme";
import { NativeStackScreenOptions } from "../../native/StackHeader";
import { resolveMobileAutoSettlePreferences } from "../../persistence/mobile-preferences";
import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
import { SettingsSection } from "./components/SettingsSection";
const AUTO_SETTLE_OPTIONS: ReadonlyArray<{
readonly mode: SidebarAutoSettleMode;
readonly label: string;
readonly description: string;
}> = [
{
mode: "never",
label: "Never",
description: "Threads settle only when you choose Settle.",
},
{
mode: "change-request",
label: "When a pull request merges or closes",
description: "A missing or uncertain pull-request timestamp keeps the thread active.",
},
{
mode: "inactivity",
label: "After inactivity",
description: "Running, blocked, and open-pull-request threads stay active.",
},
];
export function mobileAutoSettleModeLabel(mode: SidebarAutoSettleMode): string {
if (mode === "change-request") return "PR merged or closed";
if (mode === "inactivity") return "After inactivity";
return "Never";
}
export function SettingsAutoSettleRouteScreen() {
const navigation = useNavigation();
const insets = useSafeAreaInsets();
const checkmarkColor = useUniwindTheme()["--color-icon"];
const preferencesResult = useAtomValue(mobilePreferencesAtom);
const savePreferences = useAtomSet(updateMobilePreferencesAtom);
const preferencesReady = AsyncResult.isSuccess(preferencesResult) && !preferencesResult.waiting;
const resolved = resolveMobileAutoSettlePreferences(
AsyncResult.isSuccess(preferencesResult) ? preferencesResult.value : {},
);
const setDays = (days: number) => {
if (!preferencesReady) return;
savePreferences({
autoSettleAfterDays: Math.min(
MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
Math.max(MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS, days),
),
});
};
return (
<View collapsable={false} className="flex-1 bg-sheet">
{Platform.OS === "android" ? (
<>
<NativeStackScreenOptions options={{ headerShown: false }} />
<AndroidScreenHeader title="Thread Settling" onBack={() => navigation.goBack()} />
</>
) : null}
<ScrollView
contentInsetAdjustmentBehavior="automatic"
showsVerticalScrollIndicator={false}
className="flex-1"
contentContainerClassName="gap-4 px-5 pt-4"
contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }}
>
<SettingsSection title="Automatic settling">
{AUTO_SETTLE_OPTIONS.map((option, index) => (
<Pressable
key={option.mode}
accessibilityRole="radio"
accessibilityState={{
checked: resolved.autoSettleMode === option.mode,
disabled: !preferencesReady,
}}
disabled={!preferencesReady}
onPress={() => savePreferences({ autoSettleMode: option.mode })}
className={
index === 0
? "flex-row items-center gap-4 p-4"
: "flex-row items-center gap-4 border-t border-border-subtle p-4"
}
>
<View className="min-w-0 flex-1 gap-1">
<Text className="text-lg text-foreground">{option.label}</Text>
<Text className="text-sm leading-normal text-foreground-muted">
{option.description}
</Text>
</View>
{resolved.autoSettleMode === option.mode ? (
<SymbolView
name="checkmark"
size={18}
tintColor={checkmarkColor}
type="monochrome"
weight="semibold"
/>
) : null}
</Pressable>
))}
</SettingsSection>
{resolved.autoSettleMode === "inactivity" ? (
<SettingsSection title="Inactivity window">
<View className="flex-row items-center gap-4 p-4">
<View className="min-w-0 flex-1 gap-1">
<Text className="text-lg text-foreground">Days without activity</Text>
<Text className="text-sm text-foreground-muted">Between 1 and 90 days</Text>
</View>
<Pressable
accessibilityLabel="Decrease inactivity days"
accessibilityRole="button"
disabled={
!preferencesReady ||
resolved.autoSettleAfterDays <= MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS
}
onPress={() => setDays(resolved.autoSettleAfterDays - 1)}
className="size-10 items-center justify-center rounded-full bg-fill-secondary disabled:opacity-40"
>
<SymbolView
name="minus"
size={16}
tintColor={checkmarkColor}
type="monochrome"
weight="semibold"
/>
</Pressable>
<Text className="w-8 text-center text-lg text-foreground">
{resolved.autoSettleAfterDays}
</Text>
<Pressable
accessibilityLabel="Increase inactivity days"
accessibilityRole="button"
disabled={
!preferencesReady ||
resolved.autoSettleAfterDays >= MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS
}
onPress={() => setDays(resolved.autoSettleAfterDays + 1)}
className="size-10 items-center justify-center rounded-full bg-fill-secondary disabled:opacity-40"
>
<SymbolView
name="plus"
size={16}
tintColor={checkmarkColor}
type="monochrome"
weight="semibold"
/>
</Pressable>
</View>
</SettingsSection>
) : null}
</ScrollView>
</View>
);
}
@@ -4,6 +4,7 @@ import Constants from "expo-constants";
import * as Notifications from "expo-notifications";
import { useNavigation } from "@react-navigation/native";
import { NativeStackScreenOptions } from "../../native/StackHeader";
import { resolveMobileAutoSettlePreferences } from "../../persistence/mobile-preferences";
import { SymbolView } from "../../components/AppSymbol";
import * as Effect from "effect/Effect";
import { AsyncResult } from "effect/unstable/reactivity";
@@ -45,6 +46,7 @@ import { useSavedRemoteConnections } from "../../state/use-remote-environment-re
import { SettingsRow } from "./components/SettingsRow";
import { SettingsSection } from "./components/SettingsSection";
import { SettingsSwitchRow } from "./components/SettingsSwitchRow";
import { mobileAutoSettleModeLabel } from "./SettingsAutoSettleRouteScreen";
import { resolveAgentAwarenessPlatformPresentation } from "./SettingsRouteScreen.logic";
type NotificationStatus = "checking" | "enabled" | "disabled" | "unsupported";
@@ -528,19 +530,18 @@ function ConfiguredSettingsRouteScreen() {
function GeneralSettingsSection() {
const preferencesResult = useAtomValue(mobilePreferencesAtom);
const savePreferences = useAtomSet(updateMobilePreferencesAtom);
const autoSettleOnMerge =
!AsyncResult.isSuccess(preferencesResult) ||
preferencesResult.value.autoSettleOnMerge !== false;
const autoSettlePreferences = resolveMobileAutoSettlePreferences(
AsyncResult.isSuccess(preferencesResult) ? preferencesResult.value : {},
);
return (
<SettingsSection title="General">
<SettingsRow icon="folder" label="Project Grouping" target="SettingsProjectGrouping" />
<SettingsSwitchRow
<SettingsRow
icon="arrow.triangle.branch"
label="Auto-settle merged threads"
value={autoSettleOnMerge}
onValueChange={(value) => savePreferences({ autoSettleOnMerge: value })}
label="Thread Settling"
value={mobileAutoSettleModeLabel(autoSettlePreferences.autoSettleMode)}
target="SettingsAutoSettle"
/>
<SettingsRow icon="chart.bar.xaxis" label="Usage" target="SettingsUsage" />
</SettingsSection>
@@ -2,6 +2,7 @@ export type SettingsSheetTarget =
| "SettingsEnvironments"
| "SettingsArchive"
| "SettingsAppearance"
| "SettingsAutoSettle"
| "SettingsProjectGrouping"
| "SettingsClientStorage"
| "SettingsUsage";
@@ -26,6 +26,7 @@ import { ControlPillMenu } from "../../components/ControlPill";
import { SymbolView } from "../../components/AppSymbol";
import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
import { NativeStackScreenOptions } from "../../native/StackHeader";
import { resolveMobileAutoSettlePreferences } from "../../persistence/mobile-preferences";
import { scopedProjectKey, scopedThreadKey } from "../../lib/scopedEntities";
import { useProjects, useThreadShells } from "../../state/entities";
import { mobilePreferencesAtom } from "../../state/preferences";
@@ -165,9 +166,9 @@ function ThreadNavigationSidebarPane(
} = useThreadListActions();
const threadListV2Enabled = useThreadListV2Enabled();
const preferencesResult = useAtomValue(mobilePreferencesAtom);
const autoSettleOnMerge =
!AsyncResult.isSuccess(preferencesResult) ||
preferencesResult.value.autoSettleOnMerge !== false;
const autoSettlePreferences = resolveMobileAutoSettlePreferences(
AsyncResult.isSuccess(preferencesResult) ? preferencesResult.value : {},
);
const pendingTasks = usePendingNewTasks();
const { openPendingTask, confirmDeletePendingTask } = usePendingTaskListActions();
const environments = useMemo(
@@ -510,7 +511,8 @@ function ThreadNavigationSidebarPane(
searchQuery: props.searchQuery,
matchedThreadKeys,
changeRequestByKey,
autoSettleOnMerge,
autoSettleAfterDays: autoSettlePreferences.autoSettleAfterDays,
autoSettleMode: autoSettlePreferences.autoSettleMode,
settlementEnvironmentIds,
snoozeEnvironmentIds,
settledLimit: settledVisibleCount,
@@ -522,7 +524,8 @@ function ThreadNavigationSidebarPane(
});
}, [
changeRequestByKey,
autoSettleOnMerge,
autoSettlePreferences.autoSettleAfterDays,
autoSettlePreferences.autoSettleMode,
nowMinute,
snoozeWakeTick,
snoozedShelfExpanded,
@@ -360,10 +360,12 @@ describe("buildThreadListV2Items", () => {
`${environmentId}:${thread.id}`,
{
state: "merged" as const,
updatedAt: NOW,
linkedPullRequestKey: '["project-1","pingdotgg/t3code",42]',
},
],
]),
autoSettleMode: "change-request",
now: NOW,
});
@@ -371,16 +373,16 @@ describe("buildThreadListV2Items", () => {
expect(layout.items[0]?.variant).toBe("slim");
});
it("keeps a merged thread active when auto-settle on merge is off", () => {
it("keeps a merged thread active when automatic settling is off", () => {
const merged = makeThread({ id: ThreadId.make("merged"), title: "Merged" });
const layout = buildThreadListV2Items({
threads: [merged],
environmentId: null,
searchQuery: "",
changeRequestByKey: new Map([
[`${environmentId}:${merged.id}`, { state: "merged" as const }],
[`${environmentId}:${merged.id}`, { state: "merged" as const, updatedAt: NOW }],
]),
autoSettleOnMerge: false,
autoSettleMode: "never",
now: NOW,
});
@@ -449,7 +451,10 @@ describe("buildThreadListV2Items", () => {
threads: [makeThread({ id: ThreadId.make("active"), title: "Active" }), merged],
environmentId: null,
searchQuery: "",
changeRequestByKey: new Map([[`${environmentId}:${merged.id}`, { state: "merged" }]]),
changeRequestByKey: new Map([
[`${environmentId}:${merged.id}`, { state: "merged", updatedAt: NOW }],
]),
autoSettleMode: "change-request",
now: NOW,
});
@@ -478,6 +483,7 @@ describe("buildThreadListV2Items", () => {
threads: [inactive],
environmentId: null,
searchQuery: "",
autoSettleMode: "inactivity",
now: NOW,
});
@@ -489,7 +495,7 @@ describe("buildThreadListV2Items", () => {
expect(layout.settledCount).toBe(1);
});
it("keeps pinned merged threads pinned when auto-settle on merge is off", () => {
it("keeps pinned merged threads pinned when automatic settling is off", () => {
const merged = makeThread({
id: ThreadId.make("pinned-merged"),
title: "Pinned merged pull request",
@@ -499,8 +505,10 @@ describe("buildThreadListV2Items", () => {
threads: [merged],
environmentId: null,
searchQuery: "",
changeRequestByKey: new Map([[`${environmentId}:${merged.id}`, { state: "merged" }]]),
autoSettleOnMerge: false,
changeRequestByKey: new Map([
[`${environmentId}:${merged.id}`, { state: "merged", updatedAt: NOW }],
]),
autoSettleMode: "never",
now: NOW,
});
@@ -16,7 +16,12 @@ import {
activeThreadAnchorTimestampMs,
sortPinnedThreadsByOrderKey,
} from "@t3tools/client-runtime/state/thread-sort";
import type { EnvironmentId, ProjectId, ThreadLinkedPullRequest } from "@t3tools/contracts";
import type {
EnvironmentId,
ProjectId,
SidebarAutoSettleMode,
ThreadLinkedPullRequest,
} from "@t3tools/contracts";
import type { PendingNewTask } from "../../state/use-pending-new-tasks";
@@ -369,7 +374,7 @@ export function buildThreadListV2Items(input: {
contract as settlementEnvironmentIds. */
readonly snoozeEnvironmentIds?: ReadonlySet<EnvironmentId>;
readonly autoSettleAfterDays?: number;
readonly autoSettleOnMerge?: boolean;
readonly autoSettleMode?: SidebarAutoSettleMode;
/** Max settled rows to render; the rest are counted, not built. */
readonly settledLimit?: number;
/** Injectable for tests; defaults to now. */
@@ -390,7 +395,7 @@ export function buildThreadListV2Items(input: {
const now = input.now ?? new Date().toISOString();
const snoozeNow = input.snoozeNow ?? now;
const autoSettleAfterDays = input.autoSettleAfterDays ?? 3;
const autoSettleOnMerge = input.autoSettleOnMerge ?? true;
const autoSettleMode = input.autoSettleMode ?? "never";
const query = input.searchQuery.trim().toLocaleLowerCase();
const projectKeys = input.projectRefs
? new Set(input.projectRefs.map((ref) => `${ref.environmentId}:${ref.projectId}`))
@@ -447,7 +452,7 @@ export function buildThreadListV2Items(input: {
effectiveSettled(thread, {
now,
autoSettleAfterDays,
autoSettleOnMerge,
autoSettleMode,
changeRequest,
})
) {
+29
View File
@@ -100,6 +100,7 @@ import {
saveConnection,
savePreferencesPatch,
} from "../persistence/imperative";
import { resolveMobileAutoSettlePreferences } from "../persistence/mobile-preferences";
import { toStableSavedRemoteConnection } from "./connection";
const managedConnection = {
@@ -202,6 +203,34 @@ describe("mobile connection storage", () => {
await expect(loadPreferences()).resolves.toEqual({});
});
it("defaults retired mobile settling preferences to manual-only", async () => {
mocks.setPreferencesJson(JSON.stringify({ autoSettleOnMerge: true }), 10);
const preferences = await loadPreferences();
expect(preferences).toEqual({});
expect(resolveMobileAutoSettlePreferences(preferences)).toEqual({
autoSettleMode: "never",
autoSettleAfterDays: 3,
});
});
it("preserves valid mobile settling preferences", async () => {
mocks.setPreferencesJson(
JSON.stringify({ autoSettleMode: "inactivity", autoSettleAfterDays: 30 }),
10,
);
const preferences = await loadPreferences();
expect(preferences).toEqual({
autoSettleMode: "inactivity",
autoSettleAfterDays: 30,
});
expect(resolveMobileAutoSettlePreferences(preferences)).toEqual({
autoSettleMode: "inactivity",
autoSettleAfterDays: 30,
});
});
it("falls back to secure storage when SQLite cannot save preferences", async () => {
mocks.setDatabaseFailures(true, true);
await expect(savePreferencesPatch({ baseFontSize: 19 })).resolves.toEqual({ baseFontSize: 19 });
@@ -5,7 +5,15 @@ import * as Option from "effect/Option";
import * as Ref from "effect/Ref";
import * as Schema from "effect/Schema";
import * as Semaphore from "effect/Semaphore";
import type { SidebarProjectGroupingMode } from "@t3tools/contracts";
import {
DEFAULT_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
DEFAULT_SIDEBAR_AUTO_SETTLE_MODE,
MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
type SidebarAutoSettleAfterDays,
type SidebarAutoSettleMode,
type SidebarProjectGroupingMode,
} from "@t3tools/contracts";
import { MOBILE_THEME_IDS, type MobileThemeId, type MobileThemeMode } from "../lib/mobileTheme";
import * as MobileDatabase from "./mobile-database";
@@ -31,7 +39,8 @@ export interface Preferences {
/** @deprecated Kept temporarily so older OTA bundles retain the selected mode. */
readonly projectGroupingEnabled?: boolean;
readonly projectGroupingMode?: SidebarProjectGroupingMode;
readonly autoSettleOnMerge?: boolean;
readonly autoSettleMode?: SidebarAutoSettleMode;
readonly autoSettleAfterDays?: SidebarAutoSettleAfterDays;
/**
* Device-local mirror of the web `legacySidebarEnabled` setting. Mobile has
* no client-settings sync, so the legacy grouped thread list is opted into
@@ -101,7 +110,8 @@ function sanitizePreferences(parsed: Preferences): Preferences {
collapsedProjectGroups?: readonly string[];
projectGroupingEnabled?: boolean;
projectGroupingMode?: SidebarProjectGroupingMode;
autoSettleOnMerge?: boolean;
autoSettleMode?: SidebarAutoSettleMode;
autoSettleAfterDays?: SidebarAutoSettleAfterDays;
legacyThreadListEnabled?: boolean;
planModeEnabled?: boolean;
threadListV2SettledShelfExpanded?: boolean;
@@ -167,8 +177,20 @@ function sanitizePreferences(parsed: Preferences): Preferences {
) {
preferences.projectGroupingMode = parsed.projectGroupingMode;
}
if (typeof parsed.autoSettleOnMerge === "boolean") {
preferences.autoSettleOnMerge = parsed.autoSettleOnMerge;
if (
parsed.autoSettleMode === "never" ||
parsed.autoSettleMode === "change-request" ||
parsed.autoSettleMode === "inactivity"
) {
preferences.autoSettleMode = parsed.autoSettleMode;
}
if (
typeof parsed.autoSettleAfterDays === "number" &&
Number.isInteger(parsed.autoSettleAfterDays) &&
parsed.autoSettleAfterDays >= MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS &&
parsed.autoSettleAfterDays <= MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS
) {
preferences.autoSettleAfterDays = parsed.autoSettleAfterDays;
}
if (typeof parsed.legacyThreadListEnabled === "boolean") {
preferences.legacyThreadListEnabled = parsed.legacyThreadListEnabled;
@@ -185,6 +207,16 @@ function sanitizePreferences(parsed: Preferences): Preferences {
return preferences;
}
export function resolveMobileAutoSettlePreferences(preferences: Preferences): {
readonly autoSettleMode: SidebarAutoSettleMode;
readonly autoSettleAfterDays: SidebarAutoSettleAfterDays;
} {
return {
autoSettleMode: preferences.autoSettleMode ?? DEFAULT_SIDEBAR_AUTO_SETTLE_MODE,
autoSettleAfterDays: preferences.autoSettleAfterDays ?? DEFAULT_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
};
}
export const make = Effect.fn("MobilePreferencesStore.make")(function* () {
const database = yield* MobileDatabase.MobileDatabase;
const secureStorage = yield* MobileSecureStorage.MobileSecureStorage;
+6 -8
View File
@@ -4394,7 +4394,7 @@ function ChatViewContent(props: ChatViewProps) {
? activePlan.steps
: null;
const autoSettleAfterDays = useClientSettings((settings) => settings.sidebarAutoSettleAfterDays);
const autoSettleOnMerge = useClientSettings((settings) => settings.sidebarAutoSettleOnMerge);
const autoSettleMode = useClientSettings((settings) => settings.sidebarAutoSettleMode);
const linkedPullRequestStatus = useLinkedThreadPullRequest(
activeThreadRef?.environmentId ?? null,
linkedThreadPullRequest,
@@ -4465,10 +4465,8 @@ function ChatViewContent(props: ChatViewProps) {
const activeThreadWokeVisible = useMemo(() => {
if (activeThreadWokeAt === null) return false;
if (
changeRequestAutoSettles(activeThreadChangeRequest, {
autoSettleOnMerge,
thread: activeThreadShell,
})
autoSettleMode === "change-request" &&
changeRequestAutoSettles(activeThreadChangeRequest, { thread: activeThreadShell })
) {
return false;
}
@@ -4494,21 +4492,21 @@ function ChatViewContent(props: ChatViewProps) {
activeThreadChangeRequest,
activeThreadShell,
activeThreadWokeAt,
autoSettleOnMerge,
autoSettleMode,
]);
const activeThreadSettled = useMemo(() => {
if (activeThreadShell === null || !supportsSettlement) return false;
return effectiveSettled(activeThreadShell, {
now: `${nowMinute}:00.000Z`,
autoSettleAfterDays,
autoSettleOnMerge,
autoSettleMode,
changeRequest: activeThreadChangeRequest,
});
}, [
activeThreadChangeRequest,
activeThreadShell,
autoSettleAfterDays,
autoSettleOnMerge,
autoSettleMode,
changeRequestSnapshotByKey,
nowMinute,
supportsSettlement,
+7 -10
View File
@@ -31,7 +31,7 @@ import {
scopedThreadKey,
} from "@t3tools/client-runtime/environment";
import type { ScopedThreadRef, ThreadId } from "@t3tools/contracts";
import type { TimestampFormat } from "@t3tools/contracts/settings";
import type { SidebarAutoSettleMode, TimestampFormat } from "@t3tools/contracts/settings";
import {
AlarmClockIcon,
AlarmClockOffIcon,
@@ -714,7 +714,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
// False on environments whose server predates thread.settle/unsettle:
// the lifecycle affordances hide entirely rather than fail on click.
settlementSupported: boolean;
autoSettleOnMerge: boolean;
autoSettleMode: SidebarAutoSettleMode;
// Same contract for thread.snooze/unsnooze.
snoozeSupported: boolean;
// Pinned threads show the same pin marker in active, settled, and snoozed
@@ -839,10 +839,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
const isWoke =
wokeAtDate !== null &&
(lastVisitedDate === null || lastVisitedDate < wokeAtDate) &&
!changeRequestAutoSettles(pr, {
autoSettleOnMerge: props.autoSettleOnMerge,
thread,
});
!(props.autoSettleMode === "change-request" && changeRequestAutoSettles(pr, { thread }));
// In-flight rows (working, or waiting on approval/input) fade as a whole:
// there is nothing for the user to do yet, so prominence is reserved for
// rows that need a human — done (unread), read-but-unsettled, failed, and
@@ -1740,7 +1737,7 @@ export default function Sidebar() {
const { isMobile, setOpenMobile } = useSidebar();
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
const autoSettleAfterDays = useClientSettings((s) => s.sidebarAutoSettleAfterDays);
const autoSettleOnMerge = useClientSettings((s) => s.sidebarAutoSettleOnMerge);
const autoSettleMode = useClientSettings((s) => s.sidebarAutoSettleMode);
const confirmThreadDelete = useClientSettings((s) => s.confirmThreadDelete);
const confirmThreadArchive = useClientSettings((s) => s.confirmThreadArchive);
const sidebarProjectSortOrder = useClientSettings((s) => s.sidebarProjectSortOrder);
@@ -2125,7 +2122,7 @@ export default function Sidebar() {
effectiveSettled(thread, {
now,
autoSettleAfterDays,
autoSettleOnMerge,
autoSettleMode,
changeRequest,
})
) {
@@ -2164,7 +2161,7 @@ export default function Sidebar() {
};
}, [
autoSettleAfterDays,
autoSettleOnMerge,
autoSettleMode,
changeRequestSnapshotByKey,
nowMinute,
scopedProjectKeys,
@@ -3787,7 +3784,7 @@ export default function Sidebar() {
serverConfigs.get(thread.environmentId)?.environment.capabilities
.threadSettlement === true
}
autoSettleOnMerge={autoSettleOnMerge}
autoSettleMode={autoSettleMode}
snoozeSupported={
serverConfigs.get(thread.environmentId)?.environment.capabilities
.threadSnooze === true
@@ -47,6 +47,7 @@ function mergedFeaturePr(): NonNullable<VcsStatusResult["pr"]> {
baseRef: "main",
headRef: "feature/current",
state: "merged",
updatedAt: "2026-04-10T00:00:00.000Z",
};
}
@@ -545,6 +546,7 @@ describe("resolveDisplayedThreadPr + nextThreadChangeRequestSnapshot", () => {
effectiveSettled(shell, {
now: "2026-04-10T00:00:00.000Z",
autoSettleAfterDays: null,
autoSettleMode: "change-request",
changeRequest: displayed,
}),
).toBe(true);
@@ -14,9 +14,10 @@ import {
formatDiagnosticsDescription,
getChangedBrowserSettingLabels,
getChangedTypographySettingLabels,
isSamePreviewViewport,
hasChangedBackgroundActivitySettings,
hasChangedThreadSettlingSettings,
isProjectGroupingEnabled,
isSamePreviewViewport,
projectGroupingModeFromToggle,
resolveBackgroundActivityProfileOption,
} from "./SettingsPanels.logic";
@@ -152,6 +153,24 @@ describe("project grouping toggle", () => {
});
});
describe("thread settling settings restore", () => {
it("detects changes to the mode or the hidden inactivity window", () => {
expect(hasChangedThreadSettlingSettings(DEFAULT_UNIFIED_SETTINGS)).toBe(false);
expect(
hasChangedThreadSettlingSettings({
...DEFAULT_UNIFIED_SETTINGS,
sidebarAutoSettleMode: "inactivity",
}),
).toBe(true);
expect(
hasChangedThreadSettlingSettings({
...DEFAULT_UNIFIED_SETTINGS,
sidebarAutoSettleAfterDays: 30,
}),
).toBe(true);
});
});
describe("formatDiagnosticsDescription", () => {
it("collapses trace and metric URLs that share the same OTEL base path", () => {
expect(
@@ -31,6 +31,15 @@ export function projectGroupingModeFromToggle(
return lastEnabledMode === "repository_path" ? "repository_path" : "repository";
}
export function hasChangedThreadSettlingSettings(
settings: Pick<UnifiedSettings, "sidebarAutoSettleMode" | "sidebarAutoSettleAfterDays">,
): boolean {
return (
settings.sidebarAutoSettleMode !== DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleMode ||
settings.sidebarAutoSettleAfterDays !== DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleAfterDays
);
}
const LAST_ENABLED_PROJECT_GROUPING_MODE_KEY = "t3code:last-enabled-project-grouping-mode";
export function readLastEnabledProjectGroupingMode(): SidebarProjectGroupingMode {
@@ -8,6 +8,7 @@ import {
type DesktopUpdateChannel,
ProviderDriverKind,
type ScopedThreadRef,
type SidebarAutoSettleMode,
type SidebarProjectGroupingMode,
} from "@t3tools/contracts";
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
@@ -130,6 +131,7 @@ import {
normalizeIntervalSeconds,
PROVIDER_HEALTH_INTERVAL_STEP_SECONDS,
hasChangedBackgroundActivitySettings,
hasChangedThreadSettlingSettings,
isProjectGroupingEnabled,
projectGroupingModeFromToggle,
readLastEnabledProjectGroupingMode,
@@ -471,6 +473,7 @@ export function useSettingsRestore(onRestored?: () => void) {
DEFAULT_UNIFIED_SETTINGS.textGenerationModelSelection ?? null,
);
const isBackgroundActivityDirty = hasChangedBackgroundActivitySettings(settings);
const isThreadSettlingDirty = hasChangedThreadSettlingSettings(settings);
const changedSettingLabels = useMemo(
() => [
@@ -495,13 +498,7 @@ export function useSettingsRestore(onRestored?: () => void) {
DEFAULT_UNIFIED_SETTINGS.sidebarProjectGroupingMode
? ["Project Grouping"]
: []),
...(settings.sidebarAutoSettleAfterDays !==
DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleAfterDays
? ["Auto-settle inactive threads"]
: []),
...(settings.sidebarAutoSettleOnMerge !== DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleOnMerge
? ["Auto-settle merged threads"]
: []),
...(isThreadSettlingDirty ? ["Thread settling"] : []),
...(settings.wordWrap !== DEFAULT_UNIFIED_SETTINGS.wordWrap ? ["Word wrap"] : []),
...getChangedTypographySettingLabels(settings),
...(settings.diffIgnoreWhitespace !== DEFAULT_UNIFIED_SETTINGS.diffIgnoreWhitespace
@@ -547,6 +544,7 @@ export function useSettingsRestore(onRestored?: () => void) {
[
isTextGenerationModelDirty,
isBackgroundActivityDirty,
isThreadSettlingDirty,
settings.browserDefaultViewport,
settings.browserDefaultZoomFactor,
settings.browserDefaultAppearance,
@@ -572,8 +570,6 @@ export function useSettingsRestore(onRestored?: () => void) {
settings.glassOpacity,
settings.enableLegacyTokenStreaming,
settings.enableProviderUpdateChecks,
settings.sidebarAutoSettleAfterDays,
settings.sidebarAutoSettleOnMerge,
settings.sidebarProjectGroupingMode,
settings.sidebarThreadPreviewCount,
settings.showSkillsInSlashMenu,
@@ -658,7 +654,7 @@ export function useSettingsRestore(onRestored?: () => void) {
sidebarThreadPreviewCount: DEFAULT_UNIFIED_SETTINGS.sidebarThreadPreviewCount,
sidebarProjectGroupingMode: DEFAULT_UNIFIED_SETTINGS.sidebarProjectGroupingMode,
sidebarAutoSettleAfterDays: DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleAfterDays,
sidebarAutoSettleOnMerge: DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleOnMerge,
sidebarAutoSettleMode: DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleMode,
enableLegacyTokenStreaming: DEFAULT_UNIFIED_SETTINGS.enableLegacyTokenStreaming,
enableProviderUpdateChecks: DEFAULT_UNIFIED_SETTINGS.enableProviderUpdateChecks,
backgroundActivity: DEFAULT_UNIFIED_SETTINGS.backgroundActivity,
@@ -1685,6 +1681,11 @@ function FontFamilySettingsRow({
}
const AUTO_SETTLE_DEFAULT_DAYS = DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleAfterDays ?? 3;
const AUTO_SETTLE_MODE_LABELS: Readonly<Record<SidebarAutoSettleMode, string>> = {
never: "Never (manual only)",
"change-request": "When PR merges or closes",
inactivity: "After inactivity",
};
function AutoSettleDaysInput({
value,
@@ -1946,42 +1947,15 @@ export function GeneralSettingsPanel() {
/>
<SettingsRow
{...searchableSetting("auto-settle-merged-threads")}
description="Settle a thread when its pull request merges. Closed pull requests still settle automatically."
{...searchableSetting("thread-settling")}
description="Choose the only event allowed to settle a thread automatically. Manual settling always remains available."
resetAction={
settings.sidebarAutoSettleOnMerge !==
DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleOnMerge ? (
hasChangedThreadSettlingSettings(settings) ? (
<SettingResetButton
label="auto-settle on merge"
onClick={() =>
updateSettings({
sidebarAutoSettleOnMerge: DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleOnMerge,
})
}
/>
) : null
}
control={
<Switch
checked={settings.sidebarAutoSettleOnMerge}
onCheckedChange={(checked) =>
updateSettings({ sidebarAutoSettleOnMerge: Boolean(checked) })
}
aria-label="Auto-settle merged threads"
/>
}
/>
<SettingsRow
{...searchableSetting("auto-settle-inactive-threads")}
description="Sidebar threads with no activity for this long settle automatically."
resetAction={
settings.sidebarAutoSettleAfterDays !==
DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleAfterDays ? (
<SettingResetButton
label="auto-settle"
label="thread settling"
onClick={() =>
updateSettings({
sidebarAutoSettleMode: DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleMode,
sidebarAutoSettleAfterDays: DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleAfterDays,
})
}
@@ -1989,24 +1963,43 @@ export function GeneralSettingsPanel() {
) : null
}
control={
<Switch
checked={settings.sidebarAutoSettleAfterDays !== null}
onCheckedChange={(checked) =>
updateSettings({
sidebarAutoSettleAfterDays: checked ? AUTO_SETTLE_DEFAULT_DAYS : null,
})
}
aria-label="Auto-settle inactive threads"
/>
<Select
value={settings.sidebarAutoSettleMode}
onValueChange={(value) => {
if (value === "never" || value === "change-request" || value === "inactivity") {
updateSettings({
sidebarAutoSettleMode: value,
...(value === "inactivity" && settings.sidebarAutoSettleAfterDays === null
? { sidebarAutoSettleAfterDays: AUTO_SETTLE_DEFAULT_DAYS }
: {}),
});
}
}}
>
<SelectTrigger className="w-full sm:w-64" aria-label="Thread settling">
<SelectValue>{AUTO_SETTLE_MODE_LABELS[settings.sidebarAutoSettleMode]}</SelectValue>
</SelectTrigger>
<SelectPopup align="end" alignItemWithTrigger={false}>
<SelectItem hideIndicator value="never">
{AUTO_SETTLE_MODE_LABELS.never}
</SelectItem>
<SelectItem hideIndicator value="change-request">
{AUTO_SETTLE_MODE_LABELS["change-request"]}
</SelectItem>
<SelectItem hideIndicator value="inactivity">
{AUTO_SETTLE_MODE_LABELS.inactivity}
</SelectItem>
</SelectPopup>
</Select>
}
/>
{settings.sidebarAutoSettleAfterDays !== null ? (
{settings.sidebarAutoSettleMode === "inactivity" ? (
<SettingsRow
title="Days of inactivity before auto-settle"
description="Any new activity un-settles a thread automatically."
description="Running, blocked, and open-pull-request threads always stay active."
control={
<AutoSettleDaysInput
value={settings.sidebarAutoSettleAfterDays}
value={settings.sidebarAutoSettleAfterDays ?? AUTO_SETTLE_DEFAULT_DAYS}
onCommit={(days) => updateSettings({ sidebarAutoSettleAfterDays: days })}
/>
}
@@ -112,13 +112,8 @@ export const SETTINGS_SEARCH_ITEMS = [
to: "/settings/general",
},
{
id: "auto-settle-inactive-threads",
title: "Auto-settle inactive threads",
to: "/settings/general",
},
{
id: "auto-settle-merged-threads",
title: "Auto-settle merged threads",
id: "thread-settling",
title: "Thread settling",
to: "/settings/general",
},
{
+3 -3
View File
@@ -81,7 +81,7 @@ export function useThreadActionMenu(input: {
const handleNewThread = useNewThreadHandler();
const markThreadUnread = useUiStateStore((s) => s.markThreadUnread);
const autoSettleAfterDays = useClientSettings((s) => s.sidebarAutoSettleAfterDays);
const autoSettleOnMerge = useClientSettings((s) => s.sidebarAutoSettleOnMerge);
const autoSettleMode = useClientSettings((s) => s.sidebarAutoSettleMode);
const confirmThreadDelete = useClientSettings((s) => s.confirmThreadDelete);
const confirmThreadArchive = useClientSettings((s) => s.confirmThreadArchive);
const timestampFormat = useClientSettings((s) => s.timestampFormat);
@@ -135,7 +135,7 @@ export function useThreadActionMenu(input: {
// parked-thread banner within the same minute.
now: `${now.toISOString().slice(0, 16)}:00.000Z`,
autoSettleAfterDays,
autoSettleOnMerge,
autoSettleMode,
changeRequest,
}),
isSnoozed: supports.snooze && effectiveSnoozed(thread, { now: now.toISOString() }),
@@ -311,7 +311,7 @@ export function useThreadActionMenu(input: {
[
archiveThread,
autoSettleAfterDays,
autoSettleOnMerge,
autoSettleMode,
changeRequest,
confirmThreadArchive,
confirmThreadDelete,
+8 -4
View File
@@ -4,15 +4,19 @@ Pin a thread from its context menu to keep it in the pinned section above your a
`mod+shift+p` pins or unpins the thread you have open. Pinned threads are shown independently of
their project, including when you connect to more than one environment.
Pinned threads still move to **Settled** when they become inactive. They also move when their pull
request merges if **Auto-settle merged threads** is enabled.
Pinned threads follow the auto-settle policy in **Settings → General**. Choose exactly one policy:
settle when a pull request merges or closes, settle after a configurable period of inactivity, or
never auto-settle. **Never** leaves every automatic path off, so threads settle only when you choose
**Settle**.
When you un-settle a thread, it returns to the top of the active list so you can find it right
away. Its timestamps do not change. Other threads keep their positions.
Right-click a pull request link in a thread and choose **Link to thread** to show that pull request
in the sidebar. The thread settles when the linked pull request merges if **Auto-settle merged
threads** is enabled. Right-click the same link and choose **Unlink from thread** to remove it.
in the sidebar. The thread settles when the linked pull request merges or closes only when the
pull-request policy is selected. Right-click the same link and choose **Unlink from thread** to
remove it. If T3 Code cannot determine when a pull request entered its terminal state, it keeps the
thread active.
On web and desktop, drag a pinned thread to change its position. On mobile, open the thread's menu
and choose **Move up** or **Move down**. The order is stored by the server and appears on your
@@ -17,6 +17,7 @@ const THEME_INTEROP_ALLOWLIST = new Set([
"features/home/HomeHeader.tsx",
"features/review/ReviewSheet.tsx",
"features/review/useNativeReviewDiffBridge.ts",
"features/settings/SettingsAutoSettleRouteScreen.tsx",
"features/settings/SettingsEnvironmentsRouteScreen.tsx",
"features/settings/appearance/components/AppearancePreviews.tsx",
"features/settings/appearance/components/FontSizeSliderRow.tsx",
@@ -21,18 +21,6 @@ const FRESH = "2026-04-09T00:00:00.000Z";
const STALE = "2026-04-06T23:59:59.999Z";
describe("changeRequestAutoSettles", () => {
it.each([
["open", true, false],
["merged", true, true],
["merged", false, false],
["closed", false, true],
[null, false, false],
] as const)("state=%s autoSettleOnMerge=%s returns %s", (state, autoSettleOnMerge, expected) => {
expect(changeRequestAutoSettles(state === null ? null : { state }, { autoSettleOnMerge })).toBe(
expected,
);
});
const THREAD_CREATED_AT = "2026-04-01T00:00:00.000Z";
const idleThread = {
createdAt: THREAD_CREATED_AT,
@@ -40,6 +28,19 @@ describe("changeRequestAutoSettles", () => {
latestTurn: null,
};
it.each([
["open", false],
["merged", true],
["closed", true],
[null, false],
] as const)("state=%s returns %s", (state, expected) => {
expect(
changeRequestAutoSettles(state === null ? null : { state, updatedAt: THREAD_CREATED_AT }, {
thread: idleThread,
}),
).toBe(expected);
});
it("ignores a terminal change request last touched before the thread existed", () => {
for (const state of ["merged", "closed"] as const) {
expect(
@@ -105,20 +106,20 @@ describe("changeRequestAutoSettles", () => {
).toBe(true);
});
it("falls back to settling when either timestamp is missing or malformed", () => {
expect(changeRequestAutoSettles({ state: "merged" }, { thread: idleThread })).toBe(true);
it("keeps the thread active when either timestamp is missing or malformed", () => {
expect(changeRequestAutoSettles({ state: "merged" }, { thread: idleThread })).toBe(false);
expect(
changeRequestAutoSettles({ state: "merged", updatedAt: null }, { thread: idleThread }),
).toBe(true);
).toBe(false);
expect(
changeRequestAutoSettles({ state: "merged", updatedAt: "2026-03-01T00:00:00.000Z" }, {}),
).toBe(true);
).toBe(false);
expect(
changeRequestAutoSettles(
{ state: "merged", updatedAt: "not-a-date" },
{ thread: idleThread },
),
).toBe(true);
).toBe(false);
});
});
@@ -204,38 +205,47 @@ describe("effectiveSettled", () => {
] as const;
const runningCases = [false, true] as const;
const pendingCases = [undefined, "approval", "user-input"] as const;
const truthTable = overrideCases.flatMap((settledOverride) =>
changeRequestStates.flatMap((changeRequestState) =>
inactivityCases.flatMap(([inactivity, activityAt]) =>
runningCases.flatMap((running) =>
pendingCases.map((pending) => ({
settledOverride,
changeRequestState,
inactivity,
activityAt,
running,
pending,
// Settled iff nothing blocks (pending work / live session) AND
// the override says settled, or (with no override) a merged PR
// or staleness auto-settles. The "active" pin suppresses both
// auto signals, and an open PR suppresses the inactivity path:
// a thread with a PR out for review is never done, however quiet.
expected:
pending === undefined &&
!running &&
(settledOverride === "settled" ||
(settledOverride === null &&
(changeRequestState === "merged" ||
(changeRequestState !== "open" && inactivity === "stale")))),
})),
const autoSettleModes = ["never", "change-request", "inactivity"] as const;
const truthTable = autoSettleModes.flatMap((autoSettleMode) =>
overrideCases.flatMap((settledOverride) =>
changeRequestStates.flatMap((changeRequestState) =>
inactivityCases.flatMap(([inactivity, activityAt]) =>
runningCases.flatMap((running) =>
pendingCases.map((pending) => ({
autoSettleMode,
settledOverride,
changeRequestState,
inactivity,
activityAt,
running,
pending,
expected:
pending === undefined &&
!running &&
(settledOverride === "settled" ||
(settledOverride === null &&
((autoSettleMode === "change-request" && changeRequestState === "merged") ||
(autoSettleMode === "inactivity" &&
changeRequestState !== "open" &&
inactivity === "stale")))),
})),
),
),
),
),
);
it.each(truthTable)(
"override=$settledOverride pr=$changeRequestState inactivity=$inactivity running=$running pending=$pending",
({ settledOverride, changeRequestState, activityAt, running, pending, expected }) => {
"mode=$autoSettleMode override=$settledOverride pr=$changeRequestState inactivity=$inactivity running=$running pending=$pending",
({
autoSettleMode,
settledOverride,
changeRequestState,
activityAt,
running,
pending,
expected,
}) => {
const shell = makeShell({
settledOverride,
activityAt,
@@ -245,12 +255,18 @@ describe("effectiveSettled", () => {
const changeRequestOptions =
changeRequestState === undefined
? {}
: { changeRequest: { state: changeRequestState as ChangeRequestStateLike } };
: {
changeRequest: {
state: changeRequestState as ChangeRequestStateLike,
updatedAt: NOW,
},
};
expect(
effectiveSettled(shell, {
now: NOW,
autoSettleAfterDays: 3,
autoSettleMode,
...changeRequestOptions,
}),
).toBe(expected);
@@ -263,7 +279,8 @@ describe("effectiveSettled", () => {
effectiveSettled(shell, {
now: NOW,
autoSettleAfterDays: null,
changeRequest: { state: "closed" },
autoSettleMode: "change-request",
changeRequest: { state: "closed", updatedAt: NOW },
}),
).toBe(true);
});
@@ -275,7 +292,8 @@ describe("effectiveSettled", () => {
effectiveSettled(recentlyActive, {
now: NOW,
autoSettleAfterDays: null,
changeRequest: { state: changeRequestState },
autoSettleMode: "change-request",
changeRequest: { state: changeRequestState, updatedAt: NOW },
}),
).toBe(true);
}
@@ -291,6 +309,7 @@ describe("effectiveSettled", () => {
effectiveSettled(fresh, {
now: NOW,
autoSettleAfterDays: null,
autoSettleMode: "change-request",
changeRequest: { state, updatedAt: "2026-03-20T00:00:00.000Z" },
}),
).toBe(false);
@@ -300,30 +319,24 @@ describe("effectiveSettled", () => {
effectiveSettled(fresh, {
now: NOW,
autoSettleAfterDays: null,
autoSettleMode: "change-request",
changeRequest: { state: "merged", updatedAt: "2026-04-09T00:00:00.000Z" },
}),
).toBe(true);
});
it("can keep a merged change request active", () => {
it("keeps a merged change request active in every other mode", () => {
const recentlyActive = makeShell({ activityAt: "2026-04-09T23:59:59.999Z" });
expect(
effectiveSettled(recentlyActive, {
now: NOW,
autoSettleAfterDays: null,
autoSettleOnMerge: false,
changeRequest: { state: "merged" },
}),
).toBe(false);
expect(
effectiveSettled(recentlyActive, {
now: NOW,
autoSettleAfterDays: null,
autoSettleOnMerge: false,
changeRequest: { state: "closed" },
}),
).toBe(true);
for (const autoSettleMode of ["never", "inactivity"] as const) {
expect(
effectiveSettled(recentlyActive, {
now: NOW,
autoSettleAfterDays: null,
autoSettleMode,
changeRequest: { state: "merged", updatedAt: NOW },
}),
).toBe(false);
}
});
it("never auto-settles a stale thread with an open change request", () => {
@@ -332,6 +345,7 @@ describe("effectiveSettled", () => {
effectiveSettled(stale, {
now: NOW,
autoSettleAfterDays: 3,
autoSettleMode: "inactivity",
changeRequest: { state: "open" },
}),
).toBe(false);
@@ -341,6 +355,7 @@ describe("effectiveSettled", () => {
effectiveSettled(settled, {
now: NOW,
autoSettleAfterDays: 3,
autoSettleMode: "inactivity",
changeRequest: { state: "open" },
}),
).toBe(true);
@@ -355,7 +370,8 @@ describe("effectiveSettled", () => {
effectiveSettled(shell, {
now: NOW,
autoSettleAfterDays: null,
changeRequest: { state: "merged" },
autoSettleMode: "change-request",
changeRequest: { state: "merged", updatedAt: NOW },
}),
).toBe(false);
});
@@ -370,7 +386,8 @@ describe("effectiveSettled", () => {
effectiveSettled(shell, {
now: NOW,
autoSettleAfterDays: 3,
changeRequest: { state: "merged" },
autoSettleMode: "change-request",
changeRequest: { state: "merged", updatedAt: NOW },
}),
).toBe(false);
});
@@ -414,7 +431,8 @@ describe("effectiveSettled", () => {
effectiveSettled(shell, {
now: transitionNow,
autoSettleAfterDays: 3,
changeRequest: { state: "merged" },
autoSettleMode: "change-request",
changeRequest: { state: "merged", updatedAt: transitionNow },
}),
).toBe(false);
}
@@ -426,8 +444,20 @@ describe("effectiveSettled", () => {
});
const stale = makeShell({ activityAt: STALE });
expect(effectiveSettled(boundary, { now: NOW, autoSettleAfterDays: 3 })).toBe(false);
expect(effectiveSettled(stale, { now: NOW, autoSettleAfterDays: null })).toBe(false);
expect(
effectiveSettled(boundary, {
now: NOW,
autoSettleAfterDays: 3,
autoSettleMode: "inactivity",
}),
).toBe(false);
expect(
effectiveSettled(stale, {
now: NOW,
autoSettleAfterDays: null,
autoSettleMode: "inactivity",
}),
).toBe(false);
});
});
@@ -532,7 +562,8 @@ describe("canSettle", () => {
effectiveSettled(queued, {
now: justAfter,
autoSettleAfterDays: 3,
changeRequest: { state: "merged" },
autoSettleMode: "change-request",
changeRequest: { state: "merged", updatedAt: justAfter },
}),
).toBe(false);
// Past the window the message is a failed/stale start: settleable again.
@@ -554,9 +585,13 @@ describe("canSettle", () => {
settledAt: "2026-04-09T12:02:10.000Z",
};
expect(hasQueuedTurnStart(settledAfterMessage, { now: flooredNow })).toBe(true);
expect(effectiveSettled(settledAfterMessage, { now: flooredNow, autoSettleAfterDays: 3 })).toBe(
true,
);
expect(
effectiveSettled(settledAfterMessage, {
now: flooredNow,
autoSettleAfterDays: 3,
autoSettleMode: "never",
}),
).toBe(true);
// A message NEWER than settledAt is genuinely new work: still blocked
// until the server's auto-unsettle lands.
@@ -569,6 +604,7 @@ describe("canSettle", () => {
effectiveSettled(messageAfterSettle, {
now: "2026-04-09T12:03:30.000Z",
autoSettleAfterDays: 3,
autoSettleMode: "never",
}),
).toBe(false);
});
@@ -582,6 +618,12 @@ describe("canSettle", () => {
pending: "user-input",
});
expect(canSettle(blocked, { now: NOW })).toBe(false);
expect(effectiveSettled(blocked, { now: NOW, autoSettleAfterDays: 3 })).toBe(false);
expect(
effectiveSettled(blocked, {
now: NOW,
autoSettleAfterDays: 3,
autoSettleMode: "never",
}),
).toBe(false);
});
});
@@ -1,5 +1,5 @@
// @effect-diagnostics globalDate:off -- UI snooze presets use local calendar boundaries and Intl labels.
import type { OrchestrationThreadShell } from "@t3tools/contracts";
import type { OrchestrationThreadShell, SidebarAutoSettleMode } from "@t3tools/contracts";
export type ChangeRequestStateLike = "open" | "closed" | "merged";
@@ -46,26 +46,22 @@ function threadUserActivityAnchorAt(thread: ThreadActivitySource): string {
* thread started at a worktree root whose PR already merged), and one older
* than the user's latest engagement was already adjudicated — re-engaging a
* thread whose PR merged is the user saying the conversation outlived the
* PR. Unknown timestamps keep the old always-settle behavior.
* PR. Missing or malformed timestamps keep the thread active: an automatic
* transition must have enough evidence to be predictable.
*/
export function changeRequestAutoSettles(
changeRequest: ChangeRequestSettleSource | null | undefined,
options: {
readonly autoSettleOnMerge?: boolean | undefined;
readonly thread?: ThreadActivitySource | null | undefined;
} = {},
): boolean {
if (changeRequest == null) return false;
const terminal =
changeRequest.state === "closed" ||
(changeRequest.state === "merged" && options.autoSettleOnMerge !== false);
const terminal = changeRequest.state === "closed" || changeRequest.state === "merged";
if (!terminal) return false;
if (changeRequest.updatedAt == null || options.thread == null) return true;
if (changeRequest.updatedAt == null || options.thread == null) return false;
const updatedAtMs = Date.parse(changeRequest.updatedAt);
const anchorAtMs = Date.parse(threadUserActivityAnchorAt(options.thread));
// Malformed timestamps fall back to settling, matching servers that never
// report updatedAt.
if (Number.isNaN(updatedAtMs) || Number.isNaN(anchorAtMs)) return true;
if (Number.isNaN(updatedAtMs) || Number.isNaN(anchorAtMs)) return false;
return updatedAtMs >= anchorAtMs;
}
@@ -289,11 +285,11 @@ export function threadWokeAt(
* queued turn) are checked first and hold a thread active regardless of any
* override. Past the blockers, the explicit user override (thread.settle /
* thread.unsettle commands, projected into settledOverride + settledAt)
* wins in both directions; without one, a thread can auto-settle on a
* merged PR or always on a closed PR (both only while the terminal state is
* the thread's latest event, see changeRequestAutoSettles), or settles on
* inactivity past the window.
* An open PR blocks the inactivity path entirely. The server
* wins in both directions. Without one, exactly one selected policy can
* auto-settle: a merged/closed pull request whose terminal timestamp is the
* thread's latest user event (see changeRequestAutoSettles), inactivity past
* the configured window, or never. An open PR blocks the inactivity path.
* The server
* un-settles on real activity (user message, session start, approval/
* user-input request), so an override never goes stale silently.
*/
@@ -302,7 +298,7 @@ export function effectiveSettled(
options: {
readonly now: string;
readonly autoSettleAfterDays: number | null;
readonly autoSettleOnMerge?: boolean;
readonly autoSettleMode: SidebarAutoSettleMode;
readonly changeRequest?: ChangeRequestSettleSource | null;
},
): boolean {
@@ -329,18 +325,14 @@ export function effectiveSettled(
// "active" is the explicit keep-active pin: it suppresses auto-settle
// until real activity clears it server-side.
if (shell.settledOverride === "active") return false;
if (
changeRequestAutoSettles(options.changeRequest, {
autoSettleOnMerge: options.autoSettleOnMerge,
thread: shell,
})
) {
return true;
if (options.autoSettleMode === "never") return false;
if (options.autoSettleMode === "change-request") {
return changeRequestAutoSettles(options.changeRequest, { thread: shell });
}
// An open PR is unfinished business regardless of how long the thread has
// been quiet: review can take days, and hiding the thread would bury the
// work waiting on it. A configured merge, a close, or an explicit user
// settle resolves it.
// work waiting on it. Only an explicit user settle resolves it while the
// inactivity policy is selected.
if (options.changeRequest?.state === "open") return false;
if (options.autoSettleAfterDays === null) return false;
+23 -9
View File
@@ -117,11 +117,11 @@ describe("ClientSettings environment identification", () => {
});
describe("ClientSettings sidebar", () => {
it("defaults to the current sidebar with automatic merge and inactivity settling", () => {
it("defaults to the current sidebar with manual settling", () => {
const settings = decodeClientSettings({});
expect(settings.legacySidebarEnabled).toBe(false);
expect(settings.sidebarAutoSettleAfterDays).toBe(3);
expect(settings.sidebarAutoSettleOnMerge).toBe(true);
expect(settings.sidebarAutoSettleMode).toBe("never");
});
it("drops the retired sidebar v2 beta keys, resetting everyone to the default", () => {
@@ -147,13 +147,27 @@ describe("ClientSettings sidebar", () => {
).toBeNull();
});
it("allows auto-settle on merge to be disabled", () => {
expect(decodeClientSettings({ sidebarAutoSettleOnMerge: false }).sidebarAutoSettleOnMerge).toBe(
false,
);
expect(
decodeClientSettingsPatch({ sidebarAutoSettleOnMerge: false }).sidebarAutoSettleOnMerge,
).toBe(false);
it("does not preserve the retired merge switch as a hidden automatic path", () => {
const decoded = decodeClientSettings({ sidebarAutoSettleOnMerge: true });
expect(decoded.sidebarAutoSettleMode).toBe("never");
expect(decoded).not.toHaveProperty("sidebarAutoSettleOnMerge");
});
it.each(["never", "change-request", "inactivity"] as const)(
"accepts the %s auto-settle mode",
(sidebarAutoSettleMode) => {
expect(decodeClientSettings({ sidebarAutoSettleMode }).sidebarAutoSettleMode).toBe(
sidebarAutoSettleMode,
);
expect(decodeClientSettingsPatch({ sidebarAutoSettleMode }).sidebarAutoSettleMode).toBe(
sidebarAutoSettleMode,
);
},
);
it("rejects unsupported auto-settle modes", () => {
expect(() => decodeClientSettings({ sidebarAutoSettleMode: "always" })).toThrow();
expect(() => decodeClientSettingsPatch({ sidebarAutoSettleMode: "always" })).toThrow();
});
it.each([-1, 0, 91])("rejects an auto-settle threshold outside 1..90: %s", (value) => {
+10 -2
View File
@@ -65,6 +65,9 @@ export const SidebarAutoSettleAfterDays = Schema.Number.check(
);
export type SidebarAutoSettleAfterDays = typeof SidebarAutoSettleAfterDays.Type;
export const DEFAULT_SIDEBAR_AUTO_SETTLE_AFTER_DAYS: SidebarAutoSettleAfterDays = 3;
export const SidebarAutoSettleMode = Schema.Literals(["never", "change-request", "inactivity"]);
export type SidebarAutoSettleMode = typeof SidebarAutoSettleMode.Type;
export const DEFAULT_SIDEBAR_AUTO_SETTLE_MODE: SidebarAutoSettleMode = "never";
export const MIN_GLASS_OPACITY = 40;
export const MAX_GLASS_OPACITY = 100;
export const GlassOpacity = Schema.Int.check(
@@ -234,7 +237,12 @@ export const ClientSettingsSchema = Schema.Struct({
sidebarAutoSettleAfterDays: Schema.NullOr(SidebarAutoSettleAfterDays).pipe(
Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_AUTO_SETTLE_AFTER_DAYS)),
),
sidebarAutoSettleOnMerge: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
// A fresh exclusive policy replaces the old independent inactivity and
// merge switches. Missing mode means manual-only, so an upgrade cannot
// preserve one hidden automatic path after the user disabled another.
sidebarAutoSettleMode: SidebarAutoSettleMode.pipe(
Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_AUTO_SETTLE_MODE)),
),
sidebarProjectGroupingMode: SidebarProjectGroupingMode.pipe(
Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_PROJECT_GROUPING_MODE)),
),
@@ -942,7 +950,7 @@ export const ClientSettingsPatch = Schema.Struct({
showSkillsInSlashMenu: Schema.optionalKey(Schema.Boolean),
legacySidebarEnabled: Schema.optionalKey(Schema.Boolean),
sidebarAutoSettleAfterDays: Schema.optionalKey(Schema.NullOr(SidebarAutoSettleAfterDays)),
sidebarAutoSettleOnMerge: Schema.optionalKey(Schema.Boolean),
sidebarAutoSettleMode: Schema.optionalKey(SidebarAutoSettleMode),
sidebarProjectGroupingMode: Schema.optionalKey(SidebarProjectGroupingMode),
sidebarProjectGroupingOverrides: Schema.optionalKey(
Schema.Record(TrimmedNonEmptyString, SidebarProjectGroupingMode),