@cueloop/client 0.1.0-alpha.3 → 0.1.0-alpha.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/package.json +17 -11
  2. package/src/App.autoclose.test.tsx +133 -0
  3. package/src/App.diff.test.tsx +27 -20
  4. package/src/App.export.test.tsx +19 -28
  5. package/src/App.plan-review.test.tsx +507 -0
  6. package/src/App.readonly.test.tsx +26 -27
  7. package/src/App.rendering.test.tsx +119 -0
  8. package/src/App.review-panel.test.tsx +123 -0
  9. package/src/App.submit-confirm.test.tsx +216 -0
  10. package/src/App.test.tsx +83 -64
  11. package/src/App.tsx +0 -0
  12. package/src/App.walk.test.tsx +265 -0
  13. package/src/attribution.test.ts +31 -0
  14. package/src/attribution.ts +32 -0
  15. package/src/clipboard.test.ts +23 -0
  16. package/src/clipboard.ts +26 -0
  17. package/src/components/AnnotationCard.compose-rows.test.ts +49 -0
  18. package/src/components/AnnotationCard.stories.tsx +75 -0
  19. package/src/components/AnnotationCard.tsx +208 -0
  20. package/src/components/Breadcrumb.stories.tsx +19 -0
  21. package/src/components/Breadcrumb.tsx +38 -0
  22. package/src/components/CodeBlock.stories.tsx +25 -0
  23. package/src/components/CodeBlock.tsx +68 -0
  24. package/src/components/CompletionOverlay.stories.tsx +23 -0
  25. package/src/components/CompletionOverlay.tsx +49 -0
  26. package/src/components/ComposeBar.stories.tsx +18 -0
  27. package/src/components/ComposeBar.tsx +54 -0
  28. package/src/components/ConfirmCard.stories.tsx +37 -0
  29. package/src/components/ConfirmCard.tsx +117 -0
  30. package/src/components/ConfirmDialog.stories.tsx +21 -0
  31. package/src/components/ConfirmDialog.tsx +56 -0
  32. package/src/components/DiffSheet.stories.tsx +44 -0
  33. package/src/components/DiffSheet.tsx +243 -0
  34. package/src/components/InboxList.stories.tsx +18 -0
  35. package/src/components/InboxList.tsx +55 -0
  36. package/src/components/PlanSheet.stories.tsx +81 -0
  37. package/src/components/PlanSheet.tsx +329 -0
  38. package/src/components/PromptDialog.stories.tsx +36 -0
  39. package/src/components/PromptDialog.tsx +62 -0
  40. package/src/components/ReviewPanel.stories.tsx +87 -0
  41. package/src/components/ReviewPanel.tsx +116 -0
  42. package/src/components/ReviewRail.stories.tsx +107 -0
  43. package/src/components/ReviewRail.tsx +180 -0
  44. package/src/components/SettingsDialog.stories.tsx +63 -0
  45. package/src/components/SettingsDialog.tsx +132 -0
  46. package/src/components/SettingsRows.stories.tsx +18 -0
  47. package/src/components/SettingsRows.tsx +92 -0
  48. package/src/components/WalkWizard.stories.tsx +89 -0
  49. package/src/components/WalkWizard.tsx +146 -0
  50. package/src/components/__snapshots__/stories.test.tsx.snap +1519 -0
  51. package/src/components/primitives/Button.stories.tsx +32 -0
  52. package/src/components/primitives/Button.tsx +44 -0
  53. package/src/components/primitives/Card.stories.tsx +25 -0
  54. package/src/components/primitives/Card.tsx +59 -0
  55. package/src/components/primitives/Dialog.stories.tsx +24 -0
  56. package/src/components/primitives/Dialog.tsx +54 -0
  57. package/src/components/primitives/StatusBar.stories.tsx +11 -0
  58. package/src/components/primitives/StatusBar.tsx +22 -0
  59. package/src/components/primitives/Tabs.stories.tsx +29 -0
  60. package/src/components/primitives/Tabs.tsx +97 -0
  61. package/src/components/primitives/Toolbar.stories.tsx +17 -0
  62. package/src/components/primitives/Toolbar.tsx +14 -0
  63. package/src/components/primitives/frame.test.ts +12 -0
  64. package/src/components/primitives/frame.ts +14 -0
  65. package/src/components/stories-app.tsx +95 -0
  66. package/src/components/stories.test.tsx +60 -0
  67. package/src/components/story-fixtures.ts +90 -0
  68. package/src/components/story.ts +66 -0
  69. package/src/components/syntax-highlight.ts +57 -0
  70. package/src/components/theme-context.stories.tsx +41 -0
  71. package/src/components/theme-context.tsx +30 -0
  72. package/src/components/truncate-text.ts +6 -0
  73. package/src/config.test.ts +196 -30
  74. package/src/config.ts +128 -16
  75. package/src/editor.test.ts +134 -0
  76. package/src/editor.ts +101 -13
  77. package/src/herdr.test.ts +41 -0
  78. package/src/herdr.ts +21 -0
  79. package/src/index.ts +2 -0
  80. package/src/integrations.test.ts +41 -0
  81. package/src/integrations.ts +28 -0
  82. package/src/intent-dispatch.test.ts +308 -0
  83. package/src/intent-dispatch.ts +295 -0
  84. package/src/key-bindings.test.ts +142 -0
  85. package/src/key-bindings.ts +363 -0
  86. package/src/keymap.test.ts +477 -0
  87. package/src/keymap.ts +272 -0
  88. package/src/review-panel.test.ts +111 -0
  89. package/src/review-panel.ts +76 -0
  90. package/src/run.ts +9 -5
  91. package/src/serve.test.ts +13 -6
  92. package/src/serve.ts +7 -7
  93. package/src/session-controller.share.test.ts +248 -0
  94. package/src/session-controller.ts +607 -0
  95. package/src/share.ts +80 -0
  96. package/src/test-support.ts +87 -0
  97. package/src/theme.ts +26 -3
  98. package/src/view-diff.test.ts +19 -8
  99. package/src/view-diff.ts +22 -22
  100. package/src/view-plan.test.ts +260 -0
  101. package/src/view-plan.ts +365 -0
  102. package/src/walk.test.ts +116 -0
  103. package/src/walk.ts +65 -0
  104. package/src/view.test.ts +0 -157
  105. package/src/view.ts +0 -0
