authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-02-15 11:24:14-08:00
committergravatar for jmarminge@gmail.comJulius Marminge <jmarminge@gmail.com> 2026-02-15 15:51:05-08:00
log31aa32b83bb234ef7f2bdad6a898d06ea1d0552e
treea565c4f86750a68f09637d5662566e49dc03da8b
parent53c367420cac82f7c5baba55bad29432f77a9633

Extract keybindings contracts into dedicated module

- 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`

3 files changed, 24 insertions(+), 20 deletions(-)

packages/contracts/src/index.ts+1
...@@ -5,6 +5,7 @@ export * from "./terminal";...@@ -5,6 +5,7 @@ export * from "./terminal";
5export * from "./provider";5export * from "./provider";
6export * from "./model";6export * from "./model";
7export * from "./ws";7export * from "./ws";
8export * from "./keybindings";
8export * from "./server";9export * from "./server";
9export * from "./project";10export * from "./project";
10export * from "./git";11export * from "./git";
packages/contracts/src/keybindings.ts created+22
...@@ -0,0 +1,22 @@
1import { z } from "zod";
2
3export const keybindingCommandSchema = z.enum([
4 "terminal.toggle",
5 "terminal.split",
6 "terminal.new",
7]);
8
9const keybindingValueSchema = z.string().trim().min(1).max(64);
10const keybindingWhenSchema = z.string().trim().min(1).max(256);
11
12export const keybindingRuleSchema = z.object({
13 key: keybindingValueSchema,
14 command: keybindingCommandSchema,
15 when: keybindingWhenSchema.optional(),
16});
17
18export const keybindingsConfigSchema = z.array(keybindingRuleSchema).max(256);
19
20export type KeybindingCommand = z.infer<typeof keybindingCommandSchema>;
21export type KeybindingRule = z.infer<typeof keybindingRuleSchema>;
22export type KeybindingsConfig = z.infer<typeof keybindingsConfigSchema>;
packages/contracts/src/server.ts+1-20
...@@ -1,28 +1,9 @@...@@ -1,28 +1,9 @@
1import { z } from "zod";1import { z } from "zod";
22import { keybindingsConfigSchema } from "./keybindings";
3export const keybindingCommandSchema = z.enum([
4 "terminal.toggle",
5 "terminal.split",
6 "terminal.new",
7]);
8
9const keybindingValueSchema = z.string().trim().min(1).max(64);
10const keybindingWhenSchema = z.string().trim().min(1).max(256);
11
12export const keybindingRuleSchema = z.object({
13 key: keybindingValueSchema,
14 command: keybindingCommandSchema,
15 when: keybindingWhenSchema.optional(),
16});
17
18export const keybindingsConfigSchema = z.array(keybindingRuleSchema).max(256);
193
20export const serverConfigSchema = z.object({4export const serverConfigSchema = z.object({
21 cwd: z.string().min(1),5 cwd: z.string().min(1),
22 keybindings: keybindingsConfigSchema.default([]),6 keybindings: keybindingsConfigSchema.default([]),
23});7});
248
25export type KeybindingCommand = z.infer<typeof keybindingCommandSchema>;
26export type KeybindingRule = z.infer<typeof keybindingRuleSchema>;
27export type KeybindingsConfig = z.infer<typeof keybindingsConfigSchema>;
28export type ServerConfig = z.infer<typeof serverConfigSchema>;9export type ServerConfig = z.infer<typeof serverConfigSchema>;