The Open Framework for Building Agents
[1/2] feat(eve): support Option/Alt+Delete word deletion (#3430)
Ben Pankow7cfaa6f17654
diff --git a/.changeset/calm-terminals-delete.md b/.changeset/calm-terminals-delete.mdnew file mode 100644index 000000000..bfdf083f2--- /dev/null+++ b/.changeset/calm-terminals-delete.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Option+Delete on macOS and Alt+Backspace now delete to the previous word boundary in editable eve TUI fields.diff --git a/packages/eve/src/cli/dev/tui/line-editor.test.ts b/packages/eve/src/cli/dev/tui/line-editor.test.tsindex a9aeb297c..501324148 100644--- a/packages/eve/src/cli/dev/tui/line-editor.test.ts+++ b/packages/eve/src/cli/dev/tui/line-editor.test.ts@@ -6,6 +6,7 @@ import {backspace,deleteForward,deleteWord,+ deleteWordBackward,insert,killToEnd,killToStart,@@ -119,7 +120,31 @@ describe("line editing", () => {expect(killToStart({ text: "one\ntwo", cursor: 4 })).toEqual({ text: "one\ntwo", cursor: 4 });});- it("deletes the previous word", () => {+ it("deletes the previous readline-style word", () => {+ const text = "one, two_three 世界";+ expect(deleteWordBackward({ text, cursor: text.length })).toEqual({+ text: "one, two_three ",+ cursor: 16,+ });+ expect(deleteWordBackward({ text, cursor: 16 })).toEqual({ text: "one, 世界", cursor: 6 });+ expect(deleteWordBackward({ text: "e\u0301lan vital", cursor: 5 })).toEqual({+ text: " vital",+ cursor: 0,+ });+ });++ it("deletes the same span that Alt+Left traverses across lines", () => {+ expect(deleteWordBackward({ text: "one\ntwo", cursor: 7 })).toEqual({+ text: "one\n",+ cursor: 4,+ });+ expect(deleteWordBackward({ text: "one\ntwo", cursor: 4 })).toEqual({+ text: "two",+ cursor: 0,+ });+ });++ it("deletes the previous whitespace-delimited word", () => {expect(deleteWord({ text: "one two three", cursor: 13 })).toEqual({text: "one two ",cursor: 8,@@ -161,6 +186,10 @@ describe("line editing", () => {text: "one two",cursor: 3,});+ expect(applyLineEditorKey(lineOf("one two"), { type: "alt-backspace" })).toEqual({+ text: "one ",+ cursor: 4,+ });expect(applyLineEditorKey(line, { type: "enter" })).toBeUndefined();expect(applyLineEditorKey(line, { type: "escape" })).toBeUndefined();});diff --git a/packages/eve/src/cli/dev/tui/line-editor.ts b/packages/eve/src/cli/dev/tui/line-editor.tsindex e95da12e5..7970f000d 100644--- a/packages/eve/src/cli/dev/tui/line-editor.ts+++ b/packages/eve/src/cli/dev/tui/line-editor.ts@@ -146,6 +146,14 @@ export function killToStart(state: LineState): LineState {};}+/** Deletes to the previous readline-style word boundary (Alt+Backspace). */+export function deleteWordBackward(state: LineState): LineState {+ const start = moveWordBackward(state).cursor;+ if (start === state.cursor) return state;+ const text = state.text.slice(0, start) + state.text.slice(state.cursor);+ return { text, cursor: graphemeBoundaryAtOrAfter(text, start) };+}+/** Deletes the whitespace-delimited word before the caret (Ctrl+W). */export function deleteWord(state: LineState): LineState {if (state.cursor === 0) return state;@@ -213,6 +221,8 @@ export function applyLineEditorKey(return moveWordBackward(state);case "alt-f":return moveWordForward(state);+ case "alt-backspace":+ return deleteWordBackward(state);case "home":case "ctrl-a":return moveHome(state);diff --git a/packages/eve/src/cli/dev/tui/model-picker.test.ts b/packages/eve/src/cli/dev/tui/model-picker.test.tsnew file mode 100644index 000000000..d34d6e5f1--- /dev/null+++ b/packages/eve/src/cli/dev/tui/model-picker.test.ts@@ -0,0 +1,37 @@+import { describe, expect, it } from "vitest";++import type { ModelSettingsRequest } from "#setup/flows/model.js";++import { initialModelPickerState, transitionModelPicker } from "./model-picker.js";++const request: ModelSettingsRequest = {+ model: {+ kind: "pick",+ current: "anthropic/claude-sonnet",+ options: [+ { value: "anthropic/claude-sonnet", label: "Claude Sonnet" },+ { value: "openai/gpt", label: "GPT" },+ ],+ },+ reasoning: null,+ serviceTier: { kind: "standard" },+ settingsEditable: false,+ externalRouting: false,+ capabilitiesFor: () => undefined,+};++describe("transitionModelPicker", () => {+ it("deletes the previous word from the model search", () => {+ const initial = initialModelPickerState(request);+ const transition = transitionModelPicker(+ { ...initial, select: { ...initial.select, filter: "claude sonnet" } },+ { type: "delete-word-backward" },+ request,+ );++ expect(transition).toMatchObject({+ kind: "render",+ state: { select: { filter: "claude " } },+ });+ });+});diff --git a/packages/eve/src/cli/dev/tui/model-picker.ts b/packages/eve/src/cli/dev/tui/model-picker.tsindex 4a3e3632c..c922f2a51 100644--- a/packages/eve/src/cli/dev/tui/model-picker.ts+++ b/packages/eve/src/cli/dev/tui/model-picker.ts@@ -37,6 +37,7 @@ export type ModelPickerEvent =| { type: "cancel" }| { type: "submit" }| { type: "backspace" }+ | { type: "delete-word-backward" }| { type: "char"; char: string };export type ModelPickerTransition =@@ -221,7 +222,7 @@ export function transitionModelPicker(if (event.type !== "submit") {if ((state.step !== "model" || request.model.kind !== "pick") &&- (event.type === "char" || event.type === "backspace")+ (event.type === "char" || event.type === "backspace" || event.type === "delete-word-backward")) {return { kind: "render", state };}diff --git a/packages/eve/src/cli/dev/tui/setup-selection-input.test.ts b/packages/eve/src/cli/dev/tui/setup-selection-input.test.tsindex 877c854e8..7f4e81179 100644--- a/packages/eve/src/cli/dev/tui/setup-selection-input.test.ts+++ b/packages/eve/src/cli/dev/tui/setup-selection-input.test.ts@@ -156,6 +156,28 @@ describe("setupSelectionIntent", () => {).toEqual({ kind: "submit", values: ["slack"] });});+ it("deletes the previous word from searchable filters", () => {+ const options = [{ value: "claude", label: "Claude Sonnet" }];+ const searched = initialSelectState({ options, filter: "claude sonnet" });++ expect(+ reduceSetupSelectInput({+ key: { type: "alt-backspace" },+ kind: "search",+ options,+ select: searched,+ }),+ ).toMatchObject({ kind: "update", select: { filter: "claude " } });+ expect(+ reduceSetupSelectInput({+ key: { type: "alt-backspace" },+ kind: "single",+ options,+ select: searched,+ }),+ ).toEqual({ kind: "ignore" });+ });+it("clears a searchable filter with escape before cancelling the panel", () => {const options = [{ value: "recent", label: "recent-agent" },diff --git a/packages/eve/src/cli/dev/tui/setup-selection-input.ts b/packages/eve/src/cli/dev/tui/setup-selection-input.tsindex fb09f939f..370476d9c 100644--- a/packages/eve/src/cli/dev/tui/setup-selection-input.ts+++ b/packages/eve/src/cli/dev/tui/setup-selection-input.ts@@ -126,6 +126,10 @@ function editSetupSelect(input: SetupSelectInputState): SetupSelectInputResult {return isSearchableSelect(input)? updatedSelect(input, { type: "backspace" }): { kind: "ignore" };+ case "alt-backspace":+ return isSearchableSelect(input)+ ? updatedSelect(input, { type: "delete-word-backward" })+ : { kind: "ignore" };case "text": {if (input.key.framing === "unframed" && isMultiSelect(input) && input.key.value === " ") {return updatedSelect(input, { type: "toggle" });diff --git a/packages/eve/src/cli/dev/tui/stream-format.test.ts b/packages/eve/src/cli/dev/tui/stream-format.test.tsindex c5b74d591..81eff40e7 100644--- a/packages/eve/src/cli/dev/tui/stream-format.test.ts+++ b/packages/eve/src/cli/dev/tui/stream-format.test.ts@@ -101,9 +101,11 @@ describe("nextKey", () => {expect(nextKey("\x1bO")).toEqual({ consumed: 0, incomplete: true });});- it("decodes Alt+B/F as complete readline word-movement chords", () => {+ it("decodes Alt+B/F and Alt+Backspace as complete readline chords", () => {expect(nextKey("\x1bb")).toEqual({ key: { type: "alt-b" }, consumed: 2 });expect(nextKey("\x1bF")).toEqual({ key: { type: "alt-f" }, consumed: 2 });+ expect(nextKey("\x1b\x7f")).toEqual({ key: { type: "alt-backspace" }, consumed: 2 });+ expect(nextKey("\x1b\b")).toEqual({ key: { type: "alt-backspace" }, consumed: 2 });});it("takes a printable run as a single character token", () => {@@ -212,6 +214,13 @@ describe("parseKey", () => {expect(parseKey(Buffer.from("\x1b[5D"))).toEqual({ type: "alt-b" });});+ it("decodes kitty and xterm Alt+Backspace sequences", () => {+ expect(parseKey(Buffer.from("\x1b[127;3u"))).toEqual({ type: "alt-backspace" });+ expect(parseKey(Buffer.from("\x1b[8;3u"))).toEqual({ type: "alt-backspace" });+ expect(parseKey(Buffer.from("\x1b[27;3;127~"))).toEqual({ type: "alt-backspace" });+ expect(parseKey(Buffer.from("\x1b[27;3;8~"))).toEqual({ type: "alt-backspace" });+ });+it("decodes SGR mouse press and release with cell coordinates", () => {expect(parseKey(Buffer.from("\x1b[<0;35;12M"))).toEqual({type: "mouse",diff --git a/packages/eve/src/cli/dev/tui/stream-format.ts b/packages/eve/src/cli/dev/tui/stream-format.tsindex 535f529dc..dde5528b1 100644--- a/packages/eve/src/cli/dev/tui/stream-format.ts+++ b/packages/eve/src/cli/dev/tui/stream-format.ts@@ -41,6 +41,7 @@ export type TerminalKey =| { type: "ctrl-d" }| { type: "alt-b" }| { type: "alt-f" }+ | { type: "alt-backspace" }| { type: "ctrl-k" }| { type: "ctrl-n" }| { type: "ctrl-p" }@@ -194,6 +195,9 @@ export function nextKey(buffer: string): KeyToken {if (second === "f" || second === "F") {return { key: { type: "alt-f" }, consumed: 2 };}+ if (second === "\x7f" || second === "\b") {+ return { key: { type: "alt-backspace" }, consumed: 2 };+ }// Other `ESC` + byte chords surface Escape and then re-tokenize the byte.return { key: { type: "escape" }, consumed: 1 };}@@ -301,6 +305,13 @@ export function parseKey(chunk: Buffer): TerminalKey {return { type: "end" };case "\x1B[3~":return { type: "delete" };+ // Alt+Backspace commonly arrives as Meta+Backspace, kitty CSI-u, or+ // xterm's modifyOtherKeys form.+ case "\x1B[127;3u":+ case "\x1B[8;3u":+ case "\x1B[27;3;127~":+ case "\x1B[27;3;8~":+ return { type: "alt-backspace" };case "\t":return { type: "tab" };case "\x1B":diff --git a/packages/eve/src/cli/dev/tui/terminal-renderer.ts b/packages/eve/src/cli/dev/tui/terminal-renderer.tsindex d587dd4fa..137772e76 100644--- a/packages/eve/src/cli/dev/tui/terminal-renderer.ts+++ b/packages/eve/src/cli/dev/tui/terminal-renderer.ts@@ -2521,6 +2521,10 @@ export class TerminalRenderer implements AgentTUIRenderer {dispatch({ type: "backspace" });return;}+ if (key.type === "alt-backspace") {+ dispatch({ type: "delete-word-backward" });+ return;+ }if (key.type === "text") {for (const char of key.value.replaceAll("\n", " ")) {if (char >= " " && char !== "\u007f") dispatch({ type: "char", char });diff --git a/packages/eve/src/setup/cli/select-state.test.ts b/packages/eve/src/setup/cli/select-state.test.tsindex 684066681..f8b316187 100644--- a/packages/eve/src/setup/cli/select-state.test.ts+++ b/packages/eve/src/setup/cli/select-state.test.ts@@ -118,6 +118,14 @@ describe("reduceSelect", () => {expect(reduceSelect(state, { type: "backspace" }, context()).filter).toBe("");});+ it("deletes to the previous readline-style word boundary", () => {+ expect(reduceSelect(initial, { type: "delete-word-backward" }, context())).toBe(initial);+ const state = { filter: "one, two_three 世界", cursor: 2, selected: new Set<string>() };+ const next = reduceSelect(state, { type: "delete-word-backward" }, context());+ expect(next.filter).toBe("one, two_three ");+ expect(next.cursor).toBe(0);+ });+it("wraps the cursor across the visible list", () => {expect(reduceSelect(initial, { type: "up" }, context()).cursor).toBe(2);expect(reduceSelect({ ...initial, cursor: 2 }, { type: "down" }, context()).cursor).toBe(0);diff --git a/packages/eve/src/setup/cli/select-state.ts b/packages/eve/src/setup/cli/select-state.tsindex 83955d760..0659a8457 100644--- a/packages/eve/src/setup/cli/select-state.ts+++ b/packages/eve/src/setup/cli/select-state.ts@@ -35,6 +35,7 @@ export function searchActionQuery(value: string): string | undefined {export type SelectEvent =| { type: "char"; char: string }| { type: "backspace" }+ | { type: "delete-word-backward" }| { type: "clear" }| { type: "up" }| { type: "down" }@@ -100,6 +101,25 @@ function isActionable(option: PromptOption<string>): boolean {return isFocusable(option) && !option.completed;}+function previousWordBoundary(text: string): number {+ let cursor = text.length;+ while (cursor > 0) {+ const previous = previousGraphemeBoundary(text, cursor);+ if (isWordCharacter(text.slice(previous, cursor))) break;+ cursor = previous;+ }+ while (cursor > 0) {+ const previous = previousGraphemeBoundary(text, cursor);+ if (!isWordCharacter(text.slice(previous, cursor))) break;+ cursor = previous;+ }+ return cursor;+}++function isWordCharacter(text: string): boolean {+ return /^[\p{L}\p{M}\p{N}_]/u.test(text);+}+/*** First focusable index in a visible list. Falls back to the Submit row when* every entry is non-interactive and one exists, otherwise to 0.@@ -135,8 +155,8 @@ function stepCursor(/*** Advances the interaction state for a single keypress.*- * Editing the query (`char`/`backspace`) re-homes the cursor onto the first- * selectable match but leaves marked values intact, so a multi-select keeps its+ * Editing the query re-homes the cursor onto the first selectable match but+ * leaves marked values intact, so a multi-select keeps its* picks while the list is filtered. `toggle` (space) marks or unmarks the* highlighted entry; navigation skips disabled rows.*/@@ -173,6 +193,18 @@ export function reduceSelect(),};}+ case "delete-word-backward": {+ if (state.filter.length === 0) return state;+ const filter = state.filter.slice(0, previousWordBoundary(state.filter));+ return {+ ...state,+ filter,+ cursor: firstFocusableIndex(+ filterOptions(context.options, filter, context.searchAction),+ submitRow,+ ),+ };+ }case "clear": {if (state.filter.length === 0) return state;const filter = "";