Add configurable keybindings via ~/.t3/keybindings.json#52
Add configurable keybindings via ~/.t3/keybindings.json#52juliusmarminge merged 24 commits intomainfrom
~/.t3/keybindings.json#52Conversation
- extend `server.getConfig` to return sanitized keybinding rules from `~/.t3/keybindings.json` - apply resolved bindings in the web app for toggle/split/new terminal shortcuts and labels - add contracts/docs and tests for config parsing, validation, and shortcut behavior
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughServer now reads and validates Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Web Client
participant WS as WS Server
participant FS as Filesystem (~/.t3/keybindings.json)
participant Defaults as Server Defaults
Client->>WS: request serverGetConfig
WS->>FS: read ~/.t3/keybindings.json
alt file present & valid
FS-->>WS: keybindings JSON
WS->>WS: validate & sanitize via keybindingRuleSchema
WS->>Defaults: merge with DEFAULT_KEYBINDINGS (later rules win)
WS-->>Client: { cwd, keybindings }
else malformed/invalid or missing
FS-->>WS: malformed/invalid or not found
WS->>WS: log warnings, ignore invalid entries, use defaults/truncated result
WS-->>Client: { cwd, keybindings }
end
Client->>Client: resolveTerminalKeybindings(response.keybindings)
Client->>Client: global keyboard handler matches events using platform & when-context
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
Add configurable keybindings from
|
Greptile SummaryThis PR adds a configurable keybindings system that loads user overrides from
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant FS as ~/.t3/keybindings.json
participant Server as WebSocket Server
participant Client as React Client
participant UI as ChatView / Sidebar / Terminal
Note over Server: Server startup
Server->>FS: readFileSync (once)
FS-->>Server: JSON array of rules
Server->>Server: Validate & compile rules<br/>(parse shortcuts, when ASTs)
Server->>Server: Merge with defaults<br/>(custom overrides by command)
Server->>Server: Cache resolved config
Note over Client: Component mount
Client->>Server: server.getConfig (WebSocket RPC)
Server-->>Client: { cwd, keybindings: ResolvedKeybindingsConfig }
Client->>Client: React Query caches config
Note over UI: User presses key
UI->>Client: KeyboardEvent
Client->>Client: Build context<br/>(terminalFocus, terminalOpen)
Client->>Client: resolveShortcutCommand()<br/>(iterate bindings last→first,<br/>match key + evaluate when AST)
Client-->>UI: Execute matched command<br/>(toggle/split/new/chat.new/openEditor)
Last reviewed commit: 00d7519 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@apps/web/src/terminal-shortcuts.ts`:
- Around line 302-367: normalizeConfiguredKeybinding currently accepts any when
string which can be malformed and thus silently override defaults; update
normalizeConfiguredKeybinding to validate the when expression and drop the
binding if invalid: after trimming when, attempt to validate it by calling
matchesWhenExpression(with a safe context from resolveContext(undefined) or a
minimal ShortcutMatchContext) inside a try/catch (or check the parser's
validation API) and return null for bindings whose when fails validation or
throws; this ensures resolveTerminalKeybindings will not treat malformed when
rules as overrides.
🧹 Nitpick comments (1)
apps/server/src/wsServer.ts (1)
73-119: Consider avoiding sync disk reads in the WS request path.
readFileSync+ JSON.parse run on everyserver.getConfigcall; memoizing the parsed config (and optionally refreshing on change/TTL) or moving the read to startup would keep the handler non-blocking under load.As per coding guidelines, "apps/server/src/**/*.{ts,js}: Maintain predictable behavior under load and during failures (session restarts, reconnects, partial streams)".
- Rename `terminal-shortcuts.ts` and its test to `keybindings` - Update ChatView and ThreadTerminalDrawer imports to use new module path
- Reuse `KeybindingRule` and `KeybindingsConfig` directly for resolved keybinding types - Update normalization helper to accept `KeybindingRule` for consistent typing
- add `packages/contracts/src/keybindings.ts` with keybinding schemas and types - import keybindings config schema from `server.ts` - re-export keybindings contracts from `packages/contracts/src/index.ts`
- Move default keybinding resolution/override merging into `server.getConfig` - Return server-resolved keybindings to the web client instead of resolving in UI - Update docs and tests to reflect server-side defaults, overrides, and truncation behavior
- convert schema and server file references in `KEYBINDINGS.md` to clickable Markdown links
- add `serverConfigQueryOptions` in new `serverReactQuery` utility - switch `ChatView` from manual `getConfig` effect/state to `useQuery` - default to empty keybindings while config is unavailable
- add `chat.new` and `editor.openFavorite` to keybinding contracts and server defaults - use shared keybinding matching in sidebar/chat view instead of hardcoded Cmd/Ctrl combos - document new commands/defaults and extend server/web keybinding tests
- Evaluate shortcut matches by resolving the last matching key+when rule, regardless of command - Add cross-command precedence tests and switch assertions to `vitest` `assert` - Clarify precedence behavior in `KEYBINDINGS.md`
~/.t3/keybindings.json~/.t3/keybindings.json
Co-authored-by: codex <codex@users.noreply.github.com>
- add reusable `LruCache` utility with bounded eviction - replace keybinding AST cache clear-all behavior with true LRU lookups - add unit tests for eviction, recency updates, and capacity validation
- add server keybinding compiler for shortcuts and `when` AST parsing - switch websocket/server config payload to resolved keybinding rules - update web keybinding logic/types to consume resolved payload directly - add/adjust contract, server, and web tests (including plus-key parsing) and docs
- Move `KeybindingWhenNode` into `packages/contracts/src/keybindings.ts` - Remove deprecated `keybindingsWhen` module/export - Update web keybinding tests to build `whenAst` directly in fixtures
- Replace `expect` assertions with `assert` in server and contracts keybinding tests - Keep existing coverage while standardizing assertion style
- drop `key` and `when` from resolved keybinding rule schema/payload - update server/web/contracts tests and keybindings docs for `whenAst`-only resolution - delete unused web `LruCache` implementation and tests
- Move default keybindings, config parsing, validation, and merge logic out of `wsServer` - Add `loadResolvedKeybindingsConfig(logger)` in `apps/server/src/keybindings.ts` - Update server wiring docs to point to `server.getConfig` integration
- make resolved keybinding/shortcut schemas strict to reject unknown fields - export server `DEFAULT_KEYBINDINGS` as source of truth and reuse it in ws tests - simplify keybinding test fixtures and update docs to reference server defaults
|
@greptileai review |
- set server config query `staleTime` to `Infinity` to avoid unnecessary refetches - narrow `isWindowsPlatform` matching to Windows-prefixed identifiers - add unit tests for Windows and non-Windows platform cases
Summary
~/.t3/keybindings.jsonand return keybindings inserver.getConfig.whenexpressions, command precedence, and platform-aware label formatting.KEYBINDINGS.mdwith syntax, commands, defaults, and precedence behavior.Testing
apps/server/src/wsServer.test.ts: verifiedserverGetConfignow includeskeybindings, reads valid config from~/.t3/keybindings.json, and warns/ignores invalid, unsupported, or malformed config.apps/web/src/terminal-shortcuts.test.ts: verified default shortcuts, split/newwhen-gated behavior, override resolution, invalid config filtering, and shortcut label formatting.Summary by CodeRabbit
New Features
Documentation
Tests