mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-28 09:23:08 +08:00
- Added command architecture section to skill router template, detailing role organization and command delegation. - Updated role router input parsing to reflect new file structure for roles. - Introduced role isolation rules to enforce strict boundaries on role responsibilities and output tagging. - Enhanced team configuration section to include role-specific guidelines and message bus requirements. feat: Improve terminal dashboard with session status indicators - Integrated terminal status indicators in the session group tree, displaying active, idle, error, paused, and resuming states. - Updated session click handling to focus on existing panes or assign sessions to available panes. feat: Add session lifecycle controls in terminal pane - Implemented restart, pause, and resume functionalities for terminal sessions with loading states. - Enhanced UI buttons for session control with appropriate loading indicators and tooltips. i18n: Update terminal dashboard localization for session controls - Added translations for restart, pause, and resume session actions in English and Chinese. chore: Create role command template for command file generation - Established a comprehensive template for generating command files in roles, including sections for strategy, execution steps, and error handling. - Included pre-built command patterns for common tasks like exploration, analysis, implementation, validation, review, dispatch, and monitoring.
254 lines
7.3 KiB
Markdown
254 lines
7.3 KiB
Markdown
# Phase 2: Pattern Analysis
|
|
|
|
Analyze applicable patterns for each role in the team.
|
|
|
|
## Objective
|
|
|
|
- Per-role: find most similar existing command
|
|
- Per-role: select infrastructure + collaboration patterns
|
|
- Per-role: map 5-phase structure to role responsibilities
|
|
- Generate pattern-analysis.json
|
|
|
|
## Input
|
|
|
|
- Dependency: `team-config.json` (Phase 1)
|
|
- Specification: `specs/team-design-patterns.md` (read in Phase 0)
|
|
|
|
## Execution Steps
|
|
|
|
### Step 1: Load Configuration
|
|
|
|
```javascript
|
|
const config = JSON.parse(Read(`${workDir}/team-config.json`))
|
|
```
|
|
|
|
### Step 2: Per-Role Similarity Mapping
|
|
|
|
```javascript
|
|
const similarityMap = {
|
|
"Read-only analysis": {
|
|
primary: "review", secondary: "plan",
|
|
reason: "Both analyze code and report findings with severity classification"
|
|
},
|
|
"Code generation": {
|
|
primary: "execute", secondary: "test",
|
|
reason: "Both write/modify code and self-validate"
|
|
},
|
|
"Orchestration": {
|
|
primary: "plan", secondary: "coordinate",
|
|
reason: "Both coordinate sub-tasks and produce structured output"
|
|
},
|
|
"Validation": {
|
|
primary: "test", secondary: "review",
|
|
reason: "Both validate quality with structured criteria"
|
|
}
|
|
}
|
|
|
|
const roleAnalysis = config.worker_roles.map(role => {
|
|
const similarity = similarityMap[role.responsibility_type]
|
|
return {
|
|
role_name: role.name,
|
|
similar_to: similarity,
|
|
reference_command: `.claude/commands/team/${similarity.primary}.md`
|
|
}
|
|
})
|
|
```
|
|
|
|
### Step 3: Per-Role Phase Mapping
|
|
|
|
```javascript
|
|
const phaseMapping = {
|
|
"Read-only analysis": {
|
|
phase2: "Context Loading",
|
|
phase3: "Analysis Execution",
|
|
phase4: "Finding Summary"
|
|
},
|
|
"Code generation": {
|
|
phase2: "Task & Plan Loading",
|
|
phase3: "Code Implementation",
|
|
phase4: "Self-Validation"
|
|
},
|
|
"Orchestration": {
|
|
phase2: "Context & Complexity Assessment",
|
|
phase3: "Orchestrated Execution",
|
|
phase4: "Result Aggregation"
|
|
},
|
|
"Validation": {
|
|
phase2: "Environment Detection",
|
|
phase3: "Execution & Fix Cycle",
|
|
phase4: "Result Analysis"
|
|
}
|
|
}
|
|
|
|
roleAnalysis.forEach(ra => {
|
|
const role = config.worker_roles.find(r => r.name === ra.role_name)
|
|
ra.phase_structure = {
|
|
phase1: "Task Discovery",
|
|
...phaseMapping[role.responsibility_type],
|
|
phase5: "Report to Coordinator"
|
|
}
|
|
})
|
|
```
|
|
|
|
### Step 4: Per-Role Infrastructure Patterns
|
|
|
|
```javascript
|
|
roleAnalysis.forEach(ra => {
|
|
const role = config.worker_roles.find(r => r.name === ra.role_name)
|
|
|
|
// Core patterns (mandatory for all)
|
|
ra.core_patterns = [
|
|
"pattern-1-message-bus",
|
|
"pattern-2-yaml-front-matter", // Adapted: no YAML in skill role files
|
|
"pattern-3-task-lifecycle",
|
|
"pattern-4-five-phase",
|
|
"pattern-6-coordinator-spawn",
|
|
"pattern-7-error-handling"
|
|
]
|
|
|
|
// Conditional patterns
|
|
ra.conditional_patterns = []
|
|
if (role.adaptive_routing) {
|
|
ra.conditional_patterns.push("pattern-5-complexity-adaptive")
|
|
}
|
|
if (role.responsibility_type === "Code generation" || role.responsibility_type === "Orchestration") {
|
|
ra.conditional_patterns.push("pattern-8-session-files")
|
|
}
|
|
})
|
|
```
|
|
|
|
### Step 4b: Command-to-Phase Mapping
|
|
|
|
```javascript
|
|
// Map commands to phases and determine extraction criteria
|
|
roleAnalysis.forEach(ra => {
|
|
const role = config.worker_roles.find(r => r.name === ra.role_name)
|
|
|
|
ra.command_mapping = {
|
|
commands: role.commands || [],
|
|
phase_commands: role.phase_commands || {},
|
|
extraction_reasons: []
|
|
}
|
|
|
|
// Determine extraction reasons per command
|
|
for (const cmd of (role.commands || [])) {
|
|
const reasons = []
|
|
if ((role.subagents || []).length > 0) reasons.push("subagent-delegation")
|
|
if ((role.cli_tools || []).length > 0) reasons.push("cli-fan-out")
|
|
if (role.adaptive_routing) reasons.push("complexity-adaptive")
|
|
ra.command_mapping.extraction_reasons.push({ command: cmd, reasons })
|
|
}
|
|
|
|
// Pattern 9 selection
|
|
ra.uses_pattern_9 = (role.subagents || []).length > 0 || (role.cli_tools || []).length > 0
|
|
})
|
|
```
|
|
|
|
### Step 5: Collaboration Pattern Selection
|
|
|
|
```javascript
|
|
// Team-level collaboration patterns
|
|
function selectTeamPatterns(config) {
|
|
const patterns = ['CP-1'] // Linear Pipeline is always base
|
|
|
|
const hasValidation = config.worker_roles.some(r =>
|
|
r.responsibility_type === 'Validation' || r.responsibility_type === 'Read-only analysis'
|
|
)
|
|
if (hasValidation) patterns.push('CP-2') // Review-Fix Cycle
|
|
|
|
const hasOrchestration = config.worker_roles.some(r =>
|
|
r.responsibility_type === 'Orchestration'
|
|
)
|
|
if (hasOrchestration) patterns.push('CP-3') // Fan-out/Fan-in
|
|
|
|
if (config.worker_roles.length >= 4) patterns.push('CP-6') // Incremental Delivery
|
|
|
|
patterns.push('CP-5') // Escalation Chain (always available)
|
|
patterns.push('CP-10') // Post-Mortem (always at team level)
|
|
|
|
return [...new Set(patterns)]
|
|
}
|
|
|
|
const collaborationPatterns = selectTeamPatterns(config)
|
|
|
|
// Convergence defaults
|
|
const convergenceConfig = collaborationPatterns.map(cp => {
|
|
const defaults = {
|
|
'CP-1': { max_iterations: 1, success_gate: 'all_stages_completed' },
|
|
'CP-2': { max_iterations: 5, success_gate: 'verdict_approve_or_conditional' },
|
|
'CP-3': { max_iterations: 1, success_gate: 'quorum_100_percent' },
|
|
'CP-5': { max_iterations: null, success_gate: 'issue_resolved_at_any_level' },
|
|
'CP-6': { max_iterations: 3, success_gate: 'all_increments_validated' },
|
|
'CP-10': { max_iterations: 1, success_gate: 'report_generated' }
|
|
}
|
|
return { pattern: cp, convergence: defaults[cp] || {} }
|
|
})
|
|
```
|
|
|
|
### Step 6: Read Reference Commands
|
|
|
|
```javascript
|
|
// Read the most referenced commands for extraction
|
|
const referencedCommands = [...new Set(roleAnalysis.map(ra => ra.similar_to.primary))]
|
|
const referenceContent = {}
|
|
|
|
for (const cmdName of referencedCommands) {
|
|
try {
|
|
referenceContent[cmdName] = Read(`.claude/commands/team/${cmdName}.md`)
|
|
} catch {
|
|
referenceContent[cmdName] = null
|
|
}
|
|
}
|
|
```
|
|
|
|
### Step 7: Generate Analysis Document
|
|
|
|
```javascript
|
|
const analysis = {
|
|
team_name: config.team_name,
|
|
role_count: config.roles.length,
|
|
worker_count: config.worker_roles.length,
|
|
role_analysis: roleAnalysis,
|
|
collaboration_patterns: collaborationPatterns,
|
|
convergence_config: convergenceConfig,
|
|
referenced_commands: referencedCommands,
|
|
pipeline: config.pipeline,
|
|
// Skill-specific patterns
|
|
skill_patterns: {
|
|
role_router: "Parse --role from $ARGUMENTS → dispatch to roles/{role}.md",
|
|
shared_infrastructure: "Message bus + task lifecycle defined once in SKILL.md",
|
|
progressive_loading: "Only read roles/{role}.md when that role executes"
|
|
},
|
|
command_architecture: {
|
|
enabled: true,
|
|
role_commands: roleAnalysis.map(ra => ({
|
|
role: ra.role_name,
|
|
commands: ra.command_mapping?.commands || [],
|
|
phase_commands: ra.command_mapping?.phase_commands || {},
|
|
uses_pattern_9: ra.uses_pattern_9 || false
|
|
}))
|
|
}
|
|
}
|
|
|
|
Write(`${workDir}/pattern-analysis.json`, JSON.stringify(analysis, null, 2))
|
|
```
|
|
|
|
## Output
|
|
|
|
- **File**: `pattern-analysis.json`
|
|
- **Format**: JSON
|
|
- **Location**: `{workDir}/pattern-analysis.json`
|
|
|
|
## Quality Checklist
|
|
|
|
- [ ] Every worker role has similarity mapping
|
|
- [ ] Every worker role has 5-phase structure
|
|
- [ ] Infrastructure patterns include all mandatory patterns
|
|
- [ ] Collaboration patterns selected at team level
|
|
- [ ] Referenced commands are readable
|
|
- [ ] Skill-specific patterns documented
|
|
|
|
## Next Phase
|
|
|
|
-> [Phase 3: Skill Package Generation](03-skill-generation.md)
|