A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
stabilize recaps and prompt tray hints (#375)
kt26966a4b143e
diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.mdindex 9285751161..6359e26bc2 100644--- a/packages/coding-agent/CHANGELOG.md+++ b/packages/coding-agent/CHANGELOG.md@@ -13,6 +13,8 @@- Fixed stale heartbeat jobs reopening archived, deleted, or concurrently terminated sessions ([ENG-4519](https://linear.app/primeintellect/issue/ENG-4519/heartbeats-rebirth-sessions-that-were-previously-killed)).- Fixed onboarding blocking normal TUI use by reopening login or model selection after startup ([ENG-4537](https://linear.app/primeintellect/issue/ENG-4537/stop-onboarding-from-gating-normal-tui-use)).- Fixed IPython Bash cells with leading blank lines being labeled and previewed as Python ([ENG-4529](https://linear.app/primeintellect/issue/ENG-4529/leading-newline-before-percentpercentbash-names-tool-call-as-python)).+- Fixed recap layout shifts by keeping the previous recap visible until its replacement arrives ([ENG-4533](https://linear.app/primeintellect/issue/ENG-4533/reserve-space-for-recap-to-prevent-layout-shift)).+- Changed the new-chat tray to hide shortcut guidance while typing and keep the `agents` link visible.## [0.2.8] - 2026-07-09diff --git a/packages/coding-agent/src/modes/interactive/interactive-mode.ts b/packages/coding-agent/src/modes/interactive/interactive-mode.tsindex df2638af9d..d30b767fc6 100644--- a/packages/coding-agent/src/modes/interactive/interactive-mode.ts+++ b/packages/coding-agent/src/modes/interactive/interactive-mode.ts@@ -85,7 +85,6 @@ import { type AppKeybinding, KeybindingsManager } from "../../core/keybindings.jimport {createCompactionSummaryMessage,createHeartbeatPromptMessage,- HEARTBEAT_PROMPT_CUSTOM_TYPE,HEARTBEAT_PROMPT_PREVIEW_LABEL,} from "../../core/messages.js";import { findExactModelReferenceMatch, resolveModelScopeFromModels } from "../../core/model-resolver.js";@@ -2896,26 +2895,18 @@ export class InteractiveMode {this.ui.requestRender();}- /** Render the recap line above the editor, only when one exists. */+ /** Render the recap line above the editor when one exists. */private renderRecap(): void {if (!this.recapContainer) return;this.recapContainer.clear();- // The subagent panel shows its own recap; suppress the parent's while it's open.const recap = this.childAgentPanelMode ? undefined : this.sessionRecap?.trim();if (recap) {- this.recapContainer.addChild(new Text(theme.fg("dim", `Recap: ${recap}`), 1, 0));- // Blank line between the recap and the prompt bar below it.+ this.recapContainer.addChild(new TruncatedText(theme.fg("dim", `Recap: ${recap}`), 1, 0));this.recapContainer.addChild(new Spacer(1));}this.ui.requestRender();}- private clearStaleRecapForPromptTurn(): void {- this.sessionRecap = undefined;- this.renderRecap();- this.updatePendingMessagesDisplay();- }-private renderWidgetContainer(container: Container,widgets: Map<string, Component & { dispose?(): void }>,@@ -4371,13 +4362,9 @@ export class InteractiveMode {case "message_start":if (event.message.role === "custom") {this.addMessageToChat(event.message);- if (event.message.customType === HEARTBEAT_PROMPT_CUSTOM_TYPE) {- this.clearStaleRecapForPromptTurn();- }this.ui.requestRender();} else if (event.message.role === "user") {this.addMessageToChat(event.message);- this.clearStaleRecapForPromptTurn();this.ui.requestRender();} else if (event.message.role === "assistant") {this.startAssistantStreamingMessage(event.message);@@ -4936,7 +4923,7 @@ export class InteractiveMode {}private getShortcutsTrayHint(): string | undefined {- if (!this.isNewChat()) {+ if (!this.isNewChat() || this.editor.getText().length > 0) {return undefined;}return keyText("app.shortcuts") ? keyHint("app.shortcuts", "for shortcuts") : "/hotkeys for shortcuts";@@ -4971,10 +4958,7 @@ export class InteractiveMode {if (!this.options.returnToAgentsView) {return undefined;}- if (this.editor.getText().trim()) {- return undefined;- }- return keyHint("app.agents.back", "agents view");+ return keyHint("app.agents.back", "agents");}private getTrayContextLabel(): string | undefined {diff --git a/packages/coding-agent/test/interactive-mode-startup.test.ts b/packages/coding-agent/test/interactive-mode-startup.test.tsindex 6952665350..983ff8b60b 100644--- a/packages/coding-agent/test/interactive-mode-startup.test.ts+++ b/packages/coding-agent/test/interactive-mode-startup.test.ts@@ -19,12 +19,12 @@ describe("InteractiveMode startup hints", () => {setKeybindings(new KeybindingsManager());});- function createMode(sessionHasMessages = false, returnToAgentsView = false) {+ function createMode(sessionHasMessages = false, returnToAgentsView = false, getEditorText = () => "") {const mode = {childAgentPanelMode: undefined,sessionHasMessages,options: { returnToAgentsView },- editor: { getText: () => "" },+ editor: { getText: getEditorText },connectionState: {model: { name: "test-model", reasoning: true },thinkingLevel: "high",@@ -83,11 +83,32 @@ describe("InteractiveMode startup hints", () => {expect(stripAnsi(label)).toBe("test-model • high ? for shortcuts");});- it("places the Agents View hint before the model and fresh-chat help", () => {- const mode = createMode(false, true);- const label = Reflect.get(InteractiveMode.prototype, "getTrayLocationLabel").call(mode);+ it("keeps the lowercase agents hint while typing", () => {+ let editorText = "";+ const mode = createMode(false, true, () => editorText);+ const getLabel = () => Reflect.get(InteractiveMode.prototype, "getTrayLocationLabel").call(mode);++ expect(stripAnsi(getLabel())).toBe("← agents test-model • high ? for shortcuts");++ editorText = "draft prompt";+ expect(stripAnsi(getLabel())).toBe("← agents test-model • high");+ });++ it("hides the fresh-chat shortcut hint while the prompt has text", () => {+ let editorText = "";+ const mode = createMode(false, false, () => editorText);+ const getLabel = () => Reflect.get(InteractiveMode.prototype, "getTrayLocationLabel").call(mode);++ expect(stripAnsi(getLabel())).toBe("test-model • high ? for shortcuts");++ editorText = "draft prompt";+ expect(stripAnsi(getLabel())).toBe("test-model • high");++ editorText = " ";+ expect(stripAnsi(getLabel())).toBe("test-model • high");- expect(stripAnsi(label)).toBe("← agents view test-model • high ? for shortcuts");+ editorText = "";+ expect(stripAnsi(getLabel())).toBe("test-model • high ? for shortcuts");});it("hides the tray shortcut guidance for chats with history", () => {diff --git a/packages/coding-agent/test/suite/regressions/4482-heartbeat-injected-prompt.test.ts b/packages/coding-agent/test/suite/regressions/4482-heartbeat-injected-prompt.test.tsindex 0c537e775d..30c40cee77 100644--- a/packages/coding-agent/test/suite/regressions/4482-heartbeat-injected-prompt.test.ts+++ b/packages/coding-agent/test/suite/regressions/4482-heartbeat-injected-prompt.test.ts@@ -371,16 +371,16 @@ describe("ENG-4482 heartbeat injected prompt UI", () => {expect(expanded).toContain("Check whether the long-running task needs another step.");});- it("clears stale recaps when heartbeat prompt turns start", async () => {+ it("keeps the current recap when heartbeat prompt turns start", async () => {const heartbeatMode = createMessageStartMode();const heartbeatMessage = createHeartbeatPromptMessage(createHeartbeat());await handleMessageStart(heartbeatMode, heartbeatMessage);expect(heartbeatMode.addMessageToChat).toHaveBeenCalledWith(heartbeatMessage);- expect(heartbeatMode.sessionRecap).toBeUndefined();- expect(heartbeatMode.renderRecap).toHaveBeenCalled();- expect(heartbeatMode.updatePendingMessagesDisplay).toHaveBeenCalled();+ expect(heartbeatMode.sessionRecap).toBe("previous recap");+ expect(heartbeatMode.renderRecap).not.toHaveBeenCalled();+ expect(heartbeatMode.updatePendingMessagesDisplay).not.toHaveBeenCalled();const goalMode = createMessageStartMode();const goal: GoalState = {diff --git a/packages/coding-agent/test/suite/regressions/4533-preserve-recap.test.ts b/packages/coding-agent/test/suite/regressions/4533-preserve-recap.test.tsnew file mode 100644index 0000000000..c025c23b83--- /dev/null+++ b/packages/coding-agent/test/suite/regressions/4533-preserve-recap.test.ts@@ -0,0 +1,130 @@+import type { AgentMessage } from "@earendil-works/pi-agent-core";+import { Container, visibleWidth } from "@earendil-works/pi-tui";+import { beforeAll, describe, expect, it, vi } from "vitest";+import { InteractiveMode } from "../../../src/modes/interactive/interactive-mode.js";+import { initTheme } from "../../../src/modes/interactive/theme/theme.js";++type RecapRenderMode = {+ recapContainer: Container;+ childAgentPanelMode?: "detail";+ sessionRecap?: string;+ ui: { requestRender: () => void };+};++type RenderRecapHost = {+ renderRecap(this: RecapRenderMode): void;+};++type MessageStartMode = {+ isInitialized: boolean;+ footer: { invalidate: () => void };+ updateConnectionStateFromEvent: (event: unknown) => void;+ contextUsageTokenBaseline: number;+ setSessionHasMessages: (hasMessages: boolean) => void;+ clearShortcutGuide: () => void;+ activityTracker: { handleEvent: (event: unknown) => void };+ updateWorkingLoaderMessage: () => void;+ addMessageToChat: (message: AgentMessage) => void;+ ui: { requestRender: () => void };+ sessionRecap?: string;+ renderRecap: () => void;+ updatePendingMessagesDisplay: () => void;+};++type HandleEventHost = {+ handleEvent(this: MessageStartMode, event: { type: "message_start"; message: AgentMessage }): Promise<void>;+};++const renderRecap = (InteractiveMode.prototype as unknown as RenderRecapHost).renderRecap;+const handleEvent = (InteractiveMode.prototype as unknown as HandleEventHost).handleEvent;++function createRenderMode(sessionRecap?: string): RecapRenderMode {+ return Object.assign(Object.create(InteractiveMode.prototype), {+ recapContainer: new Container(),+ sessionRecap,+ ui: { requestRender: vi.fn() },+ }) as RecapRenderMode;+}++function createMessageStartMode(): MessageStartMode {+ return Object.assign(Object.create(InteractiveMode.prototype), {+ isInitialized: true,+ footer: { invalidate: vi.fn() },+ updateConnectionStateFromEvent: vi.fn(),+ contextUsageTokenBaseline: 12,+ setSessionHasMessages: vi.fn(),+ clearShortcutGuide: vi.fn(),+ activityTracker: { handleEvent: vi.fn() },+ updateWorkingLoaderMessage: vi.fn(),+ addMessageToChat: vi.fn(),+ ui: { requestRender: vi.fn() },+ sessionRecap: "previous recap",+ renderRecap: vi.fn(),+ updatePendingMessagesDisplay: vi.fn(),+ }) as MessageStartMode;+}++function render(mode: RecapRenderMode, width = 80): string[] {+ renderRecap.call(mode);+ return mode.recapContainer.render(width);+}++function stripAnsi(text: string): string {+ return text.replace(/\u001b\[[0-9;]*m/g, "");+}++describe("ENG-4533 recap layout", () => {+ beforeAll(() => {+ initTheme("dark");+ });++ it("keeps the previous recap visible when a user prompt starts", async () => {+ const mode = createMessageStartMode();+ const message: AgentMessage = {+ role: "user",+ content: [{ type: "text", text: "Continue with the implementation" }],+ timestamp: Date.now(),+ };++ await handleEvent.call(mode, { type: "message_start", message });++ expect(mode.addMessageToChat).toHaveBeenCalledWith(message);+ expect(mode.sessionRecap).toBe("previous recap");+ expect(mode.renderRecap).not.toHaveBeenCalled();+ expect(mode.updatePendingMessagesDisplay).not.toHaveBeenCalled();+ });++ it("replaces an existing recap without changing its height", () => {+ const mode = createRenderMode("Reviewing the current implementation");+ const previous = render(mode);++ mode.sessionRecap = "Preparing the fix plan";+ const updated = render(mode);++ expect(previous).toHaveLength(2);+ expect(updated).toHaveLength(2);+ expect(stripAnsi(updated[0] ?? "")).toContain("Recap: Preparing the fix plan");+ });++ it("does not reserve blank space before the first recap", () => {+ const mode = createRenderMode();++ expect(render(mode)).toEqual([]);+ });++ it("keeps long recaps to one row on narrow terminals", () => {+ const mode = createRenderMode("Reviewing the implementation and preparing a clean regression test");+ const lines = render(mode, 24);++ expect(lines).toHaveLength(2);+ expect(visibleWidth(lines[0] ?? "")).toBe(24);+ expect(stripAnsi(lines[0] ?? "")).toContain("Recap:");+ });++ it("suppresses the parent recap area in child-agent detail", () => {+ const mode = createRenderMode("Reviewing the parent session");+ mode.childAgentPanelMode = "detail";++ expect(render(mode)).toEqual([]);+ });+});