mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-14 02:42:04 +08:00
refactor(task-generate-agent): optimize N+1 parallel planning prompts
- Phase 2B: Add structured agent prompt with TASK OBJECTIVE, MODULE SCOPE, SESSION PATHS, CONTEXT METADATA, CROSS-MODULE DEPENDENCIES sections - Phase 3: Convert from function calls to agent invocation with complete prompt structure for IMPL_PLAN.md and TODO_LIST.md generation - Align prompt structure with Phase 2A (Single Agent) for consistency - Reference agent specification for template details instead of inline docs - Add dependency resolution algorithm for CROSS:: placeholder resolution 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -219,7 +219,9 @@ Hard Constraints:
|
|||||||
|
|
||||||
**Condition**: `modules.length >= 2` (multi-module detected)
|
**Condition**: `modules.length >= 2` (multi-module detected)
|
||||||
|
|
||||||
**Purpose**: Launch N action-planning-agents simultaneously, one per module, for parallel task generation.
|
**Purpose**: Launch N action-planning-agents simultaneously, one per module, for parallel task JSON generation.
|
||||||
|
|
||||||
|
**Note**: Phase 2B agents generate Task JSONs ONLY. IMPL_PLAN.md and TODO_LIST.md are generated by Phase 3 Coordinator.
|
||||||
|
|
||||||
**Parallel Agent Invocation**:
|
**Parallel Agent Invocation**:
|
||||||
```javascript
|
```javascript
|
||||||
@@ -227,27 +229,49 @@ Hard Constraints:
|
|||||||
const planningTasks = modules.map(module =>
|
const planningTasks = modules.map(module =>
|
||||||
Task(
|
Task(
|
||||||
subagent_type="action-planning-agent",
|
subagent_type="action-planning-agent",
|
||||||
description=`Plan ${module.name} module`,
|
description=`Generate ${module.name} module task JSONs`,
|
||||||
prompt=`
|
prompt=`
|
||||||
## SCOPE
|
## TASK OBJECTIVE
|
||||||
|
Generate task JSON files for ${module.name} module within workflow session
|
||||||
|
|
||||||
|
IMPORTANT: This is PLANNING ONLY - generate task JSONs, NOT implementing code.
|
||||||
|
IMPORTANT: Generate Task JSONs ONLY. IMPL_PLAN.md and TODO_LIST.md by Phase 3 Coordinator.
|
||||||
|
|
||||||
|
CRITICAL: Follow progressive loading strategy in agent specification
|
||||||
|
|
||||||
|
## MODULE SCOPE
|
||||||
- Module: ${module.name} (${module.type})
|
- Module: ${module.name} (${module.type})
|
||||||
- Focus Paths: ${module.paths.join(', ')}
|
- Focus Paths: ${module.paths.join(', ')}
|
||||||
- Task ID Prefix: IMPL-${module.prefix}
|
- Task ID Prefix: IMPL-${module.prefix}
|
||||||
- Task Limit: ≤9 tasks
|
- Task Limit: ≤9 tasks
|
||||||
- Other Modules: ${otherModules.join(', ')}
|
- Other Modules: ${otherModules.join(', ')}
|
||||||
- Cross-module deps format: "CROSS::{module}::{pattern}"
|
|
||||||
|
|
||||||
## SESSION PATHS
|
## SESSION PATHS
|
||||||
Input:
|
Input:
|
||||||
|
- Session Metadata: .workflow/active/{session-id}/workflow-session.json
|
||||||
- Context Package: .workflow/active/{session-id}/.process/context-package.json
|
- Context Package: .workflow/active/{session-id}/.process/context-package.json
|
||||||
Output:
|
Output:
|
||||||
- Task Dir: .workflow/active/{session-id}/.task/
|
- Task Dir: .workflow/active/{session-id}/.task/
|
||||||
|
|
||||||
## INSTRUCTIONS
|
## CONTEXT METADATA
|
||||||
- Generate tasks ONLY for ${module.name} module
|
Session ID: {session-id}
|
||||||
- Use task ID format: IMPL-${module.prefix}1, IMPL-${module.prefix}2, ...
|
MCP Capabilities: {exa_code, exa_web, code_index}
|
||||||
- For cross-module dependencies, use: depends_on: ["CROSS::B::api-endpoint"]
|
|
||||||
- Maximum 9 tasks per module
|
## CROSS-MODULE DEPENDENCIES
|
||||||
|
- Use placeholder: depends_on: ["CROSS::{module}::{pattern}"]
|
||||||
|
- Example: depends_on: ["CROSS::B::api-endpoint"]
|
||||||
|
- Phase 3 Coordinator resolves to actual task IDs
|
||||||
|
|
||||||
|
## EXPECTED DELIVERABLES
|
||||||
|
Task JSON Files (.task/IMPL-${module.prefix}*.json):
|
||||||
|
- 6-field schema per agent specification
|
||||||
|
- Task ID format: IMPL-${module.prefix}1, IMPL-${module.prefix}2, ...
|
||||||
|
- Focus ONLY on ${module.name} module scope
|
||||||
|
|
||||||
|
## SUCCESS CRITERIA
|
||||||
|
- Task JSONs saved to .task/ with IMPL-${module.prefix}* naming
|
||||||
|
- Cross-module dependencies use CROSS:: placeholder format
|
||||||
|
- Return task count and brief summary
|
||||||
`
|
`
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -271,37 +295,78 @@ await Promise.all(planningTasks);
|
|||||||
- Prefix: A, B, C... (assigned by detection order)
|
- Prefix: A, B, C... (assigned by detection order)
|
||||||
- Sequence: 1, 2, 3... (per-module increment)
|
- Sequence: 1, 2, 3... (per-module increment)
|
||||||
|
|
||||||
### Phase 3: Integration (+1 Coordinator, Multi-Module Only)
|
### Phase 3: Integration (+1 Coordinator Agent, Multi-Module Only)
|
||||||
|
|
||||||
**Condition**: Only executed when `modules.length >= 2`
|
**Condition**: Only executed when `modules.length >= 2`
|
||||||
|
|
||||||
**Purpose**: Collect all module tasks, resolve cross-module dependencies, generate unified documents.
|
**Purpose**: Collect all module tasks, resolve cross-module dependencies, generate unified IMPL_PLAN.md and TODO_LIST.md documents.
|
||||||
|
|
||||||
**Integration Logic**:
|
**Coordinator Agent Invocation**:
|
||||||
```javascript
|
```javascript
|
||||||
// 1. Collect all module task JSONs
|
// Wait for all Phase 2B agents to complete
|
||||||
const allTasks = glob('.task/IMPL-*.json').map(loadJson);
|
const moduleResults = await Promise.all(planningTasks);
|
||||||
|
|
||||||
// 2. Resolve cross-module dependencies
|
// Launch +1 Coordinator Agent
|
||||||
for (const task of allTasks) {
|
Task(
|
||||||
if (task.depends_on) {
|
subagent_type="action-planning-agent",
|
||||||
task.depends_on = task.depends_on.map(dep => {
|
description="Integrate module tasks and generate unified documents",
|
||||||
if (dep.startsWith('CROSS::')) {
|
prompt=`
|
||||||
// CROSS::B::api-endpoint → find matching IMPL-B* task
|
## TASK OBJECTIVE
|
||||||
const [, targetModule, pattern] = dep.match(/CROSS::(\w+)::(.+)/);
|
Integrate all module task JSONs, resolve cross-module dependencies, and generate unified IMPL_PLAN.md and TODO_LIST.md
|
||||||
return findTaskByModuleAndPattern(allTasks, targetModule, pattern);
|
|
||||||
}
|
|
||||||
return dep;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Generate unified IMPL_PLAN.md (grouped by module)
|
IMPORTANT: This is INTEGRATION ONLY - consolidate existing task JSONs, NOT creating new tasks.
|
||||||
generateIMPL_PLAN(allTasks, modules);
|
|
||||||
|
|
||||||
// 4. Generate TODO_LIST.md (hierarchical structure)
|
## SESSION PATHS
|
||||||
generateTODO_LIST(allTasks, modules);
|
Input:
|
||||||
|
- Session Metadata: .workflow/active/{session-id}/workflow-session.json
|
||||||
|
- Context Package: .workflow/active/{session-id}/.process/context-package.json
|
||||||
|
- Task JSONs: .workflow/active/{session-id}/.task/IMPL-*.json (from Phase 2B)
|
||||||
|
Output:
|
||||||
|
- Updated Task JSONs: .workflow/active/{session-id}/.task/IMPL-*.json (resolved dependencies)
|
||||||
|
- IMPL_PLAN: .workflow/active/{session-id}/IMPL_PLAN.md
|
||||||
|
- TODO_LIST: .workflow/active/{session-id}/TODO_LIST.md
|
||||||
|
|
||||||
|
## CONTEXT METADATA
|
||||||
|
Session ID: {session-id}
|
||||||
|
Modules: ${modules.map(m => m.name + '(' + m.prefix + ')').join(', ')}
|
||||||
|
Module Count: ${modules.length}
|
||||||
|
|
||||||
|
## INTEGRATION STEPS
|
||||||
|
1. Collect all .task/IMPL-*.json, group by module prefix
|
||||||
|
2. Resolve CROSS:: dependencies → actual task IDs, update task JSONs
|
||||||
|
3. Generate IMPL_PLAN.md (multi-module format per agent specification)
|
||||||
|
4. Generate TODO_LIST.md (hierarchical format per agent specification)
|
||||||
|
|
||||||
|
## CROSS-MODULE DEPENDENCY RESOLUTION
|
||||||
|
- Pattern: CROSS::{module}::{pattern} → IMPL-{module}* matching title/context
|
||||||
|
- Example: CROSS::B::api-endpoint → IMPL-B1 (if B1 title contains "api-endpoint")
|
||||||
|
- Log unresolved as warnings
|
||||||
|
|
||||||
|
## EXPECTED DELIVERABLES
|
||||||
|
1. Updated Task JSONs with resolved dependency IDs
|
||||||
|
2. IMPL_PLAN.md - multi-module format with cross-dependency section
|
||||||
|
3. TODO_LIST.md - hierarchical by module with cross-dependency section
|
||||||
|
|
||||||
|
## SUCCESS CRITERIA
|
||||||
|
- No CROSS:: placeholders remaining in task JSONs
|
||||||
|
- IMPL_PLAN.md and TODO_LIST.md generated with multi-module structure
|
||||||
|
- Return: task count, per-module breakdown, resolved dependency count
|
||||||
|
`
|
||||||
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
**Note**: IMPL_PLAN.md and TODO_LIST.md structure definitions are in `action-planning-agent.md`.
|
**Dependency Resolution Algorithm**:
|
||||||
|
```javascript
|
||||||
|
function resolveCrossModuleDependency(placeholder, allTasks) {
|
||||||
|
const [, targetModule, pattern] = placeholder.match(/CROSS::(\w+)::(.+)/);
|
||||||
|
const candidates = allTasks.filter(t =>
|
||||||
|
t.id.startsWith(`IMPL-${targetModule}`) &&
|
||||||
|
(t.title.toLowerCase().includes(pattern.toLowerCase()) ||
|
||||||
|
t.context?.description?.toLowerCase().includes(pattern.toLowerCase()))
|
||||||
|
);
|
||||||
|
return candidates.length > 0
|
||||||
|
? candidates.sort((a, b) => a.id.localeCompare(b.id))[0].id
|
||||||
|
: placeholder; // Keep for manual resolution
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user