Repository navigation
feat(subagents): add native subagents with live activity viewer #2787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
daewoongoh
wants to merge
21
commits into
Zoo-Code-Org:main
Choose a base branch
from
daewoongoh:feat/subagent-live-activity-viewer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
5e59c67
Add live transcript viewer and activity feed for native subagents
e0e1707
Make owned subagent-row collection safe when history store cannot enu…
03465a9
Move subagent settings into Experimental and default max turns to unl…
37808f9
Refine subagent live viewer and stop subagents on task change
e032be4
Merge branch 'Zoo-Code-Org:main' into feat/subagent-live-activity-viewer
daewoongoh a83912a
Fix failures in PR checks
62492d2
Add coverage for subagent runner and helpers
6fd2941
Cover the remaining subagent runner branches
3ec3a71
fix(subagents): apply the approval policy to headless asks
eff8c61
fix(subagents): settle runs and drop state before task deletion
a29e25c
fix(subagents): close the remaining review findings
920e040
fix(subagents): apply the turn cap at each request
62698e1
fix(subagents): make completion, isolation and the turn limit explicit
739e58a
test(webview): add visual baselines for the subagent surfaces
e7750de
test(subagents): build the transcript path with path.join
dd75f05
fix(subagents): close the CodeRabbit pre-merge findings
daewoongoh e329c3e
test(subagents): type the deferred group write as a resolved undefined
daewoongoh 0cda96e
Merge branch 'main' into feat/subagent-live-activity-viewer
daewoongoh a7f0494
fix(subagents): correct run ids, terminal asks and live transcripts
5da5c0c
Merge branch 'main' into feat/subagent-live-activity-viewer
daewoongoh 7ac6ce2
feat(subagent): run spawned subagents in the background
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,224 @@ | ||
| import { z } from "zod" | ||
|
|
||
| /** | ||
| * Native subagent definitions and run snapshots. | ||
| * | ||
| * A subagent is a headless child run that never becomes the active webview | ||
| * task. The parent task keeps the chat screen; each subagent streams state | ||
| * through `subagentUpdate` messages instead of `clineMessages`. | ||
| */ | ||
|
|
||
| export const subagentStatuses = ["queued", "running", "completed", "failed", "cancelled"] as const | ||
|
|
||
| export const subagentStatusSchema = z.enum(subagentStatuses) | ||
|
|
||
| export type SubagentStatus = z.infer<typeof subagentStatusSchema> | ||
|
|
||
| export const subagentIsolationModes = ["none", "worktree"] as const | ||
|
|
||
| export const subagentIsolationSchema = z.enum(subagentIsolationModes) | ||
|
|
||
| export type SubagentIsolation = z.infer<typeof subagentIsolationSchema> | ||
|
|
||
| export const subagentSources = ["builtin", "project", "user"] as const | ||
|
|
||
| export const subagentSourceSchema = z.enum(subagentSources) | ||
|
|
||
| export type SubagentSource = z.infer<typeof subagentSourceSchema> | ||
|
|
||
| /** | ||
| * Built-in agent names. Custom agents may use any slug that passes | ||
| * `subagentNameSchema`; the union with `string` keeps definitions open. | ||
| */ | ||
| export const builtinSubagentNames = ["explore", "reviewer", "general"] as const | ||
|
|
||
| export const subagentNameSchema = z | ||
| .string() | ||
| .min(1) | ||
| .max(64) | ||
| .regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/, "Agent names may contain letters, digits, hyphens and underscores") | ||
|
|
||
| export const subagentDefinitionSchema = z.object({ | ||
| name: subagentNameSchema, | ||
| /** One or two lines injected into the parent's `spawn_subagent` tool description. */ | ||
| description: z.string().min(1).max(500), | ||
| /** Full system prompt for the child session. */ | ||
| systemPrompt: z.string().min(1), | ||
| /** Model id override, or "inherit" to use the parent task's model. */ | ||
| model: z.string().min(1).optional(), | ||
| tools: z.array(z.string().min(1)).optional(), | ||
| disallowedTools: z.array(z.string().min(1)).optional(), | ||
| /** Read-only agents get read-class tools and run fully in parallel. */ | ||
| readonly: z.boolean().optional(), | ||
| maxTurns: z.number().int().min(1).max(100).optional(), | ||
| isolation: subagentIsolationSchema.optional(), | ||
| color: z.string().optional(), | ||
| source: subagentSourceSchema, | ||
| }) | ||
|
|
||
| export type SubagentDefinition = z.infer<typeof subagentDefinitionSchema> | ||
|
|
||
| /** | ||
| * YAML frontmatter accepted in `.zoo/agents/*.md` and `.claude/agents/*.md`. | ||
| * `tools`/`disallowedTools` accept either a YAML list or a comma-separated | ||
| * string, matching both Claude Code and hand-written files. | ||
| */ | ||
| const commaSeparated = z | ||
| .union([z.array(z.string()), z.string()]) | ||
| .optional() | ||
| .transform((value) => { | ||
| if (value === undefined) { | ||
| return undefined | ||
| } | ||
|
|
||
| const list = Array.isArray(value) ? value : value.split(",") | ||
|
|
||
| return list.map((entry) => entry.trim()).filter((entry) => entry.length > 0) | ||
| }) | ||
|
|
||
| export const subagentFrontmatterSchema = z.object({ | ||
| name: subagentNameSchema.optional(), | ||
| description: z.string().min(1).max(500).optional(), | ||
| model: z.string().min(1).optional(), | ||
| tools: commaSeparated, | ||
| disallowedTools: commaSeparated, | ||
| readonly: z.boolean().optional(), | ||
| maxTurns: z.number().int().min(1).max(100).optional(), | ||
| isolation: subagentIsolationSchema.optional(), | ||
| color: z.string().optional(), | ||
| }) | ||
|
|
||
| export type SubagentFrontmatter = z.infer<typeof subagentFrontmatterSchema> | ||
|
|
||
| export const subagentTokenUsageSchema = z.object({ | ||
| input: z.number().min(0), | ||
| output: z.number().min(0), | ||
| }) | ||
|
|
||
| export type SubagentTokenUsage = z.infer<typeof subagentTokenUsageSchema> | ||
|
|
||
| /** | ||
| * One live tool-call event in a subagent's activity feed. Stella sends only the | ||
| * tool name and a short structural tag, never the tool's output, so the live | ||
| * feed never leaks child context into the parent conversation. | ||
| */ | ||
| export const subagentToolActivitySchema = z.object({ | ||
| /** Stable per-run id (call counter). */ | ||
| id: z.number(), | ||
| tool: z.string(), | ||
| /** Localized label key, optional when we only know the raw tool name. */ | ||
| labelKey: z.string().optional(), | ||
| path: z.string().optional(), | ||
| ts: z.number(), | ||
| }) | ||
|
|
||
| export type SubagentToolActivity = z.infer<typeof subagentToolActivitySchema> | ||
|
|
||
| export const subagentToolActivityListSchema = z.array(subagentToolActivitySchema).max(50) | ||
|
|
||
| export const subagentRunSnapshotSchema = z.object({ | ||
| runId: z.string(), | ||
| parentTaskId: z.string(), | ||
| toolUseId: z.string(), | ||
| groupId: z.string(), | ||
| agentName: z.string(), | ||
| description: z.string(), | ||
| /** Full instruction the subagent was given, shown on demand in the viewer. */ | ||
| prompt: z.string().optional(), | ||
| modelId: z.string(), | ||
| status: subagentStatusSchema, | ||
| startedAt: z.number(), | ||
| completedAt: z.number().optional(), | ||
| durationMs: z.number().min(0).optional(), | ||
| /** Live one-line ticker, e.g. "Reading src/auth/jwt.ts...". */ | ||
| currentAction: z.string().optional(), | ||
| /** Chronological feed of recent tool calls, newest last (bounded). */ | ||
| activity: subagentToolActivityListSchema.optional(), | ||
| toolCallCount: z.number().min(0), | ||
| tokenUsage: subagentTokenUsageSchema, | ||
| summary: z.string().optional(), | ||
| error: z.string().optional(), | ||
| /** Set when the run stopped at `maxTurns` before finishing on its own. */ | ||
| partial: z.boolean().optional(), | ||
| readonly: z.boolean().optional(), | ||
| isolation: subagentIsolationSchema.optional(), | ||
| /** Worktree path and diff summary for `isolation: "worktree"` runs. */ | ||
| worktree: z | ||
| .object({ | ||
| path: z.string(), | ||
| kept: z.boolean(), | ||
| filesChanged: z.number().min(0).optional(), | ||
| diffStat: z.string().optional(), | ||
| }) | ||
| .optional(), | ||
| filesRead: z.array(z.string()), | ||
| filesModified: z.array(z.string()), | ||
| }) | ||
|
|
||
| export type SubagentRunSnapshot = z.infer<typeof subagentRunSnapshotSchema> | ||
|
|
||
| export const subagentGroupStateSchema = z.object({ | ||
| groupId: z.string(), | ||
| parentTaskId: z.string(), | ||
| startedAt: z.number(), | ||
| completedAt: z.number().optional(), | ||
| runs: z.array(subagentRunSnapshotSchema), | ||
| }) | ||
|
|
||
| export type SubagentGroupState = z.infer<typeof subagentGroupStateSchema> | ||
|
|
||
| /** Payload of the extension -> webview `subagentUpdate` message. */ | ||
| export const subagentUpdatePayloadSchema = z.object({ | ||
| parentTaskId: z.string(), | ||
| groupId: z.string(), | ||
| runs: z.array(subagentRunSnapshotSchema), | ||
| }) | ||
|
|
||
| export type SubagentUpdatePayload = z.infer<typeof subagentUpdatePayloadSchema> | ||
|
|
||
| /** Minimal history-item metadata persisted for each subagent run. */ | ||
| export const subagentHistoryMetaSchema = z.object({ | ||
| runId: z.string(), | ||
| groupId: z.string(), | ||
| parentTaskId: z.string(), | ||
| agentName: z.string(), | ||
| /** | ||
| * The terminal run status. A save made while the run is still active omits | ||
| * it; `SubagentManager` writes it from the terminal snapshot when the group | ||
| * completes, so a stored value is never a stale `"running"`. | ||
| */ | ||
| status: subagentStatusSchema.optional(), | ||
| partial: z.boolean().optional(), | ||
| }) | ||
|
|
||
| export type SubagentHistoryMeta = z.infer<typeof subagentHistoryMetaSchema> | ||
|
|
||
| export const DEFAULT_MAX_CONCURRENT_SUBAGENTS = 4 | ||
| export const MIN_CONCURRENT_SUBAGENTS = 1 | ||
| export const MAX_CONCURRENT_SUBAGENTS = 8 | ||
| // The default is unlimited (0) so subagents run until they finish or are stopped. | ||
| /** Sentinel `maxTurns` meaning "no turn limit". */ | ||
| export const UNLIMITED_SUBAGENT_MAX_TURNS = 0 | ||
| // Written as a literal (not an alias of UNLIMITED_SUBAGENT_MAX_TURNS) so Knip | ||
| // does not flag the two exports as duplicates. | ||
| export const DEFAULT_SUBAGENT_MAX_TURNS = 0 | ||
| export const MAX_SUBAGENT_MAX_TURNS = 100 | ||
|
|
||
| /** | ||
| * Tools a subagent may never call. This enforces the flat two-level hierarchy | ||
| * and the non-interactive contract: no nested spawn, no task delegation, no | ||
| * mode switching and no blocking question. | ||
| */ | ||
| export const SUBAGENT_FORBIDDEN_TOOLS = [ | ||
| "spawn_subagent", | ||
| "get_subagent_result", | ||
| "resume_subagent", | ||
| "new_task", | ||
| "ask_followup_question", | ||
| "switch_mode", | ||
| ] as const | ||
|
|
||
| export type SubagentForbiddenTool = (typeof SUBAGENT_FORBIDDEN_TOOLS)[number] | ||
|
|
||
| export const isForbiddenSubagentTool = (toolName: string): boolean => | ||
| (SUBAGENT_FORBIDDEN_TOOLS as readonly string[]).includes(toolName) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document
subagentUpdateas the payload field.The comment tells producers to put JSON in
text. The manager and viewer fixtures usesubagentUpdate. A producer that follows the comment would send an update without the expected field.