@@ -0,0 +1,142 @@
1
+ /** Config keys resolve to per-layer actions, and status hints derive from getActiveKeys() so rebinds surface. */
2
+
3
+ import { describe, expect, test } from "bun:test";
4
+ import { DEFAULT_KEYS } from "./config";
5
+ import { KeyBindings } from "./key-bindings";
6
+
7
+ function bindings(context: { overlay?: "none" | "walk" | "compose" | "submit"; spanMode?: boolean } = {}): KeyBindings {
8
+ const resolver = new KeyBindings(DEFAULT_KEYS);
9
+ resolver.setContext({ overlay: context.overlay ?? "none", spanMode: context.spanMode ?? false });
10
+ return resolver;
11
+ }
12
+
13
+ describe("grammar-layer resolution", () => {
14
+ const table: [name: string, shift: boolean, action: string | undefined][] = [
15
+ ["j", false, "down"],
16
+ ["down", false, "down"],
17
+ ["k", false, "up"],
18
+ ["g", false, "top"],
19
+ ["g", true, "bottom"],
20
+ ["v", false, "span"],
21
+ ["c", false, "comment"],
22
+ ["s", false, "suggest"],
23
+ ["x", false, "cut"],
24
+ ["e", false, "edit"],
25
+ ["n", false, "next_annotation"],
26
+ ["p", false, "prev_annotation"],
27
+ ["backspace", false, "delete_annotation"],
28
+ ["return", false, "submit"],
29
+ ["enter", false, "submit"],
30
+ ["q", false, "quit"],
31
+ ["z", false, undefined],
32
+ ];
33
+ for (const [name, shift, action] of table) {
34
+ test(`${shift ? "shift+" : ""}${name} -> ${action}`, () => {
35
+ expect(bindings().resolveAction({ name, shift })).toBe(action!);
36
+ });
37
+ }
38
+ });
39
+
40
+ describe("mode layers own their keys", () => {
41
+ test("span mode resolves the span verbs, not the grammar", () => {
42
+ // Arrange
43
+ const resolver = bindings({ spanMode: true });
44
+
45
+ // Assert
46
+ expect(resolver.resolveAction({ name: "l", shift: false })).toBe("span_grow");
47
+ expect(resolver.resolveAction({ name: "c", shift: false })).toBe("span_comment");
48
+ expect(resolver.resolveAction({ name: "escape", shift: false })).toBe("span_cancel");
49
+ });
50
+
51
+ test("the compose overlay only knows save and cancel", () => {
52
+ // Arrange
53
+ const resolver = bindings({ overlay: "compose" });
54
+
55
+ // Assert
56
+ expect(resolver.resolveAction({ name: "return", shift: false })).toBe("save_compose");
57
+ expect(resolver.resolveAction({ name: "escape", shift: false })).toBe("cancel_overlay");
58
+ expect(resolver.resolveAction({ name: "j", shift: false })).toBeUndefined();
59
+ });
60
+
61
+ test("the submit overlay adds the verdict arrows", () => {
62
+ // Arrange
63
+ const resolver = bindings({ overlay: "submit" });
64
+
65
+ // Assert
66
+ expect(resolver.resolveAction({ name: "left", shift: false })).toBe("cycle_verdict_left");
67
+ expect(resolver.resolveAction({ name: "right", shift: false })).toBe("cycle_verdict_right");
68
+ expect(resolver.resolveAction({ name: "return", shift: false })).toBe("submit_verdict");
69
+ });
70
+
71
+ test("the walk overlay owns the bracket stepping and leaves the grammar keys dead", () => {
72
+ // Arrange
73
+ const resolver = bindings({ overlay: "walk" });
74
+
75
+ // Assert
76
+ expect(resolver.resolveAction({ name: "]", shift: false })).toBe("walk_next");
77
+ expect(resolver.resolveAction({ name: "[", shift: false })).toBe("walk_prev");
78
+ expect(resolver.resolveAction({ name: "escape", shift: false })).toBe("walk_leave");
79
+ expect(resolver.resolveAction({ name: "return", shift: false })).toBe("walk_submit");
80
+ expect(resolver.resolveAction({ name: "q", shift: false })).toBe("quit");
81
+ expect(resolver.resolveAction({ name: "j", shift: false })).toBeUndefined();
82
+ expect(resolver.resolveAction({ name: "c", shift: false })).toBeUndefined();
83
+ });
84
+ });
85
+
86
+ describe("getActiveKeys-generated status hints", () => {
87
+ test("normal mode hint matches the locked string", () => {
88
+ expect(bindings().statusHint("normal")).toBe(
89
+ "j/k move · v span · drag selects · c comment · s suggest · x cut · e edit · n/p annotations · ⏎ submit · q quit",
90
+ );
91
+ });
92
+
93
+ test("card-selected hint keeps the locked Cut label", () => {
94
+ expect(bindings().statusHint("card")).toBe("card · e edit · x Cut · n/p cards · esc deselect · ⏎ submit");
95
+ });
96
+
97
+ test("span hint", () => {
98
+ expect(bindings({ spanMode: true }).statusHint("span")).toBe(
99
+ "span · l/h grow/shrink · w/b slide · $ end · c comment · s suggest · esc",
100
+ );
101
+ });
102
+
103
+ test("compose hint", () => {
104
+ expect(bindings({ overlay: "compose" }).statusHint("compose")).toBe("typing · ⏎ save · esc cancel");
105
+ });
106
+
107
+ test("submit hint", () => {
108
+ expect(bindings({ overlay: "submit" }).statusHint("submit")).toBe("verdict ←/→ · ⏎ submit · esc cancel");
109
+ });
110
+
111
+ test("walk hint", () => {
112
+ expect(bindings({ overlay: "walk" }).statusHint("walk")).toBe(
113
+ "walk · ] next (marks viewed) · [ back · esc leave walk · q quit",
114
+ );
115
+ });
116
+
117
+ test("read-only hint", () => {
118
+ expect(bindings().statusHint("read-only")).toBe("observer - read-only · j/k move · n/p annotations · q quit");
119
+ });
120
+
121
+ test("collaborator hint annotates but shows no plan edit or submit", () => {
122
+ // Arrange / Act
123
+ const hint = bindings().statusHint("collaborator");
124
+
125
+ // Assert
126
+ expect(hint).toBe("j/k move · v span · drag selects · c comment · s suggest · n/p annotations · q quit");
127
+ expect(hint).not.toContain("cut");
128
+ expect(hint).not.toContain("edit");
129
+ expect(hint).not.toContain("submit");
130
+ });
131
+
132
+ test("a rebound key shows its real binding in the hint", () => {
133
+ // Arrange
134
+ const resolver = new KeyBindings({ ...DEFAULT_KEYS, comment: ["m"] });
135
+ resolver.setContext({ overlay: "none", spanMode: false });
136
+
137
+ // Assert
138
+ expect(resolver.resolveAction({ name: "m", shift: false })).toBe("comment");
139
+ expect(resolver.resolveAction({ name: "c", shift: false })).toBeUndefined();
140
+ expect(resolver.statusHint("normal")).toContain("m comment");
141
+ });
142
+ });
@@ -0,0 +1,363 @@
1
+ /**
2
+ * Binding resolution over @opentui/keymap: the loaded config keymap
3
+ * registers as layers (grammar, span, compose, submit, completion) on one
4
+ * Keymap instance, key events resolve to action names through its dispatch,
5
+ * and the status-line hints generate from getActiveKeys() - a rebound key
6
+ * shows its real binding in the hints. The pure intent reducer (keymap.ts)
7
+ * stays the dispatch layer beneath: this module answers "which action", the
8
+ * reducer answers "which intents".
9
+ */
10
+
11
+ import { Keymap, type KeymapEvent, type KeymapHost } from "@opentui/keymap";
12
+ import { registerDefaultKeys } from "@opentui/keymap/addons";
13
+ import type { KeyState } from "./keymap";
14
+
15
+ export interface ResolvableKey {
16
+ name: string;
17
+ shift: boolean;
18
+ }
19
+
20
+ /** The layer-activation slice of the view state. */
21
+ export interface KeyLayerContext {
22
+ overlay: KeyState["overlay"];
23
+ spanMode: boolean;
24
+ }
25
+
26
+ /** Hint templates keyed by the same view states the status line shows. */
27
+ export type HintMode = "normal" | "collaborator" | "card" | "span" | "compose" | "submit" | "walk" | "read-only";
28
+
29
+ type HintEntry =
30
+ | { text: string }
31
+ | { commands: string[]; label: string; labelFirst?: boolean };
32
+
33
+ const HINT_TEMPLATES: Record<HintMode, HintEntry[]> = {
34
+ normal: [
35
+ { commands: ["down", "up"], label: "move" },
36
+ { commands: ["span"], label: "span" },
37
+ { text: "drag selects" },
38
+ { commands: ["comment"], label: "comment" },
39
+ { commands: ["suggest"], label: "suggest" },
40
+ { commands: ["cut"], label: "cut" },
41
+ { commands: ["edit"], label: "edit" },
42
+ { commands: ["next_annotation", "prev_annotation"], label: "annotations" },
43
+ { commands: ["submit"], label: "submit" },
44
+ { commands: ["quit"], label: "quit" },
45
+ ],
46
+ // A share viewer: annotate and navigate, no plan edit / verdict submit.
47
+ collaborator: [
48
+ { commands: ["down", "up"], label: "move" },
49
+ { commands: ["span"], label: "span" },
50
+ { text: "drag selects" },
51
+ { commands: ["comment"], label: "comment" },
52
+ { commands: ["suggest"], label: "suggest" },
53
+ { commands: ["next_annotation", "prev_annotation"], label: "annotations" },
54
+ { commands: ["quit"], label: "quit" },
55
+ ],
56
+ card: [
57
+ { text: "card" },
58
+ { commands: ["edit"], label: "edit" },
59
+ { commands: ["cut"], label: "Cut" },
60
+ { commands: ["next_annotation", "prev_annotation"], label: "cards" },
61
+ { commands: ["deselect"], label: "deselect" },
62
+ { commands: ["submit"], label: "submit" },
63
+ ],
64
+ span: [
65
+ { text: "span" },
66
+ { commands: ["span_grow", "span_shrink"], label: "grow/shrink" },
67
+ { commands: ["span_slide_forward", "span_slide_back"], label: "slide" },
68
+ { commands: ["span_to_end"], label: "end" },
69
+ { commands: ["span_comment"], label: "comment" },
70
+ { commands: ["span_suggest"], label: "suggest" },
71
+ { commands: ["span_cancel"], label: "" },
72
+ ],
73
+ compose: [
74
+ { text: "typing" },
75
+ { commands: ["save_compose"], label: "save" },
76
+ { commands: ["cancel_overlay"], label: "cancel" },
77
+ ],
78
+ submit: [
79
+ { commands: ["cycle_verdict_left", "cycle_verdict_right"], label: "verdict", labelFirst: true },
80
+ { commands: ["submit_verdict"], label: "submit" },
81
+ { commands: ["cancel_submit"], label: "cancel" },
82
+ ],
83
+ walk: [
84
+ { text: "walk" },
85
+ { commands: ["walk_next"], label: "next (marks viewed)" },
86
+ { commands: ["walk_prev"], label: "back" },
87
+ { commands: ["walk_leave"], label: "leave walk" },
88
+ { commands: ["quit"], label: "quit" },
89
+ ],
90
+ "read-only": [
91
+ { text: "observer - read-only" },
92
+ { commands: ["down", "up"], label: "move" },
93
+ { commands: ["next_annotation", "prev_annotation"], label: "annotations" },
94
+ { commands: ["quit"], label: "quit" },
95
+ ],
96
+ };
97
+
98
+ /** Status-line glyphs for named keys. */
99
+ const KEY_GLYPHS: Record<string, string> = {
100
+ return: "⏎",
101
+ enter: "⏎",
102
+ escape: "esc",
103
+ left: "←",
104
+ right: "→",
105
+ backspace: "⌫",
106
+ down: "↓",
107
+ up: "↑",
108
+ };
109
+
110
+ function makeKeymapEvent(name: string, shift = false): KeymapEvent {
111
+ return {
112
+ name,
113
+ ctrl: false,
114
+ shift,
115
+ meta: false,
116
+ preventDefault: () => {},
117
+ stopPropagation: () => {},
118
+ propagationStopped: false,
119
+ };
120
+ }
121
+
122
+ class HeadlessKeymapHost implements KeymapHost<object, KeymapEvent> {
123
+ readonly metadata = {
124
+ platform: "unknown" as const,
125
+ primaryModifier: "unknown" as const,
126
+ modifiers: {
127
+ ctrl: "supported" as const,
128
+ shift: "supported" as const,
129
+ meta: "supported" as const,
130
+ super: "unknown" as const,
131
+ hyper: "unknown" as const,
132
+ },
133
+ };
134
+ readonly rootTarget = {};
135
+ readonly isDestroyed = false;
136
+ private readonly pressListeners = new Set<(event: KeymapEvent) => void>();
137
+
138
+ getFocusedTarget(): object | null {
139
+ return null;
140
+ }
141
+ getParentTarget(): object | null {
142
+ return null;
143
+ }
144
+ isTargetDestroyed(): boolean {
145
+ return false;
146
+ }
147
+ onKeyPress(listener: (event: KeymapEvent) => void): () => void {
148
+ this.pressListeners.add(listener);
149
+ return () => this.pressListeners.delete(listener);
150
+ }
151
+ onKeyRelease(): () => void {
152
+ return () => {};
153
+ }
154
+ onFocusChange(): () => void {
155
+ return () => {};
156
+ }
157
+ onTargetDestroy(): () => void {
158
+ return () => {};
159
+ }
160
+ createCommandEvent(): KeymapEvent {
161
+ return makeKeymapEvent("");
162
+ }
163
+ emitKeyPress(event: KeymapEvent): void {
164
+ for (const listener of this.pressListeners) listener(event);
165
+ }
166
+ }
167
+
168
+ /**
169
+ * Terminal key events name shifted letters either "g"+shift or "G"; the
170
+ * keymap's canonical form is lowercase + the shift modifier. Non-letter
171
+ * single characters ("$", "0") already encode their shift in the character.
172
+ */
173
+ function normalizedEvent(key: ResolvableKey): { name: string; shift: boolean } {
174
+ if (key.name.length === 1) {
175
+ if (/[a-zA-Z]/.test(key.name)) {
176
+ return { name: key.name.toLowerCase(), shift: key.shift || key.name !== key.name.toLowerCase() };
177
+ }
178
+ return { name: key.name, shift: false };
179
+ }
180
+ return { name: key.name, shift: key.shift };
181
+ }
182
+
183
+ /** Config combos write shifted letters as uppercase; the parser wants shift+. */
184
+ function bindingKeyFor(combo: string): string {
185
+ if (combo.length === 1 && /[A-Z]/.test(combo)) return `shift+${combo.toLowerCase()}`;
186
+ return combo;
187
+ }
188
+
189
+ /** The grammar actions live in the base layer; these live in mode layers. */
190
+ const SPAN_COMMANDS: [key: string, command: string][] = [
191
+ ["l", "span_grow"],
192
+ ["h", "span_shrink"],
193
+ ["w", "span_slide_forward"],
194
+ ["b", "span_slide_back"],
195
+ ["$", "span_to_end"],
196
+ ["0", "span_to_start"],
197
+ ["c", "span_comment"],
198
+ ["s", "span_suggest"],
199
+ ["escape", "span_cancel"],
200
+ ];
201
+
202
+ export class KeyBindings {
203
+ private readonly host = new HeadlessKeymapHost();
204
+ private readonly keymap = new Keymap<object, KeymapEvent>(this.host);
205
+ private context: KeyLayerContext = { overlay: "none", spanMode: false };
206
+ private resolvedCommand: string | undefined;
207
+ private unregisterGrammarLayer: (() => void) | null = null;
208
+
209
+ constructor(keys: Record<string, string[]>) {
210
+ // the standard binding-string parser and event matcher
211
+ registerDefaultKeys(this.keymap);
212
+ // binding/layer `when` fields register runtime matchers, so getActiveKeys
213
+ // and dispatch only see the layer that owns the current mode
214
+ this.keymap.registerLayerFields({
215
+ when: (value, fieldContext) => {
216
+ if (typeof value === "function") fieldContext.activeWhen(value as () => boolean);
217
+ },
218
+ });
219
+ this.registerModeLayers();
220
+ this.setKeys(keys);
221
+ }
222
+
223
+ /** Rebuild the grammar layer from a (re)loaded config keymap. */
224
+ setKeys(keys: Record<string, string[]>): void {
225
+ this.unregisterGrammarLayer?.();
226
+ const bindings: { key: string; cmd: string }[] = [];
227
+ const commandNames = new Set<string>();
228
+ for (const [action, combos] of Object.entries(keys)) {
229
+ commandNames.add(action);
230
+ for (const combo of combos) bindings.push({ key: bindingKeyFor(combo), cmd: action });
231
+ }
232
+ // deselect is a hardwired escape in the plan grammar; hints show it
233
+ commandNames.add("deselect");
234
+ bindings.push({ key: "escape", cmd: "deselect" });
235
+ this.unregisterGrammarLayer = this.keymap.registerLayer({
236
+ priority: 0,
237
+ when: () => this.context.overlay === "none" && !this.context.spanMode,
238
+ bindings,
239
+ commands: [...commandNames].map((name) => ({
240
+ name,
241
+ run: () => {
242
+ this.resolvedCommand = name;
243
+ return true;
244
+ },
245
+ })),
246
+ });
247
+ }
248
+
249
+ private registerModeLayers(): void {
250
+ const record = (name: string) => ({
251
+ name,
252
+ run: () => {
253
+ this.resolvedCommand = name;
254
+ return true;
255
+ },
256
+ });
257
+ this.keymap.registerLayer({
258
+ priority: 10,
259
+ when: () => this.context.overlay === "none" && this.context.spanMode,
260
+ bindings: SPAN_COMMANDS.map(([key, command]) => ({ key, cmd: command })),
261
+ commands: SPAN_COMMANDS.map(([, command]) => record(command)),
262
+ });
263
+ // the walk wizard: prev/next stepping, leave, and submit from the end card
264
+ this.keymap.registerLayer({
265
+ priority: 20,
266
+ when: () => this.context.overlay === "walk",
267
+ bindings: [
268
+ { key: "]", cmd: "walk_next" },
269
+ { key: "[", cmd: "walk_prev" },
270
+ { key: "escape", cmd: "walk_leave" },
271
+ { key: "return", cmd: "walk_submit" },
272
+ { key: "enter", cmd: "walk_submit" },
273
+ { key: "q", cmd: "quit" },
274
+ ],
275
+ commands: [record("walk_next"), record("walk_prev"), record("walk_leave"), record("walk_submit"), record("quit")],
276
+ });
277
+ this.keymap.registerLayer({
278
+ priority: 20,
279
+ when: () => this.context.overlay === "compose",
280
+ bindings: [
281
+ { key: "return", cmd: "save_compose" },
282
+ { key: "enter", cmd: "save_compose" },
283
+ { key: "escape", cmd: "cancel_overlay" },
284
+ ],
285
+ commands: [record("save_compose"), record("cancel_overlay")],
286
+ });
287
+ this.keymap.registerLayer({
288
+ priority: 20,
289
+ when: () => this.context.overlay === "submit",
290
+ bindings: [
291
+ { key: "return", cmd: "submit_verdict" },
292
+ { key: "enter", cmd: "submit_verdict" },
293
+ { key: "left", cmd: "cycle_verdict_left" },
294
+ { key: "right", cmd: "cycle_verdict_right" },
295
+ { key: "escape", cmd: "cancel_submit" },
296
+ ],
297
+ commands: [
298
+ record("submit_verdict"),
299
+ record("cycle_verdict_left"),
300
+ record("cycle_verdict_right"),
301
+ record("cancel_submit"),
302
+ ],
303
+ });
304
+ this.keymap.registerLayer({
305
+ priority: 20,
306
+ when: () => this.context.overlay === "completion-prompt" || this.context.overlay === "completion-counting",
307
+ bindings: [
308
+ { key: "return", cmd: "finish_review" },
309
+ { key: "enter", cmd: "finish_review" },
310
+ { key: "q", cmd: "finish_review" },
311
+ { key: "a", cmd: "opt_in_auto_close" },
312
+ { key: "escape", cmd: "dismiss_completion" },
313
+ ],
314
+ commands: [record("finish_review"), record("opt_in_auto_close"), record("dismiss_completion")],
315
+ });
316
+ }
317
+
318
+ setContext(context: KeyLayerContext): void {
319
+ this.context = context;
320
+ }
321
+
322
+ /**
323
+ * Resolve a key event to its command name through the keymap's dispatch.
324
+ * In the base grammar layer the command IS the config action name, so the
325
+ * result feeds straight into the intent reducer.
326
+ */
327
+ resolveAction(key: ResolvableKey): string | undefined {
328
+ const normalized = normalizedEvent(key);
329
+ this.resolvedCommand = undefined;
330
+ this.host.emitKeyPress(makeKeymapEvent(normalized.name, normalized.shift));
331
+ return this.resolvedCommand;
332
+ }
333
+
334
+ /** First active key display for a command, mapped through the glyph table. */
335
+ private keyDisplayFor(command: string): string | null {
336
+ for (const activeKey of this.keymap.getActiveKeys({ includeBindings: true })) {
337
+ const bindingCommand =
338
+ typeof activeKey.command === "string" ? activeKey.command : activeKey.bindings?.[0]?.command;
339
+ if (bindingCommand !== command) continue;
340
+ return KEY_GLYPHS[activeKey.stroke.name] ?? activeKey.display;
341
+ }
342
+ return null;
343
+ }
344
+
345
+ /** The status-line hint for a view state, generated from the active keys. */
346
+ statusHint(mode: HintMode): string {
347
+ const fragments: string[] = [];
348
+ for (const entry of HINT_TEMPLATES[mode]) {
349
+ if ("text" in entry) {
350
+ fragments.push(entry.text);
351
+ continue;
352
+ }
353
+ const displays = entry.commands
354
+ .map((command) => this.keyDisplayFor(command))
355
+ .filter((display): display is string => display !== null);
356
+ if (!displays.length) continue;
357
+ const keyPart = displays.join("/");
358
+ if (!entry.label) fragments.push(keyPart);
359
+ else fragments.push(entry.labelFirst ? `${entry.label} ${keyPart}` : `${keyPart} ${entry.label}`);
360
+ }
361
+ return fragments.join(" · ");
362
+ }
363
+ }