Skip to content

Commit a006b3c

Browse files
committed
feat(web): settle and restore threads with a keyboard shortcut
1 parent f035a0f commit a006b3c

7 files changed

Lines changed: 94 additions & 1 deletion

File tree

‎apps/server/src/keybindings.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ it.layer(NodeServices.layer)("keybindings", (it) => {
195195

196196
assert.equal(defaultsByCommand.get("thread.previous"), "mod+shift+[");
197197
assert.equal(defaultsByCommand.get("thread.next"), "mod+shift+]");
198+
assert.equal(defaultsByCommand.get("thread.settle"), "mod+shift+s");
198199
assert.equal(defaultsByCommand.get("thread.jump.1"), "mod+1");
199200
assert.equal(defaultsByCommand.get("thread.jump.9"), "mod+9");
200201
assert.equal(defaultsByCommand.get("modelPicker.toggle"), "mod+shift+m");

‎apps/web/src/keybindings.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ const DEFAULT_BINDINGS = compile([
142142
{ shortcut: modShortcut("o"), command: "editor.openFavorite" },
143143
{ shortcut: modShortcut("[", { shiftKey: true }), command: "thread.previous" },
144144
{ shortcut: modShortcut("]", { shiftKey: true }), command: "thread.next" },
145+
{
146+
shortcut: modShortcut("s", { shiftKey: true }),
147+
command: "thread.settle",
148+
whenAst: whenNot(whenIdentifier("terminalFocus")),
149+
},
145150
{ shortcut: modShortcut("1"), command: "thread.jump.1" },
146151
{ shortcut: modShortcut("2"), command: "thread.jump.2" },
147152
{ shortcut: modShortcut("3"), command: "thread.jump.3" },
@@ -187,6 +192,27 @@ describe("isTerminalToggleShortcut", () => {
187192
});
188193
});
189194

195+
describe("settle thread shortcut", () => {
196+
it("resolves outside the terminal", () => {
197+
assert.equal(
198+
resolveShortcutCommand(event({ key: "s", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
199+
platform: "MacIntel",
200+
context: { terminalFocus: false },
201+
}),
202+
"thread.settle",
203+
);
204+
});
205+
206+
it("does not intercept the terminal", () => {
207+
assert.isNull(
208+
resolveShortcutCommand(event({ key: "s", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
209+
platform: "Win32",
210+
context: { terminalFocus: true },
211+
}),
212+
);
213+
});
214+
});
215+
190216
describe("split/new/close terminal shortcuts", () => {
191217
it("requires terminalFocus for default split/new/close bindings", () => {
192218
assert.isFalse(

‎apps/web/src/routes/_chat.tsx‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
import { Outlet, createFileRoute, redirect } from "@tanstack/react-router";
22
import { useAtomValue } from "@effect/atom-react";
3+
import { scopedThreadKey } from "@t3tools/client-runtime/environment";
4+
import {
5+
isAtomCommandInterrupted,
6+
squashAtomCommandFailure,
7+
} from "@t3tools/client-runtime/state/runtime";
8+
import { effectiveSettled } from "@t3tools/client-runtime/state/thread-settled";
39
import { useEffect, useMemo } from "react";
410

511
import { isCommandPaletteOpen } from "../commandPaletteBus";
612
import { useClientSettings, useLegacySidebarEnabled } from "../hooks/useSettings";
713
import { openCommandPalette } from "../commandPaletteBus";
8-
import { useProjects } from "../state/entities";
14+
import { readThreadShell, useProjects } from "../state/entities";
915
import { usePrimaryEnvironmentId } from "../state/environments";
1016
import { selectProjectGroupingSettings } from "../logicalProject";
1117
import { buildSidebarProjectSnapshots } from "../sidebarProjectGrouping";
1218
import { dispatchPreviewAction } from "../components/preview/previewActionBus";
1319
import { useHandleNewThread } from "../hooks/useHandleNewThread";
20+
import { useThreadActions } from "../hooks/useThreadActions";
1421
import { startNewThreadFromContext } from "../lib/chatThreadActions";
1522
import { isPreviewFocused } from "../lib/previewFocus";
1623
import { isTerminalFocused } from "../lib/terminalFocus";
@@ -19,6 +26,8 @@ import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../termina
1926
import { isPreviewSupportedInRuntime } from "../previewStateStore";
2027
import { selectActiveRightPanel, useRightPanelStore } from "../rightPanelStore";
2128
import { useThreadSelectionStore } from "../threadSelectionStore";
29+
import { threadChangeRequestSnapshotsAtom } from "../components/ThreadStatusIndicators";
30+
import { appAtomRegistry } from "../rpc/atomRegistry";
2231
import { stackedThreadToast, toastManager } from "~/components/ui/toast";
2332
import { primaryServerKeybindingsAtom } from "~/state/server";
2433

@@ -27,9 +36,12 @@ function ChatRouteGlobalShortcuts() {
2736
const selectedThreadKeysSize = useThreadSelectionStore((state) => state.selectedThreadKeys.size);
2837
const { activeDraftThread, activeThread, defaultProjectRef, handleNewThread, routeThreadRef } =
2938
useHandleNewThread();
39+
const { settleThread, unsettleThread } = useThreadActions();
3040
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
3141
const legacySidebarEnabled = useLegacySidebarEnabled();
3242
const projectGroupingSettings = useClientSettings(selectProjectGroupingSettings);
43+
const autoSettleAfterDays = useClientSettings((settings) => settings.sidebarAutoSettleAfterDays);
44+
const autoSettleOnMerge = useClientSettings((settings) => settings.sidebarAutoSettleOnMerge);
3345
const projects = useProjects();
3446
const primaryEnvironmentId = usePrimaryEnvironmentId();
3547
const projectGroupCount = useMemo(
@@ -108,6 +120,44 @@ function ChatRouteGlobalShortcuts() {
108120
return;
109121
}
110122

123+
if (command === "thread.settle") {
124+
event.preventDefault();
125+
event.stopPropagation();
126+
if (!routeThreadRef) return;
127+
128+
const thread = readThreadShell(routeThreadRef);
129+
if (!thread) return;
130+
131+
const snapshot = appAtomRegistry
132+
.get(threadChangeRequestSnapshotsAtom)
133+
.get(scopedThreadKey(routeThreadRef));
134+
const changeRequest =
135+
snapshot != null && (thread.worktreePath === null || snapshot.branch === thread.branch)
136+
? snapshot.pr
137+
: null;
138+
const settled = effectiveSettled(thread, {
139+
now: `${new Date().toISOString().slice(0, 16)}:00.000Z`,
140+
autoSettleAfterDays,
141+
autoSettleOnMerge,
142+
changeRequest,
143+
});
144+
145+
void (settled ? unsettleThread(routeThreadRef) : settleThread(routeThreadRef)).then(
146+
(result) => {
147+
if (result._tag !== "Failure" || isAtomCommandInterrupted(result)) return;
148+
const error = squashAtomCommandFailure(result);
149+
toastManager.add(
150+
stackedThreadToast({
151+
type: "error",
152+
title: settled ? "Failed to un-settle thread" : "Failed to settle thread",
153+
description: error instanceof Error ? error.message : "An error occurred.",
154+
}),
155+
);
156+
},
157+
);
158+
return;
159+
}
160+
111161
if (command === "preview.toggle") {
112162
event.preventDefault();
113163
event.stopPropagation();
@@ -159,6 +209,8 @@ function ChatRouteGlobalShortcuts() {
159209
}, [
160210
activeDraftThread,
161211
activeThread,
212+
autoSettleAfterDays,
213+
autoSettleOnMerge,
162214
clearSelection,
163215
handleNewThread,
164216
keybindings,
@@ -167,8 +219,10 @@ function ChatRouteGlobalShortcuts() {
167219
projectGroupCount,
168220
routeThreadRef,
169221
selectedThreadKeysSize,
222+
settleThread,
170223
legacySidebarEnabled,
171224
terminalOpen,
225+
unsettleThread,
172226
]);
173227

174228
return null;

‎docs/user/keybindings.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ successful pick; its hover glow and badge preview the element and color family t
5252
`rightPanel.toggleMaximized` maximizes or restores the open right panel. It has no default shortcut,
5353
so add one in **Settings** → **Keybindings** if you want to use it.
5454

55+
`thread.settle` settles the active thread or restores it when it is already settled. Its default
56+
shortcut is `mod+shift+s`, and it does not run while the terminal has focus.
57+
5558
The command palette searches active thread titles, projects, branches, user messages, and final
5659
agent responses across connected environments. Message matches show one labeled excerpt while
5760
keeping the thread's project, branch, and machine context visible. Message search begins after two

‎packages/contracts/src/keybindings.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ it.effect("parses keybinding rules", () =>
107107
command: "thread.previous",
108108
});
109109
assert.strictEqual(parsedThreadPrevious.command, "thread.previous");
110+
111+
const parsedThreadSettle = yield* decode(KeybindingRule, {
112+
key: "mod+shift+s",
113+
command: "thread.settle",
114+
when: "!terminalFocus",
115+
});
116+
assert.strictEqual(parsedThreadSettle.command, "thread.settle");
110117
}),
111118
);
112119

‎packages/contracts/src/keybindings.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export type ModelPickerJumpKeybindingCommand =
3737
export const THREAD_KEYBINDING_COMMANDS = [
3838
"thread.previous",
3939
"thread.next",
40+
"thread.settle",
4041
...THREAD_JUMP_KEYBINDING_COMMANDS,
4142
] as const;
4243
export type ThreadKeybindingCommand = (typeof THREAD_KEYBINDING_COMMANDS)[number];

‎packages/shared/src/keybindings.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const DEFAULT_KEYBINDINGS: ReadonlyArray<KeybindingRule> = [
4646
{ key: "mod+o", command: "editor.openFavorite" },
4747
{ key: "mod+shift+[", command: "thread.previous" },
4848
{ key: "mod+shift+]", command: "thread.next" },
49+
{ key: "mod+shift+s", command: "thread.settle", when: "!terminalFocus" },
4950
...THREAD_JUMP_KEYBINDING_COMMANDS.map((command, index) => ({
5051
key: `mod+${index + 1}`,
5152
command,

0 commit comments

Comments
 (0)