Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(tui): preserve foreground history during background streams (#3336)

prha7a63a68947ee
diff --git a/.changeset/preserve-tui-background-history.md b/.changeset/preserve-tui-background-history.md
new file mode 100644
index 000000000..e1867ad92
--- /dev/null
+++ b/.changeset/preserve-tui-background-history.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Keep completed foreground turns in native terminal scrollback while a background subagent continues streaming, rather than hiding them behind the live viewport.
diff --git a/packages/eve/src/cli/dev/tui/terminal-renderer.test.ts b/packages/eve/src/cli/dev/tui/terminal-renderer.test.ts
index f609b10bd..a9f079d98 100644
--- a/packages/eve/src/cli/dev/tui/terminal-renderer.test.ts
+++ b/packages/eve/src/cli/dev/tui/terminal-renderer.test.ts
@@ -1309,6 +1309,54 @@ describe("TerminalRenderer (inline scrollback)", () => {
renderer.shutdown();
});
+ it("commits completed foreground turns ahead of a live background subagent", async () => {
+ const { screen, renderer } = makeRenderer(48, 8);
+ renderer.renderAgentHeader({ name: "Weather Agent", serverUrl: "http://localhost:3000" });
+ renderer.beginSubagent({ callId: "background", name: "researcher" });
+ // These settled blocks arrive before the parent reports that the child
+ // is background work. Reclassifying the child must release them from its
+ // formerly leading live cohort.
+ renderer.renderNotice("EARLY_SETTLED_FOREGROUND_ONE");
+ renderer.renderNotice("EARLY_SETTLED_FOREGROUND_TWO");
+ renderer.backgroundSubagent({ callId: "background" });
+ renderer.upsertSubagentStep({
+ callId: "background",
+ subagentName: "researcher",
+ sectionKey: 0,
+ reasoning: "",
+ message: "still researching background details",
+ finalized: false,
+ });
+
+ await renderer.renderStream(
+ streamOf([
+ { type: "assistant-complete", id: "answer-1", text: "FIRST_COMPLETED_ANSWER" },
+ { type: "finish" },
+ ]),
+ { continueSession: true, submittedPrompt: "FIRST_COMPLETED_PROMPT" },
+ );
+ await renderer.renderStream(
+ streamOf([
+ { type: "assistant-complete", id: "answer-2", text: "SECOND_COMPLETED_ANSWER" },
+ { type: "finish" },
+ ]),
+ { continueSession: true, submittedPrompt: "SECOND_COMPLETED_PROMPT" },
+ );
+
+ const transcript = screen.snapshot();
+ expect(transcript).toContain("EARLY_SETTLED_FOREGROUND_ONE");
+ expect(transcript).toContain("EARLY_SETTLED_FOREGROUND_TWO");
+ expect(transcript).toContain("FIRST_COMPLETED_PROMPT");
+ expect(transcript).toContain("FIRST_COMPLETED_ANSWER");
+ expect(transcript).toContain("SECOND_COMPLETED_PROMPT");
+ expect(transcript).toContain("SECOND_COMPLETED_ANSWER");
+ expect(transcript).toContain("still researching background details");
+
+ renderer.completeSubagent({ authoritative: true, callId: "background" });
+ expect(screen.snapshot()).not.toContain("hidden while streaming");
+ renderer.shutdown();
+ });
+
it("keeps parent completion provisional until delayed child output reaches its boundary", async () => {
const { screen, input, renderer } = makeRenderer();
renderer.renderAgentHeader({ name: "Weather Agent", serverUrl: "http://localhost:3000" });
diff --git a/packages/eve/src/cli/dev/tui/terminal-renderer.ts b/packages/eve/src/cli/dev/tui/terminal-renderer.ts
index 3d10cce26..3a8292d52 100644
--- a/packages/eve/src/cli/dev/tui/terminal-renderer.ts
+++ b/packages/eve/src/cli/dev/tui/terminal-renderer.ts
@@ -1565,7 +1565,9 @@ export class TerminalRenderer implements AgentTUIRenderer {
header.status = "running";
header.live = true;
header.updateSeq = ++this.#updateSequence;
+ const wasBackground = this.#backgroundSubagentCallIds.has(update.callId);
this.#backgroundSubagentCallIds.add(update.callId);
+ if (!wasBackground) this.#moveSubagentCohortToBackgroundTail(update.callId);
this.#paint();
}
@@ -3484,6 +3486,18 @@ export class TerminalRenderer implements AgentTUIRenderer {
this.#blockById.delete(id);
}
+ /**
+ * Background children may outlive several foreground turns. Keep their
+ * mutable cohort at the live edge so it cannot hold those settled turns in
+ * the renderer's leading-prefix commit queue.
+ */
+ #moveSubagentCohortToBackgroundTail(callId: string): void {
+ const cohort = this.#blocks.filter((block) => block.subagentCallId === callId);
+ if (cohort.length === 0) return;
+ this.#blocks = this.#blocks.filter((block) => block.subagentCallId !== callId);
+ this.#blocks.push(...cohort);
+ }
+
#finalizeAllBlocks() {
for (const block of this.#blocks) {
// Blocks awaiting an approval decision, action.result, or OAuth callback