Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): show subagent steering as one task in the dev TUI (#4197)

Andrew Barba6ed6253f5b87
diff --git a/.changeset/tui-subagent-steering.md b/.changeset/tui-subagent-steering.md
new file mode 100644
index 000000000..cfb921abe
--- /dev/null
+++ b/.changeset/tui-subagent-steering.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+The dev TUI no longer shows a follow-up message to a working subagent as a second subagent: it reads `Message subagent` in the transcript, the task panel keeps one entry, and the task ends with a single line. Parallel `agent` tasks are now named `subagent:2` instead of `subagent(subagent:2)`, and sibling tasks in the panel get a blank row between them when there is room.
diff --git a/packages/eve/src/cli/dev/tui/task-activity.test.ts b/packages/eve/src/cli/dev/tui/task-activity.test.ts
index 11c809e71..524028c7c 100644
--- a/packages/eve/src/cli/dev/tui/task-activity.test.ts
+++ b/packages/eve/src/cli/dev/tui/task-activity.test.ts
@@ -33,6 +33,16 @@ describe("live task panel", () => {
expect(rows.join("\n")).not.toContain("Find Alice's notes");
});
+ it("separates sibling tasks while keeping nested work under its owner", () => {
+ const rows = render([task("researcher", [task("download")]), task("writer")]);
+ expect(rows.slice(2, -2)).toEqual([
+ " subagent(researcher) 12s",
+ " └ subagent(download) 12s",
+ "",
+ " subagent(writer) 12s",
+ ]);
+ });
+
it("bounds fan-out and keeps nested approvals visible ahead of ordinary work", () => {
const approval = task("reviewer");
approval.childTools.set("approve", {
diff --git a/packages/eve/src/cli/dev/tui/task-activity.ts b/packages/eve/src/cli/dev/tui/task-activity.ts
index 1b5c85b36..e4725b030 100644
--- a/packages/eve/src/cli/dev/tui/task-activity.ts
+++ b/packages/eve/src/cli/dev/tui/task-activity.ts
@@ -7,12 +7,11 @@
*/
import type { Block } from "./blocks.js";
-import { agentTaskLabel } from "./tool-presentation.js";
+import { agentTaskLabel, isSelfModificationAgent } from "./tool-presentation.js";
import type { Theme } from "./theme.js";
import { formatTurnDuration } from "./stream-format.js";
import { renderTransientDrawer } from "./flow-drawer.js";
import { truncate } from "./tool-format.js";
-import { isSelfModificationAgent } from "./tool-presentation.js";
import { clipVisible, visibleLength } from "#cli/ui/terminal-text.js";
export type TaskKind = "agent" | "tool";
@@ -41,62 +40,6 @@ export interface TaskEntry {
/** Includes the heading and overflow summary, regardless of nesting. */
const maxPanelRows = 15;
-export class TaskActivity {
- readonly #entries = new Map<string, TaskEntry>();
-
- start(input: {
- readonly callId: string;
- readonly kind: TaskKind;
- readonly baseName: string;
- readonly toolName: string;
- readonly input: unknown;
- readonly label: string | undefined;
- readonly nowMs: number;
- }): TaskEntry {
- const entry: TaskEntry = {
- callId: input.callId,
- kind: input.kind,
- name: this.#uniqueName(input.baseName),
- toolName: input.toolName,
- input: input.input,
- label: input.label,
- startedAtMs: input.nowMs,
- childTools: new Map(),
- };
- this.#entries.set(input.callId, entry);
- return entry;
- }
-
- get(callId: string): TaskEntry | undefined {
- return this.#entries.get(callId);
- }
-
- /** Removes and returns a task that ended. */
- finish(callId: string): TaskEntry | undefined {
- const entry = this.#entries.get(callId);
- this.#entries.delete(callId);
- return entry;
- }
-
- working(): readonly TaskEntry[] {
- return [...this.#entries.values()];
- }
-
- clear(): void {
- this.#entries.clear();
- }
-
- /** Parallel calls to one agent read `researcher`, `researcher:2`, …; a name is never renamed. */
- #uniqueName(baseName: string): string {
- const taken = new Set([...this.#entries.values()].map((entry) => entry.name));
- if (!taken.has(baseName)) return baseName;
- for (let ordinal = 2; ; ordinal += 1) {
- const candidate = `${baseName}:${String(ordinal)}`;
- if (!taken.has(candidate)) return candidate;
- }
- }
-}
-
/** Joins the working tasks' names for the turn bar: `Waiting for researcher and reviewer`. */
export function waitingLabel(entries: readonly TaskEntry[]): string {
if (entries.length === 1 && isSelfModificationAgent(entries[0]!.toolName)) {
@@ -181,9 +124,12 @@ export function renderTaskPanelRows(
[...attention, ...tasks.filter((task) => !attention.includes(task))].slice(0, capacity),
);
const shown = tasks.filter((task) => selected.has(task));
- const rows: string[] = [];
+ // Each top-level task and its nested work form one group, so siblings don't run together.
+ const groups: string[][] = [];
for (const { entry, path } of shown) {
const nested = path.length > 0;
+ if (!nested || groups.length === 0) groups.push([]);
+ const rows = groups.at(-1)!;
const lead = ` ${nested ? `${theme.glyph.corner} ` : ""}`;
const parentShown = shown.some((task) => task.entry === path.at(-1));
const owners = parentShown ? path.slice(1) : path;
@@ -202,6 +148,9 @@ export function renderTaskPanelRows(
if (text.length > 0) rows.push(clipVisible(`${detailLead}${color(text)}`, width));
}
const hidden = total - shown.length;
+ const dense = groups.flat();
+ const spaced = groups.flatMap((group, index) => (index === 0 ? group : ["", ...group]));
+ const rows = spaced.length + (hidden > 0 ? 1 : 0) <= contentBudget ? spaced : dense;
if (hidden > 0 && rows.length < contentBudget) {
const summary = `${theme.glyph.ellipsis} ${omitted > 0 ? "at least " : ""}${hidden} more working${omittedAttention ? " · Approval needed" : ""}`;
rows.push(clipVisible(` ${omittedAttention ? c.yellow(summary) : c.dim(summary)}`, width));
diff --git a/packages/eve/src/cli/dev/tui/task-records.ts b/packages/eve/src/cli/dev/tui/task-records.ts
new file mode 100644
index 000000000..7bb3f5737
--- /dev/null
+++ b/packages/eve/src/cli/dev/tui/task-records.ts
@@ -0,0 +1,89 @@
+import type { ConversationTask } from "#client/conversation-state.js";
+import type { EveDynamicToolPart } from "#client/message-reducer-types.js";
+import { stripTerminalControls } from "#cli/ui/terminal-text.js";
+import { agentDisplayName, presentTool } from "./tool-presentation.js";
+import { agentTaskSummary, labelContext, type TaskRecord } from "./transcript-parts.js";
+
+/**
+ * The transcript's task records, one for each stretch of a task's work. A call that reaches a
+ * task while one of its calls still works joins that task's record, as a model steering a working
+ * agent does; a call that reaches it after it settled starts a new stretch with its own lines.
+ */
+export class TaskRecords {
+ /** Records by the call that started them, in start order. */
+ readonly #started = new Map<string, TaskRecord>();
+ /** Records by every call they answer. */
+ readonly #byCall = new Map<string, TaskRecord>();
+
+ /** Records in start order. */
+ values(): IterableIterator<TaskRecord> {
+ return this.#started.values();
+ }
+
+ get(callId: string): TaskRecord | undefined {
+ return this.#byCall.get(callId);
+ }
+
+ clear(): void {
+ this.#started.clear();
+ this.#byCall.clear();
+ }
+
+ /** The record a task call belongs to, joining its task's working record or starting one. */
+ record(
+ part: EveDynamicToolPart,
+ task: ConversationTask,
+ label: string | undefined,
+ now: number,
+ ): TaskRecord {
+ const callId = part.toolCallId;
+ const known = this.#byCall.get(callId) ?? this.#join(callId, task);
+ if (known !== undefined) return known;
+ let summary = agentTaskSummary(part.input);
+ let baseName = agentDisplayName(stripTerminalControls(part.toolName));
+ if (task.kind === "tool") {
+ const presentation = presentTool(part.toolName, part.input, labelContext(label));
+ baseName = stripTerminalControls(presentation.title);
+ summary = stripTerminalControls(presentation.subtitle);
+ }
+ const record: TaskRecord = {
+ callId,
+ taskId: task.taskId,
+ callIds: [callId],
+ kind: task.kind,
+ name: this.#uniqueName(baseName),
+ toolName: part.toolName,
+ input: part.input,
+ label,
+ purpose: summary || label,
+ startedAtMs: now,
+ ended: false,
+ };
+ this.#started.set(callId, record);
+ this.#byCall.set(callId, record);
+ return record;
+ }
+
+ #join(callId: string, task: ConversationTask): TaskRecord | undefined {
+ for (const record of this.#started.values()) {
+ if (record.ended || record.taskId !== task.taskId) continue;
+ if (!record.callIds.some((id) => task.calls[id]?.status === "working")) continue;
+ record.callIds.push(callId);
+ this.#byCall.set(callId, record);
+ return record;
+ }
+ return undefined;
+ }
+
+ /** Parallel tasks of one tool read `research`, `research:2`, …; a name is never renamed. */
+ #uniqueName(baseName: string): string {
+ const taken = new Set(
+ [...this.#started.values()].filter((record) => !record.ended).map((record) => record.name),
+ );
+ if (!taken.has(baseName)) return baseName;
+ for (let ordinal = 2; ; ordinal += 1) {
+ const candidate = `${baseName}:${ordinal}`;
+ if (!taken.has(candidate)) return candidate;
+ }
+ }
+}
diff --git a/packages/eve/src/cli/dev/tui/tool-presentation.ts b/packages/eve/src/cli/dev/tui/tool-presentation.ts
index be3cb9e13..3b7e339e9 100644
--- a/packages/eve/src/cli/dev/tui/tool-presentation.ts
+++ b/packages/eve/src/cli/dev/tui/tool-presentation.ts
@@ -317,7 +317,7 @@ export function agentTaskLabel(name: string): string {
const readable = name
.replace(/^self-modification__agent(?=:\d+$|$)/u, "agent editor")
.replace(/__agent(?=:\d+$|$)/u, "");
- return readable === "subagent" || readable.startsWith("agent editor")
+ return /^subagent(?::\d+)?$/u.test(readable) || readable.startsWith("agent editor")
? readable
: `subagent(${readable})`;
}
diff --git a/packages/eve/src/cli/dev/tui/transcript-parts.ts b/packages/eve/src/cli/dev/tui/transcript-parts.ts
index 3518b3b5a..5341ab64f 100644
--- a/packages/eve/src/cli/dev/tui/transcript-parts.ts
+++ b/packages/eve/src/cli/dev/tui/transcript-parts.ts
@@ -32,9 +32,16 @@ export type ToolState = {
readonly errorText?: string;
};
-/** A task whose start line is written, named once and never renamed. */
+/**
+ * A task whose start line is written, named once and never renamed. Calls that reach the task
+ * while it works join this record rather than reading as tasks of their own.
+ */
export interface TaskRecord {
+ /** The call that started this stretch of the task. */
readonly callId: string;
+ readonly taskId: string;
+ /** Every call this record answers, the starting call first. */
+ readonly callIds: string[];
readonly kind: "agent" | "tool";
readonly name: string;
readonly toolName: string;
@@ -80,17 +87,6 @@ export function taskNeedsApproval(
);
}
-export function uniqueTaskName(baseName: string, records: Iterable<TaskRecord>): string {
- const taken = new Set(
- [...records].filter((record) => !record.ended).map((record) => record.name),
- );
- if (!taken.has(baseName)) return baseName;
- for (let ordinal = 2; ; ordinal += 1) {
- const candidate = `${baseName}:${ordinal}`;
- if (!taken.has(candidate)) return candidate;
- }
-}
-
export function startLine(record: TaskRecord): Block {
const presentation = presentTool(record.toolName, record.input, {
...labelContext(record.label),
@@ -105,6 +101,31 @@ export function startLine(record: TaskRecord): Block {
};
}
+/** A later call that reached a working task: a message to it, not a new delegation. */
+export function followUpLine(
+ record: TaskRecord,
+ part: EveDynamicToolPart,
+ label: string | undefined,
+): Block {
+ if (record.kind === "agent") {
+ return {
+ kind: "task",
+ taskKind: "agent",
+ title: `Message ${agentTaskLabel(record.name)}`,
+ subtitle: agentTaskSummary(part.input),
+ live: false,
+ };
+ }
+ const presentation = presentTool(part.toolName, part.input, labelContext(label));
+ return {
+ kind: "task",
+ taskKind: "tool",
+ title: stripTerminalControls(presentation.title),
+ subtitle: stripTerminalControls(presentation.subtitle),
+ live: false,
+ };
+}
+
export function nestedTaskRecord(
callId: string,
part: EveDynamicToolPart,
@@ -113,6 +134,8 @@ export function nestedTaskRecord(
): TaskRecord {
return {
callId,
+ taskId: task.taskId,
+ callIds: [part.toolCallId],
kind: task.kind,
name:
task.kind === "agent"
diff --git a/packages/eve/src/cli/dev/tui/transcript.test.ts b/packages/eve/src/cli/dev/tui/transcript.test.ts
index c0977031b..3593c345b 100644
--- a/packages/eve/src/cli/dev/tui/transcript.test.ts
+++ b/packages/eve/src/cli/dev/tui/transcript.test.ts
@@ -570,6 +570,69 @@ describe("ConversationTranscript", () => {
expect(transcript.tasks[1]!.omittedAttention).toBe(true);
});
+ it("folds a message steering a working agent into its task, apart from a real second task", () => {
+ const delegate = (callId: string, message: string) =>
+ event(
+ createActionsRequestedEvent({
+ actions: [{ callId, input: { message }, kind: "tool-call", toolName: "agent" }],
+ sequence: 1,
+ stepIndex: 0,
+ turnId: "turn_1",
+ }),
+ );
+ const childTurn = "child_turn_1";
+ const steered = conversation([
+ turn,
+ delegate("call_1", "Research Zeit for Alice."),
+ taskStarted("call_1", "agent"),
+ agentStarted("call_1"),
+ { type: "client.agent.following", data: { sessionId: "child_1" } },
+ ...observe([
+ createTurnStartedEvent({ sequence: 0, turnId: childTurn }),
+ createMessageReceivedEvent({ message: "Research Zeit", sequence: 0, turnId: childTurn }),
+ ]),
+ delegate("call_2", "Alice means Vercel, formerly Zeit."),
+ taskStarted("call_2", "agent"),
+ // The steering message joins the agent's running turn.
+ ...observe([
+ createMessageReceivedEvent({ message: "Vercel", sequence: 1, turnId: childTurn }),
+ ]),
+ delegate("call_3", "Summarize Bob's notes."),
+ taskStarted("call_3", "agent", "task_2"),
+ ]);
+ const transcript = new ConversationTranscript();
+ const starts = transcript.project(view(steered, true), options);
+ expect(starts.map((block) => [block.title, block.subtitle])).toEqual([
+ ["Delegate subagent", "Research Zeit for Alice."],
+ ["Message subagent", "Alice means Vercel, formerly Zeit."],
+ ["Delegate subagent:2", "Summarize Bob's notes."],
+ ]);
+ expect(transcript.tasks.map((task) => task.name)).toEqual(["subagent", "subagent:2"]);
+
+ // One reply settles both of the task's calls, so the task ends once.
+ const replied = conversation(
+ [
+ ...observe([
+ createMessageCompletedEvent({
+ message: "Vercel's profile is ready.",
+ sequence: 2,
+ stepIndex: 0,
+ turnId: childTurn,
+ }),
+ createTurnCompletedEvent({ sequence: 3, turnId: childTurn }),
+ ]),
+ settled("call_1"),
+ settled("call_2"),
+ ],
+ steered,
+ );
+ const ends = transcript
+ .project(view(replied, true), options)
+ .filter((block) => block.id?.endsWith(":end"));
+ expect(ends.map((block) => [block.title, block.status])).toEqual([["subagent", "done"]]);
+ expect(transcript.tasks.map((task) => task.name)).toEqual(["subagent:2"]);
+ });
+
it("names parallel calls apart, stops tasks a cancelled turn leaves working, and hides hidden ones", () => {
const state = conversation([
turn,
diff --git a/packages/eve/src/cli/dev/tui/transcript.ts b/packages/eve/src/cli/dev/tui/transcript.ts
index 828726b30..a103e0d70 100644
--- a/packages/eve/src/cli/dev/tui/transcript.ts
+++ b/packages/eve/src/cli/dev/tui/transcript.ts
@@ -19,12 +19,12 @@ import type { Block } from "./blocks.js";
import type { AgentTUIConversationView, AgentTUIFailure, ToolLabels } from "./conversation-view.js";
import { FileContentCache } from "./file-content-cache.js";
import { signInLabel, waitingLabel, type TaskEntry } from "./task-activity.js";
+import { TaskRecords } from "./task-records.js";
import { isTerminalToolCallPart } from "./terminal-tool-part.js";
import {
agentDisplayName,
agentTaskLabel,
isPanelRoutedTool,
- presentTool,
readWriteFileInput,
toolBaseName,
type ToolPresentationContext,
@@ -32,17 +32,15 @@ import {
import {
activeToolSteps,
taskNeedsApproval,
- uniqueTaskName,
type AgentActivity,
- agentTaskSummary,
authorizationTerminalMessage,
childToolCallIds,
endLine,
firstLine,
+ followUpLine,
formatAuthorization,
isActive,
isToolCallRow,
- labelContext,
nestedTaskRecord,
startLine,
subagentSteps,
@@ -102,7 +100,7 @@ export class ConversationTranscript {
readonly #aliases = new Map<string, string>();
#optimistic = new Map<string, string>();
readonly #confirmed = new Set<string>();
- readonly #tasks = new Map<string, TaskRecord>();
+ readonly #tasks = new TaskRecords();
readonly #nestedTasks = new Map<string, TaskRecord>();
#placed: PlacedBlock[] = [];
readonly #placedIds = new Set<string>();
@@ -254,7 +252,7 @@ export class ConversationTranscript {
return placed;
}
- /** A call became a task: its row is now the task's start line, written once. */
+ /** A call became a task: its row is now the task's start line, or a message to a working one. */
#taskStartLine(
part: EveDynamicToolPart,
task: ConversationTask,
@@ -265,31 +263,13 @@ export class ConversationTranscript {
const visible =
task.kind === "agent" ? options.subagents !== "hidden" : options.tools !== "hidden";
if (!visible) return undefined;
- const callId = part.toolCallId;
- const label = labels[callId]?.start;
- let record = this.#tasks.get(callId);
- let summary = agentTaskSummary(part.input);
- let baseName = agentDisplayName(stripTerminalControls(part.toolName));
- if (task.kind === "tool") {
- const presentation = presentTool(part.toolName, part.input, labelContext(label));
- baseName = stripTerminalControls(presentation.title);
- summary = stripTerminalControls(presentation.subtitle);
- }
- if (record === undefined) {
- record = {
- callId,
- kind: task.kind,
- name: uniqueTaskName(baseName, this.#tasks.values()),
- toolName: part.toolName,
- input: part.input,
- label,
- purpose: summary || label,
- startedAtMs: now,
- ended: false,
- };
- this.#tasks.set(callId, record);
- }
- return this.#memoize(`task:${callId}:start`, [record], () => startLine(record));
+ const label = labels[part.toolCallId]?.start;
+ const record = this.#tasks.record(part, task, label, now);
+ return record.callId === part.toolCallId
+ ? this.#memoize(`task:${record.callId}:start`, [record], () => startLine(record))
+ : this.#memoize(`task:${part.toolCallId}:message`, [record], () =>
+ followUpLine(record, part, label),
+ );
}
/**
@@ -315,16 +295,21 @@ export class ConversationTranscript {
const traversal = { remaining: 128 };
for (const record of this.#tasks.values()) {
if (record.ended) continue;
- const taskCall = taskCalls.get(record.callId);
- if (taskCall === undefined) continue;
- const { task, call } = taskCall;
- const activity = this.#agentActivity(record, task, call, conversation, options, traversal);
+ const task = taskCalls.get(record.callId)?.task;
+ if (task === undefined) continue;
+ const calls = record.callIds.flatMap((id) => {
+ const call = taskCalls.get(id)?.call;
+ return call === undefined ? [] : [call];
+ });
+ // The last call carries the task's latest outcome; one reply settles every call it answered.
+ const call = calls.at(-1)!;
+ const activity = this.#agentActivity(record, task, calls, conversation, options, traversal);
if (options.subagents === "full") {
for (const row of activity.rows) {
if (!this.#placedIds.has(row.id!)) arrivals.push(row);
}
}
- const settled = call.status !== "working";
+ const settled = calls.every((candidate) => candidate.status !== "working");
if (settled) record.settledAtMs ??= now;
const finishing =
settled &&
@@ -365,11 +350,11 @@ export class ConversationTranscript {
return arrivals;
}
- /** What an agent task has done for this call: its tool calls, latest words, and finished rows. */
+ /** What an agent task has done for these calls: its tool calls, latest words, and finished rows. */
#agentActivity(
record: TaskRecord,
task: ConversationTask,
- call: ConversationTaskCall,
+ calls: readonly ConversationTaskCall[],
conversation: ConversationState,
options: TranscriptOptions,
traversal: { remaining: number },
@@ -382,19 +367,23 @@ export class ConversationTranscript {
: agent.observation.conversation;
if (agent === undefined || child === undefined) return { tools: [], rows: [], pending: false };
const pending =
- agent.observation.status === "following" && isAgentCallContentPending(task, call, child);
- const turnIds = new Set(agentCallTurns(task, child).get(call.callId) ?? []);
+ agent.observation.status === "following" &&
+ calls.some((call) => isAgentCallContentPending(task, call, child));
+ const callTurns = agentCallTurns(task, child);
+ const turnIds = new Set(calls.flatMap((call) => callTurns.get(call.callId) ?? []));
const messages = child.messages.filter(
(message) =>
message.role === "assistant" &&
message.metadata?.turnId !== undefined &&
turnIds.has(message.metadata.turnId),
);
- const running = call.status === "working" || pending;
+ const running = calls.some((call) => call.status === "working") || pending;
const childTasks = taskCallsById(child);
const ordered: Array<{ order: number; block: Block; settled: boolean }> = [];
const tools: Block[] = [];
const children: TaskEntry[] = [];
+ // A child task's later calls join its first working call's entry.
+ const shownChildTasks = new Set<string>();
let omittedTasks = 0;
let omittedAttention = false;
let order = 0;
@@ -423,6 +412,8 @@ export class ConversationTranscript {
? options.subagents !== "hidden"
: options.tools !== "hidden";
if (childTask?.call.status === "working" && childVisible) {
+ if (shownChildTasks.has(childTask.task.taskId)) continue;
+ shownChildTasks.add(childTask.task.taskId);
if (depth >= 8 || traversal.remaining <= 0) {
omittedTasks += 1;
omittedAttention ||=
@@ -439,7 +430,7 @@ export class ConversationTranscript {
const activity = this.#agentActivity(
nested,
childTask.task,
- childTask.call,
+ Object.values(childTask.task.calls).filter((call) => call.status === "working"),
child,
options,
traversal,