Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
Add configurable shortcuts for new chat and open-in-editor
Julius Marmingeef4ce2e1ec3a
diff --git a/KEYBINDINGS.md b/KEYBINDINGS.mdindex c37ad2cf0..8cae18ebc 100644--- a/KEYBINDINGS.md+++ b/KEYBINDINGS.md@@ -19,7 +19,9 @@ The file must be a JSON array of rules:[{ "key": "mod+j", "command": "terminal.toggle" },{ "key": "mod+d", "command": "terminal.split", "when": "terminalFocus" },- { "key": "mod+shift+d", "command": "terminal.new", "when": "terminalFocus" }+ { "key": "mod+shift+d", "command": "terminal.new", "when": "terminalFocus" },+ { "key": "mod+shift+o", "command": "chat.new" },+ { "key": "mod+o", "command": "editor.openFavorite" }]```@@ -38,6 +40,8 @@ Invalid rules are ignored. Invalid config files are ignored. Warnings are logged- `terminal.toggle`: open/close terminal drawer- `terminal.split`: split terminal (in focused terminal context by default)- `terminal.new`: create new terminal (in focused terminal context by default)+- `chat.new`: create a new chat thread for the active project+- `editor.openFavorite`: open current project/worktree in the last-used editor## Key Syntax@@ -85,6 +89,8 @@ Built-in defaults are resolved on the server and sent to the web client via `ser- `terminal.toggle`: `mod+j`- `terminal.split`: `mod+d` when `terminalFocus`- `terminal.new`: `mod+shift+d` when `terminalFocus`+- `chat.new`: `mod+shift+o`+- `editor.openFavorite`: `mod+o`If you define any rules for a command, the default rule for that command is removed on the server.diff --git a/apps/server/src/wsServer.test.ts b/apps/server/src/wsServer.test.tsindex 0b4726c51..a769193fb 100644--- a/apps/server/src/wsServer.test.ts+++ b/apps/server/src/wsServer.test.ts@@ -313,6 +313,8 @@ describe("WebSocket Server", () => {{ key: "mod+j", command: "terminal.toggle" },{ key: "mod+d", command: "terminal.split", when: "terminalFocus" },{ key: "mod+shift+d", command: "terminal.new", when: "terminalFocus" },+ { key: "mod+shift+o", command: "chat.new" },+ { key: "mod+o", command: "editor.openFavorite" },],});});@@ -347,6 +349,8 @@ describe("WebSocket Server", () => {expect(response.result).toEqual({cwd: "/my/workspace",keybindings: [+ { key: "mod+shift+o", command: "chat.new" },+ { key: "mod+o", command: "editor.openFavorite" },{ key: "cmd+j", command: "terminal.toggle" },{ key: "mod+d", command: "terminal.split", when: "terminalFocus" },{ key: "mod+shift+d", command: "terminal.new", when: "terminalFocus" },@@ -386,6 +390,8 @@ describe("WebSocket Server", () => {keybindings: [{ key: "mod+d", command: "terminal.split", when: "terminalFocus" },{ key: "mod+shift+d", command: "terminal.new", when: "terminalFocus" },+ { key: "mod+shift+o", command: "chat.new" },+ { key: "mod+o", command: "editor.openFavorite" },{ key: "mod+j", command: "terminal.toggle" },],});@@ -426,6 +432,8 @@ describe("WebSocket Server", () => {{ key: "mod+j", command: "terminal.toggle" },{ key: "mod+d", command: "terminal.split", when: "terminalFocus" },{ key: "mod+shift+d", command: "terminal.new", when: "terminalFocus" },+ { key: "mod+shift+o", command: "chat.new" },+ { key: "mod+o", command: "editor.openFavorite" },],});expect(@@ -461,6 +469,8 @@ describe("WebSocket Server", () => {{ key: "mod+j", command: "terminal.toggle" },{ key: "mod+d", command: "terminal.split", when: "terminalFocus" },{ key: "mod+shift+d", command: "terminal.new", when: "terminalFocus" },+ { key: "mod+shift+o", command: "chat.new" },+ { key: "mod+o", command: "editor.openFavorite" },],});expect(diff --git a/apps/server/src/wsServer.ts b/apps/server/src/wsServer.tsindex 640b3af76..b22b906ae 100644--- a/apps/server/src/wsServer.ts+++ b/apps/server/src/wsServer.ts@@ -74,6 +74,8 @@ const DEFAULT_KEYBINDINGS: KeybindingsConfig = [{ key: "mod+j", command: "terminal.toggle" },{ key: "mod+d", command: "terminal.split", when: "terminalFocus" },{ key: "mod+shift+d", command: "terminal.new", when: "terminalFocus" },+ { key: "mod+shift+o", command: "chat.new" },+ { key: "mod+o", command: "editor.openFavorite" },];function mergeWithDefaultKeybindings(custom: KeybindingsConfig): KeybindingsConfig {diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsxindex a11d28930..61b60f605 100644--- a/apps/web/src/components/ChatView.tsx+++ b/apps/web/src/components/ChatView.tsx@@ -54,6 +54,7 @@ import type { ChatImageAttachment } from "../types";import BranchToolbar from "./BranchToolbar";import GitActionsControl from "./GitActionsControl";import {+ isOpenFavoriteEditorShortcut,isTerminalNewShortcut,isTerminalSplitShortcut,isTerminalToggleShortcut,@@ -263,20 +264,20 @@ export default function ChatView() {} as const);const gitCwd = activeThread?.worktreePath ?? activeProject?.cwd ?? null;const branchesQuery = useQuery(gitBranchesQueryOptions(api, gitCwd));- const terminalKeybindingsQuery = useQuery({+ const keybindingsQuery = useQuery({...serverConfigQueryOptions(api),select: (config) => config.keybindings,});- const terminalKeybindings = terminalKeybindingsQuery.data ?? EMPTY_KEYBINDINGS;+ const keybindings = keybindingsQuery.data ?? EMPTY_KEYBINDINGS;// Default true while loading to avoid toolbar flicker.const isGitRepo = branchesQuery.data?.isRepo ?? true;const splitTerminalShortcutLabel = useMemo(- () => shortcutLabelForCommand(terminalKeybindings, "terminal.split"),- [terminalKeybindings],+ () => shortcutLabelForCommand(keybindings, "terminal.split"),+ [keybindings],);const newTerminalShortcutLabel = useMemo(- () => shortcutLabelForCommand(terminalKeybindings, "terminal.new"),- [terminalKeybindings],+ () => shortcutLabelForCommand(keybindings, "terminal.new"),+ [keybindings],);const envLocked = Boolean(@@ -527,14 +528,14 @@ export default function ChatView() {terminalOpen: Boolean(activeThread?.terminalOpen),};- if (isTerminalToggleShortcut(event, terminalKeybindings, { context: shortcutContext })) {+ if (isTerminalToggleShortcut(event, keybindings, { context: shortcutContext })) {event.preventDefault();event.stopPropagation();toggleTerminalVisibility();return;}- if (isTerminalSplitShortcut(event, terminalKeybindings, { context: shortcutContext })) {+ if (isTerminalSplitShortcut(event, keybindings, { context: shortcutContext })) {event.preventDefault();event.stopPropagation();if (!activeThread?.terminalOpen) {@@ -548,7 +549,7 @@ export default function ChatView() {return;}- if (!isTerminalNewShortcut(event, terminalKeybindings, { context: shortcutContext })) return;+ if (!isTerminalNewShortcut(event, keybindings, { context: shortcutContext })) return;event.preventDefault();event.stopPropagation();if (!activeThread?.terminalOpen) {@@ -568,7 +569,7 @@ export default function ChatView() {createNewTerminal,dispatch,splitTerminal,- terminalKeybindings,+ keybindings,toggleTerminalVisibility,]);@@ -937,7 +938,7 @@ export default function ChatView() {</div><div className="flex items-center gap-3">{/* Open in editor */}- {activeProject && <OpenInPicker />}+ {activeProject && <OpenInPicker keybindings={keybindings} />}{/* Git actions */}{activeProject && <GitActionsControl api={api} gitCwd={gitCwd} />}@@ -1519,7 +1520,7 @@ function ReasoningEffortPicker(props: {);}-function OpenInPicker() {+function OpenInPicker({ keybindings }: { keybindings: KeybindingsConfig }) {const [lastEditor, setLastEditor] = useState<EditorId>(() => {const stored = localStorage.getItem(LAST_EDITOR_KEY);return EDITORS.some((e) => e.id === stored) ? (stored as EditorId) : EDITORS[0].id;@@ -1560,20 +1561,23 @@ function OpenInPicker() {[api, activeProject, activeThread, lastEditor, setLastEditor],);- // Cmd+O / Ctrl+O to open in last-used editor+ const openFavoriteEditorShortcutLabel = useMemo(+ () => shortcutLabelForCommand(keybindings, "editor.openFavorite"),+ [keybindings],+ );+useEffect(() => {const handler = (e: globalThis.KeyboardEvent) => {- if (e.key === "o" && (e.metaKey || e.ctrlKey) && !e.shiftKey) {- if (api && activeProject) {- e.preventDefault();- const cwd = activeThread?.worktreePath ?? activeProject.cwd;- void api.shell.openInEditor(cwd, lastEditor);- }- }+ if (!isOpenFavoriteEditorShortcut(e, keybindings)) return;+ if (!api || !activeProject) return;++ e.preventDefault();+ const cwd = activeThread?.worktreePath ?? activeProject.cwd;+ void api.shell.openInEditor(cwd, lastEditor);};window.addEventListener("keydown", handler);return () => window.removeEventListener("keydown", handler);- }, [api, activeProject, activeThread, lastEditor]);+ }, [api, activeProject, activeThread, keybindings, lastEditor]);return (<Group aria-label="Subscription actions">@@ -1591,10 +1595,8 @@ function OpenInPicker() {<MenuItem key={value} onClick={() => openInEditor(value)}><Icon aria-hidden="true" className="text-muted-foreground" />{label}- {value === lastEditor && (- <MenuShortcut>- {navigator.platform.includes("Mac") ? "\u2318O" : "Ctrl+O"}- </MenuShortcut>+ {value === lastEditor && openFavoriteEditorShortcutLabel && (+ <MenuShortcut>{openFavoriteEditorShortcutLabel}</MenuShortcut>)}</MenuItem>))}diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsxindex e85146828..cb2c059ad 100644--- a/apps/web/src/components/Sidebar.tsx+++ b/apps/web/src/components/Sidebar.tsx@@ -1,11 +1,13 @@import { MonitorIcon, MoonIcon, SunIcon, TerminalIcon } from "lucide-react";import { useCallback, useEffect, useMemo, useState } from "react";-import { useMutation, useQueryClient } from "@tanstack/react-query";+import type { KeybindingsConfig } from "@t3tools/contracts";+import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";import { isElectron } from "../env";import { useTheme } from "../hooks/useTheme";import { DEFAULT_MODEL } from "../model-logic";import { derivePendingApprovals } from "../session-logic";import { useStore } from "../store";+import { isChatNewShortcut } from "../keybindings";import {DEFAULT_THREAD_TERMINAL_HEIGHT,DEFAULT_THREAD_TERMINAL_ID,@@ -14,9 +16,12 @@ import {} from "../types";import { useNativeApi } from "../hooks/useNativeApi";import { gitRemoveWorktreeMutationOptions } from "../lib/gitReactQuery";+import { serverConfigQueryOptions } from "../lib/serverReactQuery";import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "../worktreeCleanup";const THEME_CYCLE = { system: "light", light: "dark", dark: "system" } as const;+const EMPTY_KEYBINDINGS: KeybindingsConfig = [];+function formatRelativeTime(iso: string): string {const diff = Date.now() - new Date(iso).getTime();const minutes = Math.floor(diff / 60_000);@@ -112,6 +117,11 @@ function terminalStatusIndicator(thread: Thread): TerminalStatusIndicator | nullexport default function Sidebar() {const { state, dispatch } = useStore();const api = useNativeApi();+ const keybindingsQuery = useQuery({+ ...serverConfigQueryOptions(api),+ select: (config) => config.keybindings,+ });+ const keybindings = keybindingsQuery.data ?? EMPTY_KEYBINDINGS;const queryClient = useQueryClient();const removeWorktreeMutation = useMutation(gitRemoveWorktreeMutationOptions({ api, queryClient }));const { theme, setTheme } = useTheme();@@ -324,13 +334,7 @@ export default function Sidebar() {useEffect(() => {const onWindowKeyDown = (event: KeyboardEvent) => {- const isNewThreadShortcut =- event.metaKey &&- event.shiftKey &&- !event.ctrlKey &&- !event.altKey &&- event.key.toLowerCase() === "o";- if (!isNewThreadShortcut) return;+ if (!isChatNewShortcut(event, keybindings)) return;const activeThread = state.threads.find((t) => t.id === state.activeThreadId);const projectId = activeThread?.projectId ?? state.projects[0]?.id;@@ -344,7 +348,7 @@ export default function Sidebar() {return () => {window.removeEventListener("keydown", onWindowKeyDown);};- }, [handleNewThread, state.activeThreadId, state.projects, state.threads]);+ }, [handleNewThread, keybindings, state.activeThreadId, state.projects, state.threads]);return (<aside className="sidebar flex h-full w-[260px] shrink-0 flex-col border-r border-border bg-card">diff --git a/apps/web/src/keybindings.test.ts b/apps/web/src/keybindings.test.tsindex e6d42778c..e68e4a0e3 100644--- a/apps/web/src/keybindings.test.ts+++ b/apps/web/src/keybindings.test.ts@@ -3,6 +3,8 @@ import { describe, expect, it } from "vitest";import type { KeybindingsConfig } from "@t3tools/contracts";import {formatShortcutLabel,+ isChatNewShortcut,+ isOpenFavoriteEditorShortcut,isTerminalClearShortcut,isTerminalNewShortcut,isTerminalSplitShortcut,@@ -26,6 +28,8 @@ const DEFAULT_BINDINGS: KeybindingsConfig = [{ key: "mod+j", command: "terminal.toggle" },{ key: "mod+d", command: "terminal.split", when: "terminalFocus" },{ key: "mod+shift+d", command: "terminal.new", when: "terminalFocus" },+ { key: "mod+shift+o", command: "chat.new" },+ { key: "mod+o", command: "editor.openFavorite" },];describe("isTerminalToggleShortcut", () => {@@ -112,6 +116,41 @@ describe("shortcutLabelForCommand", () => {];expect(shortcutLabelForCommand(bindings, "terminal.split", "Linux")).toBe("Ctrl+Shift+\\");});++ it("returns labels for non-terminal commands", () => {+ expect(shortcutLabelForCommand(DEFAULT_BINDINGS, "chat.new", "MacIntel")).toBe("⇧⌘O");+ expect(shortcutLabelForCommand(DEFAULT_BINDINGS, "editor.openFavorite", "Linux")).toBe(+ "Ctrl+O",+ );+ });+});++describe("chat/editor shortcuts", () => {+ it("matches chat.new shortcut", () => {+ expect(+ isChatNewShortcut(event({ key: "o", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {+ platform: "MacIntel",+ }),+ ).toBe(true);+ expect(+ isChatNewShortcut(event({ key: "o", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {+ platform: "Linux",+ }),+ ).toBe(true);+ });++ it("matches editor.openFavorite shortcut", () => {+ expect(+ isOpenFavoriteEditorShortcut(event({ key: "o", metaKey: true }), DEFAULT_BINDINGS, {+ platform: "MacIntel",+ }),+ ).toBe(true);+ expect(+ isOpenFavoriteEditorShortcut(event({ key: "o", ctrlKey: true }), DEFAULT_BINDINGS, {+ platform: "Linux",+ }),+ ).toBe(true);+ });});describe("formatShortcutLabel", () => {diff --git a/apps/web/src/keybindings.ts b/apps/web/src/keybindings.tsindex cea96b5a4..32fb04461 100644--- a/apps/web/src/keybindings.ts+++ b/apps/web/src/keybindings.ts@@ -14,7 +14,7 @@ export interface ShortcutMatchContext {[key: string]: boolean;}-export type ResolvedTerminalKeybindings = KeybindingsConfig;+export type ResolvedKeybindings = KeybindingsConfig;interface ParsedShortcut {key: string;@@ -301,7 +301,7 @@ function resolveContext(options: ShortcutMatchOptions | undefined): ShortcutMatcfunction matchesCommandShortcut(event: ShortcutEventLike,- keybindings: ResolvedTerminalKeybindings,+ keybindings: ResolvedKeybindings,command: KeybindingCommand,options?: ShortcutMatchOptions,): boolean {@@ -356,7 +356,7 @@ export function formatShortcutLabel(shortcutValue: string, platform = navigator.}export function shortcutLabelForCommand(- keybindings: ResolvedTerminalKeybindings,+ keybindings: ResolvedKeybindings,command: KeybindingCommand,platform = navigator.platform,): string | null {@@ -370,7 +370,7 @@ export function shortcutLabelForCommand(export function isTerminalToggleShortcut(event: ShortcutEventLike,- keybindings: ResolvedTerminalKeybindings,+ keybindings: ResolvedKeybindings,options?: ShortcutMatchOptions,): boolean {return matchesCommandShortcut(event, keybindings, "terminal.toggle", options);@@ -378,7 +378,7 @@ export function isTerminalToggleShortcut(export function isTerminalSplitShortcut(event: ShortcutEventLike,- keybindings: ResolvedTerminalKeybindings,+ keybindings: ResolvedKeybindings,options?: ShortcutMatchOptions,): boolean {return matchesCommandShortcut(event, keybindings, "terminal.split", options);@@ -386,12 +386,28 @@ export function isTerminalSplitShortcut(export function isTerminalNewShortcut(event: ShortcutEventLike,- keybindings: ResolvedTerminalKeybindings,+ keybindings: ResolvedKeybindings,options?: ShortcutMatchOptions,): boolean {return matchesCommandShortcut(event, keybindings, "terminal.new", options);}+export function isChatNewShortcut(+ event: ShortcutEventLike,+ keybindings: ResolvedKeybindings,+ options?: ShortcutMatchOptions,+): boolean {+ return matchesCommandShortcut(event, keybindings, "chat.new", options);+}++export function isOpenFavoriteEditorShortcut(+ event: ShortcutEventLike,+ keybindings: ResolvedKeybindings,+ options?: ShortcutMatchOptions,+): boolean {+ return matchesCommandShortcut(event, keybindings, "editor.openFavorite", options);+}+export function isTerminalClearShortcut(event: ShortcutEventLike,platform = navigator.platform,diff --git a/packages/contracts/src/keybindings.ts b/packages/contracts/src/keybindings.tsindex 5e711da98..4576d79fb 100644--- a/packages/contracts/src/keybindings.ts+++ b/packages/contracts/src/keybindings.ts@@ -4,6 +4,8 @@ export const keybindingCommandSchema = z.enum(["terminal.toggle","terminal.split","terminal.new",+ "chat.new",+ "editor.openFavorite",]);const keybindingValueSchema = z.string().trim().min(1).max(64);