From 4f8eb42dcaae4ec7e3f9aba91b52ff85ca8ffbcb Mon Sep 17 00:00:00 2001 From: liuedcson <332840681+liuedcson@users.noreply.github.com> Date: Mon, 30 Nov 2026 14:21:48 +0800 Subject: [PATCH 1/2] feat(subagent): add an optional short label to delegated tasks A task carries the child full instruction, which is too long to tell rows apart when several children share one agent type. Accept an optional description on the single call, tasks entries and chain entries, carry it through the live and final projections and the lane snapshot validation, and show it as the row title in the list widget, the subagents command and the expanded record. Without a label every surface behaves as before. --- .../src/features/step-subagent.ts | 14 +++++++++++ .../src/features/step-subagents-command.ts | 4 +++- .../src/features/subagent/execute.ts | 23 ++++++++++++++----- .../src/features/subagent/lane-events.ts | 1 + .../src/features/subagent/projection.ts | 6 +++++ .../src/features/subagent/rendering.ts | 3 ++- .../test/subagent-child-queue.test.ts | 18 +++++++++++++++ .../test/subagent-list-widget.test.ts | 14 +++++++++++ 8 files changed, 75 insertions(+), 8 deletions(-) diff --git a/packages/coding-agent/src/features/step-subagent.ts b/packages/coding-agent/src/features/step-subagent.ts index e9537f9bb..1e3112e6f 100644 --- a/packages/coding-agent/src/features/step-subagent.ts +++ b/packages/coding-agent/src/features/step-subagent.ts @@ -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 @@ -348,10 +350,19 @@ 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 lists, e.g. "Audit auth middleware". Omit to show the start of the task.'; + /** 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; @@ -363,6 +374,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 })), }, @@ -373,6 +385,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 })), }, @@ -394,6 +407,7 @@ 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 })), 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" }), diff --git a/packages/coding-agent/src/features/step-subagents-command.ts b/packages/coding-agent/src/features/step-subagents-command.ts index 351640b17..52bf04d95 100644 --- a/packages/coding-agent/src/features/step-subagents-command.ts +++ b/packages/coding-agent/src/features/step-subagents-command.ts @@ -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; diff --git a/packages/coding-agent/src/features/subagent/execute.ts b/packages/coding-agent/src/features/subagent/execute.ts index c545ea1a1..8deff481a 100644 --- a/packages/coding-agent/src/features/subagent/execute.ts +++ b/packages/coding-agent/src/features/subagent/execute.ts @@ -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; @@ -86,7 +87,9 @@ function resultRecord( agent: string, task: string, result: StepSubagentRunResult, - extra: Partial> = {}, + extra: Partial< + Pick + > = {}, ): StepSubagentResultRecord { const status = statusForResult(result); return { @@ -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: [], @@ -195,6 +199,7 @@ function makeFailureResult( task: string, message: string, source: StepAgentConfig["source"] | "unknown" = "unknown", + description?: string, ): StepSubagentResultRecord { return resultRecord( agent, @@ -207,7 +212,7 @@ function makeFailureResult( stopReason: "error", errorMessage: message, }, - { agentSource: source }, + { agentSource: source, description }, ); } @@ -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. @@ -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. @@ -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 | undefined; const execution = laneRuntime ? "background" : "blocking"; @@ -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); @@ -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); @@ -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, }); @@ -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, }); @@ -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; diff --git a/packages/coding-agent/src/features/subagent/lane-events.ts b/packages/coding-agent/src/features/subagent/lane-events.ts index f05a026c4..c99e2e3ec 100644 --- a/packages/coding-agent/src/features/subagent/lane-events.ts +++ b/packages/coding-agent/src/features/subagent/lane-events.ts @@ -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", diff --git a/packages/coding-agent/src/features/subagent/projection.ts b/packages/coding-agent/src/features/subagent/projection.ts index b5b4a2b8a..20b4ce6e9 100644 --- a/packages/coding-agent/src/features/subagent/projection.ts +++ b/packages/coding-agent/src/features/subagent/projection.ts @@ -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: [], @@ -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: [], diff --git a/packages/coding-agent/src/features/subagent/rendering.ts b/packages/coding-agent/src/features/subagent/rendering.ts index a85bfe596..5480a093b 100644 --- a/packages/coding-agent/src/features/subagent/rendering.ts +++ b/packages/coding-agent/src/features/subagent/rendering.ts @@ -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) { @@ -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); diff --git a/packages/coding-agent/test/subagent-child-queue.test.ts b/packages/coding-agent/test/subagent-child-queue.test.ts index 309fcea56..2885363b9 100644 --- a/packages/coding-agent/test/subagent-child-queue.test.ts +++ b/packages/coding-agent/test/subagent-child-queue.test.ts @@ -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(); +}); diff --git a/packages/coding-agent/test/subagent-list-widget.test.ts b/packages/coding-agent/test/subagent-list-widget.test.ts index fe50363c6..19d8787e5 100644 --- a/packages/coding-agent/test/subagent-list-widget.test.ts +++ b/packages/coding-agent/test/subagent-list-widget.test.ts @@ -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` })]), From 85017d95e003c80e3a0235cfb26faa69c0c39b1a Mon Sep 17 00:00:00 2001 From: liuedcson <332840681+liuedcson@users.noreply.github.com> Date: Mon, 30 Nov 2026 15:16:06 +0800 Subject: [PATCH 2/2] fix(subagent): mark top-level description and model as single-mode only In parallel mode a model filled the top-level description next to the per-entry labels, because the top-level field shared the entry text. Mark the top-level description and model as single-mode fields, matching the neighbouring agent and task fields. Shorten the label text to one line. --- packages/coding-agent/src/features/step-subagent.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/coding-agent/src/features/step-subagent.ts b/packages/coding-agent/src/features/step-subagent.ts index 1e3112e6f..df3dec814 100644 --- a/packages/coding-agent/src/features/step-subagent.ts +++ b/packages/coding-agent/src/features/step-subagent.ts @@ -355,8 +355,7 @@ const SUBAGENT_MODEL_DESCRIPTION = [ * 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 lists, e.g. "Audit auth middleware". Omit to show the start of the task.'; +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 { @@ -407,12 +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 })), + 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 }),