mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-13 02:41:50 +08:00
feat(codex): convert 4 workflow commands to Codex prompt format with serial execution
Convert parallel multi-agent/multi-CLI workflows to Codex-compatible serial execution:
- brainstorm-with-file: Parallel Creative/Pragmatic/Systematic perspectives → Serial CLI execution
- analyze-with-file: cli-explore-agent + parallel CLI → Native tools (Glob/Grep/Read) + serial Gemini CLI
- collaborative-plan-with-file: Parallel sub-agents → Serial domain planning loop
- unified-execute-with-file: DAG-based parallel wave execution → Serial task-by-task execution
Key Technical Changes:
- YAML header: Remove 'name' and 'allowed-tools' fields
- Variables: $ARGUMENTS → $TOPIC/$TASK/$PLAN
- Task agents: Task() calls → ccw cli commands with --tool flag
- Parallel execution: Parallel Task/Bash calls → Sequential loops
- Session format: Match existing Codex prompt structure
Pattern: For multi-step workflows, use explicit wait points with "⏳ Wait for completion before proceeding"
This commit is contained in:
@@ -1,29 +1,24 @@
|
|||||||
---
|
---
|
||||||
description: Interactive collaborative analysis with documented discussions, CLI-assisted exploration, and evolving understanding. Supports depth control and iteration limits.
|
description: Interactive collaborative analysis with documented discussions, CLI-assisted exploration, and evolving understanding. Serial analysis for Codex.
|
||||||
argument-hint: "TOPIC=\"<topic or question>\" [--depth=standard|deep|full] [--max-iterations=<n>] [--verbose]"
|
argument-hint: "TOPIC=\"<question or topic>\" [--focus=<area>] [--depth=quick|standard|deep] [--continue]"
|
||||||
---
|
---
|
||||||
|
|
||||||
# Codex Analyze-With-File Prompt
|
# Codex Analyze-With-File Prompt
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
Interactive collaborative analysis workflow with **documented discussion process**. Records understanding evolution, facilitates multi-round Q&A, and uses deep analysis for codebase and concept exploration.
|
Interactive collaborative analysis workflow with **documented discussion process**. Records understanding evolution, facilitates multi-round Q&A, and uses CLI tools for deep exploration.
|
||||||
|
|
||||||
**Core workflow**: Topic → Explore → Discuss → Document → Refine → Conclude
|
**Core workflow**: Topic → Explore → Discuss → Document → Refine → Conclude
|
||||||
|
|
||||||
**Key features**:
|
|
||||||
- **discussion.md**: Timeline of discussions and understanding evolution
|
|
||||||
- **Multi-round Q&A**: Iterative clarification with user
|
|
||||||
- **Analysis-assisted exploration**: Deep codebase and concept analysis
|
|
||||||
- **Consolidated insights**: Synthesizes discussions into actionable conclusions
|
|
||||||
- **Flexible continuation**: Resume analysis sessions to build on previous work
|
|
||||||
|
|
||||||
## Target Topic
|
## Target Topic
|
||||||
|
|
||||||
**$TOPIC**
|
**$TOPIC**
|
||||||
|
|
||||||
- `--depth`: Analysis depth (standard|deep|full)
|
**Parameters**:
|
||||||
- `--max-iterations`: Max discussion rounds
|
- `--focus`: Focus area (code|architecture|practice|diagnosis, default: code)
|
||||||
|
- `--depth`: Analysis depth (quick/standard/deep, default: standard)
|
||||||
|
- `--continue`: Resume existing analysis session
|
||||||
|
|
||||||
## Execution Process
|
## Execution Process
|
||||||
|
|
||||||
@@ -35,54 +30,68 @@ Session Detection:
|
|||||||
|
|
||||||
Phase 1: Topic Understanding
|
Phase 1: Topic Understanding
|
||||||
├─ Parse topic/question
|
├─ Parse topic/question
|
||||||
├─ Identify analysis dimensions (architecture, implementation, concept, etc.)
|
├─ Identify analysis dimensions
|
||||||
├─ Initial scoping with user
|
├─ Initial scoping with user
|
||||||
└─ Document initial understanding in discussion.md
|
└─ Initialize discussion.md
|
||||||
|
|
||||||
Phase 2: Exploration (Parallel)
|
Phase 2: CLI Exploration (Serial)
|
||||||
├─ Search codebase for relevant patterns
|
├─ Step 1: Codebase context gathering (Glob/Grep/Read)
|
||||||
├─ Analyze code structure and dependencies
|
├─ Step 2: Gemini CLI analysis (build on codebase findings)
|
||||||
└─ Aggregate findings into exploration summary
|
└─ Aggregate findings into explorations.json
|
||||||
|
|
||||||
Phase 3: Interactive Discussion (Multi-Round)
|
Phase 3: Interactive Discussion (Multi-Round)
|
||||||
├─ Present exploration findings
|
├─ Present exploration findings
|
||||||
├─ Facilitate Q&A with user
|
├─ Facilitate Q&A with user
|
||||||
├─ Capture user insights and requirements
|
├─ Capture user insights and corrections
|
||||||
|
├─ Actions: Deepen | Adjust | Answer | Complete
|
||||||
├─ Update discussion.md with each round
|
├─ Update discussion.md with each round
|
||||||
└─ Repeat until user is satisfied or clarity achieved
|
└─ Repeat until clarity achieved (max 5 rounds)
|
||||||
|
|
||||||
Phase 4: Synthesis & Conclusion
|
Phase 4: Synthesis & Conclusion
|
||||||
├─ Consolidate all insights
|
├─ Consolidate all insights
|
||||||
├─ Update discussion.md with conclusions
|
├─ Generate conclusions with recommendations
|
||||||
├─ Generate actionable recommendations
|
├─ Update discussion.md with final synthesis
|
||||||
└─ Optional: Create follow-up tasks or issues
|
└─ Offer follow-up options
|
||||||
|
|
||||||
Output:
|
Output:
|
||||||
├─ .workflow/.analysis/{slug}-{date}/discussion.md (evolving document)
|
├─ .workflow/.analysis/{slug}-{date}/discussion.md (evolution)
|
||||||
├─ .workflow/.analysis/{slug}-{date}/explorations.json (findings)
|
├─ .workflow/.analysis/{slug}-{date}/exploration-codebase.json (codebase context)
|
||||||
|
├─ .workflow/.analysis/{slug}-{date}/explorations.json (CLI findings)
|
||||||
└─ .workflow/.analysis/{slug}-{date}/conclusions.json (final synthesis)
|
└─ .workflow/.analysis/{slug}-{date}/conclusions.json (final synthesis)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Output Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
.workflow/.analysis/ANL-{slug}-{date}/
|
||||||
|
├── discussion.md # ⭐ Evolution of understanding & discussions
|
||||||
|
├── exploration-codebase.json # Phase 2: Codebase context
|
||||||
|
├── explorations.json # Phase 2: CLI analysis findings
|
||||||
|
└── conclusions.json # Phase 4: Final synthesis
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Implementation Details
|
## Implementation Details
|
||||||
|
|
||||||
### Session Setup & Mode Detection
|
### Session Setup
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const getUtc8ISOString = () => new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString()
|
const getUtc8ISOString = () => new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString()
|
||||||
|
|
||||||
const topicSlug = "$TOPIC".toLowerCase().replace(/[^a-z0-9]+/g, '-').substring(0, 40)
|
const topicSlug = "$TOPIC".toLowerCase().replace(/[^a-z0-9\u4e00-\u9fa5]+/g, '-').substring(0, 40)
|
||||||
const dateStr = getUtc8ISOString().substring(0, 10)
|
const dateStr = getUtc8ISOString().substring(0, 10)
|
||||||
|
|
||||||
const sessionId = `ANL-${topicSlug}-${dateStr}`
|
const sessionId = `ANL-${topicSlug}-${dateStr}`
|
||||||
const sessionFolder = `.workflow/.analysis/${sessionId}`
|
const sessionFolder = `.workflow/.analysis/${sessionId}`
|
||||||
const discussionPath = `${sessionFolder}/discussion.md`
|
const discussionPath = `${sessionFolder}/discussion.md`
|
||||||
|
const explorationPath = `${sessionFolder}/exploration-codebase.json`
|
||||||
const explorationsPath = `${sessionFolder}/explorations.json`
|
const explorationsPath = `${sessionFolder}/explorations.json`
|
||||||
const conclusionsPath = `${sessionFolder}/conclusions.json`
|
const conclusionsPath = `${sessionFolder}/conclusions.json`
|
||||||
|
|
||||||
// Auto-detect mode
|
// Auto-detect mode
|
||||||
const sessionExists = fs.existsSync(sessionFolder)
|
const sessionExists = fs.existsSync(sessionFolder)
|
||||||
const hasDiscussion = sessionExists && fs.existsSync(discussionPath)
|
const hasDiscussion = sessionExists && fs.existsSync(discussionPath)
|
||||||
|
|
||||||
const mode = hasDiscussion ? 'continue' : 'new'
|
const mode = hasDiscussion ? 'continue' : 'new'
|
||||||
|
|
||||||
if (!sessionExists) {
|
if (!sessionExists) {
|
||||||
@@ -97,15 +106,14 @@ if (!sessionExists) {
|
|||||||
#### Step 1.1: Parse Topic & Identify Dimensions
|
#### Step 1.1: Parse Topic & Identify Dimensions
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Analyze topic to determine analysis dimensions
|
|
||||||
const ANALYSIS_DIMENSIONS = {
|
const ANALYSIS_DIMENSIONS = {
|
||||||
architecture: ['架构', 'architecture', 'design', 'structure', '设计'],
|
architecture: ['架构', 'architecture', 'design', 'structure', '设计', 'pattern'],
|
||||||
implementation: ['实现', 'implement', 'code', 'coding', '代码'],
|
implementation: ['实现', 'implement', 'code', 'coding', '代码', 'logic'],
|
||||||
performance: ['性能', 'performance', 'optimize', 'bottleneck', '优化'],
|
performance: ['性能', 'performance', 'optimize', 'bottleneck', '优化', 'speed'],
|
||||||
security: ['安全', 'security', 'auth', 'permission', '权限'],
|
security: ['安全', 'security', 'auth', 'permission', '权限', 'vulnerability'],
|
||||||
concept: ['概念', 'concept', 'theory', 'principle', '原理'],
|
concept: ['概念', 'concept', 'theory', 'principle', '原理', 'understand'],
|
||||||
comparison: ['比较', 'compare', 'vs', 'difference', '区别'],
|
comparison: ['比较', 'compare', 'vs', 'difference', '区别', 'versus'],
|
||||||
decision: ['决策', 'decision', 'choice', 'tradeoff', '选择']
|
decision: ['决策', 'decision', 'choice', 'tradeoff', '选择', 'trade-off']
|
||||||
}
|
}
|
||||||
|
|
||||||
function identifyDimensions(topic) {
|
function identifyDimensions(topic) {
|
||||||
@@ -118,7 +126,7 @@ function identifyDimensions(topic) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return matched.length > 0 ? matched : ['general']
|
return matched.length > 0 ? matched : ['architecture', 'implementation']
|
||||||
}
|
}
|
||||||
|
|
||||||
const dimensions = identifyDimensions("$TOPIC")
|
const dimensions = identifyDimensions("$TOPIC")
|
||||||
@@ -129,14 +137,12 @@ const dimensions = identifyDimensions("$TOPIC")
|
|||||||
Ask user to scope the analysis:
|
Ask user to scope the analysis:
|
||||||
|
|
||||||
- Focus areas: 代码实现 / 架构设计 / 最佳实践 / 问题诊断
|
- Focus areas: 代码实现 / 架构设计 / 最佳实践 / 问题诊断
|
||||||
- Analysis depth: Quick Overview / Standard Analysis / Deep Dive
|
- Analysis depth: 快速概览 / 标准分析 / 深度挖掘
|
||||||
|
|
||||||
#### Step 1.3: Create/Update discussion.md
|
#### Step 1.3: Initialize discussion.md
|
||||||
|
|
||||||
For new session:
|
|
||||||
|
|
||||||
```markdown
|
```markdown
|
||||||
# Analysis Discussion
|
# Analysis Session
|
||||||
|
|
||||||
**Session ID**: ${sessionId}
|
**Session ID**: ${sessionId}
|
||||||
**Topic**: $TOPIC
|
**Topic**: $TOPIC
|
||||||
@@ -145,10 +151,17 @@ For new session:
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## User Context
|
## Analysis Context
|
||||||
|
|
||||||
**Focus Areas**: ${userFocusAreas.join(', ')}
|
**Focus Areas**: ${focusAreas.join(', ')}
|
||||||
**Analysis Depth**: ${analysisDepth}
|
**Depth**: ${analysisDepth}
|
||||||
|
**Scope**: ${scope || 'Full codebase'}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Initial Questions
|
||||||
|
|
||||||
|
${keyQuestions.map((q, i) => `${i+1}. ${q}`).join('\n')}
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -156,90 +169,112 @@ For new session:
|
|||||||
|
|
||||||
### Round 1 - Initial Understanding (${timestamp})
|
### Round 1 - Initial Understanding (${timestamp})
|
||||||
|
|
||||||
#### Topic Analysis
|
#### Key Questions
|
||||||
|
${keyQuestions.map((q, i) => `${i+1}. ${q}`).join('\n')}
|
||||||
Based on topic "$TOPIC":
|
|
||||||
|
|
||||||
- **Primary dimensions**: ${dimensions.join(', ')}
|
|
||||||
- **Initial scope**: ${initialScope}
|
|
||||||
- **Key questions to explore**:
|
|
||||||
- ${question1}
|
|
||||||
- ${question2}
|
|
||||||
- ${question3}
|
|
||||||
|
|
||||||
#### Next Steps
|
|
||||||
|
|
||||||
- Search codebase for relevant patterns
|
|
||||||
- Gather insights via analysis
|
|
||||||
- Prepare discussion points for user
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Current Understanding
|
## Current Understanding
|
||||||
|
|
||||||
${initialUnderstanding}
|
*To be populated after exploration phases*
|
||||||
```
|
|
||||||
|
|
||||||
For continue session, append:
|
|
||||||
|
|
||||||
```markdown
|
|
||||||
### Round ${n} - Continuation (${timestamp})
|
|
||||||
|
|
||||||
#### Previous Context
|
|
||||||
|
|
||||||
Resuming analysis based on prior discussion.
|
|
||||||
|
|
||||||
#### New Focus
|
|
||||||
|
|
||||||
${newFocusFromUser}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Phase 2: Exploration
|
### Phase 2: CLI Exploration (Serial)
|
||||||
|
|
||||||
#### Step 2.1: Codebase Search
|
#### Step 2.1: Codebase Context Gathering
|
||||||
|
|
||||||
|
Use built-in tools (no agent needed):
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Extract keywords from topic
|
// 1. Get project structure
|
||||||
const keywords = extractTopicKeywords("$TOPIC")
|
const modules = bash("ccw tool exec get_modules_by_depth '{}'")
|
||||||
|
|
||||||
// Search codebase for relevant code
|
// 2. Search for related code
|
||||||
const searchResults = []
|
const topicKeywords = extractKeywords("$TOPIC")
|
||||||
for (const keyword of keywords) {
|
const relatedFiles = Grep({
|
||||||
const results = Grep({ pattern: keyword, path: ".", output_mode: "content", "-C": 3 })
|
pattern: topicKeywords.join('|'),
|
||||||
searchResults.push({ keyword, results })
|
path: "src/",
|
||||||
|
output_mode: "files_with_matches"
|
||||||
|
})
|
||||||
|
|
||||||
|
// 3. Read project tech context
|
||||||
|
const projectTech = Read(".workflow/project-tech.json")
|
||||||
|
|
||||||
|
// Build exploration context
|
||||||
|
const explorationContext = {
|
||||||
|
relevant_files: relatedFiles.map(f => ({ path: f, relevance: 'high' })),
|
||||||
|
patterns: extractPatterns(modules),
|
||||||
|
constraints: projectTech?.constraints || [],
|
||||||
|
integration_points: projectTech?.integrations || []
|
||||||
}
|
}
|
||||||
|
|
||||||
// Identify affected files and patterns
|
Write(`${sessionFolder}/exploration-codebase.json`, JSON.stringify(explorationContext, null, 2))
|
||||||
const relevantLocations = analyzeSearchResults(searchResults)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Step 2.2: Pattern Analysis
|
#### Step 2.2: Gemini CLI Analysis
|
||||||
|
|
||||||
Analyze the codebase from identified dimensions:
|
**CLI Call** (synchronous):
|
||||||
|
```bash
|
||||||
|
ccw cli -p "
|
||||||
|
PURPOSE: Analyze '${topic}' from ${dimensions.join(', ')} perspectives
|
||||||
|
Success: Actionable insights with clear reasoning
|
||||||
|
|
||||||
1. Architecture patterns and structure
|
PRIOR CODEBASE CONTEXT:
|
||||||
2. Implementation conventions
|
- Key files: ${explorationContext.relevant_files.slice(0,5).map(f => f.path).join(', ')}
|
||||||
3. Dependency relationships
|
- Patterns found: ${explorationContext.patterns.slice(0,3).join(', ')}
|
||||||
4. Potential issues or improvements
|
- Constraints: ${explorationContext.constraints.slice(0,3).join(', ')}
|
||||||
|
|
||||||
|
TASK:
|
||||||
|
• Build on exploration findings above
|
||||||
|
• Analyze common patterns and anti-patterns
|
||||||
|
• Highlight potential issues or opportunities
|
||||||
|
• Generate discussion points for user clarification
|
||||||
|
• Provide 3-5 key insights with evidence
|
||||||
|
|
||||||
|
MODE: analysis
|
||||||
|
|
||||||
|
CONTEXT: @**/* | Topic: $TOPIC
|
||||||
|
|
||||||
|
EXPECTED:
|
||||||
|
- Structured analysis with clear sections
|
||||||
|
- Specific insights tied to evidence (file:line references where applicable)
|
||||||
|
- Questions to deepen understanding
|
||||||
|
- Recommendations with rationale
|
||||||
|
- Confidence levels (high/medium/low) for each conclusion
|
||||||
|
|
||||||
|
CONSTRAINTS: Focus on ${dimensions.join(', ')} | Ignore test files
|
||||||
|
" --tool gemini --mode analysis
|
||||||
|
```
|
||||||
|
|
||||||
|
**⏳ Wait for completion**
|
||||||
|
|
||||||
#### Step 2.3: Aggregate Findings
|
#### Step 2.3: Aggregate Findings
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Aggregate into explorations.json
|
|
||||||
const explorations = {
|
const explorations = {
|
||||||
session_id: sessionId,
|
session_id: sessionId,
|
||||||
timestamp: getUtc8ISOString(),
|
timestamp: getUtc8ISOString(),
|
||||||
topic: "$TOPIC",
|
topic: "$TOPIC",
|
||||||
dimensions: dimensions,
|
dimensions: dimensions,
|
||||||
|
|
||||||
sources: [
|
sources: [
|
||||||
{ type: "codebase", summary: codebaseSummary },
|
{ type: 'codebase', summary: 'Project structure and related files' },
|
||||||
{ type: "analysis", summary: analysisSummary }
|
{ type: 'cli_analysis', summary: 'Gemini deep analysis' }
|
||||||
],
|
],
|
||||||
key_findings: [...],
|
|
||||||
discussion_points: [...],
|
key_findings: [
|
||||||
open_questions: [...]
|
// Populated from CLI analysis
|
||||||
|
],
|
||||||
|
|
||||||
|
discussion_points: [
|
||||||
|
// Questions for user engagement
|
||||||
|
],
|
||||||
|
|
||||||
|
open_questions: [
|
||||||
|
// Unresolved items
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
Write(explorationsPath, JSON.stringify(explorations, null, 2))
|
Write(explorationsPath, JSON.stringify(explorations, null, 2))
|
||||||
@@ -247,104 +282,194 @@ Write(explorationsPath, JSON.stringify(explorations, null, 2))
|
|||||||
|
|
||||||
#### Step 2.4: Update discussion.md
|
#### Step 2.4: Update discussion.md
|
||||||
|
|
||||||
```markdown
|
Append Round 2 section:
|
||||||
#### Exploration Results (${timestamp})
|
|
||||||
|
|
||||||
**Sources Analyzed**:
|
```markdown
|
||||||
${sources.map(s => `- ${s.type}: ${s.summary}`).join('\n')}
|
### Round 2 - Initial Exploration (${timestamp})
|
||||||
|
|
||||||
|
#### Codebase Findings
|
||||||
|
${explorationContext.relevant_files.slice(0,5).map(f => `- ${f.path}: ${f.relevance}`).join('\n')}
|
||||||
|
|
||||||
|
#### Analysis Results
|
||||||
|
|
||||||
**Key Findings**:
|
**Key Findings**:
|
||||||
${keyFindings.map((f, i) => `${i+1}. ${f}`).join('\n')}
|
${keyFindings.map(f => `- 📍 ${f}`).join('\n')}
|
||||||
|
|
||||||
**Points for Discussion**:
|
**Discussion Points**:
|
||||||
${discussionPoints.map((p, i) => `${i+1}. ${p}`).join('\n')}
|
${discussionPoints.map(p => `- ❓ ${p}`).join('\n')}
|
||||||
|
|
||||||
**Open Questions**:
|
**Recommendations**:
|
||||||
${openQuestions.map((q, i) => `- ${q}`).join('\n')}
|
${recommendations.map(r => `- ✅ ${r}`).join('\n')}
|
||||||
|
|
||||||
|
---
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Phase 3: Interactive Discussion (Multi-Round)
|
### Phase 3: Interactive Discussion
|
||||||
|
|
||||||
#### Step 3.1: Present Findings & Gather Feedback
|
#### Step 3.1: Present & Gather Feedback
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Maximum discussion rounds
|
|
||||||
const MAX_ROUNDS = 5
|
const MAX_ROUNDS = 5
|
||||||
let roundNumber = 1
|
let roundNumber = 3
|
||||||
let discussionComplete = false
|
|
||||||
|
|
||||||
while (!discussionComplete && roundNumber <= MAX_ROUNDS) {
|
while (!analysisComplete && roundNumber <= MAX_ROUNDS) {
|
||||||
// Display current findings
|
|
||||||
|
// Present current findings
|
||||||
console.log(`
|
console.log(`
|
||||||
## Discussion Round ${roundNumber}
|
## Analysis Round ${roundNumber}
|
||||||
|
|
||||||
${currentFindings}
|
### Current Understanding
|
||||||
|
${currentUnderstanding}
|
||||||
|
|
||||||
### Key Points for Your Input
|
### Key Questions Still Open
|
||||||
${discussionPoints.map((p, i) => `${i+1}. ${p}`).join('\n')}
|
${openQuestions.map((q, i) => `${i+1}. ${q}`).join('\n')}
|
||||||
|
|
||||||
|
### User Options:
|
||||||
|
- 继续深入: Deepen current direction
|
||||||
|
- 调整方向: Change analysis angle
|
||||||
|
- 有具体问题: Ask specific question
|
||||||
|
- 分析完成: Ready for synthesis
|
||||||
`)
|
`)
|
||||||
|
|
||||||
// Gather user input
|
// User selects direction:
|
||||||
// Options:
|
// - 继续深入: Deepen analysis in current direction
|
||||||
// - 同意,继续深入: Deepen analysis in current direction
|
// - 调整方向: Change focus area
|
||||||
// - 需要调整方向: Get user's adjusted focus
|
// - 有具体问题: Capture specific questions
|
||||||
// - 分析完成: Exit loop
|
// - 分析完成: Exit discussion loop
|
||||||
// - 有具体问题: Answer specific questions
|
|
||||||
|
|
||||||
// Process user response and update understanding
|
|
||||||
updateDiscussionDocument(roundNumber, userResponse, findings)
|
|
||||||
roundNumber++
|
roundNumber++
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Step 3.2: Document Each Round
|
#### Step 3.2: Deepen Analysis
|
||||||
|
|
||||||
|
**CLI Call** (synchronous):
|
||||||
|
```bash
|
||||||
|
ccw cli -p "
|
||||||
|
PURPOSE: Deepen analysis on '${topic}' - more detailed investigation
|
||||||
|
Success: Comprehensive understanding with actionable insights
|
||||||
|
|
||||||
|
PRIOR FINDINGS:
|
||||||
|
${priorFindings.join('\n')}
|
||||||
|
|
||||||
|
DEEPEN ON:
|
||||||
|
${focusAreas.map(a => `- ${a}: ${details}`).join('\n')}
|
||||||
|
|
||||||
|
TASK:
|
||||||
|
• Elaborate on prior findings
|
||||||
|
• Investigate edge cases or special scenarios
|
||||||
|
• Identify patterns not yet discussed
|
||||||
|
• Suggest implementation or improvement approaches
|
||||||
|
• Rate risk/impact for each finding (1-5)
|
||||||
|
|
||||||
|
MODE: analysis
|
||||||
|
|
||||||
|
CONTEXT: @**/*
|
||||||
|
|
||||||
|
EXPECTED:
|
||||||
|
- Detailed breakdown of prior findings
|
||||||
|
- Risk/impact assessment
|
||||||
|
- Specific improvement suggestions
|
||||||
|
- Code examples or patterns where applicable
|
||||||
|
" --tool gemini --mode analysis
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Step 3.3: Adjust Direction
|
||||||
|
|
||||||
|
**CLI Call** (synchronous):
|
||||||
|
```bash
|
||||||
|
ccw cli -p "
|
||||||
|
PURPOSE: Analyze '${topic}' from different perspective: ${newFocus}
|
||||||
|
Success: Fresh insights from new angle
|
||||||
|
|
||||||
|
PRIOR ANALYSIS:
|
||||||
|
${priorAnalysis}
|
||||||
|
|
||||||
|
NEW FOCUS:
|
||||||
|
Shift emphasis to: ${newFocus}
|
||||||
|
|
||||||
|
TASK:
|
||||||
|
• Analyze topic from new perspective
|
||||||
|
• Identify what was missed in prior analysis
|
||||||
|
• Generate insights specific to new focus
|
||||||
|
• Cross-reference with prior findings
|
||||||
|
• Suggest next investigation steps
|
||||||
|
|
||||||
|
MODE: analysis
|
||||||
|
|
||||||
|
CONTEXT: @**/*
|
||||||
|
|
||||||
|
EXPECTED:
|
||||||
|
- New perspective insights
|
||||||
|
- Gaps in prior analysis
|
||||||
|
- Integrated view (prior + new)
|
||||||
|
" --tool gemini --mode analysis
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Step 3.4: Answer Specific Questions
|
||||||
|
|
||||||
|
**CLI Call** (synchronous):
|
||||||
|
```bash
|
||||||
|
ccw cli -p "
|
||||||
|
PURPOSE: Answer specific questions about '${topic}'
|
||||||
|
Success: Clear, evidence-based answers
|
||||||
|
|
||||||
|
QUESTIONS FROM USER:
|
||||||
|
${userQuestions.map((q, i) => `${i+1}. ${q}`).join('\n')}
|
||||||
|
|
||||||
|
PRIOR CONTEXT:
|
||||||
|
${priorAnalysis}
|
||||||
|
|
||||||
|
TASK:
|
||||||
|
• Answer each question directly
|
||||||
|
• Provide evidence or examples
|
||||||
|
• Clarify any ambiguous points
|
||||||
|
• Suggest related investigation
|
||||||
|
|
||||||
|
MODE: analysis
|
||||||
|
|
||||||
|
CONTEXT: @**/*
|
||||||
|
|
||||||
|
EXPECTED:
|
||||||
|
- Direct answer to each question
|
||||||
|
- Supporting evidence
|
||||||
|
- Confidence level for each answer
|
||||||
|
" --tool gemini --mode analysis
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Step 3.5: Document Each Round
|
||||||
|
|
||||||
Append to discussion.md:
|
Append to discussion.md:
|
||||||
|
|
||||||
```markdown
|
```markdown
|
||||||
### Round ${n} - Discussion (${timestamp})
|
### Round ${n} - ${action} (${timestamp})
|
||||||
|
|
||||||
#### User Input
|
#### User Direction
|
||||||
|
- **Action**: ${action}
|
||||||
|
- **Focus**: ${focus || 'Same as prior'}
|
||||||
|
|
||||||
${userInputSummary}
|
#### Analysis Results
|
||||||
|
|
||||||
${userResponse === 'adjustment' ? `
|
**Key Findings**:
|
||||||
**Direction Adjustment**: ${adjustmentDetails}
|
${newFindings.map(f => `- ${f}`).join('\n')}
|
||||||
` : ''}
|
|
||||||
|
|
||||||
${userResponse === 'questions' ? `
|
**Insights**:
|
||||||
**User Questions**:
|
${insights.map(i => `- 💡 ${i}`).join('\n')}
|
||||||
${userQuestions.map((q, i) => `${i+1}. ${q}`).join('\n')}
|
|
||||||
|
|
||||||
**Answers**:
|
**Next Steps**:
|
||||||
${answers.map((a, i) => `${i+1}. ${a}`).join('\n')}
|
${nextSteps.map(s => `${s.priority} - ${s.action}`).join('\n')}
|
||||||
` : ''}
|
|
||||||
|
|
||||||
#### Updated Understanding
|
|
||||||
|
|
||||||
Based on user feedback:
|
|
||||||
- ${insight1}
|
|
||||||
- ${insight2}
|
|
||||||
|
|
||||||
#### Corrected Assumptions
|
#### Corrected Assumptions
|
||||||
|
${corrections.map(c => `- ~~${c.before}~~ → ${c.after}`).join('\n')}
|
||||||
${corrections.length > 0 ? corrections.map(c => `
|
|
||||||
- ~~${c.wrong}~~ → ${c.corrected}
|
|
||||||
- Reason: ${c.reason}
|
|
||||||
`).join('\n') : 'None'}
|
|
||||||
|
|
||||||
#### New Insights
|
|
||||||
|
|
||||||
${newInsights.map(i => `- ${i}`).join('\n')}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Phase 4: Synthesis & Conclusion
|
### Phase 4: Synthesis & Conclusion
|
||||||
|
|
||||||
#### Step 4.1: Consolidate Insights
|
#### Step 4.1: Final Synthesis
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const conclusions = {
|
const conclusions = {
|
||||||
@@ -353,21 +478,20 @@ const conclusions = {
|
|||||||
completed: getUtc8ISOString(),
|
completed: getUtc8ISOString(),
|
||||||
total_rounds: roundNumber,
|
total_rounds: roundNumber,
|
||||||
|
|
||||||
summary: "...",
|
summary: executiveSummary,
|
||||||
|
|
||||||
key_conclusions: [
|
key_conclusions: [
|
||||||
{ point: "...", evidence: "...", confidence: "high|medium|low" }
|
{ point: '...', evidence: '...', confidence: 'high|medium|low' }
|
||||||
],
|
],
|
||||||
|
|
||||||
recommendations: [
|
recommendations: [
|
||||||
{ action: "...", rationale: "...", priority: "high|medium|low" }
|
{ action: '...', rationale: '...', priority: 'high|medium|low' }
|
||||||
],
|
],
|
||||||
|
|
||||||
open_questions: [...],
|
open_questions: remainingQuestions,
|
||||||
|
|
||||||
follow_up_suggestions: [
|
follow_up_suggestions: [
|
||||||
{ type: "issue", summary: "..." },
|
{ type: 'issue|task|research', summary: '...' }
|
||||||
{ type: "task", summary: "..." }
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,164 +503,108 @@ Write(conclusionsPath, JSON.stringify(conclusions, null, 2))
|
|||||||
```markdown
|
```markdown
|
||||||
---
|
---
|
||||||
|
|
||||||
## Conclusions (${timestamp})
|
## Synthesis & Conclusions (${timestamp})
|
||||||
|
|
||||||
### Summary
|
### Executive Summary
|
||||||
|
${summary}
|
||||||
${summaryParagraph}
|
|
||||||
|
|
||||||
### Key Conclusions
|
### Key Conclusions
|
||||||
|
|
||||||
${conclusions.key_conclusions.map((c, i) => `
|
${keyConclusions.map((c, i) => `
|
||||||
${i+1}. **${c.point}** (Confidence: ${c.confidence})
|
${i+1}. **${c.point}** (Confidence: ${c.confidence})
|
||||||
- Evidence: ${c.evidence}
|
Evidence: ${c.evidence}
|
||||||
`).join('\n')}
|
`).join('\n')}
|
||||||
|
|
||||||
### Recommendations
|
### Recommendations
|
||||||
|
|
||||||
${conclusions.recommendations.map((r, i) => `
|
${recommendations.map((r, i) => `
|
||||||
${i+1}. **${r.action}** (Priority: ${r.priority})
|
${i+1}. **[${r.priority}]** ${r.action}
|
||||||
- Rationale: ${r.rationale}
|
Rationale: ${r.rationale}
|
||||||
`).join('\n')}
|
`).join('\n')}
|
||||||
|
|
||||||
### Remaining Questions
|
### Remaining Open Questions
|
||||||
|
|
||||||
${conclusions.open_questions.map(q => `- ${q}`).join('\n')}
|
${openQuestions.map((q, i) => `${i+1}. ${q}`).join('\n')}
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Current Understanding (Final)
|
## Current Understanding (Final)
|
||||||
|
|
||||||
### What We Established
|
### What We Established
|
||||||
|
${established.map(p => `- ✅ ${p}`).join('\n')}
|
||||||
|
|
||||||
${establishedPoints.map(p => `- ${p}`).join('\n')}
|
### What Was Clarified
|
||||||
|
${clarified.map(c => `- ~~${c.before}~~ → ${c.after}`).join('\n')}
|
||||||
### What Was Clarified/Corrected
|
|
||||||
|
|
||||||
${corrections.map(c => `- ~~${c.original}~~ → ${c.corrected}`).join('\n')}
|
|
||||||
|
|
||||||
### Key Insights
|
### Key Insights
|
||||||
|
${insights.map(i => `- 💡 ${i}`).join('\n')}
|
||||||
${keyInsights.map(i => `- ${i}`).join('\n')}
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Session Statistics
|
## Session Statistics
|
||||||
|
|
||||||
- **Total Rounds**: ${totalRounds}
|
- **Total Rounds**: ${totalRounds}
|
||||||
- **Duration**: ${duration}
|
- **Key Findings**: ${keyFindings.length}
|
||||||
- **Sources Used**: ${sources.join(', ')}
|
- **Dimensions Analyzed**: ${dimensions.join(', ')}
|
||||||
- **Artifacts Generated**: discussion.md, explorations.json, conclusions.json
|
- **Artifacts**: discussion.md, exploration-codebase.json, explorations.json, conclusions.json
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Step 4.3: Post-Completion Options
|
#### Step 4.3: Post-Completion Options
|
||||||
|
|
||||||
Offer follow-up options:
|
Offer follow-up options:
|
||||||
- Create Issue: Convert conclusions to actionable issues
|
- Create Issue (for findings)
|
||||||
- Generate Task: Create implementation tasks
|
- Generate Task (for improvements)
|
||||||
- Export Report: Generate standalone analysis report
|
- Export Report
|
||||||
- Complete: No further action needed
|
- Complete
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Session Folder Structure
|
## Configuration
|
||||||
|
|
||||||
```
|
### Analysis Dimensions
|
||||||
.workflow/.analysis/ANL-{slug}-{date}/
|
|
||||||
├── discussion.md # Evolution of understanding & discussions
|
|
||||||
├── explorations.json # Exploration findings
|
|
||||||
├── conclusions.json # Final synthesis
|
|
||||||
└── exploration-*.json # Individual exploration results (optional)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Discussion Document Template
|
| Dimension | Keywords |
|
||||||
|
|-----------|----------|
|
||||||
|
| architecture | 架构, architecture, design, structure, 设计 |
|
||||||
|
| implementation | 实现, implement, code, coding, 代码 |
|
||||||
|
| performance | 性能, performance, optimize, bottleneck, 优化 |
|
||||||
|
| security | 安全, security, auth, permission, 权限 |
|
||||||
|
| concept | 概念, concept, theory, principle, 原理 |
|
||||||
|
| comparison | 比较, compare, vs, difference, 区别 |
|
||||||
|
| decision | 决策, decision, choice, tradeoff, 选择 |
|
||||||
|
|
||||||
```markdown
|
### Depth Settings
|
||||||
# Analysis Discussion
|
|
||||||
|
|
||||||
**Session ID**: ANL-xxx-2025-01-25
|
| Depth | Time | Scope | Questions |
|
||||||
**Topic**: [topic or question]
|
|-------|------|-------|-----------|
|
||||||
**Started**: 2025-01-25T10:00:00+08:00
|
| Quick (10-15min) | 1-2 | Surface level | 3-5 key |
|
||||||
**Dimensions**: [architecture, implementation, ...]
|
| Standard (30-60min) | 2-4 | Moderate depth | 5-8 key |
|
||||||
|
| Deep (1-2hr) | 4+ | Comprehensive | 10+ key |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## User Context
|
## Error Handling
|
||||||
|
|
||||||
**Focus Areas**: [user-selected focus]
|
| Situation | Action |
|
||||||
**Analysis Depth**: [quick|standard|deep]
|
|-----------|--------|
|
||||||
|
| CLI timeout | Retry with shorter prompt, skip analysis |
|
||||||
|
| No relevant findings | Broaden search, adjust keywords |
|
||||||
|
| User disengaged | Summarize progress, offer break point |
|
||||||
|
| Max rounds reached | Force synthesis, highlight remaining questions |
|
||||||
|
| Session folder conflict | Append timestamp suffix |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Discussion Timeline
|
|
||||||
|
|
||||||
### Round 1 - Initial Understanding (2025-01-25 10:00)
|
|
||||||
|
|
||||||
#### Topic Analysis
|
|
||||||
...
|
|
||||||
|
|
||||||
#### Exploration Results
|
|
||||||
...
|
|
||||||
|
|
||||||
### Round 2 - Discussion (2025-01-25 10:15)
|
|
||||||
|
|
||||||
#### User Input
|
|
||||||
...
|
|
||||||
|
|
||||||
#### Updated Understanding
|
|
||||||
...
|
|
||||||
|
|
||||||
#### Corrected Assumptions
|
|
||||||
- ~~[wrong]~~ → [corrected]
|
|
||||||
|
|
||||||
### Round 3 - Deep Dive (2025-01-25 10:30)
|
|
||||||
...
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Conclusions (2025-01-25 11:00)
|
|
||||||
|
|
||||||
### Summary
|
|
||||||
...
|
|
||||||
|
|
||||||
### Key Conclusions
|
|
||||||
...
|
|
||||||
|
|
||||||
### Recommendations
|
|
||||||
...
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Current Understanding (Final)
|
|
||||||
|
|
||||||
### What We Established
|
|
||||||
- [confirmed points]
|
|
||||||
|
|
||||||
### What Was Clarified/Corrected
|
|
||||||
- ~~[original assumption]~~ → [corrected understanding]
|
|
||||||
|
|
||||||
### Key Insights
|
|
||||||
- [insights gained]
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Session Statistics
|
|
||||||
|
|
||||||
- **Total Rounds**: 3
|
|
||||||
- **Duration**: 1 hour
|
|
||||||
- **Sources Used**: codebase exploration, analysis
|
|
||||||
- **Artifacts Generated**: discussion.md, explorations.json, conclusions.json
|
|
||||||
```
|
|
||||||
|
|
||||||
## Iteration Flow
|
## Iteration Flow
|
||||||
|
|
||||||
```
|
```
|
||||||
First Call (TOPIC="topic"):
|
First Call (TOPIC="topic"):
|
||||||
├─ No session exists → New mode
|
├─ No session exists → New mode
|
||||||
├─ Identify analysis dimensions
|
├─ Identify dimensions
|
||||||
├─ Scope with user
|
├─ Scope with user
|
||||||
├─ Create discussion.md with initial understanding
|
├─ Create discussion.md
|
||||||
├─ Launch explorations
|
├─ Codebase exploration
|
||||||
|
├─ Gemini CLI analysis
|
||||||
└─ Enter discussion loop
|
└─ Enter discussion loop
|
||||||
|
|
||||||
Continue Call (TOPIC="topic"):
|
Continue Call (TOPIC="topic"):
|
||||||
@@ -549,10 +617,10 @@ Discussion Loop:
|
|||||||
├─ Present current findings
|
├─ Present current findings
|
||||||
├─ Gather user feedback
|
├─ Gather user feedback
|
||||||
├─ Process response:
|
├─ Process response:
|
||||||
│ ├─ Agree → Deepen analysis
|
│ ├─ Deepen → Deeper analysis on same topic
|
||||||
│ ├─ Adjust → Change direction
|
│ ├─ Adjust → Shift analysis focus
|
||||||
│ ├─ Question → Answer then continue
|
│ ├─ Questions → Answer specific questions
|
||||||
│ └─ Complete → Exit loop
|
│ └─ Complete → Exit loop for synthesis
|
||||||
├─ Update discussion.md
|
├─ Update discussion.md
|
||||||
└─ Repeat until complete or max rounds
|
└─ Repeat until complete or max rounds
|
||||||
|
|
||||||
@@ -562,49 +630,6 @@ Completion:
|
|||||||
└─ Offer follow-up options
|
└─ Offer follow-up options
|
||||||
```
|
```
|
||||||
|
|
||||||
## Consolidation Rules
|
|
||||||
|
|
||||||
When updating "Current Understanding":
|
|
||||||
|
|
||||||
1. **Promote confirmed insights**: Move validated findings to "What We Established"
|
|
||||||
2. **Track corrections**: Keep important wrong→right transformations
|
|
||||||
3. **Focus on current state**: What do we know NOW
|
|
||||||
4. **Avoid timeline repetition**: Don't copy discussion details
|
|
||||||
5. **Preserve key learnings**: Keep insights valuable for future reference
|
|
||||||
|
|
||||||
**Bad (cluttered)**:
|
|
||||||
```markdown
|
|
||||||
## Current Understanding
|
|
||||||
|
|
||||||
In round 1 we discussed X, then in round 2 user said Y, and we explored Z...
|
|
||||||
```
|
|
||||||
|
|
||||||
**Good (consolidated)**:
|
|
||||||
```markdown
|
|
||||||
## Current Understanding
|
|
||||||
|
|
||||||
### What We Established
|
|
||||||
- The authentication flow uses JWT with refresh tokens
|
|
||||||
- Rate limiting is implemented at API gateway level
|
|
||||||
|
|
||||||
### What Was Clarified
|
|
||||||
- ~~Assumed Redis for sessions~~ → Actually uses database-backed sessions
|
|
||||||
|
|
||||||
### Key Insights
|
|
||||||
- Current architecture supports horizontal scaling
|
|
||||||
- Security audit recommended before production
|
|
||||||
```
|
|
||||||
|
|
||||||
## Error Handling
|
|
||||||
|
|
||||||
| Situation | Action |
|
|
||||||
|-----------|--------|
|
|
||||||
| Exploration fails | Continue with available context, note limitation |
|
|
||||||
| User timeout in discussion | Save state, show resume instructions |
|
|
||||||
| Max rounds reached | Force synthesis, offer continuation option |
|
|
||||||
| No relevant findings | Broaden search, ask user for clarification |
|
|
||||||
| Session folder conflict | Append timestamp suffix |
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**Now execute the analyze-with-file workflow for topic**: $TOPIC
|
**Now execute the analysis-with-file workflow for topic**: $TOPIC
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
549
.codex/prompts/collaborative-plan-with-file.md
Normal file
549
.codex/prompts/collaborative-plan-with-file.md
Normal file
@@ -0,0 +1,549 @@
|
|||||||
|
---
|
||||||
|
description: Serial collaborative planning with Plan Note - Single-agent sequential task generation, unified plan-note.md, conflict detection. Codex-optimized.
|
||||||
|
argument-hint: "TASK=\"<description>\" [--max-domains=5] [--focus=<domain>]"
|
||||||
|
---
|
||||||
|
|
||||||
|
# Codex Collaborative-Plan-With-File Prompt
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
Serial collaborative planning workflow using **Plan Note** architecture:
|
||||||
|
|
||||||
|
1. **Understanding**: Analyze requirements and identify 2-5 sub-domains
|
||||||
|
2. **Sequential Planning**: Process each sub-domain sequentially, generating plan.json + updating plan-note.md
|
||||||
|
3. **Conflict Detection**: Scan plan-note.md for conflicts
|
||||||
|
4. **Completion**: Generate executable plan.md summary
|
||||||
|
|
||||||
|
**Note**: Codex does not support parallel agent execution. All domains processed serially.
|
||||||
|
|
||||||
|
## Target Task
|
||||||
|
|
||||||
|
**$TASK**
|
||||||
|
|
||||||
|
**Parameters**:
|
||||||
|
- `--max-domains`: Maximum sub-domains to identify (default: 5)
|
||||||
|
- `--focus`: Focus specific domain (optional)
|
||||||
|
|
||||||
|
## Execution Process
|
||||||
|
|
||||||
|
```
|
||||||
|
Session Detection:
|
||||||
|
├─ Check if planning session exists for task
|
||||||
|
├─ EXISTS + plan-note.md exists → Continue mode
|
||||||
|
└─ NOT_FOUND → New session mode
|
||||||
|
|
||||||
|
Phase 1: Understanding & Template Creation
|
||||||
|
├─ Analyze task description (Glob/Grep/Bash)
|
||||||
|
├─ Identify 2-5 sub-domains
|
||||||
|
├─ Create plan-note.md template
|
||||||
|
└─ Generate requirement-analysis.json
|
||||||
|
|
||||||
|
Phase 2: Sequential Sub-Domain Planning (Serial)
|
||||||
|
├─ For each sub-domain (LOOP):
|
||||||
|
│ ├─ Gemini CLI: Generate detailed plan
|
||||||
|
│ ├─ Extract task summary
|
||||||
|
│ └─ Update plan-note.md section
|
||||||
|
└─ Complete all domains sequentially
|
||||||
|
|
||||||
|
Phase 3: Conflict Detection
|
||||||
|
├─ Parse plan-note.md
|
||||||
|
├─ Extract all tasks from all sections
|
||||||
|
├─ Detect file/dependency/strategy conflicts
|
||||||
|
└─ Update conflict markers in plan-note.md
|
||||||
|
|
||||||
|
Phase 4: Completion
|
||||||
|
├─ Generate conflicts.json
|
||||||
|
├─ Generate plan.md summary
|
||||||
|
└─ Ready for execution
|
||||||
|
|
||||||
|
Output:
|
||||||
|
├─ .workflow/.planning/{slug}-{date}/plan-note.md (executable)
|
||||||
|
├─ .workflow/.planning/{slug}-{date}/requirement-analysis.json (metadata)
|
||||||
|
├─ .workflow/.planning/{slug}-{date}/conflicts.json (conflict report)
|
||||||
|
├─ .workflow/.planning/{slug}-{date}/plan.md (human-readable)
|
||||||
|
└─ .workflow/.planning/{slug}-{date}/agents/{domain}/plan.json (detailed)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Output Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
.workflow/.planning/CPLAN-{slug}-{date}/
|
||||||
|
├── plan-note.md # ⭐ Core: Requirements + Tasks + Conflicts
|
||||||
|
├── requirement-analysis.json # Phase 1: Sub-domain assignments
|
||||||
|
├── agents/ # Phase 2: Per-domain plans (serial)
|
||||||
|
│ ├── {domain-1}/
|
||||||
|
│ │ └── plan.json # Detailed plan
|
||||||
|
│ ├── {domain-2}/
|
||||||
|
│ │ └── plan.json
|
||||||
|
│ └── ...
|
||||||
|
├── conflicts.json # Phase 3: Conflict report
|
||||||
|
└── plan.md # Phase 4: Human-readable summary
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Implementation Details
|
||||||
|
|
||||||
|
### Session Setup
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const getUtc8ISOString = () => new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString()
|
||||||
|
|
||||||
|
const taskSlug = "$TASK".toLowerCase().replace(/[^a-z0-9\u4e00-\u9fa5]+/g, '-').substring(0, 30)
|
||||||
|
const dateStr = getUtc8ISOString().substring(0, 10)
|
||||||
|
|
||||||
|
const sessionId = `CPLAN-${taskSlug}-${dateStr}`
|
||||||
|
const sessionFolder = `.workflow/.planning/${sessionId}`
|
||||||
|
const planNotePath = `${sessionFolder}/plan-note.md`
|
||||||
|
const requirementsPath = `${sessionFolder}/requirement-analysis.json`
|
||||||
|
const conflictsPath = `${sessionFolder}/conflicts.json`
|
||||||
|
const planPath = `${sessionFolder}/plan.md`
|
||||||
|
|
||||||
|
// Auto-detect mode
|
||||||
|
const sessionExists = fs.existsSync(sessionFolder)
|
||||||
|
const hasPlanNote = sessionExists && fs.existsSync(planNotePath)
|
||||||
|
const mode = hasPlanNote ? 'continue' : 'new'
|
||||||
|
|
||||||
|
if (!sessionExists) {
|
||||||
|
bash(`mkdir -p ${sessionFolder}/agents`)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Phase 1: Understanding & Template Creation
|
||||||
|
|
||||||
|
#### Step 1.1: Analyze Task Description
|
||||||
|
|
||||||
|
Use built-in tools (no agent):
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// 1. Extract task keywords
|
||||||
|
const taskKeywords = extractKeywords("$TASK")
|
||||||
|
|
||||||
|
// 2. Identify sub-domains via analysis
|
||||||
|
// Example: "Implement real-time notification system"
|
||||||
|
// → Domains: [Backend API, Frontend UI, Notification Service, Data Storage, Testing]
|
||||||
|
|
||||||
|
const subDomains = identifySubDomains("$TASK", {
|
||||||
|
maxDomains: 5, // --max-domains parameter
|
||||||
|
keywords: taskKeywords
|
||||||
|
})
|
||||||
|
|
||||||
|
// 3. Estimate scope
|
||||||
|
const complexity = assessComplexity("$TASK")
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Step 1.2: Create plan-note.md Template
|
||||||
|
|
||||||
|
Generate structured template:
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
---
|
||||||
|
session_id: ${sessionId}
|
||||||
|
original_requirement: |
|
||||||
|
$TASK
|
||||||
|
created_at: ${getUtc8ISOString()}
|
||||||
|
complexity: ${complexity}
|
||||||
|
sub_domains: ${subDomains.map(d => d.name).join(', ')}
|
||||||
|
status: in_progress
|
||||||
|
---
|
||||||
|
|
||||||
|
# 协作规划
|
||||||
|
|
||||||
|
**Session ID**: ${sessionId}
|
||||||
|
**任务**: $TASK
|
||||||
|
**复杂度**: ${complexity}
|
||||||
|
**创建时间**: ${getUtc8ISOString()}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 需求理解
|
||||||
|
|
||||||
|
### 核心目标
|
||||||
|
${extractObjectives("$TASK")}
|
||||||
|
|
||||||
|
### 关键要点
|
||||||
|
${extractKeyPoints("$TASK")}
|
||||||
|
|
||||||
|
### 约束条件
|
||||||
|
${extractConstraints("$TASK")}
|
||||||
|
|
||||||
|
### 拆分策略
|
||||||
|
${subDomains.length} 个子领域:
|
||||||
|
${subDomains.map((d, i) => `${i+1}. **${d.name}**: ${d.description}`).join('\n')}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 任务池 - ${subDomains[0].name}
|
||||||
|
*(TASK-001 ~ TASK-100)*
|
||||||
|
|
||||||
|
*待由规划流程填充*
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 任务池 - ${subDomains[1].name}
|
||||||
|
*(TASK-101 ~ TASK-200)*
|
||||||
|
|
||||||
|
*待由规划流程填充*
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 依赖关系
|
||||||
|
|
||||||
|
*所有子域规划完成后自动生成*
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 冲突标记
|
||||||
|
|
||||||
|
*冲突检测阶段生成*
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 上下文证据 - ${subDomains[0].name}
|
||||||
|
|
||||||
|
*相关文件、现有模式、约束等*
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 上下文证据 - ${subDomains[1].name}
|
||||||
|
|
||||||
|
*相关文件、现有模式、约束等*
|
||||||
|
|
||||||
|
---
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Step 1.3: Generate requirement-analysis.json
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const requirements = {
|
||||||
|
session_id: sessionId,
|
||||||
|
original_requirement: "$TASK",
|
||||||
|
complexity: complexity,
|
||||||
|
sub_domains: subDomains.map((domain, index) => ({
|
||||||
|
focus_area: domain.name,
|
||||||
|
description: domain.description,
|
||||||
|
task_id_range: [index * 100 + 1, (index + 1) * 100],
|
||||||
|
estimated_effort: domain.effort,
|
||||||
|
dependencies: domain.dependencies || []
|
||||||
|
})),
|
||||||
|
total_domains: subDomains.length
|
||||||
|
}
|
||||||
|
|
||||||
|
Write(requirementsPath, JSON.stringify(requirements, null, 2))
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Phase 2: Sequential Sub-Domain Planning
|
||||||
|
|
||||||
|
#### Step 2.1: Plan Each Domain Sequentially
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
for (let i = 0; i < subDomains.length; i++) {
|
||||||
|
const domain = subDomains[i]
|
||||||
|
const domainFolder = `${sessionFolder}/agents/${domain.slug}`
|
||||||
|
const domainPlanPath = `${domainFolder}/plan.json`
|
||||||
|
|
||||||
|
console.log(`Planning Domain ${i+1}/${subDomains.length}: ${domain.name}`)
|
||||||
|
|
||||||
|
// Execute Gemini CLI for this domain
|
||||||
|
// ⏳ Wait for completion before proceeding to next domain
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Step 2.2: CLI Planning for Current Domain
|
||||||
|
|
||||||
|
**CLI Call** (synchronous):
|
||||||
|
```bash
|
||||||
|
ccw cli -p "
|
||||||
|
PURPOSE: Generate detailed implementation plan for domain '${domain.name}' in task: $TASK
|
||||||
|
Success: Comprehensive task breakdown with clear dependencies and effort estimates
|
||||||
|
|
||||||
|
DOMAIN CONTEXT:
|
||||||
|
- Focus Area: ${domain.name}
|
||||||
|
- Description: ${domain.description}
|
||||||
|
- Task ID Range: ${domain.task_id_range[0]}-${domain.task_id_range[1]}
|
||||||
|
- Related Domains: ${relatedDomains.join(', ')}
|
||||||
|
|
||||||
|
PRIOR DOMAINS (if any):
|
||||||
|
${completedDomains.map(d => `- ${d.name}: ${completedTaskCount} tasks`).join('\n')}
|
||||||
|
|
||||||
|
TASK:
|
||||||
|
• Analyze ${domain.name} in detail
|
||||||
|
• Identify all necessary tasks (use TASK-ID range: ${domain.task_id_range[0]}-${domain.task_id_range[1]})
|
||||||
|
• Define task dependencies and order
|
||||||
|
• Estimate effort and complexity for each task
|
||||||
|
• Identify file modifications needed
|
||||||
|
• Assess conflict risks with other domains
|
||||||
|
|
||||||
|
MODE: analysis
|
||||||
|
|
||||||
|
CONTEXT: @**/*
|
||||||
|
|
||||||
|
EXPECTED:
|
||||||
|
JSON output with:
|
||||||
|
- tasks[]: {id, title, description, complexity, depends_on[], files_to_modify[], conflict_risk}
|
||||||
|
- summary: Overview of domain plan
|
||||||
|
- interdependencies: Links to other domains
|
||||||
|
- total_effort: Estimated effort points
|
||||||
|
|
||||||
|
OUTPUT FORMAT: Structured JSON
|
||||||
|
" --tool gemini --mode analysis
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Step 2.3: Parse and Update plan-note.md
|
||||||
|
|
||||||
|
After CLI completes for each domain:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Parse CLI output
|
||||||
|
const planJson = parseCLIOutput(cliResult)
|
||||||
|
|
||||||
|
// Save detailed plan
|
||||||
|
Write(domainPlanPath, JSON.stringify(planJson, null, 2))
|
||||||
|
|
||||||
|
// Extract task summary
|
||||||
|
const taskSummary = planJson.tasks.map((t, idx) => `
|
||||||
|
### TASK-${t.id}: ${t.title} [${domain.slug}]
|
||||||
|
|
||||||
|
**状态**: 规划中
|
||||||
|
**复杂度**: ${t.complexity}
|
||||||
|
**依赖**: ${t.depends_on.length > 0 ? t.depends_on.map(d => `TASK-${d}`).join(', ') : 'None'}
|
||||||
|
**范围**: ${t.description}
|
||||||
|
|
||||||
|
**修改点**:
|
||||||
|
${t.files_to_modify.map(f => `- \`${f.path}:${f.line_range}\`: ${f.summary}`).join('\n')}
|
||||||
|
|
||||||
|
**冲突风险**: ${t.conflict_risk}
|
||||||
|
`).join('\n')
|
||||||
|
|
||||||
|
// Update plan-note.md
|
||||||
|
updatePlanNoteSection(
|
||||||
|
planNotePath,
|
||||||
|
`## 任务池 - ${domain.name}`,
|
||||||
|
taskSummary
|
||||||
|
)
|
||||||
|
|
||||||
|
// Extract evidence
|
||||||
|
const evidence = `
|
||||||
|
**相关文件**:
|
||||||
|
${planJson.related_files.map(f => `- ${f.path}: ${f.relevance}`).join('\n')}
|
||||||
|
|
||||||
|
**现有模式**:
|
||||||
|
${planJson.existing_patterns.map(p => `- ${p}`).join('\n')}
|
||||||
|
|
||||||
|
**约束**:
|
||||||
|
${planJson.constraints.map(c => `- ${c}`).join('\n')}
|
||||||
|
`
|
||||||
|
|
||||||
|
updatePlanNoteSection(
|
||||||
|
planNotePath,
|
||||||
|
`## 上下文证据 - ${domain.name}`,
|
||||||
|
evidence
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Step 2.4: Process All Domains
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const completedDomains = []
|
||||||
|
|
||||||
|
for (const domain of subDomains) {
|
||||||
|
// Step 2.2: CLI call (synchronous)
|
||||||
|
const cliResult = executeCLI(domain)
|
||||||
|
|
||||||
|
// Step 2.3: Parse and update
|
||||||
|
updatePlanNoteFromCLI(domain, cliResult)
|
||||||
|
|
||||||
|
completedDomains.push(domain)
|
||||||
|
console.log(`✅ Completed: ${domain.name}`)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Phase 3: Conflict Detection
|
||||||
|
|
||||||
|
#### Step 3.1: Parse plan-note.md
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const planContent = Read(planNotePath)
|
||||||
|
const sections = parsePlanNoteSections(planContent)
|
||||||
|
const allTasks = []
|
||||||
|
|
||||||
|
// Extract tasks from all domains
|
||||||
|
for (const section of sections) {
|
||||||
|
if (section.heading.includes('任务池')) {
|
||||||
|
const tasks = extractTasks(section.content)
|
||||||
|
allTasks.push(...tasks)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Step 3.2: Detect Conflicts
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const conflicts = []
|
||||||
|
|
||||||
|
// 1. File conflicts
|
||||||
|
const fileMap = new Map()
|
||||||
|
for (const task of allTasks) {
|
||||||
|
for (const file of task.files_to_modify) {
|
||||||
|
const key = `${file.path}:${file.line_range}`
|
||||||
|
if (!fileMap.has(key)) fileMap.set(key, [])
|
||||||
|
fileMap.get(key).push(task)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [location, tasks] of fileMap.entries()) {
|
||||||
|
if (tasks.length > 1) {
|
||||||
|
const agents = new Set(tasks.map(t => t.domain))
|
||||||
|
if (agents.size > 1) {
|
||||||
|
conflicts.push({
|
||||||
|
type: 'file_conflict',
|
||||||
|
severity: 'high',
|
||||||
|
location: location,
|
||||||
|
tasks_involved: tasks.map(t => t.id),
|
||||||
|
agents_involved: Array.from(agents),
|
||||||
|
description: `Multiple domains modifying: ${location}`,
|
||||||
|
suggested_resolution: 'Coordinate modification order'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Dependency cycles
|
||||||
|
const depGraph = buildDependencyGraph(allTasks)
|
||||||
|
const cycles = detectCycles(depGraph)
|
||||||
|
for (const cycle of cycles) {
|
||||||
|
conflicts.push({
|
||||||
|
type: 'dependency_cycle',
|
||||||
|
severity: 'critical',
|
||||||
|
tasks_involved: cycle,
|
||||||
|
description: `Circular dependency: ${cycle.join(' → ')}`,
|
||||||
|
suggested_resolution: 'Remove or reorganize dependencies'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write conflicts.json
|
||||||
|
Write(conflictsPath, JSON.stringify({
|
||||||
|
detected_at: getUtc8ISOString(),
|
||||||
|
total_conflicts: conflicts.length,
|
||||||
|
conflicts: conflicts
|
||||||
|
}, null, 2))
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Step 3.3: Update plan-note.md
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const conflictMarkdown = generateConflictMarkdown(conflicts)
|
||||||
|
|
||||||
|
updatePlanNoteSection(
|
||||||
|
planNotePath,
|
||||||
|
'## 冲突标记',
|
||||||
|
conflictMarkdown
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Phase 4: Completion
|
||||||
|
|
||||||
|
#### Step 4.1: Generate plan.md
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
# 实现计划
|
||||||
|
|
||||||
|
**Session**: ${sessionId}
|
||||||
|
**任务**: $TASK
|
||||||
|
**创建**: ${getUtc8ISOString()}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 需求
|
||||||
|
|
||||||
|
${copySection(planNotePath, '## 需求理解')}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 子领域拆分
|
||||||
|
|
||||||
|
${subDomains.map((domain, i) => `
|
||||||
|
### ${i+1}. ${domain.name}
|
||||||
|
- **描述**: ${domain.description}
|
||||||
|
- **任务范围**: TASK-${domain.task_id_range[0]} ~ TASK-${domain.task_id_range[1]}
|
||||||
|
- **预估工作量**: ${domain.effort}
|
||||||
|
`).join('\n')}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 任务概览
|
||||||
|
|
||||||
|
${allTasks.map(t => `
|
||||||
|
### ${t.id}: ${t.title}
|
||||||
|
- **复杂度**: ${t.complexity}
|
||||||
|
- **依赖**: ${t.depends_on.length > 0 ? t.depends_on.join(', ') : 'None'}
|
||||||
|
- **文件**: ${t.files_to_modify.map(f => f.path).join(', ')}
|
||||||
|
`).join('\n')}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 冲突报告
|
||||||
|
|
||||||
|
${conflicts.length > 0
|
||||||
|
? `检测到 ${conflicts.length} 个冲突:\n${copySection(planNotePath, '## 冲突标记')}`
|
||||||
|
: '✅ 无冲突检测到'}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 执行指令
|
||||||
|
|
||||||
|
\`\`\`bash
|
||||||
|
/workflow:unified-execute-with-file ${planPath}
|
||||||
|
\`\`\`
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Step 4.2: Write Summary
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
Write(planPath, planMarkdown)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
### Sub-Domain Identification
|
||||||
|
|
||||||
|
Common domain patterns:
|
||||||
|
- Backend API: "服务", "后端", "API", "接口"
|
||||||
|
- Frontend: "界面", "前端", "UI", "视图"
|
||||||
|
- Database: "数据", "存储", "数据库", "持久化"
|
||||||
|
- Testing: "测试", "验证", "QA"
|
||||||
|
- Infrastructure: "部署", "基础", "运维", "配置"
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Error Handling
|
||||||
|
|
||||||
|
| Error | Resolution |
|
||||||
|
|-------|------------|
|
||||||
|
| CLI timeout | Retry with shorter prompt |
|
||||||
|
| No tasks generated | Review domain description, retry |
|
||||||
|
| Section not found | Recreate section in plan-note.md |
|
||||||
|
| Conflict detection fails | Continue with empty conflicts |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Best Practices
|
||||||
|
|
||||||
|
1. **Clear Task Description**: Detailed requirements → better sub-domains
|
||||||
|
2. **Review plan-note.md**: Check before moving to next phase
|
||||||
|
3. **Resolve Conflicts**: Address before execution
|
||||||
|
4. **Inspect Details**: Review agents/{domain}/plan.json for specifics
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Now execute collaborative-plan-with-file for**: $TASK
|
||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user