Merge pull request #21 from xixingde/main

refactor(agents): migrate agents to dedicated module and add new agent types
This commit is contained in:
geroge 2026-04-10 16:17:23 +08:00 committed by GitHub
commit 8d456ae7dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 71 additions and 35 deletions

View File

@ -3,19 +3,23 @@ import type { BuiltInAgentDefinition } from 'src/tools/AgentTool/loadAgentsDir.j
function getStrictPlanSystemPrompt(): string { function getStrictPlanSystemPrompt(): string {
return `你是一个专门为软件项目创建结构化需求提案的 PlanAgent。 return `你是一个专门为软件项目创建结构化需求提案并协调实施StrictPlan Agent。
"**理解用户需求→探索项目→需求澄清→创建提案→实施提案**" "**理解用户需求→探索项目→需求澄清→创建提案→实施提案**"
****** CodingAgent ** SubCodingAgent ******** SubCodingAgent
********使'Agent工具'\`QuickExplore\` Agent进行深度的项目探索从而快速了解项目结构、实现细节、技术架构等信息为需求澄清和提案制定提供准确的项目现状基础。 ********使'Agent工具'\`QuickExplore\` Agent进行深度的项目探索从而快速了解项目结构、实现细节、技术架构等信息为需求澄清和提案制定提供准确的项目现状基础。
****使\`AskUserQuestion\`工具对用户进行提问式需求澄清,在需求未充分澄清前,禁止草率生成提案或任务清单。 ****使\`AskUserQuestion\`工具对用户进行提问式需求澄清,在需求未充分澄清前,禁止草率生成提案或任务清单。
**** \`@文件\` 引用的详细需求文档。无论哪种形式,你都需要仔细阅读并理解需求内容。 **** \`@文件\` 引用的详细需求文档。无论哪种形式,你都需要仔细阅读并理解需求内容。
**** task.md
**** SubCodingAgent
**** SubCodingAgent
**** SubCodingAgent
**** task.md
## PlanAgent ## PlanAgent
**** ****
- MVP开发模式 - MVP开发模式
- -
- Plan模式约束或最佳实践**Plan约束和最佳实践**
### ###
@ -59,16 +63,7 @@ function getStrictPlanSystemPrompt(): string {
#### ####
- 使\`AskUserQuestion\`向用户确认是否进入实施阶段,提供两个选项(立即实施/稍后实施),用户选择"立即实施"后再开始下面的实施操作。 - 使\`AskUserQuestion\`向用户确认是否进入实施阶段,提供两个选项(立即实施/稍后实施),用户选择"立即实施"后再开始下面的实施操作。
- "立即实施"** CodingAgent ** - "立即实施"****
#####
CodingAgent
1. **** task.md
2. **** SubCodingAgent
3. **** SubCodingAgent
4. **** SubCodingAgent
5. **** task.md
##### #####
@ -79,9 +74,9 @@ function getStrictPlanSystemPrompt(): string {
##### #####
- 使 \`edit\` 修改项目代码文件 - 使 \`Edit\` 修改项目代码文件
- \`task\` 分发给 SubCodingAgent 执行 - \`Agent\` 分发给 SubCodingAgent 执行
- ****使 \`edit\` 修改 task.md - ****使 \`Edit\` 修改 proposal.md、task.md
##### #####
@ -116,10 +111,7 @@ SubCodingAgent 只需理解与其任务直接相关的内容。分发任务时
1. **** \`task\` 工具启动 SubCodingAgent 分发任务 1. **** \`task\` 工具启动 SubCodingAgent 分发任务
2. **** 2. ****
- SubCodingAgent - SubCodingAgent的任务完成情况
- 使 \`checkpoint (action: list)\` 工具了解当前已经完成的代码编写工作,如果存在重复记录,以最新的一条为准
- list 使 \`checkpoint (action: show_diff)\` 工具查看具体变更内容
-
- SubCodingAgent - SubCodingAgent
- -
- ** task.md**使 \`edit\` 更新 task.md 文件,将刚完成的任务标记为已完成(\`- [x]\` - ** task.md**使 \`edit\` 更新 task.md 文件,将刚完成的任务标记为已完成(\`- [x]\`
@ -133,12 +125,6 @@ SubCodingAgent 只需理解与其任务直接相关的内容。分发任务时
- task.md - task.md
- -
##### git使用原则
- 使 \`git commit\`\`git push\` 等提交操作
- 使 restoreresetrevert
- 使 git \`git status\`, \`git diff\`, \`git log\`
### ###
# Plan # Plan
@ -237,9 +223,6 @@ export const STRICT_PLAN_AGENT: BuiltInAgentDefinition = {
agentType: 'StrictPlan', agentType: 'StrictPlan',
whenToUse: whenToUse:
'根据用户的需求创建具体可实施的计划。Use this when you need to create structured, actionable implementation plans based on user requirements. This agent follows a strict workflow: understand requirements → QuickExplore project → clarify requirements → create proposal → implement proposal.', '根据用户的需求创建具体可实施的计划。Use this when you need to create structured, actionable implementation plans based on user requirements. This agent follows a strict workflow: understand requirements → QuickExplore project → clarify requirements → create proposal → implement proposal.',
disallowedTools: [
EXIT_PLAN_MODE_TOOL_NAME,
],
tools:[ tools:[
"AskUserQuestion", "AskUserQuestion",
"Agent", "Agent",
@ -252,5 +235,8 @@ export const STRICT_PLAN_AGENT: BuiltInAgentDefinition = {
baseDir: 'built-in', baseDir: 'built-in',
model: 'inherit', model: 'inherit',
omitClaudeMd: false, omitClaudeMd: false,
// 通过斜杠命令从主线程启动时,使 resolveAgentTools 跳过 filterToolsForAgent
// 从而保留主线程完整工具集(包括 Agent 工具)。
isMainThread: true,
getSystemPrompt: () => getStrictPlanSystemPrompt(), getSystemPrompt: () => getStrictPlanSystemPrompt(),
} }

View File

@ -1,4 +1,3 @@
import { EXIT_PLAN_MODE_TOOL_NAME } from 'src/tools/ExitPlanModeTool/constants.js'
import type { BuiltInAgentDefinition } from 'src/tools/AgentTool/loadAgentsDir.js' import type { BuiltInAgentDefinition } from 'src/tools/AgentTool/loadAgentsDir.js'
function getSpecPlanSystemPrompt(): string { function getSpecPlanSystemPrompt(): string {

View File

@ -0,0 +1,41 @@
import { registerBundledSkill } from '../../skills/bundledSkills.js'
export function registerStrictPlanSkill(): void {
registerBundledSkill({
name: 'strict-plan',
description:
'创建结构化需求提案并协调实施 - 遵循"理解需求→探索项目→需求澄清→创建提案→实施提案"工作流',
whenToUse:
'根据用户的需求创建具体可实施的计划。Use this when you need to create structured, actionable implementation plans based on user requirements. This agent follows a strict workflow: understand requirements → QuickExplore project → clarify requirements → create proposal → implement proposal.',
userInvocable: true,
allowedTools:[
"AskUserQuestion",
"Agent",
"Read",
"Write",
"Edit",
"TodoWrite",
],
// 关键:在子 Agent 中运行
context: 'fork',
// 关键:使用 StrictPlan Agent
agent: 'StrictPlan',
async getPromptForCommand(args) {
const userRequest = args.trim()
if (!userRequest) {
return [
{
type: 'text',
text: '请提供需要规划的需求描述。用法: /strict-plan <需求描述>',
},
]
}
return [
{
type: 'text',
text: `用户需求:${userRequest}`,
},
]
},
})
}

View File

@ -15,6 +15,7 @@ import { registerLoopSkill } from './loop.js'
import { registerDreamSkill } from './dream.js' import { registerDreamSkill } from './dream.js'
import { registerUpdateConfigSkill } from './updateConfig.js' import { registerUpdateConfigSkill } from './updateConfig.js'
import { registerVerifySkill } from './verify.js' import { registerVerifySkill } from './verify.js'
import { registerStrictPlanSkill } from '../../costrict/skill/strictPlan.js'
import { registerProjectWikiSkill } from 'src/costrict/skill/projectWiki.js' import { registerProjectWikiSkill } from 'src/costrict/skill/projectWiki.js'
import { registerTddSkill } from 'src/costrict/skill/tdd.js' import { registerTddSkill } from 'src/costrict/skill/tdd.js'
@ -32,6 +33,7 @@ export function initBundledSkills(): void {
registerUpdateConfigSkill() registerUpdateConfigSkill()
registerProjectWikiSkill() registerProjectWikiSkill()
registerTddSkill() registerTddSkill()
registerStrictPlanSkill()
registerKeybindingsSkill() registerKeybindingsSkill()
registerVerifySkill() registerVerifySkill()
registerDebugSkill() registerDebugSkill()

View File

@ -122,7 +122,7 @@ export function filterToolsForAgent({
export function resolveAgentTools( export function resolveAgentTools(
agentDefinition: Pick< agentDefinition: Pick<
AgentDefinition, AgentDefinition,
'tools' | 'disallowedTools' | 'source' | 'permissionMode' 'tools' | 'disallowedTools' | 'source' | 'permissionMode' | 'isMainThread'
>, >,
availableTools: Tools, availableTools: Tools,
isAsync = false, isAsync = false,
@ -133,11 +133,15 @@ export function resolveAgentTools(
disallowedTools, disallowedTools,
source, source,
permissionMode, permissionMode,
isMainThread: agentIsMainThread,
} = agentDefinition } = agentDefinition
// When isMainThread is true, skip filterToolsForAgent entirely — the main // Allow the agent definition itself to declare isMainThread=true,
// thread's tool pool is already properly assembled by useMergedTools(), so // which takes precedence over the isMainThread parameter.
const effectiveIsMainThread = agentIsMainThread ?? isMainThread
// When effectiveIsMainThread is true, skip filterToolsForAgent entirely — the
// main thread's tool pool is already properly assembled by useMergedTools(), so
// the sub-agent disallow lists shouldn't apply. // the sub-agent disallow lists shouldn't apply.
const filteredAvailableTools = isMainThread const filteredAvailableTools = effectiveIsMainThread
? availableTools ? availableTools
: filterToolsForAgent({ : filterToolsForAgent({
tools: availableTools, tools: availableTools,
@ -195,7 +199,7 @@ export function resolveAgentTools(
} }
// For sub-agents, Agent is excluded by filterToolsForAgent — mark the spec // For sub-agents, Agent is excluded by filterToolsForAgent — mark the spec
// valid for allowedAgentTypes tracking but skip tool resolution. // valid for allowedAgentTypes tracking but skip tool resolution.
if (!isMainThread) { if (!effectiveIsMainThread) {
validTools.push(toolSpec) validTools.push(toolSpec)
continue continue
} }

View File

@ -130,6 +130,10 @@ export type BaseAgentDefinition = {
* full CLAUDE.md and interprets their output. Saves ~5-15 Gtok/week across * full CLAUDE.md and interprets their output. Saves ~5-15 Gtok/week across
* 34M+ Explore spawns. Kill-switch: tengu_slim_subagent_claudemd. */ * 34M+ Explore spawns. Kill-switch: tengu_slim_subagent_claudemd. */
omitClaudeMd?: boolean omitClaudeMd?: boolean
/** When true, resolveAgentTools skips filterToolsForAgent so the agent
* receives the full main-thread tool pool (including Agent tool).
* Use for agents launched directly via slash command from the main thread. */
isMainThread?: boolean
} }
// Built-in agents - dynamic prompts only, no static systemPrompt field // Built-in agents - dynamic prompts only, no static systemPrompt field