feat: allow disabling auto-settle on merge (#5880)
This commit is contained in:
1 parent
96bfa67b3d
commit
db1507e986
17 files changed
+192
-33
No files matched your search
@@ -32,6 +32,7 @@ const clientSettings: ClientSettings = {
|
||||
planModeEnabled: false,
|
||||
providerModelPreferences: {},
|
||||
sidebarAutoSettleAfterDays: 3,
|
||||
sidebarAutoSettleOnMerge: true,
|
||||
sidebarProjectGroupingMode: "repository_path",
|
||||
sidebarProjectGroupingOverrides: {
|
||||
"environment-1:/tmp/project-a": "separate",
|
||||
|
||||
@@ -207,6 +207,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 savePreferences = useAtomSet(updateMobilePreferencesAtom);
|
||||
const openSwipeableRef = useRef<SwipeableMethods | null>(null);
|
||||
const listRef = useRef<LegendListRef | null>(null);
|
||||
@@ -483,8 +486,8 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
// Settled threads stay in the live shell stream (settled ≠ archived), so
|
||||
// the partition works directly off live shells — no snapshot merging or
|
||||
// optimistic holds.
|
||||
// PR states stream in per-row (rows own the VCS subscriptions); a merged or
|
||||
// closed PR auto-settles its thread on the next partition (mirrors web).
|
||||
// PR states stream in per-row. The next partition applies the configured
|
||||
// merge rule and the always-on close rule, matching web.
|
||||
const [changeRequestStateByKey, setChangeRequestStateByKey] = useState<
|
||||
ReadonlyMap<string, "open" | "closed" | "merged">
|
||||
>(() => new Map());
|
||||
@@ -665,6 +668,7 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
searchQuery: props.searchQuery,
|
||||
matchedThreadKeys,
|
||||
changeRequestStateByKey,
|
||||
autoSettleOnMerge,
|
||||
settlementEnvironmentIds,
|
||||
snoozeEnvironmentIds,
|
||||
settledLimit: settledVisibleCount,
|
||||
@@ -676,6 +680,7 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
});
|
||||
}, [
|
||||
changeRequestStateByKey,
|
||||
autoSettleOnMerge,
|
||||
nowMinute,
|
||||
snoozeWakeTick,
|
||||
snoozedShelfExpanded,
|
||||
|
||||
@@ -522,9 +522,21 @@ function ConfiguredSettingsRouteScreen() {
|
||||
}
|
||||
|
||||
function GeneralSettingsSection() {
|
||||
const preferencesResult = useAtomValue(mobilePreferencesAtom);
|
||||
const savePreferences = useAtomSet(updateMobilePreferencesAtom);
|
||||
const autoSettleOnMerge =
|
||||
!AsyncResult.isSuccess(preferencesResult) ||
|
||||
preferencesResult.value.autoSettleOnMerge !== false;
|
||||
|
||||
return (
|
||||
<SettingsSection title="General">
|
||||
<SettingsRow icon="folder" label="Project Grouping" target="SettingsProjectGrouping" />
|
||||
<SettingsSwitchRow
|
||||
icon="arrow.triangle.branch"
|
||||
label="Auto-settle merged threads"
|
||||
value={autoSettleOnMerge}
|
||||
onValueChange={(value) => savePreferences({ autoSettleOnMerge: value })}
|
||||
/>
|
||||
<SettingsRow icon="chart.bar.xaxis" label="Usage" target="SettingsUsage" />
|
||||
</SettingsSection>
|
||||
);
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
import { LegendList } from "@legendapp/list/react-native";
|
||||
import type { MenuAction } from "@react-native-menu/menu";
|
||||
import { useAtomValue } from "@effect/atom-react";
|
||||
import { AsyncResult } from "effect/unstable/reactivity";
|
||||
import type { EnvironmentId } from "@t3tools/contracts";
|
||||
import { sortPinnedThreadsByOrderKey } from "@t3tools/client-runtime/state/thread-sort";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react";
|
||||
@@ -29,6 +30,7 @@ import { NativeStackScreenOptions } from "../../native/StackHeader";
|
||||
import { scopedProjectKey, scopedThreadKey } from "../../lib/scopedEntities";
|
||||
import { useThemeColor } from "../../lib/useThemeColor";
|
||||
import { useProjects, useThreadShells } from "../../state/entities";
|
||||
import { mobilePreferencesAtom } from "../../state/preferences";
|
||||
import { useThreadSearch } from "../../state/queries";
|
||||
import { useThreadListV2Enabled } from "./use-thread-list-v2-enabled";
|
||||
import { environmentServerConfigsAtom } from "../../state/server";
|
||||
@@ -214,6 +216,10 @@ function ThreadNavigationSidebarPane(
|
||||
regenerateThreadTitle,
|
||||
} = useThreadListActions();
|
||||
const threadListV2Enabled = useThreadListV2Enabled();
|
||||
const preferencesResult = useAtomValue(mobilePreferencesAtom);
|
||||
const autoSettleOnMerge =
|
||||
!AsyncResult.isSuccess(preferencesResult) ||
|
||||
preferencesResult.value.autoSettleOnMerge !== false;
|
||||
const pendingTasks = usePendingNewTasks();
|
||||
const { openPendingTask, confirmDeletePendingTask } = usePendingTaskListActions();
|
||||
const environments = useMemo(
|
||||
@@ -411,8 +417,8 @@ function ThreadNavigationSidebarPane(
|
||||
|
||||
// Thread List v2 (beta) support — same model as the compact Home list
|
||||
// (HomeScreen.tsx): flat creation-order card block + settled recency tail.
|
||||
// PR states stream in per-row; merged/closed PRs auto-settle their thread
|
||||
// on the next partition.
|
||||
// PR states stream in per-row. The next partition applies the configured
|
||||
// merge rule and the always-on close rule.
|
||||
const [changeRequestStateByKey, setChangeRequestStateByKey] = useState<
|
||||
ReadonlyMap<string, "open" | "closed" | "merged">
|
||||
>(() => new Map());
|
||||
@@ -546,6 +552,7 @@ function ThreadNavigationSidebarPane(
|
||||
searchQuery: props.searchQuery,
|
||||
matchedThreadKeys,
|
||||
changeRequestStateByKey,
|
||||
autoSettleOnMerge,
|
||||
settlementEnvironmentIds,
|
||||
snoozeEnvironmentIds,
|
||||
settledLimit: settledVisibleCount,
|
||||
@@ -557,6 +564,7 @@ function ThreadNavigationSidebarPane(
|
||||
});
|
||||
}, [
|
||||
changeRequestStateByKey,
|
||||
autoSettleOnMerge,
|
||||
nowMinute,
|
||||
snoozeWakeTick,
|
||||
snoozedShelfExpanded,
|
||||
|
||||
@@ -369,8 +369,8 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
readonly canMovePinnedDown?: boolean;
|
||||
readonly onSwipeableWillOpen: (methods: SwipeableMethods) => void;
|
||||
readonly onSwipeableClose: (methods: SwipeableMethods) => void;
|
||||
/** Reports this row's live PR state up so the partition can auto-settle
|
||||
merged/closed work (mirrors web's onChangeRequestState). */
|
||||
/** Reports this row's live PR state for the partition's merge and close
|
||||
rules. Mirrors web's onChangeRequestState. */
|
||||
readonly onChangeRequestState?: (
|
||||
threadKey: string,
|
||||
state: "open" | "closed" | "merged" | null,
|
||||
|
||||
@@ -263,6 +263,21 @@ describe("sortThreadsForListV2", () => {
|
||||
});
|
||||
|
||||
describe("buildThreadListV2Items", () => {
|
||||
it("keeps a merged thread active when auto-settle on merge is off", () => {
|
||||
const merged = makeThread({ id: ThreadId.make("merged"), title: "Merged" });
|
||||
const layout = buildThreadListV2Items({
|
||||
threads: [merged],
|
||||
environmentId: null,
|
||||
searchQuery: "",
|
||||
changeRequestStateByKey: new Map([[`${environmentId}:${merged.id}`, "merged"]]),
|
||||
autoSettleOnMerge: false,
|
||||
now: NOW,
|
||||
});
|
||||
|
||||
expect(layout.items.map((item) => item.thread.id)).toEqual(["merged"]);
|
||||
expect(layout.settledCount).toBe(0);
|
||||
});
|
||||
|
||||
it("hides snoozed threads and counts them — visibility parity with web", () => {
|
||||
const layout = buildThreadListV2Items({
|
||||
threads: [
|
||||
|
||||
@@ -306,9 +306,8 @@ export function buildThreadListV2ListItems(input: {
|
||||
|
||||
/**
|
||||
* Partitions visible threads into the active card block (creation order) and
|
||||
* the settled recency tail, matching the web v2 list. `autoSettleAfterDays`
|
||||
* mirrors the web default of 3 — mobile has no client-settings sync yet, so
|
||||
* the default is fixed here rather than user-configurable.
|
||||
* the settled recency tail, matching the web v2 list. Mobile stores these
|
||||
* auto-settle preferences per device.
|
||||
*/
|
||||
export function buildThreadListV2Items(input: {
|
||||
readonly threads: ReadonlyArray<EnvironmentThreadShell>;
|
||||
@@ -329,6 +328,7 @@ export function buildThreadListV2Items(input: {
|
||||
contract as settlementEnvironmentIds. */
|
||||
readonly snoozeEnvironmentIds?: ReadonlySet<EnvironmentId>;
|
||||
readonly autoSettleAfterDays?: number;
|
||||
readonly autoSettleOnMerge?: boolean;
|
||||
/** Max settled rows to render; the rest are counted, not built. */
|
||||
readonly settledLimit?: number;
|
||||
/** Injectable for tests; defaults to now. */
|
||||
@@ -349,6 +349,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 query = input.searchQuery.trim().toLocaleLowerCase();
|
||||
const projectKeys = input.projectRefs
|
||||
? new Set(input.projectRefs.map((ref) => `${ref.environmentId}:${ref.projectId}`))
|
||||
@@ -405,7 +406,12 @@ export function buildThreadListV2Items(input: {
|
||||
}
|
||||
if (
|
||||
supportsSettlement &&
|
||||
effectiveSettled(thread, { now, autoSettleAfterDays, changeRequestState })
|
||||
effectiveSettled(thread, {
|
||||
now,
|
||||
autoSettleAfterDays,
|
||||
autoSettleOnMerge,
|
||||
changeRequestState,
|
||||
})
|
||||
) {
|
||||
settled.push(thread);
|
||||
} else {
|
||||
|
||||
@@ -26,6 +26,7 @@ export interface Preferences {
|
||||
/** @deprecated Kept temporarily so older OTA bundles retain the selected mode. */
|
||||
readonly projectGroupingEnabled?: boolean;
|
||||
readonly projectGroupingMode?: SidebarProjectGroupingMode;
|
||||
readonly autoSettleOnMerge?: boolean;
|
||||
/**
|
||||
* Device-local mirror of the web `legacySidebarEnabled` setting. Mobile has
|
||||
* no client-settings sync, so the legacy grouped thread list is opted into
|
||||
@@ -85,6 +86,7 @@ function sanitizePreferences(parsed: Preferences): Preferences {
|
||||
collapsedProjectGroups?: readonly string[];
|
||||
projectGroupingEnabled?: boolean;
|
||||
projectGroupingMode?: SidebarProjectGroupingMode;
|
||||
autoSettleOnMerge?: boolean;
|
||||
legacyThreadListEnabled?: boolean;
|
||||
} = {};
|
||||
|
||||
@@ -122,6 +124,9 @@ function sanitizePreferences(parsed: Preferences): Preferences {
|
||||
) {
|
||||
preferences.projectGroupingMode = parsed.projectGroupingMode;
|
||||
}
|
||||
if (typeof parsed.autoSettleOnMerge === "boolean") {
|
||||
preferences.autoSettleOnMerge = parsed.autoSettleOnMerge;
|
||||
}
|
||||
if (typeof parsed.legacyThreadListEnabled === "boolean") {
|
||||
preferences.legacyThreadListEnabled = parsed.legacyThreadListEnabled;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
type EnvironmentConnectionPresentation,
|
||||
} from "@t3tools/client-runtime/connection";
|
||||
import {
|
||||
changeRequestAutoSettles,
|
||||
effectiveSettled,
|
||||
effectiveSnoozed,
|
||||
threadWokeAt,
|
||||
@@ -4101,6 +4102,7 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
// so the banner and the sidebar row never disagree.
|
||||
const activeThreadShell = useThreadShell(isServerThread ? activeThreadRef : null);
|
||||
const autoSettleAfterDays = useClientSettings((settings) => settings.sidebarAutoSettleAfterDays);
|
||||
const autoSettleOnMerge = useClientSettings((settings) => settings.sidebarAutoSettleOnMerge);
|
||||
const activeThreadPr = resolveThreadPr({
|
||||
threadBranch: activeThread?.branch ?? null,
|
||||
gitStatus: gitStatusQuery.data ?? null,
|
||||
@@ -4141,15 +4143,14 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
if (activeThreadRef === null || activeThreadWokeAt === null) return;
|
||||
markThreadVisited(scopedThreadKey(activeThreadRef), activeThreadWokeAt);
|
||||
}, [activeThreadRef, activeThreadWokeAt, markThreadVisited]);
|
||||
// Mirror of the sidebar's Woke pill for the open thread: same visit
|
||||
// comparison, same merged/closed-PR suppression (finished work needs no
|
||||
// wake-up call). Drives the dismissible composer banner below.
|
||||
// Mirror of the sidebar's Woke pill for the open thread. It uses the same
|
||||
// visit comparison and change request settle rule.
|
||||
const activeThreadLastVisitedAt = useUiStateStore((store) =>
|
||||
activeThreadKey === null ? undefined : store.threadLastVisitedAtById[activeThreadKey],
|
||||
);
|
||||
const activeThreadWokeVisible = useMemo(() => {
|
||||
if (activeThreadWokeAt === null) return false;
|
||||
if (activeThreadPr?.state === "merged" || activeThreadPr?.state === "closed") return false;
|
||||
if (changeRequestAutoSettles(activeThreadPr?.state, autoSettleOnMerge)) return false;
|
||||
const wokeAtMs = Date.parse(activeThreadWokeAt);
|
||||
if (Number.isNaN(wokeAtMs)) return false;
|
||||
// Having the thread open counts as a visit at completedAt (the effect
|
||||
@@ -4171,18 +4172,21 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
activeThreadLastVisitedAt,
|
||||
activeThreadPr?.state,
|
||||
activeThreadWokeAt,
|
||||
autoSettleOnMerge,
|
||||
]);
|
||||
const activeThreadSettled = useMemo(() => {
|
||||
if (activeThreadShell === null || !supportsSettlement) return false;
|
||||
return effectiveSettled(activeThreadShell, {
|
||||
now: `${nowMinute}:00.000Z`,
|
||||
autoSettleAfterDays,
|
||||
autoSettleOnMerge,
|
||||
changeRequestState: activeThreadPr?.state ?? null,
|
||||
});
|
||||
}, [
|
||||
activeThreadPr?.state,
|
||||
activeThreadShell,
|
||||
autoSettleAfterDays,
|
||||
autoSettleOnMerge,
|
||||
nowMinute,
|
||||
supportsSettlement,
|
||||
]);
|
||||
|
||||
@@ -19,6 +19,7 @@ import { restrictToFirstScrollableAncestor, restrictToVerticalAxis } from "@dnd-
|
||||
import { CSS } from "@dnd-kit/utilities";
|
||||
import {
|
||||
canSnooze,
|
||||
changeRequestAutoSettles,
|
||||
effectiveSettled,
|
||||
effectiveSnoozed,
|
||||
threadWokeAt,
|
||||
@@ -657,6 +658,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;
|
||||
// Same contract for thread.snooze/unsnooze.
|
||||
snoozeSupported: boolean;
|
||||
// Renders the pin glyph. Pinned cards keep the full settle/snooze quick
|
||||
@@ -765,17 +767,15 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
|
||||
// deliberately static), so the pill has to carry the weight. Snoozing is
|
||||
// an explicit act, so the pill clears only when the user re-engages:
|
||||
// reading a completion-triggered wake, clicking the pill, sending a
|
||||
// message, settling, archiving — or finishing the work outright (merged
|
||||
// or closed PR). Timer wakes survive a mere visit. An unparseable visit
|
||||
// timestamp counts as never-visited — corrupt local data must not eat
|
||||
// the wake signal.
|
||||
// message, settling, archiving, or a change request state that settles the
|
||||
// thread. Timer wakes survive a mere visit. An unparseable visit timestamp
|
||||
// counts as never-visited, so corrupt local data cannot eat the wake signal.
|
||||
const lastVisitedDate = lastVisitedAt === undefined ? null : parseTimestampDate(lastVisitedAt);
|
||||
const wokeAtDate = props.wokeAt === null ? null : parseTimestampDate(props.wokeAt);
|
||||
const isWoke =
|
||||
wokeAtDate !== null &&
|
||||
(lastVisitedDate === null || lastVisitedDate < wokeAtDate) &&
|
||||
prState !== "merged" &&
|
||||
prState !== "closed";
|
||||
!changeRequestAutoSettles(prState, props.autoSettleOnMerge);
|
||||
// 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
|
||||
@@ -851,8 +851,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
|
||||
});
|
||||
const prStatus = prStatusIndicator(pr, gitStatus.data?.sourceControlProvider);
|
||||
const settledPrHoverClass = pr ? settledPrHoverColorClass(pr.state) : undefined;
|
||||
// Report the PR state up: the parent partitions rows with effectiveSettled,
|
||||
// and a merged/closed PR auto-settles a thread — data only rows have.
|
||||
// Report the PR state so the parent can apply the configured merge rule
|
||||
// and the always-on close rule during partitioning.
|
||||
useEffect(() => {
|
||||
onChangeRequestState(threadKey, prState);
|
||||
}, [onChangeRequestState, prState, threadKey]);
|
||||
@@ -1599,6 +1599,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 confirmThreadDelete = useClientSettings((s) => s.confirmThreadDelete);
|
||||
const sidebarProjectSortOrder = useClientSettings((s) => s.sidebarProjectSortOrder);
|
||||
const timestampFormat = useClientSettings((s) => s.timestampFormat);
|
||||
@@ -1801,8 +1802,8 @@ export default function Sidebar() {
|
||||
// fresh clock whenever it recomputes.
|
||||
const [snoozeWakeTick, bumpSnoozeWakeTick] = useState(0);
|
||||
|
||||
// PR states stream in per-row (rows own the VCS subscriptions); a merged or
|
||||
// closed PR auto-settles its thread on the next partition.
|
||||
// PR states stream in per-row. The next partition applies the configured
|
||||
// merge rule and the always-on close rule.
|
||||
const [changeRequestStateByKey, setChangeRequestStateByKey] = useState<
|
||||
ReadonlyMap<string, "open" | "closed" | "merged">
|
||||
>(() => new Map());
|
||||
@@ -1953,7 +1954,12 @@ export default function Sidebar() {
|
||||
pinned.push(thread);
|
||||
} else if (
|
||||
supportsSettlement &&
|
||||
effectiveSettled(thread, { now, autoSettleAfterDays, changeRequestState })
|
||||
effectiveSettled(thread, {
|
||||
now,
|
||||
autoSettleAfterDays,
|
||||
autoSettleOnMerge,
|
||||
changeRequestState,
|
||||
})
|
||||
) {
|
||||
settled.push(thread);
|
||||
} else {
|
||||
@@ -1988,6 +1994,7 @@ export default function Sidebar() {
|
||||
};
|
||||
}, [
|
||||
autoSettleAfterDays,
|
||||
autoSettleOnMerge,
|
||||
changeRequestStateByKey,
|
||||
nowMinute,
|
||||
scopedProjectKeys,
|
||||
@@ -3532,6 +3539,7 @@ export default function Sidebar() {
|
||||
serverConfigs.get(thread.environmentId)?.environment.capabilities
|
||||
.threadSettlement === true
|
||||
}
|
||||
autoSettleOnMerge={autoSettleOnMerge}
|
||||
snoozeSupported={
|
||||
serverConfigs.get(thread.environmentId)?.environment.capabilities
|
||||
.threadSnooze === true
|
||||
|
||||
@@ -493,6 +493,9 @@ export function useSettingsRestore(onRestored?: () => void) {
|
||||
DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleAfterDays
|
||||
? ["Auto-settle inactive threads"]
|
||||
: []),
|
||||
...(settings.sidebarAutoSettleOnMerge !== DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleOnMerge
|
||||
? ["Auto-settle merged threads"]
|
||||
: []),
|
||||
...(settings.wordWrap !== DEFAULT_UNIFIED_SETTINGS.wordWrap ? ["Word wrap"] : []),
|
||||
...getChangedTypographySettingLabels(settings),
|
||||
...(settings.diffIgnoreWhitespace !== DEFAULT_UNIFIED_SETTINGS.diffIgnoreWhitespace
|
||||
@@ -547,6 +550,7 @@ export function useSettingsRestore(onRestored?: () => void) {
|
||||
settings.enableLegacyTokenStreaming,
|
||||
settings.enableProviderUpdateChecks,
|
||||
settings.sidebarAutoSettleAfterDays,
|
||||
settings.sidebarAutoSettleOnMerge,
|
||||
settings.sidebarProjectGroupingMode,
|
||||
settings.sidebarThreadPreviewCount,
|
||||
settings.timestampFormat,
|
||||
@@ -628,6 +632,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,
|
||||
enableLegacyTokenStreaming: DEFAULT_UNIFIED_SETTINGS.enableLegacyTokenStreaming,
|
||||
enableProviderUpdateChecks: DEFAULT_UNIFIED_SETTINGS.enableProviderUpdateChecks,
|
||||
backgroundActivity: DEFAULT_UNIFIED_SETTINGS.backgroundActivity,
|
||||
@@ -1828,9 +1833,36 @@ export function GeneralSettingsPanel() {
|
||||
}
|
||||
/>
|
||||
|
||||
<SettingsRow
|
||||
{...searchableSetting("auto-settle-merged-threads")}
|
||||
description="Settle a thread when its pull request merges. Closed pull requests still settle automatically."
|
||||
resetAction={
|
||||
settings.sidebarAutoSettleOnMerge !==
|
||||
DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleOnMerge ? (
|
||||
<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. Threads on merged or closed PRs always settle."
|
||||
description="Sidebar threads with no activity for this long settle automatically."
|
||||
resetAction={
|
||||
settings.sidebarAutoSettleAfterDays !==
|
||||
DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleAfterDays ? (
|
||||
|
||||
@@ -103,6 +103,11 @@ export const SETTINGS_SEARCH_ITEMS = [
|
||||
title: "Auto-settle inactive threads",
|
||||
to: "/settings/general",
|
||||
},
|
||||
{
|
||||
id: "auto-settle-merged-threads",
|
||||
title: "Auto-settle merged threads",
|
||||
to: "/settings/general",
|
||||
},
|
||||
{
|
||||
id: "time-format",
|
||||
title: "Time format",
|
||||
|
||||
@@ -80,6 +80,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 confirmThreadDelete = useClientSettings((s) => s.confirmThreadDelete);
|
||||
const timestampFormat = useClientSettings((s) => s.timestampFormat);
|
||||
const { copyToClipboard: copyPathToClipboard } = useCopyToClipboard<{ path: string }>({
|
||||
@@ -132,6 +133,7 @@ export function useThreadActionMenu(input: {
|
||||
// parked-thread banner within the same minute.
|
||||
now: `${now.toISOString().slice(0, 16)}:00.000Z`,
|
||||
autoSettleAfterDays,
|
||||
autoSettleOnMerge,
|
||||
changeRequestState,
|
||||
}),
|
||||
isSnoozed: supports.snooze && effectiveSnoozed(thread, { now: now.toISOString() }),
|
||||
@@ -284,6 +286,7 @@ export function useThreadActionMenu(input: {
|
||||
},
|
||||
[
|
||||
autoSettleAfterDays,
|
||||
autoSettleOnMerge,
|
||||
changeRequestState,
|
||||
confirmThreadDelete,
|
||||
copyBranchToClipboard,
|
||||
|
||||
@@ -9,6 +9,7 @@ import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import {
|
||||
canSettle,
|
||||
changeRequestAutoSettles,
|
||||
effectiveSettled,
|
||||
hasQueuedTurnStart,
|
||||
threadLastActivityAt,
|
||||
@@ -19,6 +20,18 @@ const NOW = "2026-04-10T00:00:00.000Z";
|
||||
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, autoSettleOnMerge)).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
function makeShell(input: {
|
||||
readonly settledOverride?: "settled" | "active" | null;
|
||||
readonly activityAt: string | null;
|
||||
@@ -178,6 +191,27 @@ describe("effectiveSettled", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("can keep a merged change request active", () => {
|
||||
const recentlyActive = makeShell({ activityAt: "2026-04-09T23:59:59.999Z" });
|
||||
expect(
|
||||
effectiveSettled(recentlyActive, {
|
||||
now: NOW,
|
||||
autoSettleAfterDays: null,
|
||||
autoSettleOnMerge: false,
|
||||
changeRequestState: "merged",
|
||||
}),
|
||||
).toBe(false);
|
||||
|
||||
expect(
|
||||
effectiveSettled(recentlyActive, {
|
||||
now: NOW,
|
||||
autoSettleAfterDays: null,
|
||||
autoSettleOnMerge: false,
|
||||
changeRequestState: "closed",
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("never auto-settles a stale thread with an open change request", () => {
|
||||
const stale = makeShell({ activityAt: STALE });
|
||||
expect(
|
||||
|
||||
@@ -3,6 +3,14 @@ import type { OrchestrationThreadShell } from "@t3tools/contracts";
|
||||
|
||||
export type ChangeRequestStateLike = "open" | "closed" | "merged";
|
||||
|
||||
/** Returns whether the change request state settles the thread immediately. */
|
||||
export function changeRequestAutoSettles(
|
||||
state: ChangeRequestStateLike | null | undefined,
|
||||
autoSettleOnMerge = true,
|
||||
): boolean {
|
||||
return state === "closed" || (state === "merged" && autoSettleOnMerge);
|
||||
}
|
||||
|
||||
const DAY_MS = 24 * 60 * 60 * 1_000;
|
||||
|
||||
export function threadLastActivityAt(shell: OrchestrationThreadShell): string | null {
|
||||
@@ -221,9 +229,9 @@ 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 auto-settles on a
|
||||
* merged/closed PR immediately or on inactivity past the window — except
|
||||
* that an open PR blocks the inactivity path entirely. The server
|
||||
* wins in both directions; without one, a thread can auto-settle on a
|
||||
* merged PR, always settles on a closed PR, or settles on inactivity past
|
||||
* the window. An open PR blocks the inactivity path entirely. The server
|
||||
* un-settles on real activity (user message, session start, approval/
|
||||
* user-input request), so an override never goes stale silently.
|
||||
*/
|
||||
@@ -232,6 +240,7 @@ export function effectiveSettled(
|
||||
options: {
|
||||
readonly now: string;
|
||||
readonly autoSettleAfterDays: number | null;
|
||||
readonly autoSettleOnMerge?: boolean;
|
||||
readonly changeRequestState?: ChangeRequestStateLike | null;
|
||||
},
|
||||
): boolean {
|
||||
@@ -258,13 +267,13 @@ 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 (options.changeRequestState === "merged" || options.changeRequestState === "closed") {
|
||||
if (changeRequestAutoSettles(options.changeRequestState, options.autoSettleOnMerge !== false)) {
|
||||
return true;
|
||||
}
|
||||
// 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. Only merge/close (above) or an explicit user settle
|
||||
// resolves it.
|
||||
// work waiting on it. A configured merge, a close, or an explicit user
|
||||
// settle resolves it.
|
||||
if (options.changeRequestState === "open") return false;
|
||||
if (options.autoSettleAfterDays === null) return false;
|
||||
|
||||
|
||||
@@ -68,10 +68,11 @@ describe("ClientSettings environment identification", () => {
|
||||
});
|
||||
|
||||
describe("ClientSettings sidebar", () => {
|
||||
it("defaults to the current sidebar with a three-day auto-settle threshold", () => {
|
||||
it("defaults to the current sidebar with automatic merge and inactivity settling", () => {
|
||||
const settings = decodeClientSettings({});
|
||||
expect(settings.legacySidebarEnabled).toBe(false);
|
||||
expect(settings.sidebarAutoSettleAfterDays).toBe(3);
|
||||
expect(settings.sidebarAutoSettleOnMerge).toBe(true);
|
||||
});
|
||||
|
||||
it("drops the retired sidebar v2 beta keys, resetting everyone to the default", () => {
|
||||
@@ -97,6 +98,15 @@ 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.each([-1, 0, 91])("rejects an auto-settle threshold outside 1..90: %s", (value) => {
|
||||
expect(() => decodeClientSettings({ sidebarAutoSettleAfterDays: value })).toThrow();
|
||||
expect(() => decodeClientSettingsPatch({ sidebarAutoSettleAfterDays: value })).toThrow();
|
||||
|
||||
@@ -180,6 +180,7 @@ 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))),
|
||||
sidebarProjectGroupingMode: SidebarProjectGroupingMode.pipe(
|
||||
Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_PROJECT_GROUPING_MODE)),
|
||||
),
|
||||
@@ -793,6 +794,7 @@ export const ClientSettingsPatch = Schema.Struct({
|
||||
planModeEnabled: Schema.optionalKey(Schema.Boolean),
|
||||
legacySidebarEnabled: Schema.optionalKey(Schema.Boolean),
|
||||
sidebarAutoSettleAfterDays: Schema.optionalKey(Schema.NullOr(SidebarAutoSettleAfterDays)),
|
||||
sidebarAutoSettleOnMerge: Schema.optionalKey(Schema.Boolean),
|
||||
sidebarProjectGroupingMode: Schema.optionalKey(SidebarProjectGroupingMode),
|
||||
sidebarProjectGroupingOverrides: Schema.optionalKey(
|
||||
Schema.Record(TrimmedNonEmptyString, SidebarProjectGroupingMode),
|
||||
|
||||
Reference in new issue
Block a user