Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/coding-agent/src/features/step-subagent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ export interface StepSubagentResultRecord extends StepSubagentRunResult {
agent: string;
agentSource: StepAgentConfig["source"] | "unknown";
task: string;
/** Caller-supplied short label for the task; absent when the call gave none. */
description?: string;
/**
* `queued`: not started yet (a later chain step, or a parallel task waiting
* on maxConcurrency). `skipped`: a chain step that never started because an
Expand Down Expand Up @@ -348,10 +350,18 @@ const SUBAGENT_MODEL_DESCRIPTION = [
"Omit to inherit this session's model.",
].join(" ");

/**
* The short label a task shows in lists and headings. `task` is the child's
* full instruction and is far too long to identify a row, so a caller that
* starts several children of one agent type names each of them here.
*/
const SUBAGENT_DESCRIPTION_LABEL = "Short label (3-5 words) naming this task in the UI";

/** A `tasks`/`chain` entry. Same shape as before plus the route. */
export interface StepDelegatedTaskItem {
agent: string;
task: string;
description?: string;
cwd?: string;
model?: string;
isolateWorkspace?: boolean;
Expand All @@ -363,6 +373,7 @@ export const StepTaskItem = Type.Object(
{
agent: Type.String({ description: "Name of the agent to invoke" }),
task: Type.String({ description: "Task to delegate to the agent" }),
description: Type.Optional(Type.String({ description: SUBAGENT_DESCRIPTION_LABEL })),
cwd: Type.Optional(Type.String({ description: "Working directory for the agent process" })),
model: Type.Optional(Type.String({ description: SUBAGENT_MODEL_DESCRIPTION })),
},
Expand All @@ -373,6 +384,7 @@ export const StepChainItem = Type.Object(
{
agent: Type.String({ description: "Name of the agent to invoke" }),
task: Type.String({ description: "Task with optional {previous} placeholder for prior output" }),
description: Type.Optional(Type.String({ description: SUBAGENT_DESCRIPTION_LABEL })),
cwd: Type.Optional(Type.String({ description: "Working directory for the agent process" })),
model: Type.Optional(Type.String({ description: SUBAGENT_MODEL_DESCRIPTION })),
},
Expand All @@ -394,11 +406,12 @@ const StepSubagentParamsSchema = Type.Object(
{
agent: Type.Optional(Type.String({ description: "Name of the agent to invoke (for single mode)" })),
task: Type.Optional(Type.String({ description: "Task to delegate (for single mode)" })),
description: Type.Optional(Type.String({ description: `${SUBAGENT_DESCRIPTION_LABEL} (for single mode)` })),
tasks: Type.Optional(Type.Array(StepTaskItem, { description: "Array of {agent, task} for parallel execution" })),
chain: Type.Optional(
Type.Array(StepChainItem, { description: "Array of {agent, task} for sequential execution" }),
),
model: Type.Optional(Type.String({ description: SUBAGENT_MODEL_DESCRIPTION })),
model: Type.Optional(Type.String({ description: `${SUBAGENT_MODEL_DESCRIPTION} (single mode)` })),
agentScope: Type.Optional(StepAgentScopeSchema),
confirmProjectAgents: Type.Optional(
Type.Boolean({ description: "Prompt before running project-local agents. Default: true.", default: true }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ function formatLane(snapshot: SubagentLaneSnapshot, now: number): string[] {
for (const record of shown) {
const activity = activityOf(record);
const meta = [record.status, elapsedOf(record, now)].filter(Boolean).join(" \u00b7 ");
lines.push(` ${statusMark(record.status)} ${record.agent} \u2014 ${oneLine(record.task, 70) ?? "(no task)"}`);
lines.push(
` ${statusMark(record.status)} ${record.agent} \u2014 ${oneLine(record.description ?? record.task, 70) ?? "(no task)"}`,
);
lines.push(` ${meta}${activity ? ` \u2014 ${activity}` : ""}`);
}
const omitted = total - shown.length;
Expand Down
23 changes: 17 additions & 6 deletions packages/coding-agent/src/features/subagent/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const LIVE_FRAME_INTERVAL_MS = 100;
export interface StepSubagentTaskInput {
agent: string;
task: string;
description?: string;
cwd?: string;
/** Canonical `provider/model` the child must run on, or undefined to inherit. */
model?: string;
Expand All @@ -86,7 +87,9 @@ function resultRecord(
agent: string,
task: string,
result: StepSubagentRunResult,
extra: Partial<Pick<StepSubagentResultRecord, "agentSource" | "step" | "worktreePath" | "worktreeBranch">> = {},
extra: Partial<
Pick<StepSubagentResultRecord, "agentSource" | "step" | "worktreePath" | "worktreeBranch" | "description">
> = {},
): StepSubagentResultRecord {
const status = statusForResult(result);
return {
Expand All @@ -101,11 +104,12 @@ function resultRecord(
};
}

function makeEmptyResult(agent: string, task: string): StepSubagentResultRecord {
function makeEmptyResult(agent: string, task: string, description?: string): StepSubagentResultRecord {
return {
agent,
agentSource: "unknown",
task,
...(description === undefined ? {} : { description }),
status: "queued",
exitCode: -1,
messages: [],
Expand Down Expand Up @@ -195,6 +199,7 @@ function makeFailureResult(
task: string,
message: string,
source: StepAgentConfig["source"] | "unknown" = "unknown",
description?: string,
): StepSubagentResultRecord {
return resultRecord(
agent,
Expand All @@ -207,7 +212,7 @@ function makeFailureResult(
stopReason: "error",
errorMessage: message,
},
{ agentSource: source },
{ agentSource: source, description },
);
}

Expand All @@ -222,6 +227,7 @@ function taskFromParams(params: SubagentParams): StepSubagentTaskInput | undefin
return {
agent,
task,
description: params.description?.trim() || undefined,
cwd: params.cwd,
// A route named on the call rides with its task, so single and batch modes
// carry it the same way and one code path reads it back.
Expand All @@ -236,6 +242,7 @@ function normalizeTaskInput(task: StepDelegatedTaskItem): StepSubagentTaskInput
return {
agent: task.agent,
task: task.task,
description: task.description?.trim() || undefined,
cwd: task.cwd,
// Without this a route named inside `tasks`/`chain` never reaches the child,
// and the delegation silently falls back to the parent model.
Expand Down Expand Up @@ -464,7 +471,7 @@ export async function runPreparedSubagent(
const parallel = mode === "parallel" ? tasks : undefined;
const chain = mode === "chain" ? tasks : undefined;

const records = tasks.map((task) => makeEmptyResult(task.agent, task.task));
const records = tasks.map((task) => makeEmptyResult(task.agent, task.task, task.description));
let lastFrameAt = 0;
let pendingFrame: ReturnType<typeof setTimeout> | undefined;
const execution = laneRuntime ? "background" : "blocking";
Expand Down Expand Up @@ -545,6 +552,8 @@ export async function runPreparedSubagent(
task.agent,
task.task,
`Unknown agent: "${task.agent}". Available agents: ${formatStepAgentCatalog(discovery.agents)}`,
"unknown",
task.description,
);
records[index] = failed;
emit(mode);
Expand Down Expand Up @@ -577,7 +586,7 @@ export async function runPreparedSubagent(
stopReason: "aborted",
errorMessage: error instanceof Error ? error.message : String(error),
},
{ agentSource: agent.source },
{ agentSource: agent.source, description: task.description },
);
records[index] = aborted;
emit(mode);
Expand Down Expand Up @@ -643,6 +652,7 @@ export async function runPreparedSubagent(
retainCompletedResponses(partial);
records[index] = resultRecord(agent.name, task.task, withSession(partial), {
agentSource: agent.source,
description: task.description,
worktreePath: worktree?.path,
worktreeBranch: worktree?.branch,
});
Expand Down Expand Up @@ -681,6 +691,7 @@ export async function runPreparedSubagent(
retainCompletedResponses(child);
const completed = resultRecord(agent.name, task.task, withSession(child), {
agentSource: agent.source,
description: task.description,
worktreePath: worktree?.path,
worktreeBranch: worktree?.branch,
});
Expand All @@ -695,7 +706,7 @@ export async function runPreparedSubagent(
if (worktree && task.retainWorktree === false) await worktree.cleanup().catch(() => undefined);
const message = error instanceof Error ? error.message : String(error);
const failed = {
...makeFailureResult(agent.name, task.task, message, agent.source),
...makeFailureResult(agent.name, task.task, message, agent.source, task.description),
sessionId,
};
records[index] = failed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface SubagentLaneSnapshot {

const USAGE_FIELDS = ["input", "output", "cacheRead", "cacheWrite", "cost", "contextTokens", "turns"];
const LIVE_STRING_FIELDS = [
"description",
"model",
"stopReason",
"errorMessage",
Expand Down
6 changes: 6 additions & 0 deletions packages/coding-agent/src/features/subagent/projection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ export function liveRecord(record: StepSubagentResultRecord): StepSubagentResult
agent: clipMiddle(record.agent, LIVE_IDENTIFIER_CHARS),
agentSource: record.agentSource,
task: clipMiddle(record.task, LIVE_TASK_CHARS),
...(record.description === undefined
? {}
: { description: clipMiddle(record.description, LIVE_IDENTIFIER_CHARS) }),
status: record.status,
exitCode: record.exitCode,
messages: [],
Expand Down Expand Up @@ -224,6 +227,9 @@ export function finalRecord(record: StepSubagentResultRecord, budget: Budget): S
agent: clipMiddle(record.agent, FINAL_IDENTIFIER_CHARS),
agentSource: record.agentSource,
task: task ?? "(unspecified task)",
...(record.description === undefined
? {}
: { description: clipMiddle(record.description, FINAL_IDENTIFIER_CHARS) }),
status: record.status,
exitCode: record.exitCode,
messages: [],
Expand Down
3 changes: 2 additions & 1 deletion packages/coding-agent/src/features/subagent/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ function renderExpandedRecord(record: StepSubagentResultRecord, theme: Theme): C
),
);
container.addChild(new Spacer(1));
if (record.description) container.addChild(new Text(theme.bold(record.description), 0, 0));
container.addChild(new Text(theme.fg("muted", "Task"), 0, 0));
container.addChild(new Text(theme.fg("dim", record.task), 0, 0));
if (record.worktreePath) {
Expand Down Expand Up @@ -269,7 +270,7 @@ export class SubagentListWidget implements Component {
// child's live tool call, then its streamed text, which rewrote every
// row on every delta: the column churned too fast to read and each
// change dragged the host through another republish and redraw.
const title = fitLine(record.task, width - fixed);
const title = fitLine(record.description ?? record.task, width - fixed);
const gap = Math.max(1, width - fixed - visibleWidth(title) + 1);
const row = ` ${statusIcon(record.status, theme)} ${theme.fg("accent", name)} ${theme.fg("toolOutput", title)}${" ".repeat(gap)}${theme.fg("dim", metric.padStart(metricWidth))}`;
lines.push(visibleWidth(row) > width ? truncateToWidth(row, width, "\u2026") : row);
Expand Down
18 changes: 18 additions & 0 deletions packages/coding-agent/test/subagent-child-queue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,21 @@ test("a lane snapshot with a malformed queue is refused whole, never half truste
expect(readSubagentLaneSnapshot(lane({ state: "waiting", position: -1 }))).toBeUndefined();
expect(readSubagentLaneSnapshot(lane("waiting"))).toBeUndefined();
});

test("a task's short label crosses the live projection and the validation boundary", () => {
const labelled = { ...record(), description: "Audit auth middleware" };
expect(liveRecord(labelled).description).toBe("Audit auth middleware");
expect("description" in liveRecord(record())).toBe(false);
// A label is bounded like every other live identifier.
expect(liveRecord({ ...record(), description: "x".repeat(5000) }).description?.length).toBeLessThan(500);

const withLabel = (description: unknown) => {
const value = lane(undefined);
value.details.results = [{ ...value.details.results[0], description }] as typeof value.details.results;
return value;
};
expect(readSubagentLaneSnapshot(withLabel("Audit auth middleware"))?.details.results[0]?.description).toBe(
"Audit auth middleware",
);
expect(readSubagentLaneSnapshot(withLabel(42))).toBeUndefined();
});
14 changes: 14 additions & 0 deletions packages/coding-agent/test/subagent-list-widget.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ test("the title is the task, not the child's live activity", () => {
expect(rows[2]).not.toContain("429");
});

test("a row is titled by its short label, and falls back to the task without one", () => {
const widget = new SubagentListWidget(
details([
record({ agent: "a", task: "long instruction for the scheduler audit", description: "Audit scheduler" }),
record({ agent: "b", task: "audit the parser" }),
]),
plainTheme,
);
const rows = widget.render(120).slice(1);
expect(rows[0]).toContain("Audit scheduler");
expect(rows[0]).not.toContain("long instruction");
expect(rows[1]).toContain("audit the parser");
});

test("a task too long for its cell keeps its head, so the row stays identifiable", () => {
const widget = new SubagentListWidget(
details([record({ task: `Audit packages/agent-core ${"x".repeat(200)} TAIL-MARKER` })]),
Expand Down