For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: 在 Settings 面板新增用户级 subagent 管理界面,支持全局 user agents 的查看、创建、编辑、删除、启用和禁用,并保证 GUI 写出的 Markdown 被当前 zcode-cli runtime 真实加载和消费。
Architecture: 先把 subagent 的用户级文件路径、profile 字段、启用状态从 UI/service 的临时实现收敛到 runtime 实际消费的边界,再接入 Settings UI。P0 只管理 global/user agents;workspace/project agents、plugin agents、structured MCP object editor 和 provider-visible agent 列表载体调整都不进入本计划。
Tech Stack: TypeScript、React、Zustand、@zcode/services、@zcode/shared、zcode-cli bootstrap/core、Vitest、Tailwind semantic tokens、现有 Settings 页面组件。
~/.zcode/agents,不是 ~/.zcode/cli/agents。general-purpose 和 Explore 在 P0 只读展示,不支持编辑/删除。<workspace>/.zcode/agents 读取;Settings P0 不提供编辑入口。packages/services 直接依赖 @zcode/core 或 runtime 具体实现。packages/ui 必须遵守根目录 DESIGN.md:使用 semantic color tokens、现有 Button/Input/Switch/Select/Dialog primitives、紧凑 settings 布局、支持 Zai Light/Dark 和响应式。packages/ui/src/i18n/locales/zh-CN.ts 与 packages/ui/src/i18n/locales/en-US.ts 同步补齐。apps/zcode-cli/packages/bootstrap/src/subagents.ts。join(storageRoot, "agents")join(workingDirectory, ".zcode", "agents")storageRoot 默认来自 DefaultRuntimeConfig.storage.dir = "~/.zcode"。packages/services/src/subagents/subagentsService.ts 仍用 ZCODE_AGENT_RUNTIME.nativeConfigDir 推导 ~/.zcode/cli/agents 和 <workspace>/.zcode/cli/agents,这和 runtime loader 不一致。name、description、color、model、tools、body;runtime profile 还支持 disallowedTools、skills、permissionMode、maxTurns、background、mcpServers。agents-state.json 当前只被 service 读写,runtime 不消费。packages/shared/src/subagents-types.ts
AgentSummary / SubAgentConfig 字段。tools 等字段转为 string array 语义。packages/services/src/subagents/subagentMarkdown.ts
@zcode/core。packages/services/src/subagents/subagentStorage.ts
~/.zcode/cli/config.json 中的 storage.dir,fallback 到 ~/.zcode。packages/services/src/subagents/subagents.ts
packages/services/src/subagents/subagentsService.ts
apps/zcode-cli/packages/bootstrap/src/subagents.ts
apps/zcode-cli/packages/bootstrap/src/app/create-app.ts
loadZCodeAgentProfiles。apps/zcode-cli/packages/core/src/subagent/profile.ts
packages/ui/src/settings/SubagentsSection.tsx
packages/ui/src/settings/SubagentForm.tsx
packages/ui/src/settings/SubagentCard.tsx
packages/ui/src/settings/settingsPageConfig.ts
subagents sidebar section。packages/ui/src/lib/settingsNavigation.ts
SettingsSectionId = "subagents"。packages/ui/src/SettingsPage.tsx
<SubagentsSection />。packages/ui/src/store/subagentsStore.ts
packages/ui/src/hooks/useSubagents.ts
packages/ui/src/i18n/locales/zh-CN.tspackages/ui/src/i18n/locales/en-US.tspackages/shared/src/test-ids.ts
packages/services/test/subagentsService.test.tsapps/zcode-cli/packages/bootstrap/tests/subagents.test.tsapps/zcode-cli/packages/core/tests/subagent-profile.test.tspackages/ui/test/subagentsSettingsSection.test.tsxpackages/ui/test/settingsPageConfig.test.tspackages/ui/test/settingsNavigation.test.tspackages/ui/test/subagentsMentionProvider.test.tsexport type AgentScope = "built-in" | "workspace" | "user";
export type AgentSource = "built-in" | "user" | "plugin";
export type AgentProfileModel = "inherit" | "main" | "lite";
export type AgentPermissionMode =
| "acceptEdits"
| "auto"
| "bypassPermissions"
| "default"
| "dontAsk"
| "plan";
export type AgentColor =
| "red"
| "blue"
| "green"
| "yellow"
| "purple"
| "orange"
| "pink"
| "cyan";
export interface AgentSummary {
id: string;
name: string;
description: string;
systemPrompt: string;
color?: AgentColor;
model?: AgentProfileModel;
tools?: string[];
disallowedTools?: string[];
skills?: string[];
permissionMode?: AgentPermissionMode;
maxTurns?: number;
background?: boolean;
mcpServers?: unknown[];
path: string;
scope: AgentScope;
source: AgentSource;
enabled: boolean;
readOnly: boolean;
projectPath?: string;
}
export interface SubAgentConfig {
name: string;
description: string;
systemPrompt: string;
color?: AgentColor;
model?: AgentProfileModel;
tools?: string[];
disallowedTools?: string[];
skills?: string[];
permissionMode?: AgentPermissionMode;
maxTurns?: number;
background?: boolean;
mcpServers?: unknown[];
}
export type SubagentsListMode = "allRuntimeScopes" | "settingsUserOnly";
interface SubagentsListParams {
workspacePath: string;
workspaceIdentity?: string;
provider?: ZCodeProvider;
mode?: SubagentsListMode;
}
Semantics:
allRuntimeScopes: mention provider and future runtime-aware surfaces use this. Includes built-in, user, and workspace readonly profiles.settingsUserOnly: Settings P0 uses this. Includes built-in readonly and user editable profiles only. Workspace profiles are intentionally hidden.function createAgentStateId(input: {
source: AgentSource;
scope: AgentScope;
name: string;
}): string {
return `${input.source}:${input.scope}:${input.name.trim().toLowerCase()}`;
}
P0 runtime consumes disabled user state ids. Built-in ids are stable for future use but not toggled in P0 UI.
Files:
packages/shared/src/subagents-types.tsInterfaces:
AgentProfileModel、AgentPermissionMode、AgentColor、SubagentsListMode、扩展后的 AgentSummary 和 SubAgentConfig。Consumes: 现有 service/store/hook 的 AgentSummary、SubAgentConfig。
[ ] Step 1: 修改 shared 类型
将 packages/shared/src/subagents-types.ts 调整为支持完整 P0 profile 字段。保留 AgentScope 中的 workspace,因为 mention provider 仍可能需要展示 runtime project profiles;Settings P0 只传 settingsUserOnly。
核心形状:
export type AgentScope = "built-in" | "workspace" | "user";
export type AgentSource = "built-in" | "user" | "plugin";
export type AgentProfileModel = "inherit" | "main" | "lite";
export type AgentPermissionMode =
| "acceptEdits"
| "auto"
| "bypassPermissions"
| "default"
| "dontAsk"
| "plan";
export type AgentColor =
| "red"
| "blue"
| "green"
| "yellow"
| "purple"
| "orange"
| "pink"
| "cyan";
export type SubagentsListMode = "allRuntimeScopes" | "settingsUserOnly";
更新编译错误最小集合:
packages/ui/src/mentions/providers/subagentsMentionProvider.tspackages/ui/src/store/subagentsStore.tspackages/services/src/subagents/subagentsService.ts对于旧的 tools?: string 读取,改成:
const toolSummary = agent.tools?.length ? agent.tools.join(", ") : "";
Run:
pnpm --filter @zcode/shared lint
pnpm --filter @zcode/ui test -- --run test/subagentsMentionProvider.test.ts
Expected:
@zcode/shared lint PASS。Files:
packages/services/src/subagents/subagentMarkdown.tspackages/services/test/subagentsService.test.tsInterfaces:
SubAgentConfig from @zcode/shared。Produces:
parseSubagentMarkdown(content: string, path: string, scope: AgentScope): AgentSummary | SubagentMarkdownDiagnosticserializeSubagentMarkdown(config: SubAgentConfig): string[ ] Step 1: 写 failing parser/serializer test
在 packages/services/test/subagentsService.test.ts 增加 helper-level tests,覆盖数组字段和 body 保真:
it("serializes user subagent markdown with runtime profile fields", () => {
const markdown = serializeSubagentMarkdown({
name: "code-reviewer",
description: "提交前审查代码",
systemPrompt: "你是严格的代码审查员。",
color: "cyan",
model: "lite",
tools: ["Read", "Grep", "Bash(git diff *)"],
disallowedTools: ["Write"],
skills: ["code-review"],
permissionMode: "acceptEdits",
maxTurns: 7,
background: true,
});
expect(markdown).toContain('name: "code-reviewer"');
expect(markdown).toContain("tools:");
expect(markdown).toContain("- Read");
expect(markdown).toContain("- Bash(git diff *)");
expect(markdown).toContain("permissionMode: acceptEdits");
expect(markdown).toContain("maxTurns: 7");
expect(markdown).toContain("background: true");
expect(markdown).toContain("你是严格的代码审查员。");
});
serializeSubagentMarkdown 使用 YAML frontmatter 风格,但不引入 service->core 依赖。推荐复用 yaml package,避免手写转义遗漏。
import YAML from "yaml";
import type { SubAgentConfig } from "@zcode/shared";
export function serializeSubagentMarkdown(config: SubAgentConfig): string {
const frontmatter: Record<string, unknown> = {
name: config.name.trim(),
description: config.description.trim(),
};
if (config.color) frontmatter.color = config.color;
if (config.model && config.model !== "inherit") frontmatter.model = config.model;
if (config.tools?.length) frontmatter.tools = config.tools;
if (config.disallowedTools?.length) frontmatter.disallowedTools = config.disallowedTools;
if (config.skills?.length) frontmatter.skills = config.skills;
if (config.permissionMode) frontmatter.permissionMode = config.permissionMode;
if (config.maxTurns !== undefined) frontmatter.maxTurns = config.maxTurns;
if (config.background !== undefined) frontmatter.background = config.background;
if (config.mcpServers?.length) frontmatter.mcpServers = config.mcpServers;
return `---\n${YAML.stringify(frontmatter).trimEnd()}\n---\n\n${config.systemPrompt.trim()}\n`;
}
Parser 要接受 runtime 当前 loose parser 能接受的格式。P0 不支持嵌套 MCP object editor,但 parser 可以把 mcpServers array 保留下来。
export interface SubagentMarkdownDiagnostic {
code: "agent_missing_frontmatter" | "agent_missing_required_frontmatter" | "agent_invalid_frontmatter";
message: string;
path: string;
}
解析失败时不要 throw;返回 diagnostic,让 Settings 页能展示诊断。
Run:
pnpm --filter @zcode/services test -- --run test/subagentsService.test.ts
Expected:
如果 @zcode/services 当前没有 test script,用根命令运行:
pnpm test -- --run packages/services/test/subagentsService.test.ts
Files:
packages/services/src/subagents/subagentStorage.tspackages/services/src/subagents/subagentsService.tspackages/services/test/subagentsService.test.tsInterfaces:
resolveUserSubagentRoot(): Promise<string>resolveWorkspaceSubagentRoot(workspacePath: string): stringresolveSubagentStateFile(): Promise<string>Consumes: ~/.zcode/cli/config.json 的 storage.dir,fallback ~/.zcode。
[ ] Step 1: 写 failing root resolution test
使用临时 HOME,创建 ~/.zcode/cli/config.json:
it("uses runtime storage.dir agents root for user subagents", async () => {
const home = await mkdtemp(join(tmpdir(), "zcode-subagents-home-"));
const storageRoot = join(home, "custom-storage");
await mkdir(join(home, ".zcode", "cli"), { recursive: true });
await writeFile(
join(home, ".zcode", "cli", "config.json"),
JSON.stringify({ storage: { dir: storageRoot } }),
"utf8",
);
const root = await resolveUserSubagentRoot({ homeDir: home });
expect(root).toBe(join(storageRoot, "agents"));
});
subagentStorage.ts 不直接使用 ZCODE_AGENT_RUNTIME.nativeConfigDir 推导 agent root。它只用 native config path 读取 config 文件:
const DEFAULT_STORAGE_DIR = "~/.zcode";
const ZCODE_CONFIG_PATH = join(resolveUserHomeDir(), ".zcode", "cli", "config.json");
export async function resolveUserSubagentRoot(): Promise<string> {
const storageDir = await readStorageDirFromCliConfig();
return join(resolveConfigPath(storageDir), "agents");
}
export function resolveWorkspaceSubagentRoot(workspacePath: string): string {
return join(workspacePath, ".zcode", "agents");
}
export async function resolveSubagentStateFile(): Promise<string> {
const storageDir = await readStorageDirFromCliConfig();
return join(resolveConfigPath(storageDir), "v2", "agents-state.json");
}
createAgent / updateAgent 只写 resolveUserSubagentRoot()。list 默认可以读 workspace root,但 Settings P0 通过 mode: "settingsUserOnly" 隐藏 workspace。
为了不让已有 ~/.zcode/cli/agents 用户立刻消失,P0 可以只读 legacy root 但不再写 legacy root。实现为:
const roots = [
{ scope: "user" as const, rootPath: await resolveUserSubagentRoot(), writable: true },
{ scope: "user" as const, rootPath: resolveLegacyUserSubagentRoot(), writable: false },
];
同名时 runtime root 优先,legacy root 被 shadow,不可编辑。若产品决定不迁移旧路径,可以删掉这一步;但要在最终说明中明确。
Run:
pnpm test -- --run packages/services/test/subagentsService.test.ts
Expected:
${storage.dir}/agents/<name>.md。Files:
apps/zcode-cli/packages/bootstrap/src/subagents.tsapps/zcode-cli/packages/bootstrap/src/app/create-app.tsapps/zcode-cli/packages/bootstrap/tests/subagents.test.tsInterfaces:
${storageRoot}/v2/agents-state.jsonProduces: loadZCodeAgentProfiles(...) 返回已过滤 disabled user profiles。
[ ] Step 1: 写 failing runtime disabled test
在 apps/zcode-cli/packages/bootstrap/tests/subagents.test.ts 增加:
it("does not load disabled user agent profiles into runtime config", async () => {
const root = await mkdtemp(join(tmpdir(), "zcode-subagents-disabled-"));
const storageRoot = join(root, "home");
const workingDirectory = join(root, "workspace");
await mkdir(join(storageRoot, "agents"), { recursive: true });
await mkdir(join(storageRoot, "v2"), { recursive: true });
await writeFile(
join(storageRoot, "agents", "reviewer.md"),
`---
name: reviewer
description: review code
---
review prompt`,
"utf8",
);
await writeFile(
join(storageRoot, "v2", "agents-state.json"),
JSON.stringify({ disabledAgentIds: ["user:user:reviewer"] }),
"utf8",
);
const result = loadZCodeAgentProfiles({ storageRoot, workingDirectory });
expect(result.profiles.map((profile) => profile.name)).not.toContain("reviewer");
});
在 bootstrap 侧新增本地 pure helper,避免依赖 app service:
function readDisabledAgentIds(storageRoot: string): Set<string> {
const path = join(storageRoot, "v2", "agents-state.json");
try {
const parsed = JSON.parse(readFileSync(path, "utf8")) as { disabledAgentIds?: unknown };
return new Set(
Array.isArray(parsed.disabledAgentIds)
? parsed.disabledAgentIds.filter((id): id is string => typeof id === "string")
: [],
);
} catch {
return new Set();
}
}
加载 profile 后计算:
const stateId = `${result.profile.source}:${result.profile.source === "project" ? "workspace" : "user"}:${result.profile.name.trim().toLowerCase()}`;
if (result.profile.source === "user" && disabledAgentIds.has(stateId)) {
continue;
}
P0 只让 user disabled 影响 runtime。Project disabled 留给 P1。
在 apps/zcode-cli/packages/core/tests/subagent-profile.test.ts 增加或更新测试:传入 profiles 不包含 disabled user 时,formatAgentProfilesForPrompt 不输出该 agent。
Run:
pnpm --filter @zcode/bootstrap test -- --run tests/subagents.test.ts
pnpm --filter @zcode/core test -- --run tests/subagent-profile.test.ts
Expected:
Files:
packages/services/src/subagents/subagents.tspackages/services/src/subagents/subagentsService.tspackages/services/test/subagentsService.test.tsInterfaces:
list({ mode: "settingsUserOnly" }) 返回 built-in readonly + user editable。list({ mode: "allRuntimeScopes" }) 返回 built-in + user + workspace readonly。createAgent / updateAgent / deleteAgent 只允许 user scope。
[ ] Step 1: 写 list mode tests
it("settings user-only list hides workspace agents", async () => {
const result = await service.list({
workspacePath,
provider: "glm",
mode: "settingsUserOnly",
});
expect(result.agents.every((agent) => agent.scope !== "workspace")).toBe(true);
expect(result.agents.some((agent) => agent.source === "built-in")).toBe(true);
expect(result.agents.some((agent) => agent.scope === "user")).toBe(true);
});
[ ] Step 2: 添加 built-in readonly summaries
Service 不能依赖 @zcode/core。在 service 内定义与 runtime built-ins 同名的 summary 常量:
const BUILT_IN_AGENT_SUMMARIES: AgentSummary[] = [
{
id: "built-in:built-in:general-purpose",
name: "general-purpose",
description: "General-purpose agent for researching complex questions...",
systemPrompt: "",
tools: ["*"],
path: "built-in:general-purpose",
scope: "built-in",
source: "built-in",
enabled: true,
readOnly: true,
},
{
id: "built-in:built-in:Explore",
name: "Explore",
description: "Read-only search agent for broad fan-out searches...",
model: "lite",
tools: ["Bash", "Glob", "Grep", "Read", "WebFetch", "WebSearch", "TodoWrite"],
systemPrompt: "",
path: "built-in:Explore",
scope: "built-in",
source: "built-in",
enabled: true,
readOnly: true,
},
];
If duplication becomes uncomfortable later, move built-in metadata to a shared pure package. Do not make services import runtime core in this task.
P0 validation:
const NAME_REGEX = /^[a-zA-Z0-9-]+$/;
const MIN_NAME_LENGTH = 3;
const MAX_NAME_LENGTH = 50;
Validate:
inherit/main/lite when presentmaxTurns must be positive integer when present
[ ] Step 4: enabled state writes runtime-consumed ids
setEnabled({ agentId, enabled }) should store ids like user:user:code-reviewer. For backwards compatibility, when reading old user:code-reviewer, normalize it to new id once on write.
Run:
pnpm test -- --run packages/services/test/subagentsService.test.ts
pnpm --filter @zcode/ui test -- --run test/subagentsMentionProvider.test.ts
Expected:
Files:
packages/ui/src/hooks/useSubagents.tspackages/ui/src/store/subagentsStore.tspackages/ui/test/subagentsMentionProvider.test.tsInterfaces:
useSubagents(workspacePath, provider, { mode })Consumes: ISubagentsService.list({ mode })
[ ] Step 1: 扩展 hook signature
export function useSubagents(
workspacePath: string | null,
provider: ZCodeProvider,
options: { mode?: SubagentsListMode } = {},
) {
// existing logic
}
[ ] Step 2: store cache key 加 mode
Current key is workspace + provider。改为:
function getAgentLoadKey(
workspacePath: string,
provider: ZCodeProvider,
mode: SubagentsListMode,
workspaceIdentity?: string,
): string {
return `${workspaceIdentity?.trim() || workspacePath}::${provider}::${mode}`;
}
useSubagentsMentionProvider 不传 mode 或显式传 allRuntimeScopes,确保 workspace readonly profiles 不被 Settings P0 隐藏逻辑影响。
Run:
pnpm --filter @zcode/ui test -- --run test/subagentsMentionProvider.test.ts
Expected:
Files:
packages/ui/src/settings/settingsPageConfig.tspackages/ui/src/lib/settingsNavigation.tspackages/ui/src/SettingsPage.tsxpackages/ui/src/i18n/locales/zh-CN.tspackages/ui/src/i18n/locales/en-US.tspackages/shared/src/test-ids.tspackages/ui/test/settingsPageConfig.test.tspackages/ui/test/settingsNavigation.test.tsInterfaces:
"subagents"。Consumes: existing Settings section rendering branch。
[ ] Step 1: 写 failing config tests
Update settingsPageConfig.test.ts:
expect(SETTINGS_SECTIONS.map((section) => section.id)).toContain("subagents");
Update settingsNavigation.test.ts:
expect(navigation.resolveSettingsSection("subagents", "general")).toBe("subagents");
packages/ui/src/lib/settingsNavigation.ts:
export type SettingsSectionId =
| "general"
| "codePreview"
| "migration"
| "indexing"
| "modelProvider"
| "mcp"
| "plugins"
| "usage"
| "skills"
| "commands"
| "subagents"
| "hooks";
同步更新 isSettingsSectionId。
packages/ui/src/settings/settingsPageConfig.ts 引入 lucide icon,推荐 Bot 或 UsersRound:
{
id: "subagents",
icon: Bot,
titleId: "settings.subagents.title",
}
位置建议放在 skills 之后、mcp 之前。
先接入 <SubagentsSection />,Task 8 实现组件。
) : activeSection === "subagents" ? (
<SubagentsSection workspacePath={activeWorkspacePath} workspaceIdentity={activeWorkspaceIdentity} />
) : activeSection === "skills" ? (
zh-CN.ts:
"settings.subagents.title": "子代理",
"settings.subagents.description": "管理全局用户子代理。子代理由 Markdown 文件定义,运行时会在 Agent 工具中使用这些定义。",
en-US.ts:
"settings.subagents.title": "Subagents",
"settings.subagents.description": "Manage global user subagents. Subagents are defined by Markdown files and are consumed by the Agent tool at runtime.",
Run:
pnpm --filter @zcode/ui test -- --run test/settingsPageConfig.test.ts test/settingsNavigation.test.ts
Expected: PASS。
Files:
packages/ui/src/settings/SubagentsSection.tsxpackages/ui/src/settings/SubagentCard.tsxpackages/ui/src/i18n/locales/zh-CN.tspackages/ui/src/i18n/locales/en-US.tspackages/ui/test/subagentsSettingsSection.test.tsxInterfaces:
useSubagents(activeWorkspacePath, ZCODE_AGENT_PROVIDER, { mode: "settingsUserOnly" })Produces: search/filter/list/toggle/edit/delete entry points。
[ ] Step 1: 写 failing render test
Use existing UI test pattern. Mock useServices().subagentsService.list to return built-in + user:
it("renders built-in and user subagents in settings user-only mode", async () => {
render(<SubagentsSection workspacePath="/repo" />);
expect(await screen.findByText("general-purpose")).toBeInTheDocument();
expect(await screen.findByText("code-reviewer")).toBeInTheDocument();
expect(screen.queryByText("workspace-reviewer")).not.toBeInTheDocument();
});
UI shape:
Use:
Button variant ghost size icon-smInput size lgControlHintTooltipPlus, FolderOpen, RefreshCw
[ ] Step 3: 实现 grouped list
Group order:
SubagentCard props:
interface SubagentCardProps {
agent: AgentSummary;
operating: boolean;
onToggle: (agent: AgentSummary, enabled: boolean) => void;
onEdit: (agent: AgentSummary) => void;
onDelete: (agent: AgentSummary) => void;
}
Rules:
agent.readOnly === true: hide edit/delete, disable switch or hide switch for built-ins.Use color swatch only from runtime enum; fallback to neutral dot.
[ ] Step 4: open user folder
Use existing subagentsService.getPrimaryUserAgentsDirectory({ provider: ZCODE_AGENT_PROVIDER }) then platform.openInFileManager(path)。Failure toast uses existing appHeader.openInFileManagerFailed。
Call store/hook setEnabled(agent.id, enabled)。On failure show toast and keep list refreshed from service.
Run:
pnpm --filter @zcode/ui test -- --run test/subagentsSettingsSection.test.tsx
Expected:
subagentsService.setEnabled with expected id.Files:
packages/ui/src/settings/SubagentForm.tsxpackages/ui/src/settings/SubagentsSection.tsxpackages/ui/src/i18n/locales/zh-CN.tspackages/ui/src/i18n/locales/en-US.tspackages/ui/test/subagentsSettingsSection.test.tsxInterfaces:
SubAgentConfigProduces: validated SubAgentConfig for createAgent / updateAgent
[ ] Step 1: 写 failing create form test
it("creates a user subagent from the settings form", async () => {
render(<SubagentsSection workspacePath="/repo" />);
await user.click(screen.getByLabelText("新建子代理"));
await user.type(screen.getByLabelText("名称"), "code-reviewer");
await user.type(screen.getByLabelText("描述"), "提交前审查代码");
await user.type(screen.getByLabelText("系统提示词"), "你是严格的代码审查员。");
await user.click(screen.getByRole("button", { name: "保存" }));
expect(subagentsService.createAgent).toHaveBeenCalledWith(
expect.objectContaining({
config: expect.objectContaining({
name: "code-reviewer",
description: "提交前审查代码",
systemPrompt: "你是严格的代码审查员。",
}),
}),
);
});
[ ] Step 2: 表单字段
P0 fields:
Bash(git diff *)P0 advanced collapsed fields:
mcpServers text field as comma/newline string only
[ ] Step 3: validation
Validation:
const NAME_REGEX = /^[a-zA-Z0-9-]+$/;
const MIN_NAME_LENGTH = 3;
const MAX_NAME_LENGTH = 50;
Errors:
maxTurns positive integer if set
[ ] Step 4: save behavior
Create:
await createAgent(config, ZCODE_AGENT_PROVIDER, subagentsService);
Edit:
await updateAgent(agent.id, config, agent.path, ZCODE_AGENT_PROVIDER, subagentsService);
After success:
toast saved
[ ] Step 5: responsive layout
Follow DESIGN.md:
rounded-xl border border-border bg-card p-4text-smgrid gap-3 md:grid-cols-2 for top fieldsTextarea min height for prompt, no raw color valuesNo nested cards
[ ] Step 6: run tests
Run:
pnpm --filter @zcode/ui test -- --run test/subagentsSettingsSection.test.tsx
Expected:
Files:
packages/ui/src/settings/SubagentsSection.tsxpackages/ui/src/settings/SubagentCard.tsxpackages/ui/src/i18n/locales/zh-CN.tspackages/ui/src/i18n/locales/en-US.tspackages/ui/test/subagentsSettingsSection.test.tsxInterfaces:
useConfirmDialog pattern from CommandsSection。Produces: delete confirm flow and diagnostics/error display。
[ ] Step 1: 写 delete confirmation test
it("confirms before deleting a user subagent", async () => {
render(<SubagentsSection workspacePath="/repo" />);
await user.click(await screen.findByLabelText("删除子代理"));
await user.click(screen.getByRole("button", { name: "删除" }));
expect(subagentsService.deleteAgent).toHaveBeenCalledWith(
expect.objectContaining({
agentId: "user:user:code-reviewer",
filePath: expect.stringContaining("code-reviewer.md"),
}),
);
});
[ ] Step 2: implement confirmation
Use:
const confirmed = await confirmDialog({
title: intl.formatMessage({ id: "settings.subagents.delete.title" }),
description: intl.formatMessage(
{ id: "settings.subagents.delete.description" },
{ name: agent.name },
),
confirmLabel: intl.formatMessage({ id: "common.delete" }),
});
If service returns diagnostics for invalid Markdown, show collapsible warning block near top:
Do not block valid agents from rendering.
Run:
pnpm --filter @zcode/ui test -- --run test/subagentsSettingsSection.test.tsx
Expected:
Files:
apps/zcode-cli/packages/bootstrap/tests/subagents.test.tsapps/zcode-cli/packages/core/tests/subagent-profile.test.tsInterfaces:
Produces: confidence that GUI-created profiles are runtime-loadable and disabled profiles are provider-invisible.
[ ] Step 1: Add GUI markdown compatibility test in bootstrap
Use a Markdown fixture generated by service serializer format:
await writeFile(
join(storageRoot, "agents", "code-reviewer.md"),
`---
name: code-reviewer
description: 提交前审查代码
model: lite
tools:
- Read
- Grep
- Bash(git diff *)
disallowedTools:
- Write
skills:
- code-review
permissionMode: acceptEdits
maxTurns: 7
background: true
color: cyan
---
你是严格的代码审查员。`,
"utf8",
);
Expect:
expect(result.profiles[0]).toMatchObject({
name: "code-reviewer",
model: "lite",
tools: ["Read", "Grep", "Bash"],
disallowedTools: ["Write"],
skills: ["code-review"],
permissionMode: "acceptEdits",
maxTurns: 7,
background: true,
color: "cyan",
});
formatAgentProfilesForPrompt with loaded profiles should include enabled user agent and omit disabled one.
If implementation changes current diff facts, update 历史差异审计文档(已删除):
enabled state now affects runtime profile load.
[ ] Step 4: run tests
Run:
pnpm --filter @zcode/bootstrap test -- --run tests/subagents.test.ts
pnpm --filter @zcode/core test -- --run tests/subagent-profile.test.ts
Expected: PASS。
Files:
Interfaces:
Produces: final verification evidence.
[ ] Step 1: Targeted tests
Run:
pnpm --filter @zcode/ui test -- --run \
test/settingsPageConfig.test.ts \
test/settingsNavigation.test.ts \
test/subagentsMentionProvider.test.ts \
test/subagentsSettingsSection.test.tsx
Expected: PASS。
Run:
pnpm test -- --run packages/services/test/subagentsService.test.ts
pnpm --filter @zcode/bootstrap test -- --run tests/subagents.test.ts
pnpm --filter @zcode/core test -- --run tests/subagent-profile.test.ts
Expected: PASS。
Run:
pnpm typecheck
pnpm lint
Expected: PASS。
Start the app using the repo's normal dev command for this worktree. Then:
code-reviewer.~/.zcode/agents/code-reviewer.md or configured ${storage.dir}/agents/code-reviewer.md.code-reviewer.code-reviewer is absent from available agent list.code-reviewer.code-reviewer appears in provider-visible agent list.Expected:
context_prefix rather than the Agent tool prompt.mcpServers; P0 preserves simple array values and can expose raw text only.Agent / Task tool schema or SendMessage behavior.@zcode/core.pnpm typecheck and pnpm lint are included in validation.