From 3db020a683398511a169c411513a945a1cd2f384 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 15 Feb 2026 13:56:37 -0800 Subject: [PATCH] Simplify resolved keybinding payload and remove unused LRU cache - 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 --- KEYBINDINGS.md | 8 ++++- apps/server/src/keybindings.test.ts | 2 -- apps/server/src/keybindings.ts | 3 -- apps/web/src/keybindings.test.ts | 2 -- apps/web/src/lib/lru.test.ts | 33 ------------------- apps/web/src/lib/lru.ts | 38 ---------------------- packages/contracts/src/keybindings.test.ts | 2 -- packages/contracts/src/keybindings.ts | 2 -- 8 files changed, 7 insertions(+), 83 deletions(-) delete mode 100644 apps/web/src/lib/lru.test.ts delete mode 100644 apps/web/src/lib/lru.ts diff --git a/KEYBINDINGS.md b/KEYBINDINGS.md index 84cbfe090a242d4e303b04a2851540225caeae5b..87c502b685ee8bd7319b8d0710f9f9ae8ee2388b 100644 --- a/KEYBINDINGS.md +++ b/KEYBINDINGS.md @@ -97,7 +97,13 @@ If you define any rules for a command, the default rule for that command is remo ## Server-Resolved Payload -`~/.t3/keybindings.json` is parsed and compiled on the server. The web client receives resolved rules (including parsed shortcut/when fields) and does not parse raw keybinding strings. +`~/.t3/keybindings.json` is parsed and compiled on the server. The web client receives resolved rules and does not parse raw keybinding strings. + +Resolved rule payload fields: + +- `command` +- `shortcut` +- `whenAst` (optional) See: diff --git a/apps/server/src/keybindings.test.ts b/apps/server/src/keybindings.test.ts index db85b0a47547fd6fc17327b4d7c5eb7d4e80091d..d761588e93872b3fa084d7cefde627f87a3728b5 100644 --- a/apps/server/src/keybindings.test.ts +++ b/apps/server/src/keybindings.test.ts @@ -30,9 +30,7 @@ describe("server keybindings", () => { }); assert.deepEqual(compiled, { - key: "mod+d", command: "terminal.split", - when: "terminalOpen && !terminalFocus", shortcut: { key: "d", metaKey: false, diff --git a/apps/server/src/keybindings.ts b/apps/server/src/keybindings.ts index 2a56e00e25fb6e404d03dc1aefc646baa281469c..7939286c1a991aba83e8739ece45c26ae4a5562a 100644 --- a/apps/server/src/keybindings.ts +++ b/apps/server/src/keybindings.ts @@ -216,16 +216,13 @@ export function compileResolvedKeybindingRule( const whenAst = parseKeybindingWhenExpression(when); if (!whenAst) return null; return { - key, command: rule.command, - when, shortcut, whenAst, }; } return { - key, command: rule.command, shortcut, }; diff --git a/apps/web/src/keybindings.test.ts b/apps/web/src/keybindings.test.ts index 7579db44cac7b83ec4e647eade32c28a1511b481..43f38637c2fe7da4fbf724a6681df580124853ed 100644 --- a/apps/web/src/keybindings.test.ts +++ b/apps/web/src/keybindings.test.ts @@ -125,7 +125,6 @@ function compile(bindings: TestBinding[]): ResolvedKeybindingsConfig { } if (binding.whenAst) { resolved.push({ - key: binding.key.trim(), command: binding.command, shortcut: parsedShortcut, whenAst: binding.whenAst, @@ -133,7 +132,6 @@ function compile(bindings: TestBinding[]): ResolvedKeybindingsConfig { continue; } resolved.push({ - key: binding.key.trim(), command: binding.command, shortcut: parsedShortcut, }); diff --git a/apps/web/src/lib/lru.test.ts b/apps/web/src/lib/lru.test.ts deleted file mode 100644 index 1d001796d625ba198853a5a5ee1e0606445ead02..0000000000000000000000000000000000000000 --- a/apps/web/src/lib/lru.test.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { assert, describe, it } from "vitest"; -import { LruCache } from "./lru"; - -describe("LruCache", () => { - it("evicts the least recently used entry", () => { - const cache = new LruCache(2); - cache.set("a", 1); - cache.set("b", 2); - assert.strictEqual(cache.get("a"), 1); - - cache.set("c", 3); - - assert.strictEqual(cache.get("b"), undefined); - assert.strictEqual(cache.get("a"), 1); - assert.strictEqual(cache.get("c"), 3); - }); - - it("refreshes recency on update", () => { - const cache = new LruCache(2); - cache.set("a", 1); - cache.set("b", 2); - cache.set("a", 10); - cache.set("c", 3); - - assert.strictEqual(cache.get("b"), undefined); - assert.strictEqual(cache.get("a"), 10); - assert.strictEqual(cache.get("c"), 3); - }); - - it("rejects non-positive capacities", () => { - assert.throws(() => new LruCache(0), "positive integer"); - }); -}); diff --git a/apps/web/src/lib/lru.ts b/apps/web/src/lib/lru.ts deleted file mode 100644 index d4f61bd3f32f55feb9e954703a9bd779a1838e74..0000000000000000000000000000000000000000 --- a/apps/web/src/lib/lru.ts +++ /dev/null @@ -1,38 +0,0 @@ -export class LruCache { - private readonly entries = new Map(); - - constructor(private readonly maxEntries: number) { - if (!Number.isInteger(maxEntries) || maxEntries <= 0) { - throw new Error("LruCache maxEntries must be a positive integer."); - } - } - - get size(): number { - return this.entries.size; - } - - get(key: K): V | undefined { - const value = this.entries.get(key); - if (value === undefined && !this.entries.has(key)) { - return undefined; - } - - // Refresh recency on successful lookup. - this.entries.delete(key); - this.entries.set(key, value as V); - return value; - } - - set(key: K, value: V): void { - if (this.entries.has(key)) { - this.entries.delete(key); - } - this.entries.set(key, value); - - while (this.entries.size > this.maxEntries) { - const oldest = this.entries.keys().next().value as K | undefined; - if (oldest === undefined) break; - this.entries.delete(oldest); - } - } -} diff --git a/packages/contracts/src/keybindings.test.ts b/packages/contracts/src/keybindings.test.ts index 90dc821132a505c305c07aa0ee1a371ea817b80a..3261d63408ac3b0982dcab215f573541c67e8f0d 100644 --- a/packages/contracts/src/keybindings.test.ts +++ b/packages/contracts/src/keybindings.test.ts @@ -37,9 +37,7 @@ describe("keybindings contracts", () => { it("parses resolved keybinding rules", () => { const parsed = resolvedKeybindingRuleSchema.parse({ - key: "mod+d", command: "terminal.split", - when: "terminalOpen && !terminalFocus", shortcut: { key: "d", metaKey: false, diff --git a/packages/contracts/src/keybindings.ts b/packages/contracts/src/keybindings.ts index 37a1def91547424eca48dac5f1dfb8f0941931f4..a17c695bc661e236ab0c3c609f0e5a298a8bb54b 100644 --- a/packages/contracts/src/keybindings.ts +++ b/packages/contracts/src/keybindings.ts @@ -58,9 +58,7 @@ export const keybindingWhenNodeSchema: z.ZodType = z.lazy(() ); export const resolvedKeybindingRuleSchema = z.object({ - key: keybindingValueSchema, command: keybindingCommandSchema, - when: keybindingWhenSchema.optional(), shortcut: keybindingShortcutSchema, whenAst: keybindingWhenNodeSchema.optional(), }); -- 2.54.0