Merge pull request #21 from xixingde/main
refactor(agents): migrate agents to dedicated module and add new agent types
This commit is contained in:
commit
8d456ae7dd
|
|
@ -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\` 等提交操作
|
|
||||||
- 禁止使用 restore、reset、revert 等撤销修改的操作
|
|
||||||
- 只允许使用 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(),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
41
src/costrict/skill/strictPlan.ts
Normal file
41
src/costrict/skill/strictPlan.ts
Normal 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}`,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -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()
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user