Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

fix(coding-agent): restore empty editor caret (#403)

ktcf65f0cdec6c
diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md
index 90a570f8aa..fa2f6e6bee 100644
--- a/packages/coding-agent/CHANGELOG.md
+++ b/packages/coding-agent/CHANGELOG.md
@@ -5,6 +5,7 @@
- Added compact file change stats to collapsed tool calls and an agent-run edit total above the recap.
- Changed tool expansion hints to appear only on the latest tool row instead of every tool call ([ENG-4583](https://linear.app/primeintellect/issue/ENG-4583/too-many-ctrlo-alerts)).
- Changed IPython kernels to set `NO_COLOR=1`, preventing ANSI color escapes from inflating `%%bash` output.
+- Fixed empty prompt placeholders hiding the input caret.
- Fixed missing ripgrep blocking subagents and added actionable installation guidance for the optional search helper ([ENG-4572](https://linear.app/primeintellect/issue/ENG-4572/ripgrep-not-installed)).
- Fixed tool-only responses rendering directly against the preceding user prompt.
diff --git a/packages/coding-agent/src/modes/interactive/components/custom-editor.ts b/packages/coding-agent/src/modes/interactive/components/custom-editor.ts
index bd64b5cf19..6b44dd27c9 100644
--- a/packages/coding-agent/src/modes/interactive/components/custom-editor.ts
+++ b/packages/coding-agent/src/modes/interactive/components/custom-editor.ts
@@ -1,4 +1,5 @@
import {
+ CURSOR_MARKER,
Editor,
type EditorOptions,
type EditorTheme,
@@ -287,9 +288,12 @@ export class CustomEditor extends Editor {
const promptLeadingPadding = " ".repeat(promptPrefixInset);
const promptTrailingPadding = " ".repeat(Math.max(0, paddingX - promptPrefixInset));
const rightPadding = " ".repeat(paddingX);
- const placeholderText = truncateToWidth(this.placeholder ?? "", inputWidth, "");
- const displayText = this.placeholderColor(placeholderText);
- const padding = " ".repeat(Math.max(0, inputWidth - visibleWidth(placeholderText)));
+ const placeholderWidth = Math.max(0, inputWidth - 1);
+ const placeholderText = truncateToWidth(this.placeholder ?? "", placeholderWidth, "");
+ const cursorMarker = this.focused && !this.isShowingAutocomplete() ? CURSOR_MARKER : "";
+ const cursorReset = this.backgroundColor ? "\x1b[27m" : "\x1b[0m";
+ const displayText = `${cursorMarker}\x1b[7m ${cursorReset}${this.placeholderColor(placeholderText)}`;
+ const padding = " ".repeat(Math.max(0, placeholderWidth - visibleWidth(placeholderText)));
const line = `${promptLeadingPadding}${promptPrefix}${promptTrailingPadding}${displayText}${padding}${rightPadding}`;
const padded = line + " ".repeat(Math.max(0, width - visibleWidth(line)));
return this.backgroundColor ? this.backgroundColor(padded) : padded;
diff --git a/packages/coding-agent/test/custom-editor.test.ts b/packages/coding-agent/test/custom-editor.test.ts
index 413660bb9b..9a13ff50c6 100644
--- a/packages/coding-agent/test/custom-editor.test.ts
+++ b/packages/coding-agent/test/custom-editor.test.ts
@@ -1,5 +1,5 @@
import type { AutocompleteProvider, EditorTheme, TUI } from "@earendil-works/pi-tui";
-import { setKeybindings } from "@earendil-works/pi-tui";
+import { CURSOR_MARKER, setKeybindings, visibleWidth } from "@earendil-works/pi-tui";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { KeybindingsManager } from "../src/core/keybindings.js";
import { CustomEditor } from "../src/modes/interactive/components/custom-editor.js";
@@ -137,6 +137,75 @@ describe("CustomEditor", () => {
expect(handler).toHaveBeenCalledTimes(2);
});
+ it("renders the editor caret before an empty prompt placeholder", () => {
+ const editor = new CustomEditor(fakeTui, editorTheme, new KeybindingsManager(), {
+ placeholder: "type to start",
+ });
+ editor.focused = true;
+
+ const line = editor.render(40)[1]!;
+
+ expect(line).toContain(`${CURSOR_MARKER}\x1b[7m \x1b[0mtype to start`);
+ expect(visibleWidth(line)).toBe(40);
+ });
+
+ it("omits the hardware cursor marker when the placeholder editor is unfocused", () => {
+ const editor = new CustomEditor(fakeTui, editorTheme, new KeybindingsManager(), {
+ placeholder: "type to start",
+ });
+
+ const line = editor.render(40)[1]!;
+
+ expect(line).not.toContain(CURSOR_MARKER);
+ expect(line).toContain("\x1b[7m \x1b[0mtype to start");
+ });
+
+ it("suppresses the hardware cursor marker while placeholder autocomplete is visible", async () => {
+ const editor = new CustomEditor(fakeTui, editorTheme, new KeybindingsManager(), {
+ placeholder: "type to start",
+ });
+ editor.focused = true;
+ editor.setAutocompleteProvider(autocompleteProvider);
+
+ editor.handleInput("\t");
+ await vi.waitFor(() => expect(editor.isShowingAutocomplete()).toBe(true));
+ const line = editor.render(40)[1]!;
+
+ expect(line).not.toContain(CURSOR_MARKER);
+ expect(line).toContain("\x1b[7m \x1b[0mtype to start");
+ });
+
+ it("preserves the editor background and exact width around placeholder carets", () => {
+ const backgroundColor = (text: string) => `\x1b[48;5;234m${text}\x1b[49m`;
+ const editor = new CustomEditor(fakeTui, { ...editorTheme, backgroundColor }, new KeybindingsManager(), {
+ paddingX: 2,
+ placeholder: "type to start",
+ });
+ editor.focused = true;
+
+ for (const width of [1, 2, 3, 4, 8, 40]) {
+ const line = editor.render(width)[1]!;
+
+ expect(line).toContain(`${CURSOR_MARKER}\x1b[7m \x1b[27m`);
+ expect(visibleWidth(line)).toBe(width);
+ }
+ });
+
+ it("keeps the placeholder caret on the input row below a header", () => {
+ const editor = new CustomEditor(fakeTui, editorTheme, new KeybindingsManager(), {
+ placeholder: "reply to agent",
+ });
+ editor.focused = true;
+ editor.getHeaderLine = () => "6h last agent response";
+
+ const lines = editor.render(40);
+
+ expect(lines[1]).toContain("6h last agent response");
+ expect(lines[1]).not.toContain(CURSOR_MARKER);
+ expect(lines[2]).not.toContain(CURSOR_MARKER);
+ expect(lines[3]).toContain(`${CURSOR_MARKER}\x1b[7m \x1b[0mreply to agent`);
+ });
+
it("renders a header line and blank spacer inside the top of the editor box", () => {
const editor = new CustomEditor(fakeTui, editorTheme, new KeybindingsManager());
const withoutHeader = editor.render(40);