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
This commit is contained in:
Julius Marminge authored and Julius Marminge committed 2026-02-15 15:51:05 -08:00
1 parent 20d3ad5d50
commit 3db020a683
8 files changed
+7 -83

No files matched your search

+7 -1
View File
@@ -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:
-2
View File
@@ -30,9 +30,7 @@ describe("server keybindings", () => {
});
assert.deepEqual(compiled, {
key: "mod+d",
command: "terminal.split",
when: "terminalOpen && !terminalFocus",
shortcut: {
key: "d",
metaKey: false,
-3
View File
@@ -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,
};
-2
View File
@@ -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,
});
-33
View File
@@ -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");
});
});
-38
View File
@@ -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);
}
}
}
@@ -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,
-2
View File
@@ -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(),
});