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.
Simplify resolved keybinding payload and remove unused LRU cache
Julius Marminge3db020a68339
diff --git a/KEYBINDINGS.md b/KEYBINDINGS.mdindex 84cbfe090..87c502b68 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.tsindex db85b0a47..d761588e9 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.tsindex 2a56e00e2..7939286c1 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.tsindex 7579db44c..43f38637c 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.tsdeleted file mode 100644index 1d001796d..000000000--- 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<string, number>(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<string, number>(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<string, number>(0), "positive integer");- });-});diff --git a/apps/web/src/lib/lru.ts b/apps/web/src/lib/lru.tsdeleted file mode 100644index d4f61bd3f..000000000--- a/apps/web/src/lib/lru.ts+++ /dev/null@@ -1,38 +0,0 @@-export class LruCache<K, V> {- private readonly entries = new Map<K, V>();-- 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.tsindex 90dc82113..3261d6340 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.tsindex 37a1def91..a17c695bc 100644--- a/packages/contracts/src/keybindings.ts+++ b/packages/contracts/src/keybindings.ts@@ -58,9 +58,7 @@ export const keybindingWhenNodeSchema: z.ZodType<KeybindingWhenNode> = z.lazy(());export const resolvedKeybindingRuleSchema = z.object({- key: keybindingValueSchema,command: keybindingCommandSchema,- when: keybindingWhenSchema.optional(),shortcut: keybindingShortcutSchema,whenAst: keybindingWhenNodeSchema.optional(),});