feat(threads): add per-thread auto-settle switch (#11846)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
d5d48742c9
commit
0109670411
42 files changed
+862
-11
No files matched your search
@@ -80,6 +80,7 @@ function normalizeContextMenuItems(source: readonly ContextMenuItem[]): ContextM
|
||||
destructive: sourceItem.destructive === true,
|
||||
disabled: sourceItem.disabled === true,
|
||||
...(sourceItem.separatorBefore === true ? { separatorBefore: true } : {}),
|
||||
...(typeof sourceItem.checked === "boolean" ? { checked: sourceItem.checked } : {}),
|
||||
};
|
||||
|
||||
if (sourceItem.children) {
|
||||
@@ -168,6 +169,7 @@ export const make = Effect.gen(function* () {
|
||||
const itemOption: Electron.MenuItemConstructorOptions = {
|
||||
label: item.label,
|
||||
enabled: !item.disabled,
|
||||
...(typeof item.checked === "boolean" ? { type: "checkbox", checked: item.checked } : {}),
|
||||
};
|
||||
if (item.children && item.children.length > 0) {
|
||||
itemOption.submenu = buildTemplate(item.children, complete);
|
||||
|
||||
@@ -140,6 +140,7 @@ const ANDROID_ICON_BY_SF_SYMBOL = {
|
||||
"checkmark.circle": IconCircleCheck,
|
||||
circle: IconCircle,
|
||||
clock: IconClock,
|
||||
timer: IconClock,
|
||||
ticket: IconTicket,
|
||||
cloud: IconCloud,
|
||||
cube: IconBox,
|
||||
|
||||
@@ -49,6 +49,7 @@ export function HomeRouteScreen() {
|
||||
unsnoozeThread,
|
||||
pinThread,
|
||||
unpinThread,
|
||||
setThreadAutoSettle,
|
||||
moveThread,
|
||||
renameThread,
|
||||
regenerateThreadTitle,
|
||||
@@ -206,6 +207,7 @@ export function HomeRouteScreen() {
|
||||
onUnsettleThread={unsettleThread}
|
||||
onPinThread={pinThread}
|
||||
onUnpinThread={unpinThread}
|
||||
onSetThreadAutoSettle={setThreadAutoSettle}
|
||||
onMoveThread={moveThread}
|
||||
onRenameThread={renameThread}
|
||||
onRegenerateThreadTitle={regenerateThreadTitle}
|
||||
|
||||
@@ -96,6 +96,10 @@ interface HomeScreenProps {
|
||||
readonly onUnsettleThread: (thread: EnvironmentThreadShell) => void;
|
||||
readonly onPinThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
|
||||
readonly onUnpinThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
|
||||
readonly onSetThreadAutoSettle: (
|
||||
thread: EnvironmentThreadShell,
|
||||
enabled: boolean,
|
||||
) => Promise<boolean>;
|
||||
readonly onMoveThread: (
|
||||
thread: EnvironmentThreadShell,
|
||||
direction: ThreadMoveDestination,
|
||||
@@ -378,6 +382,12 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
},
|
||||
[props.onUnpinThread],
|
||||
);
|
||||
const handleSetThreadAutoSettle = useCallback(
|
||||
(thread: EnvironmentThreadShell, enabled: boolean) => {
|
||||
void props.onSetThreadAutoSettle(thread, enabled);
|
||||
},
|
||||
[props.onSetThreadAutoSettle],
|
||||
);
|
||||
const handleRegenerateThreadTitle = useCallback(
|
||||
(thread: EnvironmentThreadShell) => {
|
||||
void props.onRegenerateThreadTitle(thread);
|
||||
@@ -456,6 +466,15 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
}
|
||||
return supported;
|
||||
}, [serverConfigs]);
|
||||
const autoSettleOptOutEnvironmentIds = useMemo(() => {
|
||||
const supported = new Set<EnvironmentId>();
|
||||
for (const [environmentId, config] of serverConfigs) {
|
||||
if (config.environment.capabilities.threadAutoSettleOptOut === true) {
|
||||
supported.add(environmentId);
|
||||
}
|
||||
}
|
||||
return supported;
|
||||
}, [serverConfigs]);
|
||||
const pinReorderEnvironmentIds = useMemo(() => {
|
||||
const supported = new Set<EnvironmentId>();
|
||||
for (const [environmentId, config] of serverConfigs) {
|
||||
@@ -726,6 +745,7 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
onSettleThread={handleSettleThread}
|
||||
snoozeSupported={snoozeEnvironmentIds.has(thread.environmentId)}
|
||||
pinningSupported={pinningEnvironmentIds.has(thread.environmentId)}
|
||||
autoSettleOptOutSupported={autoSettleOptOutEnvironmentIds.has(thread.environmentId)}
|
||||
reorderSupported={
|
||||
item.item.pinned
|
||||
? pinReorderEnvironmentIds.has(thread.environmentId)
|
||||
@@ -738,6 +758,7 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
onUnsettleThread={handleUnsettleThread}
|
||||
onPinThread={handlePinThread}
|
||||
onUnpinThread={handleUnpinThread}
|
||||
onSetThreadAutoSettle={handleSetThreadAutoSettle}
|
||||
onMoveThread={handleMoveThread}
|
||||
onSwipeableClose={handleSwipeableClose}
|
||||
onSwipeableWillOpen={handleSwipeableWillOpen}
|
||||
@@ -758,6 +779,8 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
handleSwipeableClose,
|
||||
handleSwipeableWillOpen,
|
||||
handleUnsettleThread,
|
||||
handleSetThreadAutoSettle,
|
||||
autoSettleOptOutEnvironmentIds,
|
||||
pinningEnvironmentIds,
|
||||
machineByEnvironmentId,
|
||||
pinReorderEnvironmentIds,
|
||||
|
||||
@@ -59,6 +59,15 @@ function environmentSupportsPinReorder(environmentId: EnvironmentThreadShell["en
|
||||
);
|
||||
}
|
||||
|
||||
function environmentSupportsAutoSettleOptOut(
|
||||
environmentId: EnvironmentThreadShell["environmentId"],
|
||||
) {
|
||||
return (
|
||||
appAtomRegistry.get(environmentServerConfigsAtom).get(environmentId)?.environment.capabilities
|
||||
.threadAutoSettleOptOut === true
|
||||
);
|
||||
}
|
||||
|
||||
function environmentSupportsTitleRegeneration(
|
||||
environmentId: EnvironmentThreadShell["environmentId"],
|
||||
) {
|
||||
@@ -237,6 +246,11 @@ export function useThreadListActions(): {
|
||||
readonly unsettleThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
|
||||
readonly pinThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
|
||||
readonly unpinThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
|
||||
/** Sets per-thread automatic settlement on or off. */
|
||||
readonly setThreadAutoSettle: (
|
||||
thread: EnvironmentThreadShell,
|
||||
enabled: boolean,
|
||||
) => Promise<boolean>;
|
||||
readonly moveThread: (
|
||||
thread: EnvironmentThreadShell,
|
||||
direction: ThreadMoveDestination,
|
||||
@@ -249,6 +263,9 @@ export function useThreadListActions(): {
|
||||
const unsnoozeMutation = useAtomCommand(threadEnvironment.unsnooze, { reportFailure: false });
|
||||
const pinMutation = useAtomCommand(threadEnvironment.pin, { reportFailure: false });
|
||||
const unpinMutation = useAtomCommand(threadEnvironment.unpin, { reportFailure: false });
|
||||
const setAutoSettleMutation = useAtomCommand(threadEnvironment.setAutoSettle, {
|
||||
reportFailure: false,
|
||||
});
|
||||
const updateThreadMetadata = useAtomCommand(threadEnvironment.updateMetadata, {
|
||||
reportFailure: false,
|
||||
});
|
||||
@@ -435,6 +452,34 @@ export function useThreadListActions(): {
|
||||
},
|
||||
[unpinMutation],
|
||||
);
|
||||
const setThreadAutoSettle = useCallback(
|
||||
async (thread: EnvironmentThreadShell, enabled: boolean) => {
|
||||
if (!environmentSupportsAutoSettleOptOut(thread.environmentId)) {
|
||||
Alert.alert(
|
||||
"Could not update auto-settle",
|
||||
"This environment's server does not support turning auto-settle off per thread yet. Update the server to use it.",
|
||||
);
|
||||
return false;
|
||||
}
|
||||
selectionHaptic();
|
||||
const result = await setAutoSettleMutation({
|
||||
environmentId: thread.environmentId,
|
||||
input: { threadId: thread.id, enabled },
|
||||
});
|
||||
if (result._tag === "Failure") {
|
||||
const error = Cause.squash(result.cause);
|
||||
Alert.alert(
|
||||
"Could not update auto-settle",
|
||||
error instanceof Error && error.message.trim().length > 0
|
||||
? error.message
|
||||
: "The auto-settle setting could not be changed.",
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
[setAutoSettleMutation],
|
||||
);
|
||||
const regenerateThreadTitle = useCallback(
|
||||
async (thread: EnvironmentThreadShell) => {
|
||||
const key = scopedThreadKey(thread.environmentId, thread.id);
|
||||
@@ -698,6 +743,7 @@ export function useThreadListActions(): {
|
||||
unsettleThread,
|
||||
pinThread,
|
||||
unpinThread,
|
||||
setThreadAutoSettle,
|
||||
moveThread,
|
||||
renameThread,
|
||||
regenerateThreadTitle,
|
||||
|
||||
@@ -150,6 +150,7 @@ function ThreadNavigationSidebarPane(
|
||||
unsettleThread,
|
||||
pinThread,
|
||||
unpinThread,
|
||||
setThreadAutoSettle,
|
||||
moveThread,
|
||||
renameThread,
|
||||
regenerateThreadTitle,
|
||||
@@ -334,6 +335,15 @@ function ThreadNavigationSidebarPane(
|
||||
}
|
||||
return supported;
|
||||
}, [serverConfigs]);
|
||||
const autoSettleOptOutEnvironmentIds = useMemo(() => {
|
||||
const supported = new Set<EnvironmentId>();
|
||||
for (const [environmentId, config] of serverConfigs) {
|
||||
if (config.environment.capabilities.threadAutoSettleOptOut === true) {
|
||||
supported.add(environmentId);
|
||||
}
|
||||
}
|
||||
return supported;
|
||||
}, [serverConfigs]);
|
||||
const pinReorderEnvironmentIds = useMemo(() => {
|
||||
const supported = new Set<EnvironmentId>();
|
||||
for (const [environmentId, config] of serverConfigs) {
|
||||
@@ -766,6 +776,7 @@ function ThreadNavigationSidebarPane(
|
||||
onSettleThread={settleThread}
|
||||
snoozeSupported={snoozeEnvironmentIds.has(thread.environmentId)}
|
||||
pinningSupported={pinningEnvironmentIds.has(thread.environmentId)}
|
||||
autoSettleOptOutSupported={autoSettleOptOutEnvironmentIds.has(thread.environmentId)}
|
||||
reorderSupported={
|
||||
item.item.pinned
|
||||
? pinReorderEnvironmentIds.has(thread.environmentId)
|
||||
@@ -778,6 +789,7 @@ function ThreadNavigationSidebarPane(
|
||||
onUnsettleThread={unsettleThread}
|
||||
onPinThread={pinThread}
|
||||
onUnpinThread={unpinThread}
|
||||
onSetThreadAutoSettle={setThreadAutoSettle}
|
||||
onMoveThread={moveThread}
|
||||
onSwipeableClose={handleSwipeableClose}
|
||||
onSwipeableWillOpen={handleSwipeableWillOpen}
|
||||
@@ -829,6 +841,8 @@ function ThreadNavigationSidebarPane(
|
||||
pinReorderEnvironmentIds,
|
||||
pinThread,
|
||||
pinningEnvironmentIds,
|
||||
autoSettleOptOutEnvironmentIds,
|
||||
setThreadAutoSettle,
|
||||
projectByKey,
|
||||
projectTitleByProjectKey,
|
||||
regenerateThreadTitle,
|
||||
|
||||
@@ -493,6 +493,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
readonly onArchiveThread: (thread: EnvironmentThreadShell) => void;
|
||||
readonly onPinThread: (thread: EnvironmentThreadShell) => void;
|
||||
readonly onUnpinThread: (thread: EnvironmentThreadShell) => void;
|
||||
readonly onSetThreadAutoSettle: (thread: EnvironmentThreadShell, enabled: boolean) => void;
|
||||
/** False on environments whose server predates thread.settle/unsettle:
|
||||
swipe + menu fall back to Archive instead of failing on use. */
|
||||
readonly settlementSupported: boolean;
|
||||
@@ -500,6 +501,8 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
readonly snoozeSupported: boolean;
|
||||
/** False on servers that predate thread.pin/unpin. */
|
||||
readonly pinningSupported: boolean;
|
||||
/** False on servers that predate thread.auto-settle.set. */
|
||||
readonly autoSettleOptOutSupported: boolean;
|
||||
/** False on servers that predate thread title regeneration. */
|
||||
readonly titleRegenerationSupported: boolean;
|
||||
/** Server supports reordering this card's section. */
|
||||
@@ -536,6 +539,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
onArchiveThread,
|
||||
onPinThread,
|
||||
onUnpinThread,
|
||||
onSetThreadAutoSettle,
|
||||
onMoveThread,
|
||||
} = props;
|
||||
const snoozedRow = props.snoozed === true;
|
||||
@@ -583,6 +587,10 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
const handleUnsettle = useCallback(() => onUnsettleThread(thread), [onUnsettleThread, thread]);
|
||||
const handlePin = useCallback(() => onPinThread(thread), [onPinThread, thread]);
|
||||
const handleUnpin = useCallback(() => onUnpinThread(thread), [onUnpinThread, thread]);
|
||||
const handleSetAutoSettle = useCallback(
|
||||
(enabled: boolean) => onSetThreadAutoSettle(thread, enabled),
|
||||
[onSetThreadAutoSettle, thread],
|
||||
);
|
||||
const handleMoveUp = useCallback(() => onMoveThread?.(thread, "up"), [onMoveThread, thread]);
|
||||
const handleMoveDown = useCallback(() => onMoveThread?.(thread, "down"), [onMoveThread, thread]);
|
||||
const handleArchive = useCallback(() => onArchiveThread(thread), [onArchiveThread, thread]);
|
||||
@@ -661,6 +669,33 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
variant,
|
||||
],
|
||||
);
|
||||
// A submenu with the current option checked, matching web. This is a
|
||||
// per-thread setting, not a lifecycle verb.
|
||||
const autoSettleMenuItems = useMemo<MenuAction[]>(
|
||||
() =>
|
||||
props.autoSettleOptOutSupported
|
||||
? [
|
||||
{
|
||||
id: "auto-settle",
|
||||
title: "Auto-settle behavior",
|
||||
image: "timer",
|
||||
subactions: [
|
||||
{
|
||||
id: "auto-settle:enabled",
|
||||
title: "Enabled",
|
||||
state: thread.autoSettleDisabledAt == null ? "on" : "off",
|
||||
},
|
||||
{
|
||||
id: "auto-settle:disabled",
|
||||
title: "Disabled",
|
||||
state: thread.autoSettleDisabledAt == null ? "off" : "on",
|
||||
},
|
||||
],
|
||||
} satisfies MenuAction,
|
||||
]
|
||||
: [],
|
||||
[props.autoSettleOptOutSupported, thread.autoSettleDisabledAt],
|
||||
);
|
||||
const titleMenuItems = useMemo<MenuAction[]>(
|
||||
() => [
|
||||
{ id: "rename", title: "Rename", image: "square.and.pencil" },
|
||||
@@ -682,19 +717,23 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
},
|
||||
...arrangementMenuItems,
|
||||
...titleMenuItems,
|
||||
...autoSettleMenuItems,
|
||||
{ id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
|
||||
],
|
||||
[arrangementMenuItems, snoozePresetActions, titleMenuItems],
|
||||
[arrangementMenuItems, autoSettleMenuItems, snoozePresetActions, titleMenuItems],
|
||||
);
|
||||
const cardMenuActions = useMemo<MenuAction[]>(
|
||||
() => [
|
||||
CARD_MENU_ACTIONS[0]!,
|
||||
...arrangementMenuItems,
|
||||
...titleMenuItems,
|
||||
...autoSettleMenuItems,
|
||||
...CARD_MENU_ACTIONS.slice(1),
|
||||
],
|
||||
[arrangementMenuItems, titleMenuItems],
|
||||
[arrangementMenuItems, autoSettleMenuItems, titleMenuItems],
|
||||
);
|
||||
// Settled and snoozed rows keep the setting too, matching web where every
|
||||
// row shares one menu builder.
|
||||
const slimMenuActions = useMemo<MenuAction[]>(
|
||||
() => [
|
||||
SLIM_MENU_ACTIONS[0]!,
|
||||
@@ -702,13 +741,19 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
(action) => action.id !== "move-up" && action.id !== "move-down",
|
||||
),
|
||||
...titleMenuItems,
|
||||
...autoSettleMenuItems,
|
||||
SLIM_MENU_ACTIONS[1]!,
|
||||
],
|
||||
[arrangementMenuItems, titleMenuItems],
|
||||
[arrangementMenuItems, autoSettleMenuItems, titleMenuItems],
|
||||
);
|
||||
const snoozedMenuActions = useMemo<MenuAction[]>(
|
||||
() => [SNOOZED_MENU_ACTIONS[0]!, ...titleMenuItems, SNOOZED_MENU_ACTIONS[1]!],
|
||||
[titleMenuItems],
|
||||
() => [
|
||||
SNOOZED_MENU_ACTIONS[0]!,
|
||||
...titleMenuItems,
|
||||
...autoSettleMenuItems,
|
||||
SNOOZED_MENU_ACTIONS[1]!,
|
||||
],
|
||||
[autoSettleMenuItems, titleMenuItems],
|
||||
);
|
||||
const legacyMenuActions = useMemo<MenuAction[]>(
|
||||
() => [
|
||||
@@ -727,6 +772,8 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
if (nativeEvent.event === "unsnooze") handleUnsnooze();
|
||||
if (nativeEvent.event === "pin") handlePin();
|
||||
if (nativeEvent.event === "unpin") handleUnpin();
|
||||
if (nativeEvent.event === "auto-settle:enabled") handleSetAutoSettle(true);
|
||||
if (nativeEvent.event === "auto-settle:disabled") handleSetAutoSettle(false);
|
||||
if (nativeEvent.event === "arrange") appAtomRegistry.set(threadArrangementOpenAtom, true);
|
||||
if (nativeEvent.event === "move-up") handleMoveUp();
|
||||
if (nativeEvent.event === "move-down") handleMoveDown();
|
||||
@@ -764,6 +811,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
handlePin,
|
||||
handleSettle,
|
||||
handleSnooze,
|
||||
handleSetAutoSettle,
|
||||
handleUnpin,
|
||||
handleUnsettle,
|
||||
handleUnsnooze,
|
||||
|
||||
@@ -74,6 +74,7 @@ function threadDetailToShell(
|
||||
settledAt: thread.settledAt,
|
||||
unsettledAt: thread.unsettledAt,
|
||||
activeOrderKey: thread.activeOrderKey,
|
||||
autoSettleDisabledAt: thread.autoSettleDisabledAt,
|
||||
pinnedAt: thread.pinnedAt,
|
||||
pinOrderKey: thread.pinOrderKey,
|
||||
snoozedUntil: thread.snoozedUntil ?? null,
|
||||
|
||||
@@ -236,6 +236,7 @@ export const make = Effect.gen(function* () {
|
||||
threadPinning: true,
|
||||
threadPinReorder: true,
|
||||
threadActiveReorder: true,
|
||||
threadAutoSettleOptOut: true,
|
||||
threadTitleRegeneration: true,
|
||||
threadPullRequests: true,
|
||||
pullRequestStackActions: true,
|
||||
|
||||
@@ -633,6 +633,7 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
|
||||
pinnedAt: null,
|
||||
pinOrderKey: null,
|
||||
activeOrderKey: null,
|
||||
autoSettleDisabledAt: null,
|
||||
titleRegenerationRequestId: null,
|
||||
titleRegenerationStartedAt: null,
|
||||
latestUserMessageAt: null,
|
||||
@@ -782,6 +783,21 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
|
||||
return;
|
||||
}
|
||||
|
||||
case "thread.auto-settle-set": {
|
||||
const existingRow = yield* projectionThreadRepository.getById({
|
||||
threadId: event.payload.threadId,
|
||||
});
|
||||
if (Option.isNone(existingRow)) {
|
||||
return;
|
||||
}
|
||||
yield* projectionThreadRepository.upsert({
|
||||
...existingRow.value,
|
||||
autoSettleDisabledAt: event.payload.autoSettleDisabledAt,
|
||||
updatedAt: event.payload.updatedAt,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
case "thread.pin-reordered": {
|
||||
const existingRow = yield* projectionThreadRepository.getById({
|
||||
threadId: event.payload.threadId,
|
||||
|
||||
@@ -485,6 +485,7 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
|
||||
pinnedAt: "2026-02-24T00:00:01.000Z",
|
||||
pinOrderKey: "gm",
|
||||
activeOrderKey: "hq",
|
||||
autoSettleDisabledAt: null,
|
||||
titleRegeneration: null,
|
||||
titleState: null,
|
||||
deletedAt: null,
|
||||
@@ -611,6 +612,7 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
|
||||
pinnedAt: "2026-02-24T00:00:01.000Z",
|
||||
pinOrderKey: "gm",
|
||||
activeOrderKey: "hq",
|
||||
autoSettleDisabledAt: null,
|
||||
titleRegeneration: null,
|
||||
titleState: null,
|
||||
session: {
|
||||
|
||||
@@ -587,6 +587,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
pinned_at AS "pinnedAt",
|
||||
pin_order_key AS "pinOrderKey",
|
||||
active_order_key AS "activeOrderKey",
|
||||
auto_settle_disabled_at AS "autoSettleDisabledAt",
|
||||
title_regeneration_request_id AS "titleRegenerationRequestId",
|
||||
title_regeneration_started_at AS "titleRegenerationStartedAt",
|
||||
latest_user_message_at AS "latestUserMessageAt",
|
||||
@@ -628,6 +629,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
pinned_at AS "pinnedAt",
|
||||
pin_order_key AS "pinOrderKey",
|
||||
active_order_key AS "activeOrderKey",
|
||||
auto_settle_disabled_at AS "autoSettleDisabledAt",
|
||||
title_regeneration_request_id AS "titleRegenerationRequestId",
|
||||
title_regeneration_started_at AS "titleRegenerationStartedAt",
|
||||
latest_user_message_at AS "latestUserMessageAt",
|
||||
@@ -701,6 +703,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
pinned_at AS "pinnedAt",
|
||||
pin_order_key AS "pinOrderKey",
|
||||
active_order_key AS "activeOrderKey",
|
||||
auto_settle_disabled_at AS "autoSettleDisabledAt",
|
||||
title_regeneration_request_id AS "titleRegenerationRequestId",
|
||||
title_regeneration_started_at AS "titleRegenerationStartedAt",
|
||||
latest_user_message_at AS "latestUserMessageAt",
|
||||
@@ -1266,6 +1269,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
pinned_at AS "pinnedAt",
|
||||
pin_order_key AS "pinOrderKey",
|
||||
active_order_key AS "activeOrderKey",
|
||||
auto_settle_disabled_at AS "autoSettleDisabledAt",
|
||||
title_regeneration_request_id AS "titleRegenerationRequestId",
|
||||
title_regeneration_started_at AS "titleRegenerationStartedAt",
|
||||
latest_user_message_at AS "latestUserMessageAt",
|
||||
@@ -2341,6 +2345,7 @@ pending_approval_requests AS (
|
||||
pinnedAt: row.pinnedAt,
|
||||
pinOrderKey: row.pinOrderKey ?? null,
|
||||
activeOrderKey: row.activeOrderKey ?? null,
|
||||
autoSettleDisabledAt: row.autoSettleDisabledAt ?? null,
|
||||
titleRegeneration: mapTitleRegeneration(row),
|
||||
titleState: row.titleState,
|
||||
deletedAt: row.deletedAt,
|
||||
@@ -2586,6 +2591,7 @@ pending_approval_requests AS (
|
||||
pinnedAt: row.pinnedAt,
|
||||
pinOrderKey: row.pinOrderKey ?? null,
|
||||
activeOrderKey: row.activeOrderKey ?? null,
|
||||
autoSettleDisabledAt: row.autoSettleDisabledAt ?? null,
|
||||
titleRegeneration: mapTitleRegeneration(row),
|
||||
titleState: row.titleState,
|
||||
deletedAt: row.deletedAt,
|
||||
@@ -2742,6 +2748,7 @@ pending_approval_requests AS (
|
||||
pinnedAt: row.pinnedAt,
|
||||
pinOrderKey: row.pinOrderKey ?? null,
|
||||
activeOrderKey: row.activeOrderKey ?? null,
|
||||
autoSettleDisabledAt: row.autoSettleDisabledAt ?? null,
|
||||
titleRegeneration: mapTitleRegeneration(row),
|
||||
titleState: row.titleState,
|
||||
session: sessionByThread.get(row.threadId) ?? null,
|
||||
@@ -2905,6 +2912,7 @@ pending_approval_requests AS (
|
||||
pinnedAt: row.pinnedAt,
|
||||
pinOrderKey: row.pinOrderKey ?? null,
|
||||
activeOrderKey: row.activeOrderKey ?? null,
|
||||
autoSettleDisabledAt: row.autoSettleDisabledAt ?? null,
|
||||
titleRegeneration: mapTitleRegeneration(row),
|
||||
titleState: row.titleState,
|
||||
session: sessionByThread.get(row.threadId) ?? null,
|
||||
@@ -3261,6 +3269,7 @@ pending_approval_requests AS (
|
||||
pinnedAt: threadRow.value.pinnedAt,
|
||||
pinOrderKey: threadRow.value.pinOrderKey ?? null,
|
||||
activeOrderKey: threadRow.value.activeOrderKey ?? null,
|
||||
autoSettleDisabledAt: threadRow.value.autoSettleDisabledAt ?? null,
|
||||
titleRegeneration: mapTitleRegeneration(threadRow.value),
|
||||
titleState: threadRow.value.titleState,
|
||||
session: Option.isSome(sessionRow) ? mapSessionRow(sessionRow.value) : null,
|
||||
@@ -3562,6 +3571,7 @@ pending_approval_requests AS (
|
||||
pinnedAt: threadRow.value.pinnedAt,
|
||||
pinOrderKey: threadRow.value.pinOrderKey ?? null,
|
||||
activeOrderKey: threadRow.value.activeOrderKey ?? null,
|
||||
autoSettleDisabledAt: threadRow.value.autoSettleDisabledAt ?? null,
|
||||
titleRegeneration: mapTitleRegeneration(threadRow.value),
|
||||
titleState: threadRow.value.titleState,
|
||||
deletedAt: null,
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
ThreadPinnedPayload as ContractsThreadPinnedPayloadSchema,
|
||||
ThreadUnpinnedPayload as ContractsThreadUnpinnedPayloadSchema,
|
||||
ThreadPinReorderedPayload as ContractsThreadPinReorderedPayloadSchema,
|
||||
ThreadAutoSettleSetPayload as ContractsThreadAutoSettleSetPayloadSchema,
|
||||
ThreadPullRequestLinkedPayload as ContractsThreadPullRequestLinkedPayloadSchema,
|
||||
ThreadPullRequestUnlinkedPayload as ContractsThreadPullRequestUnlinkedPayloadSchema,
|
||||
ThreadPullRequestSyncedPayload as ContractsThreadPullRequestSyncedPayloadSchema,
|
||||
@@ -51,6 +52,7 @@ export const ThreadUnsnoozedPayload = ContractsThreadUnsnoozedPayloadSchema;
|
||||
export const ThreadPinnedPayload = ContractsThreadPinnedPayloadSchema;
|
||||
export const ThreadUnpinnedPayload = ContractsThreadUnpinnedPayloadSchema;
|
||||
export const ThreadPinReorderedPayload = ContractsThreadPinReorderedPayloadSchema;
|
||||
export const ThreadAutoSettleSetPayload = ContractsThreadAutoSettleSetPayloadSchema;
|
||||
export const ThreadPullRequestLinkedPayload = ContractsThreadPullRequestLinkedPayloadSchema;
|
||||
export const ThreadPullRequestUnlinkedPayload = ContractsThreadPullRequestUnlinkedPayloadSchema;
|
||||
export const ThreadPullRequestSyncedPayload = ContractsThreadPullRequestSyncedPayloadSchema;
|
||||
|
||||
@@ -171,6 +171,15 @@ describe("resolveAutoSettlementAt", () => {
|
||||
|
||||
it("blocks pins, snooze, pending work, live sessions, and queued starts", () => {
|
||||
expect(decide(makeThread({ settledOverride: "active" }))).toBe(false);
|
||||
});
|
||||
|
||||
it("never settles a thread whose auto-settle is turned off, by inactivity or merge", () => {
|
||||
const held = makeThread({ autoSettleDisabledAt: "2026-08-21T00:00:00.000Z" });
|
||||
expect(decide(held)).toBe(false);
|
||||
expect(
|
||||
decide(held, { state: "merged", mergedAt: "2026-08-21T00:00:00.000Z", closedAt: null }),
|
||||
).toBe(false);
|
||||
expect(decide(makeThread({ autoSettleDisabledAt: null }))).toBe(true);
|
||||
expect(decide(makeThread({ snoozedUntil: "2026-08-29T00:00:00.000Z" }))).toBe(false);
|
||||
expect(decide(makeThread({ hasPendingApprovals: true }))).toBe(false);
|
||||
expect(decide(makeThread({ hasPendingUserInput: true }))).toBe(false);
|
||||
@@ -248,6 +257,21 @@ const terminalSnapshot = (
|
||||
syncedAt: NOW,
|
||||
});
|
||||
|
||||
describe("per-thread auto-settle opt out", () => {
|
||||
it("blocks both inactivity and merge settlement while auto-settle is off", () => {
|
||||
const merged = linkedRequest(1, terminalSnapshot("merged", NOW));
|
||||
expect(decide(makeThread({ latestUserMessageAt: "2026-08-01T00:00:00.000Z" }))).toBe(true);
|
||||
expect(decide(makeThread({ pullRequests: [merged] }), null, { days: null })).toBe(true);
|
||||
const held = { autoSettleDisabledAt: NOW };
|
||||
expect(decide(makeThread({ ...held, latestUserMessageAt: "2026-08-01T00:00:00.000Z" }))).toBe(
|
||||
false,
|
||||
);
|
||||
expect(decide(makeThread({ ...held, pullRequests: [merged] }), null, { days: null })).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("linked request settlement", () => {
|
||||
it.each(["closed", "merged"] as const)(
|
||||
"uses the latest actual %s transition despite later comments on another PR",
|
||||
|
||||
@@ -117,6 +117,7 @@ export function resolveAutoSettlementAt(input: {
|
||||
/** Cheap checks that run before any source control lookup. */
|
||||
export function isAutoSettlementCandidate(thread: OrchestrationThreadShell, now: string): boolean {
|
||||
if (thread.archivedAt !== null || thread.settledOverride !== null) return false;
|
||||
if (thread.autoSettleDisabledAt != null) return false;
|
||||
if (thread.hasPendingApprovals || thread.hasPendingUserInput) return false;
|
||||
if (thread.session?.status === "starting" || thread.session?.status === "running") return false;
|
||||
if (thread.backgroundLiveness != null) return false;
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
import {
|
||||
CommandId,
|
||||
ProjectId,
|
||||
ProviderInstanceId,
|
||||
ThreadId,
|
||||
type OrchestrationReadModel,
|
||||
} from "@t3tools/contracts";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { expect, it } from "@effect/vitest";
|
||||
import * as Effect from "effect/Effect";
|
||||
|
||||
import { decideOrchestrationCommand } from "./decider.ts";
|
||||
|
||||
const NOW = "2026-01-01T00:00:00.000Z";
|
||||
const DISABLED_AT = "2025-12-30T00:00:00.000Z";
|
||||
|
||||
function makeReadModel(input: {
|
||||
readonly autoSettleDisabledAt?: string | null;
|
||||
readonly settledOverride?: "settled" | "active" | null;
|
||||
}): OrchestrationReadModel {
|
||||
return {
|
||||
snapshotSequence: 0,
|
||||
projects: [],
|
||||
threads: [
|
||||
{
|
||||
id: ThreadId.make("thread-1"),
|
||||
projectId: ProjectId.make("project-1"),
|
||||
title: "Thread",
|
||||
modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" },
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
pullRequests: [],
|
||||
latestTurn: null,
|
||||
createdAt: NOW,
|
||||
updatedAt: NOW,
|
||||
archivedAt: null,
|
||||
settledOverride: input.settledOverride ?? null,
|
||||
settledAt: input.settledOverride === "settled" ? NOW : null,
|
||||
autoSettleDisabledAt: input.autoSettleDisabledAt ?? null,
|
||||
deletedAt: null,
|
||||
messages: [],
|
||||
proposedPlans: [],
|
||||
activities: [],
|
||||
checkpoints: [],
|
||||
session: null,
|
||||
},
|
||||
],
|
||||
updatedAt: NOW,
|
||||
};
|
||||
}
|
||||
|
||||
const events = (event: Effect.Success<ReturnType<typeof decideOrchestrationCommand>>) =>
|
||||
Array.isArray(event) ? event : [event];
|
||||
|
||||
it.layer(NodeServices.layer)("thread.auto-settle.set decider", (it) => {
|
||||
it.effect("turning auto-settle off stamps autoSettleDisabledAt and updatedAt together", () =>
|
||||
Effect.gen(function* () {
|
||||
const [event] = events(
|
||||
yield* decideOrchestrationCommand({
|
||||
command: {
|
||||
type: "thread.auto-settle.set",
|
||||
commandId: CommandId.make("cmd-off"),
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
enabled: false,
|
||||
},
|
||||
readModel: makeReadModel({}),
|
||||
}),
|
||||
);
|
||||
expect(event?.type).toBe("thread.auto-settle-set");
|
||||
if (event?.type === "thread.auto-settle-set") {
|
||||
expect(event.payload.autoSettleDisabledAt).toBe(event.payload.updatedAt);
|
||||
expect(event.payload.updatedAt).not.toBe(NOW);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("turning it off again keeps the original stamp and updatedAt", () =>
|
||||
Effect.gen(function* () {
|
||||
const [event] = events(
|
||||
yield* decideOrchestrationCommand({
|
||||
command: {
|
||||
type: "thread.auto-settle.set",
|
||||
commandId: CommandId.make("cmd-off-again"),
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
enabled: false,
|
||||
},
|
||||
readModel: makeReadModel({ autoSettleDisabledAt: DISABLED_AT }),
|
||||
}),
|
||||
);
|
||||
expect(event?.type).toBe("thread.auto-settle-set");
|
||||
if (event?.type === "thread.auto-settle-set") {
|
||||
expect(event.payload.autoSettleDisabledAt).toBe(DISABLED_AT);
|
||||
expect(event.payload.updatedAt).toBe(NOW);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("turning auto-settle back on clears the stamp", () =>
|
||||
Effect.gen(function* () {
|
||||
const [event] = events(
|
||||
yield* decideOrchestrationCommand({
|
||||
command: {
|
||||
type: "thread.auto-settle.set",
|
||||
commandId: CommandId.make("cmd-on"),
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
enabled: true,
|
||||
},
|
||||
readModel: makeReadModel({ autoSettleDisabledAt: DISABLED_AT }),
|
||||
}),
|
||||
);
|
||||
expect(event?.type).toBe("thread.auto-settle-set");
|
||||
if (event?.type === "thread.auto-settle-set") {
|
||||
expect(event.payload.autoSettleDisabledAt).toBeNull();
|
||||
expect(event.payload.updatedAt).not.toBe(NOW);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("automatic settlement is rejected while auto-settle is off", () =>
|
||||
Effect.gen(function* () {
|
||||
const result = yield* Effect.exit(
|
||||
decideOrchestrationCommand({
|
||||
command: {
|
||||
type: "thread.auto-settle",
|
||||
commandId: CommandId.make("cmd-auto"),
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
snapshotSequence: 0,
|
||||
settledAt: NOW,
|
||||
},
|
||||
readModel: makeReadModel({ autoSettleDisabledAt: DISABLED_AT }),
|
||||
}),
|
||||
);
|
||||
expect(result._tag).toBe("Failure");
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("a manual settle still works while auto-settle is off", () =>
|
||||
Effect.gen(function* () {
|
||||
const [event] = events(
|
||||
yield* decideOrchestrationCommand({
|
||||
command: {
|
||||
type: "thread.settle",
|
||||
commandId: CommandId.make("cmd-manual"),
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
},
|
||||
readModel: makeReadModel({ autoSettleDisabledAt: DISABLED_AT }),
|
||||
}),
|
||||
);
|
||||
expect(event?.type).toBe("thread.settled");
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -484,7 +484,10 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
command,
|
||||
threadId: command.threadId,
|
||||
});
|
||||
if (command.type === "thread.auto-settle" && thread.settledOverride !== null) {
|
||||
if (
|
||||
command.type === "thread.auto-settle" &&
|
||||
(thread.settledOverride !== null || thread.autoSettleDisabledAt != null)
|
||||
) {
|
||||
return yield* Effect.fail(
|
||||
new OrchestrationCommandInvariantError({
|
||||
commandType: command.type,
|
||||
@@ -860,6 +863,37 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
};
|
||||
}
|
||||
|
||||
case "thread.auto-settle.set": {
|
||||
const thread = yield* requireThreadNotArchived({
|
||||
readModel,
|
||||
command,
|
||||
threadId: command.threadId,
|
||||
});
|
||||
// Idempotent by re-emission (see thread.unpin): setting the current
|
||||
// state again keeps the existing timestamps so duplicates do not churn
|
||||
// ordering. The flag is independent of the settled lifecycle: it only
|
||||
// gates the automatic paths, so it never blocks a manual settle.
|
||||
const currentlyDisabledAt = thread.autoSettleDisabledAt ?? null;
|
||||
const unchanged = command.enabled
|
||||
? currentlyDisabledAt === null
|
||||
: currentlyDisabledAt !== null;
|
||||
const occurredAt = yield* nowIso;
|
||||
return {
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt,
|
||||
commandId: command.commandId,
|
||||
})),
|
||||
type: "thread.auto-settle-set",
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
autoSettleDisabledAt: command.enabled ? null : (currentlyDisabledAt ?? occurredAt),
|
||||
updatedAt: unchanged ? thread.updatedAt : occurredAt,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
case "thread.active.reorder": {
|
||||
const thread = yield* requireThreadNotArchived({
|
||||
readModel,
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
import {
|
||||
CommandId,
|
||||
EventId,
|
||||
ProjectId,
|
||||
ThreadId,
|
||||
type OrchestrationEvent,
|
||||
} from "@t3tools/contracts";
|
||||
import { expect, it } from "@effect/vitest";
|
||||
import * as Effect from "effect/Effect";
|
||||
|
||||
import { createEmptyReadModel, projectEvent } from "./projector.ts";
|
||||
|
||||
function makeEvent(input: {
|
||||
readonly sequence: number;
|
||||
readonly type: OrchestrationEvent["type"];
|
||||
readonly payload: unknown;
|
||||
}): OrchestrationEvent {
|
||||
return {
|
||||
sequence: input.sequence,
|
||||
eventId: EventId.make(`event-${input.sequence}`),
|
||||
type: input.type,
|
||||
aggregateKind: "thread",
|
||||
aggregateId: ThreadId.make("thread-1"),
|
||||
occurredAt: "2026-01-01T00:00:00.000Z",
|
||||
commandId: CommandId.make(`command-${input.sequence}`),
|
||||
causationEventId: null,
|
||||
correlationId: null,
|
||||
metadata: {},
|
||||
payload: input.payload as never,
|
||||
} as OrchestrationEvent;
|
||||
}
|
||||
|
||||
it.effect("projects auto-settle opt-out and survives a manual settle", () =>
|
||||
Effect.gen(function* () {
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
const later = "2026-01-02T00:00:00.000Z";
|
||||
const created = yield* projectEvent(
|
||||
createEmptyReadModel(now),
|
||||
makeEvent({
|
||||
sequence: 1,
|
||||
type: "thread.created",
|
||||
payload: {
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
projectId: ProjectId.make("project-1"),
|
||||
title: "Thread",
|
||||
modelSelection: { provider: "codex", model: "gpt-5.4" },
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(created.threads[0]?.autoSettleDisabledAt ?? null).toBeNull();
|
||||
|
||||
const disabled = yield* projectEvent(
|
||||
created,
|
||||
makeEvent({
|
||||
sequence: 2,
|
||||
type: "thread.auto-settle-set",
|
||||
payload: { threadId: ThreadId.make("thread-1"), autoSettleDisabledAt: now, updatedAt: now },
|
||||
}),
|
||||
);
|
||||
expect(disabled.threads[0]?.autoSettleDisabledAt).toBe(now);
|
||||
|
||||
// The flag is independent of the settled lifecycle: settling by hand and
|
||||
// un-settling later must not clear it.
|
||||
const settled = yield* projectEvent(
|
||||
disabled,
|
||||
makeEvent({
|
||||
sequence: 3,
|
||||
type: "thread.settled",
|
||||
payload: { threadId: ThreadId.make("thread-1"), settledAt: later, updatedAt: later },
|
||||
}),
|
||||
);
|
||||
expect(settled.threads[0]?.settledOverride).toBe("settled");
|
||||
expect(settled.threads[0]?.autoSettleDisabledAt).toBe(now);
|
||||
|
||||
const unsettled = yield* projectEvent(
|
||||
settled,
|
||||
makeEvent({
|
||||
sequence: 4,
|
||||
type: "thread.unsettled",
|
||||
payload: { threadId: ThreadId.make("thread-1"), reason: "user", updatedAt: later },
|
||||
}),
|
||||
);
|
||||
expect(unsettled.threads[0]?.autoSettleDisabledAt).toBe(now);
|
||||
|
||||
const enabled = yield* projectEvent(
|
||||
unsettled,
|
||||
makeEvent({
|
||||
sequence: 5,
|
||||
type: "thread.auto-settle-set",
|
||||
payload: {
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
autoSettleDisabledAt: null,
|
||||
updatedAt: later,
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(enabled.threads[0]?.autoSettleDisabledAt).toBeNull();
|
||||
}),
|
||||
);
|
||||
@@ -93,6 +93,7 @@ describe("orchestration projector", () => {
|
||||
updatedAt: now,
|
||||
archivedAt: null,
|
||||
activeOrderKey: null,
|
||||
autoSettleDisabledAt: null,
|
||||
settledOverride: null,
|
||||
settledAt: null,
|
||||
unsettledAt: null,
|
||||
|
||||
@@ -42,6 +42,7 @@ import {
|
||||
ThreadSettledPayload,
|
||||
ThreadPinnedPayload,
|
||||
ThreadPinReorderedPayload,
|
||||
ThreadAutoSettleSetPayload,
|
||||
ThreadPullRequestLinkedPayload,
|
||||
ThreadPullRequestSyncedPayload,
|
||||
ThreadPullRequestUnlinkedPayload,
|
||||
@@ -440,6 +441,7 @@ export function projectEvent(
|
||||
settledAt: null,
|
||||
unsettledAt: null,
|
||||
activeOrderKey: null,
|
||||
autoSettleDisabledAt: null,
|
||||
snoozedUntil: null,
|
||||
snoozedAt: null,
|
||||
deletedAt: null,
|
||||
@@ -580,6 +582,17 @@ export function projectEvent(
|
||||
})),
|
||||
);
|
||||
|
||||
case "thread.auto-settle-set":
|
||||
return decodeForEvent(ThreadAutoSettleSetPayload, event.payload, event.type, "payload").pipe(
|
||||
Effect.map((payload) => ({
|
||||
...nextBase,
|
||||
threads: updateThread(nextBase.threads, payload.threadId, {
|
||||
autoSettleDisabledAt: payload.autoSettleDisabledAt,
|
||||
updatedAt: payload.updatedAt,
|
||||
}),
|
||||
})),
|
||||
);
|
||||
|
||||
case "thread.pin-reordered":
|
||||
return decodeForEvent(ThreadPinReorderedPayload, event.payload, event.type, "payload").pipe(
|
||||
Effect.map((payload) => ({
|
||||
|
||||
@@ -54,6 +54,7 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
|
||||
pinned_at,
|
||||
pin_order_key,
|
||||
active_order_key,
|
||||
auto_settle_disabled_at,
|
||||
title_regeneration_request_id,
|
||||
title_regeneration_started_at,
|
||||
latest_user_message_at,
|
||||
@@ -86,6 +87,7 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
|
||||
${row.pinnedAt},
|
||||
${row.pinOrderKey ?? null},
|
||||
${row.activeOrderKey ?? null},
|
||||
${row.autoSettleDisabledAt ?? null},
|
||||
${row.titleRegenerationRequestId ?? null},
|
||||
${row.titleRegenerationStartedAt ?? null},
|
||||
${row.latestUserMessageAt},
|
||||
@@ -118,6 +120,7 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
|
||||
pinned_at = excluded.pinned_at,
|
||||
pin_order_key = excluded.pin_order_key,
|
||||
active_order_key = excluded.active_order_key,
|
||||
auto_settle_disabled_at = excluded.auto_settle_disabled_at,
|
||||
title_regeneration_request_id = excluded.title_regeneration_request_id,
|
||||
title_regeneration_started_at = excluded.title_regeneration_started_at,
|
||||
latest_user_message_at = excluded.latest_user_message_at,
|
||||
@@ -157,6 +160,7 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
|
||||
pinned_at AS "pinnedAt",
|
||||
pin_order_key AS "pinOrderKey",
|
||||
active_order_key AS "activeOrderKey",
|
||||
auto_settle_disabled_at AS "autoSettleDisabledAt",
|
||||
title_regeneration_request_id AS "titleRegenerationRequestId",
|
||||
title_regeneration_started_at AS "titleRegenerationStartedAt",
|
||||
latest_user_message_at AS "latestUserMessageAt",
|
||||
|
||||
@@ -65,6 +65,7 @@ import Migration0050 from "./Migrations/050_ProjectionThreadPullRequests.ts";
|
||||
import Migration0051 from "./Migrations/051_ProjectionThreadMessageContext.ts";
|
||||
import Migration0052 from "./Migrations/052_ProjectionThreadTitleState.ts";
|
||||
import Migration0053 from "./Migrations/053_PullRequestFilesViewed.ts";
|
||||
import Migration0054 from "./Migrations/054_ProjectionThreadsAutoSettleDisabledAt.ts";
|
||||
|
||||
/**
|
||||
* Migration loader with all migrations defined inline.
|
||||
@@ -130,6 +131,7 @@ const migrationEntries = [
|
||||
[51, "ProjectionThreadMessageContext", Migration0051],
|
||||
[52, "ProjectionThreadTitleState", Migration0052],
|
||||
[53, "PullRequestFilesViewed", Migration0053],
|
||||
[54, "ProjectionThreadsAutoSettleDisabledAt", Migration0054],
|
||||
] as const;
|
||||
|
||||
export const migrationManifest = migrationEntries.map(([id, name]) => [id, name] as const);
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
|
||||
|
||||
import { runMigrations } from "../Migrations.ts";
|
||||
import migrateAutoSettleDisabledAt from "./054_ProjectionThreadsAutoSettleDisabledAt.ts";
|
||||
|
||||
it.layer(NodeSqliteClient.layer({ filename: ":memory:" }))(
|
||||
"054_ProjectionThreadsAutoSettleDisabledAt",
|
||||
(it) => {
|
||||
it.effect("adds the column with auto-settle left on for existing threads", () =>
|
||||
Effect.gen(function* () {
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
yield* runMigrations({ toMigrationInclusive: 53 });
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
yield* sql`
|
||||
INSERT INTO projection_threads (
|
||||
thread_id, project_id, title, model_selection_json, runtime_mode,
|
||||
created_at, updated_at
|
||||
) VALUES (
|
||||
'thread-1', 'project-1', 'Existing thread',
|
||||
'{"instanceId":"codex","model":"gpt-5.4"}', 'full-access', ${now}, ${now}
|
||||
)
|
||||
`;
|
||||
yield* runMigrations({ toMigrationInclusive: 54 });
|
||||
const migrated = yield* sql<{ readonly autoSettleDisabledAt: string | null }>`
|
||||
SELECT auto_settle_disabled_at AS "autoSettleDisabledAt" FROM projection_threads WHERE thread_id = 'thread-1'
|
||||
`;
|
||||
assert.deepEqual(migrated, [{ autoSettleDisabledAt: null }]);
|
||||
// Re-running against a database that already has the column keeps its value.
|
||||
yield* sql`UPDATE projection_threads SET auto_settle_disabled_at = ${now} WHERE thread_id = 'thread-1'`;
|
||||
yield* migrateAutoSettleDisabledAt;
|
||||
const rows = yield* sql<{ readonly autoSettleDisabledAt: string | null }>`
|
||||
SELECT auto_settle_disabled_at AS "autoSettleDisabledAt" FROM projection_threads WHERE thread_id = 'thread-1'
|
||||
`;
|
||||
assert.deepEqual(rows, [{ autoSettleDisabledAt: now }]);
|
||||
}),
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,15 @@
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
|
||||
export default Effect.gen(function* () {
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
const columns = yield* sql<{ readonly name: string }>`
|
||||
PRAGMA table_info(projection_threads)
|
||||
`;
|
||||
if (!columns.some((column) => column.name === "auto_settle_disabled_at")) {
|
||||
yield* sql`
|
||||
ALTER TABLE projection_threads
|
||||
ADD COLUMN auto_settle_disabled_at TEXT
|
||||
`;
|
||||
}
|
||||
});
|
||||
@@ -50,6 +50,7 @@ export const ProjectionThread = Schema.Struct({
|
||||
pinnedAt: Schema.NullOr(IsoDateTime),
|
||||
pinOrderKey: Schema.optional(Schema.NullOr(Schema.String)),
|
||||
activeOrderKey: Schema.optional(Schema.NullOr(Schema.String)),
|
||||
autoSettleDisabledAt: Schema.optional(Schema.NullOr(IsoDateTime)),
|
||||
titleRegenerationRequestId: Schema.optional(Schema.NullOr(CommandId)),
|
||||
titleRegenerationStartedAt: Schema.optional(Schema.NullOr(IsoDateTime)),
|
||||
latestUserMessageAt: Schema.NullOr(IsoDateTime),
|
||||
|
||||
@@ -87,6 +87,7 @@ function hasImportBlockingActivity(
|
||||
thread.snoozedAt != null ||
|
||||
thread.pinnedAt != null ||
|
||||
thread.pinOrderKey != null ||
|
||||
thread.autoSettleDisabledAt != null ||
|
||||
thread.titleRegeneration != null ||
|
||||
thread.linkedPullRequest != null ||
|
||||
thread.unsettledAt != null ||
|
||||
|
||||
@@ -2154,6 +2154,7 @@ export default function Sidebar() {
|
||||
confirmAndUnpinThread,
|
||||
reorderPinnedThread,
|
||||
reorderActiveThread,
|
||||
setThreadAutoSettle,
|
||||
archiveThread,
|
||||
deleteThread,
|
||||
} = useThreadActions();
|
||||
@@ -4020,6 +4021,9 @@ export default function Sidebar() {
|
||||
serverConfigs.get(thread.environmentId)?.environment.capabilities.threadSnooze === true;
|
||||
const supportsPinning =
|
||||
serverConfigs.get(thread.environmentId)?.environment.capabilities.threadPinning === true;
|
||||
const supportsAutoSettleOptOut =
|
||||
serverConfigs.get(thread.environmentId)?.environment.capabilities
|
||||
.threadAutoSettleOptOut === true;
|
||||
const supportsTitleRegeneration =
|
||||
serverConfigs.get(thread.environmentId)?.environment.capabilities
|
||||
.threadTitleRegeneration === true;
|
||||
@@ -4049,6 +4053,7 @@ export default function Sidebar() {
|
||||
: null,
|
||||
isPinned,
|
||||
isSettled,
|
||||
autoSettleEnabled: thread.autoSettleDisabledAt == null,
|
||||
isSnoozed,
|
||||
canSnoozeNow: canSnooze(thread, { now: new Date().toISOString() }),
|
||||
isRegeneratingTitle,
|
||||
@@ -4056,6 +4061,7 @@ export default function Sidebar() {
|
||||
thread.session?.status === "running" && thread.session.activeTurnId != null,
|
||||
supports: {
|
||||
settlement: supportsSettlement,
|
||||
autoSettleOptOut: supportsAutoSettleOptOut,
|
||||
snooze: supportsSnooze,
|
||||
pinning: supportsPinning,
|
||||
titleRegeneration: supportsTitleRegeneration,
|
||||
@@ -4127,6 +4133,24 @@ export default function Sidebar() {
|
||||
case "unpin":
|
||||
attemptUnpin(threadRef);
|
||||
return;
|
||||
case "auto-settle:enabled":
|
||||
case "auto-settle:disabled": {
|
||||
const result = await setThreadAutoSettle(
|
||||
threadRef,
|
||||
clicked.value === "auto-settle:enabled",
|
||||
);
|
||||
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
|
||||
const error = squashAtomCommandFailure(result);
|
||||
toastManager.add(
|
||||
stackedThreadToast({
|
||||
type: "error",
|
||||
title: "Failed to update auto-settle",
|
||||
description: error instanceof Error ? error.message : "An error occurred.",
|
||||
}),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
case "rename":
|
||||
startThreadRename(threadRef, thread.title);
|
||||
return;
|
||||
@@ -4253,6 +4277,7 @@ export default function Sidebar() {
|
||||
projectByKey,
|
||||
serverConfigs,
|
||||
setProjectScopeKey,
|
||||
setThreadAutoSettle,
|
||||
startThreadRename,
|
||||
updateThreadMetadata,
|
||||
timestampFormat,
|
||||
|
||||
@@ -7,11 +7,18 @@ const baseState: ThreadActionMenuState = {
|
||||
projectFilter: null,
|
||||
isPinned: false,
|
||||
isSettled: false,
|
||||
autoSettleEnabled: true,
|
||||
isSnoozed: false,
|
||||
canSnoozeNow: true,
|
||||
isRegeneratingTitle: false,
|
||||
isRunning: false,
|
||||
supports: { settlement: true, snooze: true, pinning: true, titleRegeneration: true },
|
||||
supports: {
|
||||
settlement: true,
|
||||
autoSettleOptOut: true,
|
||||
snooze: true,
|
||||
pinning: true,
|
||||
titleRegeneration: true,
|
||||
},
|
||||
snoozePresets: [
|
||||
{ id: "hour", label: "In 1 hour", whenLabel: "3:00 PM", snoozedUntil: "2026-08-07T15:00:00Z" },
|
||||
],
|
||||
@@ -32,7 +39,13 @@ describe("buildThreadActionMenuItems", () => {
|
||||
expect(
|
||||
ids({
|
||||
...baseState,
|
||||
supports: { settlement: false, snooze: false, pinning: false, titleRegeneration: false },
|
||||
supports: {
|
||||
settlement: false,
|
||||
autoSettleOptOut: false,
|
||||
snooze: false,
|
||||
pinning: false,
|
||||
titleRegeneration: false,
|
||||
},
|
||||
}),
|
||||
).toEqual(["rename", "mark-unread", "copy", "project-settings", "archive", "delete"]);
|
||||
});
|
||||
@@ -66,7 +79,7 @@ describe("buildThreadActionMenuItems", () => {
|
||||
const filterIndex = items.findIndex((candidate) => candidate.id === "filter-by-project");
|
||||
expect(items[filterIndex]).toMatchObject({ label: "Show all projects", icon: "folder-tree" });
|
||||
expect(items[filterIndex - 1]?.id).toBe("mark-unread");
|
||||
expect(items[filterIndex + 1]?.id).toBe("copy");
|
||||
expect(items[filterIndex + 1]?.id).toBe("auto-settle");
|
||||
});
|
||||
|
||||
it("includes branch items only for threads with a branch", () => {
|
||||
@@ -84,6 +97,25 @@ describe("buildThreadActionMenuItems", () => {
|
||||
expect(ids(baseState)).toEqual(expect.arrayContaining(["pin", "settle", "snooze"]));
|
||||
});
|
||||
|
||||
it("offers auto-settle as a submenu with the current option checked", () => {
|
||||
const find = (state: ThreadActionMenuState) =>
|
||||
buildThreadActionMenuItems(state).find((item) => item.id === "auto-settle");
|
||||
const on = find(baseState);
|
||||
expect(on?.label).toBe("Auto-settle behavior");
|
||||
expect(on?.children?.map((child) => [child.id, child.checked])).toEqual([
|
||||
["auto-settle:enabled", true],
|
||||
["auto-settle:disabled", false],
|
||||
]);
|
||||
const off = find({ ...baseState, autoSettleEnabled: false });
|
||||
expect(off?.children?.map((child) => child.checked)).toEqual([false, true]);
|
||||
// Sits with the per-thread settings after Mark unread, not the lifecycle verbs.
|
||||
const items = buildThreadActionMenuItems(baseState);
|
||||
expect(items[items.findIndex((item) => item.id === "mark-unread") + 1]?.id).toBe("auto-settle");
|
||||
expect(
|
||||
ids({ ...baseState, supports: { ...baseState.supports, autoSettleOptOut: false } }),
|
||||
).not.toContain("auto-settle");
|
||||
});
|
||||
|
||||
it("disables snooze when the thread cannot snooze, keeping presets visible", () => {
|
||||
const snooze = buildThreadActionMenuItems({ ...baseState, canSnoozeNow: false }).find(
|
||||
(item) => item.id === "snooze",
|
||||
@@ -117,7 +149,13 @@ describe("buildThreadActionMenuItems", () => {
|
||||
expect(
|
||||
ids({
|
||||
...baseState,
|
||||
supports: { settlement: false, snooze: false, pinning: false, titleRegeneration: false },
|
||||
supports: {
|
||||
settlement: false,
|
||||
autoSettleOptOut: false,
|
||||
snooze: false,
|
||||
pinning: false,
|
||||
titleRegeneration: false,
|
||||
},
|
||||
}),
|
||||
).toContain("archive");
|
||||
});
|
||||
|
||||
@@ -14,6 +14,9 @@ export type ThreadActionMenuId =
|
||||
| "unpin"
|
||||
| "settle"
|
||||
| "unsettle"
|
||||
| "auto-settle"
|
||||
| "auto-settle:enabled"
|
||||
| "auto-settle:disabled"
|
||||
| "snooze"
|
||||
| `snooze:${string}`
|
||||
| "unsnooze"
|
||||
@@ -40,6 +43,8 @@ export interface ThreadActionMenuState {
|
||||
} | null;
|
||||
readonly isPinned: boolean;
|
||||
readonly isSettled: boolean;
|
||||
/** False while the user has turned automatic settlement off for this thread. */
|
||||
readonly autoSettleEnabled: boolean;
|
||||
readonly isSnoozed: boolean;
|
||||
readonly canSnoozeNow: boolean;
|
||||
readonly isRegeneratingTitle: boolean;
|
||||
@@ -47,6 +52,8 @@ export interface ThreadActionMenuState {
|
||||
readonly isRunning: boolean;
|
||||
readonly supports: {
|
||||
readonly settlement: boolean;
|
||||
/** Server understands thread.auto-settle.set. */
|
||||
readonly autoSettleOptOut: boolean;
|
||||
readonly snooze: boolean;
|
||||
readonly pinning: boolean;
|
||||
readonly titleRegeneration: boolean;
|
||||
@@ -131,6 +138,31 @@ export function buildThreadActionMenuItems(
|
||||
},
|
||||
]
|
||||
: []),
|
||||
// A submenu with the current option checked, not a one-shot action:
|
||||
// this is a setting, and it sits with the other per-thread settings
|
||||
// rather than the lifecycle verbs above. Disabled keeps long-running
|
||||
// threads out of the settled shelf no matter how quiet they get.
|
||||
...(state.supports.autoSettleOptOut
|
||||
? [
|
||||
{
|
||||
id: "auto-settle" as const,
|
||||
label: "Auto-settle behavior",
|
||||
icon: "timer",
|
||||
children: [
|
||||
{
|
||||
id: "auto-settle:enabled" as const,
|
||||
label: "Enabled",
|
||||
checked: state.autoSettleEnabled,
|
||||
},
|
||||
{
|
||||
id: "auto-settle:disabled" as const,
|
||||
label: "Disabled",
|
||||
checked: !state.autoSettleEnabled,
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
id: "copy",
|
||||
label: "Copy",
|
||||
|
||||
@@ -9,6 +9,12 @@ const ICON_PATHS: Record<string, ReadonlyArray<{ tag: string; attrs: Record<stri
|
||||
{ tag: "path", attrs: { d: "M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8" } },
|
||||
{ tag: "path", attrs: { d: "M10 12h4" } },
|
||||
],
|
||||
check: [{ tag: "path", attrs: { d: "M20 6 9 17l-5-5" } }],
|
||||
timer: [
|
||||
{ tag: "line", attrs: { x1: "10", x2: "14", y1: "2", y2: "2" } },
|
||||
{ tag: "line", attrs: { x1: "12", x2: "15", y1: "14", y2: "11" } },
|
||||
{ tag: "circle", attrs: { cx: "12", cy: "14", r: "8" } },
|
||||
],
|
||||
"chevron-right": [{ tag: "path", attrs: { d: "m9 19 7-7-7-7" } }],
|
||||
"circle-check": [
|
||||
{ tag: "circle", attrs: { cx: "12", cy: "12", r: "10" } },
|
||||
@@ -347,7 +353,22 @@ export function showContextMenuFallback<T extends string>(
|
||||
button.style.pointerEvents = "none";
|
||||
}
|
||||
|
||||
if (typeof item.icon === "string") {
|
||||
if (typeof item.checked === "boolean") {
|
||||
// Option rows use the icon slot for the check so labels line up
|
||||
// with icon rows. The unselected option keeps the slot empty.
|
||||
button.setAttribute("role", "menuitemradio");
|
||||
button.setAttribute("aria-checked", item.checked ? "true" : "false");
|
||||
const check = item.checked ? createIconElement("check", "neutral") : null;
|
||||
if (check) {
|
||||
button.appendChild(check);
|
||||
} else {
|
||||
const spacer = document.createElement("span");
|
||||
spacer.className = "size-4.5 shrink-0 sm:size-4";
|
||||
spacer.style.cssText = "display:inline-block;width:1rem;height:1rem;flex-shrink:0;";
|
||||
spacer.setAttribute("aria-hidden", "true");
|
||||
button.appendChild(spacer);
|
||||
}
|
||||
} else if (typeof item.icon === "string") {
|
||||
const icon = createIconElement(item.icon, isLeafDestructive ? "destructive" : "neutral");
|
||||
if (icon) {
|
||||
button.appendChild(icon);
|
||||
|
||||
@@ -20,6 +20,7 @@ import { stackedThreadToast, toastManager } from "../components/ui/toast";
|
||||
import { threadEnvironment } from "../state/threads";
|
||||
import { useAtomCommand } from "../state/use-atom-command";
|
||||
import {
|
||||
readEnvironmentSupportsAutoSettleOptOut,
|
||||
readEnvironmentSupportsPinning,
|
||||
readEnvironmentSupportsSettlement,
|
||||
readEnvironmentSupportsSnooze,
|
||||
@@ -88,6 +89,7 @@ export function useThreadActionMenu(input: {
|
||||
unsnoozeThread,
|
||||
pinThread,
|
||||
confirmAndUnpinThread,
|
||||
setThreadAutoSettle,
|
||||
archiveThread,
|
||||
deleteThread,
|
||||
} = useThreadActions();
|
||||
@@ -132,6 +134,7 @@ export function useThreadActionMenu(input: {
|
||||
const now = new Date();
|
||||
const supports = {
|
||||
settlement: readEnvironmentSupportsSettlement(threadRef.environmentId),
|
||||
autoSettleOptOut: readEnvironmentSupportsAutoSettleOptOut(threadRef.environmentId),
|
||||
snooze: readEnvironmentSupportsSnooze(threadRef.environmentId),
|
||||
pinning: readEnvironmentSupportsPinning(threadRef.environmentId),
|
||||
titleRegeneration: readEnvironmentSupportsTitleRegeneration(threadRef.environmentId),
|
||||
@@ -145,6 +148,7 @@ export function useThreadActionMenu(input: {
|
||||
projectFilter: null,
|
||||
isPinned: thread.pinnedAt != null,
|
||||
isSettled: supports.settlement && thread.settledOverride === "settled",
|
||||
autoSettleEnabled: thread.autoSettleDisabledAt == null,
|
||||
isSnoozed: supports.snooze && effectiveSnoozed(thread, { now: now.toISOString() }),
|
||||
canSnoozeNow: canSnooze(thread, { now: now.toISOString() }),
|
||||
isRegeneratingTitle,
|
||||
@@ -225,6 +229,12 @@ export function useThreadActionMenu(input: {
|
||||
await reportFailure("Failed to unpin thread", () => confirmAndUnpinThread(threadRef));
|
||||
return;
|
||||
}
|
||||
case "auto-settle:enabled":
|
||||
case "auto-settle:disabled":
|
||||
await reportFailure("Failed to update auto-settle", () =>
|
||||
setThreadAutoSettle(threadRef, action === "auto-settle:enabled"),
|
||||
);
|
||||
return;
|
||||
case "rename":
|
||||
onStartRename();
|
||||
return;
|
||||
@@ -333,6 +343,7 @@ export function useThreadActionMenu(input: {
|
||||
projectGroupingSettings,
|
||||
projects,
|
||||
router,
|
||||
setThreadAutoSettle,
|
||||
settleThread,
|
||||
snoozeThread,
|
||||
threadRef,
|
||||
|
||||
@@ -26,6 +26,7 @@ import { refreshArchivedThreadsForEnvironment } from "../lib/archivedThreadsStat
|
||||
import { releaseComposerDraftUploads } from "../lib/composerDraftUploads";
|
||||
import { readLocalApi } from "../localApi";
|
||||
import {
|
||||
readEnvironmentSupportsAutoSettleOptOut,
|
||||
readEnvironmentSupportsPinning,
|
||||
readEnvironmentSupportsPinReorder,
|
||||
readEnvironmentSupportsActiveReorder,
|
||||
@@ -106,6 +107,18 @@ function topOfPinnedRunOrderKey(): string | undefined {
|
||||
return pinOrderKeyBetween(null, firstKey) ?? undefined;
|
||||
}
|
||||
|
||||
export class ThreadAutoSettleOptOutUnsupportedError extends Schema.TaggedError<ThreadAutoSettleOptOutUnsupportedError>()(
|
||||
"ThreadAutoSettleOptOutUnsupportedError",
|
||||
{
|
||||
environmentId: EnvironmentId,
|
||||
threadId: ThreadId,
|
||||
},
|
||||
) {
|
||||
override get message(): string {
|
||||
return "This environment's server does not support turning auto-settle off per thread yet. Update the server to use it.";
|
||||
}
|
||||
}
|
||||
|
||||
export class ThreadPinningUnsupportedError extends Schema.TaggedError<ThreadPinningUnsupportedError>()(
|
||||
"ThreadPinningUnsupportedError",
|
||||
{
|
||||
@@ -200,6 +213,9 @@ export function useThreadActions() {
|
||||
const unpinThreadMutation = useAtomCommand(threadEnvironment.unpin, {
|
||||
reportFailure: false,
|
||||
});
|
||||
const setThreadAutoSettleMutation = useAtomCommand(threadEnvironment.setAutoSettle, {
|
||||
reportFailure: false,
|
||||
});
|
||||
const reorderPinnedThreadMutation = useAtomCommand(threadEnvironment.reorderPin, {
|
||||
reportFailure: false,
|
||||
});
|
||||
@@ -556,6 +572,27 @@ export function useThreadActions() {
|
||||
[unsettleThreadMutation],
|
||||
);
|
||||
|
||||
/** Turns automatic settlement (inactivity, merged PR) on or off for one thread. */
|
||||
const setThreadAutoSettle = useCallback(
|
||||
async (target: ScopedThreadRef, enabled: boolean) => {
|
||||
if (!readEnvironmentSupportsAutoSettleOptOut(target.environmentId)) {
|
||||
return AsyncResult.failure(
|
||||
Cause.fail(
|
||||
new ThreadAutoSettleOptOutUnsupportedError({
|
||||
environmentId: target.environmentId,
|
||||
threadId: target.threadId,
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
return setThreadAutoSettleMutation({
|
||||
environmentId: target.environmentId,
|
||||
input: { threadId: target.threadId, enabled },
|
||||
});
|
||||
},
|
||||
[setThreadAutoSettleMutation],
|
||||
);
|
||||
|
||||
const pinThread = useCallback(
|
||||
async (target: ScopedThreadRef, opts: { orderKey?: string } = {}) => {
|
||||
// Version skew: never send the command to a server that predates it.
|
||||
@@ -875,6 +912,7 @@ export function useThreadActions() {
|
||||
confirmAndUnpinThread,
|
||||
reorderPinnedThread,
|
||||
reorderActiveThread,
|
||||
setThreadAutoSettle,
|
||||
}),
|
||||
[
|
||||
archiveThread,
|
||||
@@ -884,6 +922,7 @@ export function useThreadActions() {
|
||||
pinThread,
|
||||
reorderPinnedThread,
|
||||
reorderActiveThread,
|
||||
setThreadAutoSettle,
|
||||
settleThread,
|
||||
snoozeThread,
|
||||
unarchiveThread,
|
||||
|
||||
@@ -229,6 +229,15 @@ export function readEnvironmentSupportsPinReorder(environmentId: EnvironmentId):
|
||||
);
|
||||
}
|
||||
|
||||
/** Whether the environment's server understands thread.auto-settle.set.
|
||||
Same version-skew contract as settlement. */
|
||||
export function readEnvironmentSupportsAutoSettleOptOut(environmentId: EnvironmentId): boolean {
|
||||
return (
|
||||
appAtomRegistry.get(environmentServerConfigsAtom).get(environmentId)?.environment.capabilities
|
||||
.threadAutoSettleOptOut === true
|
||||
);
|
||||
}
|
||||
|
||||
export function readEnvironmentSupportsActiveReorder(environmentId: EnvironmentId): boolean {
|
||||
return (
|
||||
appAtomRegistry.get(environmentServerConfigsAtom).get(environmentId)?.environment.capabilities
|
||||
|
||||
@@ -99,6 +99,11 @@ prevent automatic settlement. An open pull request does not prevent inactivity
|
||||
settlement, but an old closed or merged pull request does not settle work you
|
||||
resumed after it closed.
|
||||
|
||||
To keep one thread out of the settled shelf no matter how long it sits idle, open its menu,
|
||||
choose **Auto-settle behavior**, and pick **Disabled**. The current option is checked. Pick
|
||||
**Enabled** to return to the usual rules. Manual settle, snooze, and archive still work while it
|
||||
is disabled.
|
||||
|
||||
Change these rules in **Settings → General** on web and desktop, or **Settings → Thread behavior** on mobile.
|
||||
They continue to run when your apps are closed. On web and desktop, choose an environment at the
|
||||
top to change only its rules, or **All environments** to update connected environments together.
|
||||
|
||||
@@ -42,6 +42,7 @@ export type UnsnoozeThreadInput = CommandInput<"thread.unsnooze">;
|
||||
export type PinThreadInput = CommandInput<"thread.pin">;
|
||||
export type UnpinThreadInput = CommandInput<"thread.unpin">;
|
||||
export type ReorderPinnedThreadInput = CommandInput<"thread.pin.reorder">;
|
||||
export type SetThreadAutoSettleInput = CommandInput<"thread.auto-settle.set">;
|
||||
export type ReorderActiveThreadInput = CommandInput<"thread.active.reorder">;
|
||||
export type UpdateThreadMetadataInput = CommandInput<"thread.meta.update">;
|
||||
export type LinkThreadPullRequestInput = CommandInput<"thread.pull-request.link">;
|
||||
@@ -226,6 +227,16 @@ export const unpinThread: (input: UnpinThreadInput) => CommandEffect = Effect.fn
|
||||
});
|
||||
});
|
||||
|
||||
export const setThreadAutoSettle: (input: SetThreadAutoSettleInput) => CommandEffect = Effect.fn(
|
||||
"EnvironmentCommands.setThreadAutoSettle",
|
||||
)(function* (input) {
|
||||
return yield* dispatch({
|
||||
...input,
|
||||
type: "thread.auto-settle.set",
|
||||
commandId: yield* commandId(input),
|
||||
});
|
||||
});
|
||||
|
||||
export const reorderPinnedThread: (input: ReorderPinnedThreadInput) => CommandEffect = Effect.fn(
|
||||
"EnvironmentCommands.reorderPinnedThread",
|
||||
)(function* (input) {
|
||||
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
type PinThreadInput,
|
||||
type ReorderPinnedThreadInput,
|
||||
type ReorderActiveThreadInput,
|
||||
type SetThreadAutoSettleInput,
|
||||
type SettleThreadInput,
|
||||
type SnoozeThreadInput,
|
||||
type StartThreadTurnInput,
|
||||
@@ -53,6 +54,7 @@ import {
|
||||
pinThread,
|
||||
reorderPinnedThread,
|
||||
reorderActiveThread,
|
||||
setThreadAutoSettle,
|
||||
settleThread,
|
||||
snoozeThread,
|
||||
startThreadTurn,
|
||||
@@ -81,6 +83,7 @@ export type {
|
||||
PinThreadInput,
|
||||
ReorderPinnedThreadInput,
|
||||
ReorderActiveThreadInput,
|
||||
SetThreadAutoSettleInput,
|
||||
SettleThreadInput,
|
||||
SnoozeThreadInput,
|
||||
StartThreadTurnInput,
|
||||
@@ -170,6 +173,12 @@ export function createThreadEnvironmentAtoms<R, E>(
|
||||
scheduler,
|
||||
concurrency,
|
||||
}),
|
||||
setAutoSettle: createEnvironmentCommand(runtime, {
|
||||
label: "environment-data:commands:thread:set-auto-settle",
|
||||
execute: (input: SetThreadAutoSettleInput) => setThreadAutoSettle(input),
|
||||
scheduler,
|
||||
concurrency,
|
||||
}),
|
||||
reorderActive: createEnvironmentCommand(runtime, {
|
||||
label: "environment-data:commands:thread:reorder-active",
|
||||
execute: (input: ReorderActiveThreadInput) => reorderActiveThread(input),
|
||||
|
||||
@@ -60,6 +60,7 @@ export function mergeEnvironmentThread(
|
||||
settledAt: shell.settledAt,
|
||||
unsettledAt: shell.unsettledAt,
|
||||
activeOrderKey: shell.activeOrderKey,
|
||||
autoSettleDisabledAt: shell.autoSettleDisabledAt,
|
||||
snoozedUntil: shell.snoozedUntil,
|
||||
snoozedAt: shell.snoozedAt,
|
||||
pinnedAt: shell.pinnedAt,
|
||||
|
||||
@@ -290,6 +290,46 @@ describe("applyThreadDetailEvent", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("thread.auto-settle-set", () => {
|
||||
it("stores and clears autoSettleDisabledAt", () => {
|
||||
const disabledAt = "2026-04-01T05:00:00.000Z";
|
||||
const off = applyThreadDetailEvent(baseThread, {
|
||||
...baseEventFields,
|
||||
sequence: 7,
|
||||
occurredAt: disabledAt,
|
||||
aggregateKind: "thread",
|
||||
aggregateId: ThreadId.make("thread-1"),
|
||||
type: "thread.auto-settle-set",
|
||||
payload: {
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
autoSettleDisabledAt: disabledAt,
|
||||
updatedAt: disabledAt,
|
||||
},
|
||||
});
|
||||
expect(off.kind).toBe("updated");
|
||||
if (off.kind !== "updated") return;
|
||||
expect(off.thread.autoSettleDisabledAt).toBe(disabledAt);
|
||||
|
||||
const on = applyThreadDetailEvent(off.thread, {
|
||||
...baseEventFields,
|
||||
sequence: 8,
|
||||
occurredAt: "2026-04-01T06:00:00.000Z",
|
||||
aggregateKind: "thread",
|
||||
aggregateId: ThreadId.make("thread-1"),
|
||||
type: "thread.auto-settle-set",
|
||||
payload: {
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
autoSettleDisabledAt: null,
|
||||
updatedAt: "2026-04-01T06:00:00.000Z",
|
||||
},
|
||||
});
|
||||
expect(on.kind).toBe("updated");
|
||||
if (on.kind === "updated") {
|
||||
expect(on.thread.autoSettleDisabledAt).toBeNull();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("thread.meta-updated", () => {
|
||||
it.each(["f", null] as const)(
|
||||
"updates the active key to %s without activity",
|
||||
|
||||
@@ -131,6 +131,7 @@ export function applyThreadDetailEvent(
|
||||
settledAt: null,
|
||||
unsettledAt: null,
|
||||
activeOrderKey: null,
|
||||
autoSettleDisabledAt: null,
|
||||
snoozedUntil: null,
|
||||
snoozedAt: null,
|
||||
deletedAt: null,
|
||||
@@ -249,6 +250,16 @@ export function applyThreadDetailEvent(
|
||||
},
|
||||
};
|
||||
|
||||
case "thread.auto-settle-set":
|
||||
return {
|
||||
kind: "updated",
|
||||
thread: {
|
||||
...thread,
|
||||
autoSettleDisabledAt: event.payload.autoSettleDisabledAt,
|
||||
updatedAt: event.payload.updatedAt,
|
||||
},
|
||||
};
|
||||
|
||||
// ── Thread metadata ─────────────────────────────────────────────
|
||||
case "thread.meta-updated":
|
||||
return {
|
||||
|
||||
@@ -141,6 +141,9 @@ export const ExecutionEnvironmentCapabilities = Schema.Struct({
|
||||
threadPinReorder: Schema.optionalKey(Schema.Boolean),
|
||||
/** Server persists manual Active order through thread.active.reorder. */
|
||||
threadActiveReorder: Schema.optionalKey(Schema.Boolean),
|
||||
/** Server understands thread.auto-settle.set (per-thread auto-settle off).
|
||||
Same version-skew contract as threadSettlement. */
|
||||
threadAutoSettleOptOut: Schema.optionalKey(Schema.Boolean),
|
||||
/** Server understands regenerateTitle on thread.meta.update. Absent on
|
||||
older servers, so clients hide the action instead of sending it. */
|
||||
threadTitleRegeneration: Schema.optionalKey(Schema.Boolean),
|
||||
|
||||
@@ -40,6 +40,8 @@ export interface ContextMenuItem<T extends string = string> {
|
||||
icon?: string;
|
||||
/** Inserts a visual section divider immediately before this item. */
|
||||
separatorBefore?: boolean;
|
||||
/** Shows a check mark. Used to mark the current option inside a submenu. */
|
||||
checked?: boolean;
|
||||
children?: readonly ContextMenuItem<T>[];
|
||||
}
|
||||
|
||||
@@ -55,6 +57,7 @@ export interface ContextMenuItemSchemaType {
|
||||
readonly header?: boolean;
|
||||
readonly icon?: string;
|
||||
readonly separatorBefore?: boolean;
|
||||
readonly checked?: boolean;
|
||||
readonly children?: readonly ContextMenuItemSchemaType[];
|
||||
}
|
||||
|
||||
@@ -66,6 +69,7 @@ export const ContextMenuItemSchema: Schema.Codec<ContextMenuItemSchemaType> = Sc
|
||||
header: Schema.optionalKey(Schema.Boolean),
|
||||
icon: Schema.optionalKey(Schema.String),
|
||||
separatorBefore: Schema.optionalKey(Schema.Boolean),
|
||||
checked: Schema.optionalKey(Schema.Boolean),
|
||||
children: Schema.optionalKey(
|
||||
Schema.Array(
|
||||
Schema.suspend((): Schema.Codec<ContextMenuItemSchemaType> => ContextMenuItemSchema),
|
||||
|
||||
@@ -838,6 +838,10 @@ export const OrchestrationThread = Schema.Struct({
|
||||
// Manual Active placement. Keyless threads retain their creation/re-entry
|
||||
// order above the arranged run. Settling clears this slot.
|
||||
activeOrderKey: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
// Set while the user has turned automatic settlement off for this thread.
|
||||
// Survives manual settle, un-settle, and activity: only the user clears it.
|
||||
// Optional so payloads from older servers still decode.
|
||||
autoSettleDisabledAt: Schema.optional(Schema.NullOr(IsoDateTime)),
|
||||
// Pending-only state. Optional so older servers remain compatible.
|
||||
titleRegeneration: Schema.optional(Schema.NullOr(ThreadTitleRegeneration)),
|
||||
titleState: Schema.optional(Schema.NullOr(ThreadTitleState)),
|
||||
@@ -908,6 +912,7 @@ export const OrchestrationThreadShell = Schema.Struct({
|
||||
pinnedAt: Schema.optional(Schema.NullOr(IsoDateTime)),
|
||||
pinOrderKey: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
activeOrderKey: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
autoSettleDisabledAt: Schema.optional(Schema.NullOr(IsoDateTime)),
|
||||
titleRegeneration: Schema.optional(Schema.NullOr(ThreadTitleRegeneration)),
|
||||
titleState: Schema.optional(Schema.NullOr(ThreadTitleState)),
|
||||
session: Schema.NullOr(OrchestrationSession),
|
||||
@@ -1218,6 +1223,14 @@ const ThreadPinReorderCommand = Schema.Struct({
|
||||
orderKey: TrimmedNonEmptyString,
|
||||
});
|
||||
|
||||
const ThreadAutoSettleSetCommand = Schema.Struct({
|
||||
type: Schema.Literal("thread.auto-settle.set"),
|
||||
commandId: CommandId,
|
||||
threadId: ThreadId,
|
||||
// false turns automatic settlement off for this thread, true turns it back on.
|
||||
enabled: Schema.Boolean,
|
||||
});
|
||||
|
||||
const ThreadActiveReorderCommand = Schema.Struct({
|
||||
type: Schema.Literal("thread.active.reorder"),
|
||||
commandId: CommandId,
|
||||
@@ -1426,6 +1439,7 @@ const DispatchableClientOrchestrationCommand = Schema.Union([
|
||||
ThreadPinCommand,
|
||||
ThreadUnpinCommand,
|
||||
ThreadPinReorderCommand,
|
||||
ThreadAutoSettleSetCommand,
|
||||
ThreadActiveReorderCommand,
|
||||
ThreadMetaUpdateCommand,
|
||||
ThreadPullRequestLinkCommand,
|
||||
@@ -1459,6 +1473,7 @@ export const ClientOrchestrationCommand = Schema.Union([
|
||||
ThreadPinCommand,
|
||||
ThreadUnpinCommand,
|
||||
ThreadPinReorderCommand,
|
||||
ThreadAutoSettleSetCommand,
|
||||
ThreadActiveReorderCommand,
|
||||
ThreadMetaUpdateCommand,
|
||||
ThreadPullRequestLinkCommand,
|
||||
@@ -1687,6 +1702,7 @@ export const OrchestrationEventType = Schema.Literals([
|
||||
"thread.pinned",
|
||||
"thread.unpinned",
|
||||
"thread.pin-reordered",
|
||||
"thread.auto-settle-set",
|
||||
"thread.meta-updated",
|
||||
"thread.pull-request-linked",
|
||||
"thread.pull-request-unlinked",
|
||||
@@ -1825,6 +1841,13 @@ export const ThreadPinReorderedPayload = Schema.Struct({
|
||||
updatedAt: IsoDateTime,
|
||||
});
|
||||
|
||||
export const ThreadAutoSettleSetPayload = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
// Null re-enables automatic settlement.
|
||||
autoSettleDisabledAt: Schema.NullOr(IsoDateTime),
|
||||
updatedAt: IsoDateTime,
|
||||
});
|
||||
|
||||
export const ThreadMetaUpdatedPayload = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
// Order updates use this existing event so older clients can ignore the
|
||||
@@ -2089,6 +2112,11 @@ export const OrchestrationEvent = Schema.Union([
|
||||
type: Schema.Literal("thread.pin-reordered"),
|
||||
payload: ThreadPinReorderedPayload,
|
||||
}),
|
||||
Schema.Struct({
|
||||
...EventBaseFields,
|
||||
type: Schema.Literal("thread.auto-settle-set"),
|
||||
payload: ThreadAutoSettleSetPayload,
|
||||
}),
|
||||
Schema.Struct({
|
||||
...EventBaseFields,
|
||||
type: Schema.Literal("thread.meta-updated"),
|
||||
|
||||
Reference in new issue
Block a user