GeezerVison is showing github.com — feat(web): add bindable thread.regenerateTitle keybinding command · pingdotgg/t3code@4b04a2e
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ChatView.tsx +33-1Lines changed: 33 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1590,7 +1590,8 @@ export default function ChatView(props: ChatViewProps) { | 1590 | 1590 | const canReadTerminal = useEnvironmentScope(environmentId, AuthTerminalReadScope); | 1591 | 1591 | const draftId = routeKind === "draft" ? props.draftId : null; | 1592 | 1592 | const handleNewThread = useNewThreadHandler(); | 1593 | | - const { settleThread, pinThread, confirmAndUnpinThread } = useThreadActions(); | | 1593 | + const { settleThread, pinThread, confirmAndUnpinThread, regenerateThreadTitle } = | | 1594 | + useThreadActions(); | 1594 | 1595 | const routeThreadRef = useMemo( | 1595 | 1596 | () => scopeThreadRef(environmentId, threadId), | 1596 | 1597 | [environmentId, threadId], | @@ -7147,6 +7148,8 @@ export default function ChatView(props: ChatViewProps) { | 7147 | 7148 | const supportsSnooze = serverConfig?.environment.capabilities.threadSnooze === true; | 7148 | 7149 | const supportsPinning = serverConfig?.environment.capabilities.threadPinning === true; | 7149 | 7150 | const activeThreadPinned = supportsPinning && activeThreadShell?.pinnedAt != null; | | 7151 | + const supportsTitleRegeneration = | | 7152 | + serverConfig?.environment.capabilities.threadTitleRegeneration === true; | 7150 | 7153 | const activeThreadSnoozed = | 7151 | 7154 | activeThreadShell !== null && | 7152 | 7155 | supportsSnooze && | @@ -8111,6 +8114,33 @@ export default function ChatView(props: ChatViewProps) { | 8111 | 8114 | return; | 8112 | 8115 | } | 8113 | 8116 |
| | 8117 | + if (command === "thread.regenerateTitle") { | | 8118 | + // Unavailable: leave the key to anything else that wants it. Once available | | 8119 | + // the key is always consumed; the command skips a regeneration already running. | | 8120 | + if ( | | 8121 | + !isServerThread || | | 8122 | + !activeThreadRef || | | 8123 | + !supportsTitleRegeneration || | | 8124 | + !readEnvironmentScope(environmentId, AuthOrchestrationOperateScope) | | 8125 | + ) | | 8126 | + return; | | 8127 | + event.preventDefault(); | | 8128 | + event.stopPropagation(); | | 8129 | + if (event.repeat) return; | | 8130 | + void regenerateThreadTitle(activeThreadRef).then((result) => { | | 8131 | + if (result._tag !== "Failure" || isAtomCommandInterrupted(result)) return; | | 8132 | + const error = squashAtomCommandFailure(result); | | 8133 | + toastManager.add( | | 8134 | + stackedThreadToast({ | | 8135 | + type: "error", | | 8136 | + title: "Failed to regenerate thread title", | | 8137 | + description: error instanceof Error ? error.message : "An error occurred.", | | 8138 | + }), | | 8139 | + ); | | 8140 | + }); | | 8141 | + return; | | 8142 | + } | | 8143 | + | 8114 | 8144 | if (command === "terminal.toggle") { | 8115 | 8145 | if (!terminalUiState.terminalOpen && !canReadTerminal && !canOperateTerminal) return; | 8116 | 8146 | event.preventDefault(); | @@ -8371,6 +8401,8 @@ export default function ChatView(props: ChatViewProps) { | 8371 | 8401 | settleThread, | 8372 | 8402 | supportsPinning, | 8373 | 8403 | supportsSettlement, | | 8404 | + supportsTitleRegeneration, | | 8405 | + regenerateThreadTitle, | 8374 | 8406 | confirmAndUnpinThread, | 8375 | 8407 | copyActiveThreadReference, | 8376 | 8408 | getShortcutContext, | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/CommandPalette.tsx +32Lines changed: 32 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -72,6 +72,7 @@ import { | 72 | 72 | MonitorIcon, | 73 | 73 | MoonIcon, | 74 | 74 | PaletteIcon, | | 75 | + RefreshCwIcon, | 75 | 76 | RotateCcwIcon, | 76 | 77 | SettingsIcon, | 77 | 78 | SquarePenIcon, | @@ -127,6 +128,7 @@ import { sourceControlEnvironment } from "../state/sourceControl"; | 127 | 128 | import { useAtomCommand } from "../state/use-atom-command"; | 128 | 129 | import { useAtomQueryRunner } from "../state/use-atom-query-runner"; | 129 | 130 | import { useScratchProject } from "../hooks/useScratchProject"; | | 131 | +import { useThreadActions } from "../hooks/useThreadActions"; | 130 | 132 | import { useNewProject } from "../hooks/useNewProject"; | 131 | 133 | import { isScratchProject } from "@t3tools/client-runtime/state/projects"; | 132 | 134 | import { useEnvironments, usePrimaryEnvironmentId } from "../state/environments"; | @@ -637,6 +639,7 @@ function OpenCommandPaletteDialog(props: { | 637 | 639 | const stopThreadSession = useAtomCommand(threadEnvironment.stopSession, { | 638 | 640 | reportFailure: false, | 639 | 641 | }); | | 642 | + const { regenerateThreadTitle } = useThreadActions(); | 640 | 643 | const refreshProviders = useAtomCommand(serverEnvironment.refreshProviders, { | 641 | 644 | reportFailure: false, | 642 | 645 | }); | @@ -665,6 +668,10 @@ function OpenCommandPaletteDialog(props: { | 665 | 668 | const activeThreadServerConfig = useServerConfigs().get( | 666 | 669 | activeThread?.environmentId ?? ("" as EnvironmentId), | 667 | 670 | ); | | 671 | + const canOperateActiveThread = useEnvironmentScope( | | 672 | + activeThread?.environmentId ?? null, | | 673 | + AuthOrchestrationOperateScope, | | 674 | + ); | 668 | 675 | const activeThreadReferenceCopyTarget = | 669 | 676 | referenceThreadRef === null || (pathname === "/pull-requests" && !openPanelPullRequestUrl) | 670 | 677 | ? null | @@ -1964,6 +1971,31 @@ function OpenCommandPaletteDialog(props: { | 1964 | 1971 | } | 1965 | 1972 | } | 1966 | 1973 |
| | 1974 | + if ( | | 1975 | + activeThread !== null && | | 1976 | + canOperateActiveThread && | | 1977 | + activeThreadServerConfig?.environment.capabilities.threadTitleRegeneration === true | | 1978 | + ) { | | 1979 | + const threadRef = scopeThreadRef(activeThread.environmentId, activeThread.id); | | 1980 | + const isRegeneratingTitle = activeThread.titleRegeneration != null; | | 1981 | + actionItems.push({ | | 1982 | + kind: "action", | | 1983 | + value: "action:regenerate-thread-title", | | 1984 | + searchTerms: ["regenerate", "title", "rename", "thread name", "refresh"], | | 1985 | + title: isRegeneratingTitle ? "Regenerating thread title…" : "Regenerate thread title", | | 1986 | + icon: <RefreshCwIcon className={ITEM_ICON_CLASS} />, | | 1987 | + disabled: isRegeneratingTitle, | | 1988 | + shortcutCommand: "thread.regenerateTitle", | | 1989 | + // Failures throw into executeItem's error toast. | | 1990 | + run: async () => { | | 1991 | + const result = await regenerateThreadTitle(threadRef); | | 1992 | + if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) { | | 1993 | + throw squashAtomCommandFailure(result); | | 1994 | + } | | 1995 | + }, | | 1996 | + }); | | 1997 | + } | | 1998 | + | 1967 | 1999 | if (activeThread !== null) { | 1968 | 2000 | const thread = activeThread; | 1969 | 2001 | actionItems.push({ | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/Sidebar.tsx +3-6Lines changed: 3 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2448,6 +2448,7 @@ export default function Sidebar() { | 2448 | 2448 | markThreadUnread, | 2449 | 2449 | archiveThread, | 2450 | 2450 | deleteThread, | | 2451 | + regenerateThreadTitle, | 2451 | 2452 | } = useThreadActions(); | 2452 | 2453 | const updateThreadMetadata = useOrchestrationCommand(threadEnvironment.updateMetadata, { | 2453 | 2454 | reportFailure: false, | @@ -4806,11 +4807,7 @@ export default function Sidebar() { | 4806 | 4807 | startThreadRename(threadRef, thread.title); | 4807 | 4808 | return; | 4808 | 4809 | case "regenerate-title": { | 4809 | | - if (isRegeneratingTitle) return; | 4810 | | - const result = await updateThreadMetadata({ | 4811 | | - environmentId: threadRef.environmentId, | 4812 | | - input: { threadId: threadRef.threadId, regenerateTitle: true }, | 4813 | | - }); | | 4810 | + const result = await regenerateThreadTitle(threadRef); | 4814 | 4811 | if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) { | 4815 | 4812 | const error = squashAtomCommandFailure(result); | 4816 | 4813 | toastManager.add( | @@ -4929,8 +4926,8 @@ export default function Sidebar() { | 4929 | 4926 | serverConfigs, | 4930 | 4927 | setProjectScopeKey, | 4931 | 4928 | setThreadAutoSettle, | | 4929 | + regenerateThreadTitle, | 4932 | 4930 | startThreadRename, | 4933 | | - updateThreadMetadata, | 4934 | 4931 | timestampFormat, | 4935 | 4932 | ], | 4936 | 4933 | ); | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/settings/KeybindingsSettings.logic.test.ts +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -285,6 +285,7 @@ describe("KeybindingsSettings.logic", () => { | 285 | 285 | expect(commandLabel("themeEditor.toggle")).toBe("Theme Editor: Toggle"); | 286 | 286 | expect(commandLabel("view.reopenClosed")).toBe("Reopen Closed Tab"); | 287 | 287 | expect(commandLabel("preview.focusUrl")).toBe("Preview: Focus URL"); | | 288 | + expect(commandLabel("thread.regenerateTitle")).toBe("Thread: Regenerate Title"); | 288 | 289 | expect(commandLabel("script.setup-db.run")).toBe("Run Script: Setup Db"); | 289 | 290 | }); | 290 | 291 |
| @@ -327,11 +328,12 @@ describe("KeybindingsSettings.logic", () => { | 327 | 328 | "rightPanel.toggleMaximized", | 328 | 329 | "composer.cycleHost", | 329 | 330 | "thread.stop", | | 331 | + "thread.regenerateTitle", | 330 | 332 | "usage.open", | 331 | 333 | "script.setup-db.run", | 332 | 334 | ]), | 333 | 335 | ); | 334 | | - for (const command of ["thread.stop", "composer.cycleHost"]) { | | 336 | + for (const command of ["thread.stop", "composer.cycleHost", "thread.regenerateTitle"]) { | 335 | 337 | expect(DEFAULT_RESOLVED_KEYBINDINGS.some((binding) => binding.command === command)).toBe( | 336 | 338 | false, | 337 | 339 | ); | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/hooks/useThreadActionMenu.test.ts +1-7Lines changed: 1 addition & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -65,13 +65,6 @@ vi.mock("../state/entities", () => ({ | 65 | 65 | useProjects: () => [{ id: "project", environmentId: "secondary" }], | 66 | 66 | })); | 67 | 67 | vi.mock("../state/environments", () => ({ usePrimaryEnvironmentId: () => "primary" })); | 68 | | -vi.mock("../state/threads", () => ({ threadEnvironment: { updateMetadata: "metadata" } })); | 69 | | -vi.mock("../state/use-atom-command", () => ({ | 70 | | - useAtomCommand: () => async () => { | 71 | | - recordEffect("metadata"); | 72 | | - return AsyncResult.success(undefined); | 73 | | - }, | 74 | | -})); | 75 | 68 | vi.mock("../localApi", () => ({ | 76 | 69 | readLocalApi: () => ({ | 77 | 70 | contextMenu: { show: state.show, close: () => {} }, | @@ -134,6 +127,7 @@ vi.mock("./useThreadActions", () => ({ | 134 | 127 | "confirmAndUnpinThread", | 135 | 128 | "archiveThread", | 136 | 129 | "deleteThread", | | 130 | + "regenerateThreadTitle", | 137 | 131 | ].map((action) => [ | 138 | 132 | action, | 139 | 133 | async () => { | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/hooks/useThreadActionMenu.ts +3-11Lines changed: 3 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -22,8 +22,6 @@ import { | 22 | 22 | type ThreadActionMenuId, | 23 | 23 | } from "../components/threadActionMenu.logic"; | 24 | 24 | import { stackedThreadToast, toastManager } from "../components/ui/toast"; | 25 | | -import { threadEnvironment } from "../state/threads"; | 26 | | -import { useOrchestrationCommand } from "../state/use-orchestration-command"; | 27 | 25 | import { readEnvironmentScope } from "../state/session"; | 28 | 26 | import { | 29 | 27 | readEnvironmentSupportsAutoSettleOptOut, | @@ -99,10 +97,8 @@ export function useThreadActionMenu(input: { | 99 | 97 | archiveThread, | 100 | 98 | deleteThread, | 101 | 99 | markThreadUnread, | | 100 | + regenerateThreadTitle, | 102 | 101 | } = useThreadActions(); | 103 | | - const updateThreadMetadata = useOrchestrationCommand(threadEnvironment.updateMetadata, { | 104 | | - reportFailure: false, | 105 | | - }); | 106 | 102 | const handleNewThread = useNewThreadHandler(); | 107 | 103 | const confirmThreadDelete = useClientSettings((s) => s.confirmThreadDelete); | 108 | 104 | const confirmThreadArchive = useClientSettings((s) => s.confirmThreadArchive); | @@ -254,12 +250,8 @@ export function useThreadActionMenu(input: { | 254 | 250 | onStartRename(); | 255 | 251 | return; | 256 | 252 | case "regenerate-title": | 257 | | - if (isRegeneratingTitle) return; | 258 | 253 | await reportFailure("Failed to regenerate thread title", () => | 259 | | - updateThreadMetadata({ | 260 | | - environmentId: threadRef.environmentId, | 261 | | - input: { threadId: threadRef.threadId, regenerateTitle: true }, | 262 | | - }), | | 254 | + regenerateThreadTitle(threadRef), | 263 | 255 | ); | 264 | 256 | return; | 265 | 257 | case "mark-unread": | @@ -365,7 +357,7 @@ export function useThreadActionMenu(input: { | 365 | 357 | timestampFormat, | 366 | 358 | unsettleThread, | 367 | 359 | unsnoozeThread, | 368 | | - updateThreadMetadata, | | 360 | + regenerateThreadTitle, | 369 | 361 | ], | 370 | 362 | ); | 371 | 363 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/hooks/useThreadActions.ts +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -305,6 +305,9 @@ export function useThreadActions() { | 305 | 305 | const unsnoozeThreadMutation = useOrchestrationCommand(threadEnvironment.unsnooze, { | 306 | 306 | reportFailure: false, | 307 | 307 | }); | | 308 | + const updateThreadMetadataMutation = useOrchestrationCommand(threadEnvironment.updateMetadata, { | | 309 | + reportFailure: false, | | 310 | + }); | 308 | 311 | const markThreadUnread = useMarkThreadUnread(); | 309 | 312 | const stopThreadSession = useOrchestrationCommand(threadEnvironment.stopSession); | 310 | 313 | const removeWorktree = useAtomCommand(vcsEnvironment.removeWorktree, { | @@ -863,6 +866,16 @@ export function useThreadActions() { | 863 | 866 | [confirmThreadUnpin, resolveThreadTarget, unpinThread], | 864 | 867 | ); | 865 | 868 |
| | 869 | + /** Skipped (successfully) while the thread's title is already regenerating. */ | | 870 | + const regenerateThreadTitle = useCallback( | | 871 | + (target: ScopedThreadRef) => | | 872 | + updateThreadMetadataMutation({ | | 873 | + environmentId: target.environmentId, | | 874 | + input: { threadId: target.threadId, regenerateTitle: true }, | | 875 | + }), | | 876 | + [updateThreadMetadataMutation], | | 877 | + ); | | 878 | + | 866 | 879 | const reorderPinnedThread = useCallback( | 867 | 880 | async (target: ScopedThreadRef, orderKey: string) => { | 868 | 881 | // Callers (the sidebar drag handler) only enable dragging on | @@ -1024,6 +1037,7 @@ export function useThreadActions() { | 1024 | 1037 | reorderActiveThread, | 1025 | 1038 | markThreadUnread, | 1026 | 1039 | setThreadAutoSettle, | | 1040 | + regenerateThreadTitle, | 1027 | 1041 | }), | 1028 | 1042 | [ | 1029 | 1043 | archiveThread, | @@ -1032,6 +1046,7 @@ export function useThreadActions() { | 1032 | 1046 | deleteThread, | 1033 | 1047 | markThreadUnread, | 1034 | 1048 | pinThread, | | 1049 | + regenerateThreadTitle, | 1035 | 1050 | reorderPinnedThread, | 1036 | 1051 | reorderActiveThread, | 1037 | 1052 | setThreadAutoSettle, | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/keybindings.test.ts +25Lines changed: 25 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1064,6 +1064,31 @@ describe("resolveShortcutCommand", () => { | 1064 | 1064 | ); | 1065 | 1065 | }); | 1066 | 1066 |
| | 1067 | + it("resolves a custom regenerate-title shortcut outside the terminal only", () => { | | 1068 | + const keybindings = compile([ | | 1069 | + { | | 1070 | + shortcut: modShortcut("t", { shiftKey: true }), | | 1071 | + command: "thread.regenerateTitle", | | 1072 | + whenAst: whenNot(whenIdentifier("terminalFocus")), | | 1073 | + }, | | 1074 | + ]); | | 1075 | + const input = event({ key: "t", metaKey: true, shiftKey: true }); | | 1076 | + | | 1077 | + assert.strictEqual( | | 1078 | + resolveShortcutCommand(input, keybindings, { | | 1079 | + platform: "MacIntel", | | 1080 | + context: { terminalFocus: false }, | | 1081 | + }), | | 1082 | + "thread.regenerateTitle", | | 1083 | + ); | | 1084 | + assert.isNull( | | 1085 | + resolveShortcutCommand(input, keybindings, { | | 1086 | + platform: "MacIntel", | | 1087 | + context: { terminalFocus: true }, | | 1088 | + }), | | 1089 | + ); | | 1090 | + }); | | 1091 | + | 1067 | 1092 | it("returns dynamic script commands", () => { | 1068 | 1093 | const keybindings = compile([{ shortcut: modShortcut("r"), command: "script.setup.run" }]); | 1069 | 1094 |
| |
Collapse file Copy file name to clipboardExpand all lines: docs/user/keybindings.md +4Lines changed: 4 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -141,6 +141,10 @@ a shortcut. | 141 | 141 | `thread.stop` interrupts the running turn in the focused thread. It has no default | 142 | 142 | shortcut; assign one in **Settings → Keybindings**. | 143 | 143 |
| | 144 | +`thread.regenerateTitle` generates a fresh title for the focused thread. It has no | | 145 | +default shortcut. It does nothing while a title is already being generated or when | | 146 | +the thread's environment does not support title regeneration. | | 147 | + | 144 | 148 | `thread.undo` (`mod+z` by default) reverses the actions shown in the notice at the | 145 | 149 | bottom of the sidebar, such as unpin, settle, snooze, archive, or discarding a | 146 | 150 | draft. Consecutive | |
Collapse file Copy file name to clipboardExpand all lines: docs/user/thread-sidebar.md +4-2Lines changed: 4 additions & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -104,8 +104,10 @@ environment. Pinned and active reordering require server support. Threads from o | 104 | 104 | their default order until the server is updated. | 105 | 105 |
| 106 | 106 | To generate a fresh title from the conversation, open a thread's menu and choose | 107 | | -**Regenerate title**. The action is unavailable while title generation is in progress | 108 | | -or when the connected environment needs a server update. | | 107 | +**Regenerate title**. The same action is in the command palette, and you can bind | | 108 | +**Thread: Regenerate Title** in **Settings → Keybindings**. The action is unavailable | | 109 | +while title generation is in progress or when the connected environment needs a server | | 110 | +update. | 109 | 111 |
| 110 | 112 | Agents connected through T3 Code can use the same server-owned metadata workflow to | 111 | 113 | rename a thread, regenerate its title, or link and unlink a pull request. These changes | |
|