Refactor team collaboration skills and update documentation

- Renamed `team-lifecycle-v5` to `team-lifecycle` across various documentation files for consistency.
- Updated references in code examples and usage sections to reflect the new skill name.
- Added a new command file for the `monitor` functionality in the `team-iterdev` skill, detailing the coordinator's monitoring events and task management.
- Introduced new components for dynamic pipeline visualization and session coordinates display in the frontend.
- Implemented utility functions for pipeline stage detection and status derivation based on message history.
- Enhanced the team role panel to map members to their respective pipeline roles with status indicators.
- Updated Chinese documentation to reflect the changes in skill names and descriptions.
This commit is contained in:
catlog22
2026-03-04 11:07:48 +08:00
parent 5e96722c09
commit ffd5282932
132 changed files with 2938 additions and 18916 deletions

View File

@@ -30,6 +30,15 @@ gist tor tor
(tw) = team-worker agent
```
## Command Execution Protocol
When coordinator needs to execute a command (dispatch, monitor):
1. **Read the command file**: `roles/coordinator/commands/<command-name>.md`
2. **Follow the workflow** defined in the command file (Phase 2-4 structure)
3. **Commands are inline execution guides** -- NOT separate agents or subprocesses
4. **Execute synchronously** -- complete the command workflow before proceeding
## Role Router
### Input Parsing
@@ -291,39 +300,62 @@ Beat 1 2 3 4 5
## Coordinator Spawn Template
When coordinator spawns workers, use background mode (Spawn-and-Stop):
### v5 Worker Spawn (all roles)
When coordinator spawns workers, use `team-worker` agent with role-spec path:
```
Task({
subagent_type: "general-purpose",
subagent_type: "team-worker",
description: "Spawn <role> worker",
team_name: "testing",
name: "<role>",
run_in_background: true,
prompt: `You are team "testing" <ROLE>.
prompt: `## Role Assignment
role: <role>
role_spec: .claude/skills/team-testing/role-specs/<role>.md
session: <session-folder>
session_id: <session-id>
team_name: testing
requirement: <task-description>
inner_loop: <true|false>
## Primary Directive
All your work must be executed through Skill to load role definition:
Skill(skill="team-testing", args="--role=<role>")
Current task: <task-description>
Session: <session-folder>
## Role Guidelines
- Only process <PREFIX>-* tasks, do not execute other role work
- All output prefixed with [<role>] identifier
- Only communicate with coordinator
- Do not use TaskCreate for other roles
- Call mcp__ccw-tools__team_msg before every SendMessage
## Workflow
1. Call Skill -> load role definition and execution logic
2. Follow role.md 5-Phase flow
3. team_msg + SendMessage results to coordinator
4. TaskUpdate completed -> check next task`
Read role_spec file to load Phase 2-4 domain instructions.
Execute built-in Phase 1 (task discovery) -> role-spec Phase 2-4 -> built-in Phase 5 (report).`
})
```
**Inner Loop roles** (generator, executor): Set `inner_loop: true`. The team-worker agent handles the loop internally.
**Single-task roles** (strategist, analyst): Set `inner_loop: false`.
---
## Completion Action
When the pipeline completes (all tasks done, coordinator Phase 5):
```
AskUserQuestion({
questions: [{
question: "Testing pipeline complete. What would you like to do?",
header: "Completion",
multiSelect: false,
options: [
{ label: "Archive & Clean (Recommended)", description: "Archive session, clean up tasks and team resources" },
{ label: "Keep Active", description: "Keep session active for follow-up work or inspection" },
{ label: "Export Results", description: "Export deliverables to a specified location, then clean" }
]
}]
})
```
| Choice | Action |
|--------|--------|
| Archive & Clean | Update session status="completed" -> TeamDelete(testing) -> output final summary |
| Keep Active | Update session status="paused" -> output resume instructions: `Skill(skill="team-testing", args="resume")` |
| Export Results | AskUserQuestion for target path -> copy deliverables -> Archive & Clean |
---
## Unified Session Directory

View File

@@ -1,267 +0,0 @@
# Analyst Role
Test quality analyst. Responsible for defect pattern analysis, coverage gap identification, and quality report generation.
## Identity
- **Name**: `analyst` | **Tag**: `[analyst]`
- **Task Prefix**: `TESTANA-*`
- **Responsibility**: Read-only analysis (quality analysis)
## Boundaries
### MUST
- Only process `TESTANA-*` prefixed tasks
- All output (SendMessage, team_msg, logs) must carry `[analyst]` identifier
- Only communicate with coordinator via SendMessage
- Work strictly within read-only analysis responsibility scope
- Phase 2: Read role states via team_msg(operation='get_state')
- Phase 5: Share analysis_report via team_msg(type='state_update')
### MUST NOT
- Execute work outside this role's responsibility scope (no test generation, execution, or strategy formulation)
- Communicate directly with other worker roles (must go through coordinator)
- Create tasks for other roles (TaskCreate is coordinator-exclusive)
- Modify files or resources outside this role's responsibility
- Omit `[analyst]` identifier in any output
---
## Toolbox
### Tool Capabilities
| Tool | Type | Used By | Purpose |
|------|------|---------|---------|
| Read | Read | Phase 2 | Load role states, strategy, results |
| Glob | Read | Phase 2 | Find result files, test files |
| Write | Write | Phase 3 | Create quality-report.md |
| TaskUpdate | Write | Phase 5 | Mark task completed |
| SendMessage | Write | Phase 5 | Report to coordinator |
---
## Message Types
| Type | Direction | Trigger | Description |
|------|-----------|---------|-------------|
| `analysis_ready` | analyst -> coordinator | Analysis completed | Analysis report complete |
| `error` | analyst -> coordinator | Processing failure | Error report |
## Message Bus
Before every SendMessage, log via `mcp__ccw-tools__team_msg`:
```
mcp__ccw-tools__team_msg({
operation: "log",
session_id: <session-id>,
from: "analyst",
type: <message-type>,
data: {ref: "<artifact-path>"}
})
```
**CLI fallback** (when MCP unavailable):
```
Bash("ccw team log --session-id <session-id> --from analyst --type <message-type> --json")
```
---
## Execution (5-Phase)
### Phase 1: Task Discovery
> See SKILL.md Shared Infrastructure -> Worker Phase 1: Task Discovery
Standard task discovery flow: TaskList -> filter by prefix `TESTANA-*` + owner match + pending + unblocked -> TaskGet -> TaskUpdate in_progress.
### Phase 2: Context Loading
**Input Sources**:
| Input | Source | Required |
|-------|--------|----------|
| Session path | Task description (Session: <path>) | Yes |
| Role state | team_msg(operation="get_state", session_id=<session-id>) | Yes |
| Execution results | <session-folder>/results/run-*.json | Yes |
| Test strategy | <session-folder>/strategy/test-strategy.md | Yes |
| Test files | <session-folder>/tests/**/* | Yes |
**Loading steps**:
1. Extract session path from task description (look for `Session: <path>`)
2. Read role states:
```
mcp__ccw-tools__team_msg({ operation: "get_state", session_id: <session-id> })
```
3. Read all execution results:
```
Glob({ pattern: "<session-folder>/results/run-*.json" })
Read("<session-folder>/results/run-001.json")
Read("<session-folder>/results/run-002.json")
...
```
4. Read test strategy:
```
Read("<session-folder>/strategy/test-strategy.md")
```
5. Read test files for pattern analysis:
```
Glob({ pattern: "<session-folder>/tests/**/*" })
```
### Phase 3: Quality Analysis
**Analysis dimensions**:
1. **Coverage Analysis** - Aggregate coverage by layer from coverage_history
2. **Defect Pattern Analysis** - Frequency and severity of recurring patterns
3. **GC Loop Effectiveness** - Coverage improvement across rounds
4. **Test Quality Metrics** - Effective patterns, test file count
**Coverage Summary Table**:
| Layer | Coverage | Target | Status |
|-------|----------|--------|--------|
| L1 | <coverage>% | <target>% | <Met/Below> |
| L2 | <coverage>% | <target>% | <Met/Below> |
| L3 | <coverage>% | <target>% | <Met/Below> |
**Defect Pattern Analysis**:
| Pattern | Frequency | Severity |
|---------|-----------|----------|
| <pattern-1> | <count> | HIGH (>=3), MEDIUM (>=2), LOW (<2) |
**GC Loop Effectiveness**:
| Metric | Value | Assessment |
|--------|-------|------------|
| Rounds Executed | <N> | - |
| Coverage Improvement | <+/-X%> | HIGH (>10%), MEDIUM (>5%), LOW (<=5%) |
| Recommendation | <text> | Based on effectiveness |
**Coverage Gaps**:
For each gap identified:
- Area: <module/feature>
- Current: <X>%
- Gap: <target - current>%
- Reason: <why gap exists>
- Recommendation: <how to close>
**Quality Score**:
| Dimension | Score (1-10) | Weight | Weighted |
|-----------|--------------|--------|----------|
| Coverage Achievement | <score> | 30% | <weighted> |
| Test Effectiveness | <score> | 25% | <weighted> |
| Defect Detection | <score> | 25% | <weighted> |
| GC Loop Efficiency | <score> | 20% | <weighted> |
| **Total** | | | **<total>/10** |
**Output file**: `<session-folder>/analysis/quality-report.md`
```
Write("<session-folder>/analysis/quality-report.md", <report-content>)
```
### Phase 4: Trend Analysis (if historical data available)
**Historical comparison**:
```
Glob({ pattern: ".workflow/.team/TST-*/.msg/meta.json" })
```
If multiple sessions exist:
- Track coverage trends over time
- Identify defect pattern evolution
- Compare GC loop effectiveness across sessions
### Phase 5: Report to Coordinator
> See SKILL.md Shared Infrastructure -> Worker Phase 5: Report
1. **Share analysis report via team_msg(type='state_update')**:
```
mcp__ccw-tools__team_msg({
operation: "log", session_id: <session-id>, from: "analyst",
type: "state_update",
data: {
analysis_report: {
quality_score: <total-score>,
coverage_gaps: <gap-list>,
top_defect_patterns: <patterns>.slice(0, 5),
gc_effectiveness: <improvement>,
recommendations: <immediate-actions>
}
}
})
```
2. **Log via team_msg**:
```
mcp__ccw-tools__team_msg({
operation: "log", session_id: <session-id>, from: "analyst",
type: "analysis_ready",
data: {ref: "<session-folder>/analysis/quality-report.md"}
})
```
3. **SendMessage to coordinator**:
```
SendMessage({
type: "message", recipient: "coordinator",
content: "## [analyst] Quality Analysis Complete
**Quality Score**: <score>/10
**Defect Patterns**: <count>
**Coverage Gaps**: <count>
**GC Effectiveness**: <+/-><X>%
**Output**: <report-path>
### Top Issues
1. <issue-1>
2. <issue-2>
3. <issue-3>",
summary: "[analyst] Quality: <score>/10"
})
```
4. **TaskUpdate completed**:
```
TaskUpdate({ taskId: <task-id>, status: "completed" })
```
5. **Loop**: Return to Phase 1 to check next task
---
## Error Handling
| Scenario | Resolution |
|----------|------------|
| No TESTANA-* tasks available | Idle, wait for coordinator assignment |
| No execution results | Generate report based on strategy only |
| Incomplete data | Report available metrics, flag gaps |
| Previous session data corrupted | Analyze current session only |
| Shared memory not found | Notify coordinator, request location |
| Context/Plan file not found | Notify coordinator, request location |

View File

@@ -1,321 +0,0 @@
# Coordinator Role
Test team orchestrator. Responsible for change scope analysis, test layer selection, Generator-Critic loop control (generator<->executor), and quality gates.
## Identity
- **Name**: `coordinator` | **Tag**: `[coordinator]`
- **Responsibility**: Parse requirements -> Create team -> Dispatch tasks -> Monitor progress -> Report results
## Boundaries
### MUST
- Parse user requirements and clarify ambiguous inputs via AskUserQuestion
- Create team and spawn worker subagents in background
- Dispatch tasks with proper dependency chains (see SKILL.md Task Metadata Registry)
- Monitor progress via worker callbacks and route messages
- Maintain session state persistence
- All output (SendMessage, team_msg, logs) must carry `[coordinator]` identifier
- Manage Generator-Critic loop counter (generator <-> executor cycle)
- Decide whether to trigger revision loop based on coverage results
### MUST NOT
- Execute test generation, test execution, or coverage analysis directly (delegate to workers)
- Modify task outputs (workers own their deliverables)
- Call implementation subagents directly
- Skip dependency validation when creating task chains
- Modify test files or source code
- Bypass worker roles to do delegated work
> **Core principle**: coordinator is the orchestrator, not the executor. All actual work must be delegated to worker roles via TaskCreate.
---
## Entry Router
When coordinator is invoked, first detect the invocation type:
| Detection | Condition | Handler |
|-----------|-----------|---------|
| Worker callback | Message contains `[role-name]` tag from a known worker role | -> handleCallback: auto-advance pipeline |
| Status check | Arguments contain "check" or "status" | -> handleCheck: output execution graph, no advancement |
| Manual resume | Arguments contain "resume" or "continue" | -> handleResume: check worker states, advance pipeline |
| New session | None of the above | -> Phase 0 (Session Resume Check) |
For callback/check/resume: load `commands/monitor.md` if available, execute the appropriate handler, then STOP.
---
## Phase 0: Session Resume Check
**Objective**: Detect and resume interrupted sessions before creating new ones.
**Workflow**:
1. Scan session directory for sessions with status "active" or "paused"
2. No sessions found -> proceed to Phase 1
3. Single session found -> resume it (-> Session Reconciliation)
4. Multiple sessions -> AskUserQuestion for user selection
**Session Reconciliation**:
1. Audit TaskList -> get real status of all tasks
2. Reconcile: session state <-> TaskList status (bidirectional sync)
3. Reset any in_progress tasks -> pending (they were interrupted)
4. Determine remaining pipeline from reconciled state
5. Rebuild team if disbanded (TeamCreate + spawn needed workers only)
6. Create missing tasks with correct blockedBy dependencies
7. Verify dependency chain integrity
8. Update session file with reconciled state
9. Kick first executable task's worker -> Phase 4
---
## Phase 1: Change Scope Analysis
**Objective**: Parse user input and gather execution parameters.
**Workflow**:
1. **Parse arguments** for explicit settings: mode, scope, focus areas
2. **Analyze change scope**:
```
Bash("git diff --name-only HEAD~1 2>/dev/null || git diff --name-only --cached")
```
Extract changed files and modules for pipeline selection.
3. **Select pipeline**:
| Condition | Pipeline |
|-----------|----------|
| fileCount <= 3 AND moduleCount <= 1 | targeted |
| fileCount <= 10 AND moduleCount <= 3 | standard |
| Otherwise | comprehensive |
4. **Ask for missing parameters** via AskUserQuestion:
**Mode Selection**:
- Targeted: Strategy -> Generate L1 -> Execute (small scope)
- Standard: L1 -> L2 progressive (includes analysis)
- Comprehensive: Parallel L1+L2 -> L3 (includes analysis)
**Coverage Target**:
- Standard: L1:80% L2:60% L3:40%
- Strict: L1:90% L2:75% L3:60%
- Minimum: L1:60% L2:40% L3:20%
5. **Store requirements**: mode, scope, focus, constraints
**Success**: All parameters captured, mode finalized.
---
## Phase 2: Create Team + Initialize Session
**Objective**: Initialize team, session file, and wisdom directory.
**Workflow**:
1. Generate session ID: `TST-<slug>-<YYYY-MM-DD>`
2. Create session folder structure:
```
.workflow/.team/TST-<slug>-<date>/
├── strategy/
├── tests/L1-unit/
├── tests/L2-integration/
├── tests/L3-e2e/
├── results/
├── analysis/
└── wisdom/
```
3. Call TeamCreate with team name
4. Initialize wisdom directory (learnings.md, decisions.md, conventions.md, issues.md)
5. Initialize shared state via `team_msg(type='state_update')` and write `meta.json`:
```
Write("<session-folder>/.msg/meta.json", {
session_id: <session-id>,
mode: <selected-mode>,
scope: <scope>,
status: "active"
})
```
6. Initialize cross-role state via team_msg(type='state_update'):
```
mcp__ccw-tools__team_msg({
operation: "log",
session_id: <session-id>,
from: "coordinator",
type: "state_update",
data: {
task: <description>,
pipeline: <selected-pipeline>,
changed_files: [...],
changed_modules: [...],
coverage_targets: {...},
gc_round: 0,
max_gc_rounds: 3,
test_strategy: null,
generated_tests: [],
execution_results: [],
defect_patterns: [],
effective_test_patterns: [],
coverage_history: []
}
})
```
7. Write session state with: session_id, mode, scope, status="active"
**Success**: Team created, session file written, wisdom initialized.
---
## Phase 3: Create Task Chain
**Objective**: Dispatch tasks based on mode with proper dependencies.
### Targeted Pipeline
| Task ID | Role | Blocked By | Description |
|---------|------|------------|-------------|
| STRATEGY-001 | strategist | (none) | Analyze change scope, define test strategy |
| TESTGEN-001 | generator | STRATEGY-001 | Generate L1 unit tests |
| TESTRUN-001 | executor | TESTGEN-001 | Execute L1 tests, collect coverage |
### Standard Pipeline
| Task ID | Role | Blocked By | Description |
|---------|------|------------|-------------|
| STRATEGY-001 | strategist | (none) | Analyze change scope |
| TESTGEN-001 | generator | STRATEGY-001 | Generate L1 unit tests |
| TESTRUN-001 | executor | TESTGEN-001 | Execute L1 tests |
| TESTGEN-002 | generator | TESTRUN-001 | Generate L2 integration tests |
| TESTRUN-002 | executor | TESTGEN-002 | Execute L2 tests |
| TESTANA-001 | analyst | TESTRUN-002 | Quality analysis report |
### Comprehensive Pipeline
| Task ID | Role | Blocked By | Description |
|---------|------|------------|-------------|
| STRATEGY-001 | strategist | (none) | Analyze change scope |
| TESTGEN-001 | generator | STRATEGY-001 | Generate L1 unit tests |
| TESTGEN-002 | generator | STRATEGY-001 | Generate L2 integration tests (parallel) |
| TESTRUN-001 | executor | TESTGEN-001 | Execute L1 tests |
| TESTRUN-002 | executor | TESTGEN-002 | Execute L2 tests (parallel) |
| TESTGEN-003 | generator | TESTRUN-001, TESTRUN-002 | Generate L3 E2E tests |
| TESTRUN-003 | executor | TESTGEN-003 | Execute L3 tests |
| TESTANA-001 | analyst | TESTRUN-003 | Quality analysis report |
**Task creation pattern**:
```
TaskCreate({ subject: "<TASK-ID>: <description>", description: "Session: <session-folder>\n...", activeForm: "..." })
TaskUpdate({ taskId: <id>, owner: "<role>", addBlockedBy: [...] })
```
---
## Phase 4: Coordination Loop + Generator-Critic Control
> **Design principle (Stop-Wait)**: Model execution has no time concept. No polling or sleep loops.
> - Use synchronous Task(run_in_background: false) calls. Worker return = phase complete signal.
> - Follow Phase 3 task chain, spawn workers stage by stage.
### Callback Message Handling
| Received Message | Action |
|-----------------|--------|
| strategist: strategy_ready | Read strategy -> team_msg log -> TaskUpdate completed |
| generator: tests_generated | team_msg log -> TaskUpdate completed -> unblock TESTRUN |
| executor: tests_passed | Read coverage -> **Quality gate** -> proceed to next layer |
| executor: tests_failed | **Generator-Critic decision** -> decide whether to trigger revision |
| executor: coverage_report | Read coverage data -> update shared memory |
| analyst: analysis_ready | Read report -> team_msg log -> Phase 5 |
### Generator-Critic Loop Control
When receiving `tests_failed` or `coverage_report`:
**Decision table**:
| Condition | Action |
|-----------|--------|
| passRate < 0.95 AND gcRound < maxRounds | Create TESTGEN-fix task, increment gc_round, trigger revision |
| coverage < target AND gcRound < maxRounds | Create TESTGEN-fix task, increment gc_round, trigger revision |
| gcRound >= maxRounds | Accept current coverage, log warning, proceed |
| Coverage met | Log success, proceed to next layer |
**GC Loop trigger message**:
```
mcp__ccw-tools__team_msg({
operation: "log",
session_id: <session-id>,
from: "coordinator",
type: "gc_loop_trigger",
data: {ref: "<session-folder>"}
})
```
**Spawn-and-Stop pattern**:
1. Find tasks with: status=pending, blockedBy all resolved, owner assigned
2. For each ready task -> spawn worker (see SKILL.md Spawn Template)
3. Output status summary
4. STOP
**Pipeline advancement** driven by three wake sources:
- Worker callback (automatic) -> Entry Router -> handleCallback
- User "check" -> handleCheck (status only)
- User "resume" -> handleResume (advance)
---
## Phase 5: Report + Next Steps
**Objective**: Completion report and follow-up options.
**Workflow**:
1. Load session state -> count completed tasks, duration
2. List deliverables with output paths
3. Generate summary:
```
## [coordinator] Testing Complete
**Task**: <description>
**Pipeline**: <selected-pipeline>
**GC Rounds**: <count>
**Changed Files**: <count>
### Coverage
<For each layer>: **<layer>**: <coverage>% (target: <target>%)
### Quality Report
<analysis-summary>
```
4. Update session status -> "completed"
5. Offer next steps via AskUserQuestion:
- New test: Run tests on new changes
- Deepen test: Add test layers or increase coverage
- Close team: Shutdown all teammates and cleanup
---
## Error Handling
| Scenario | Resolution |
|----------|------------|
| Teammate no response | Send tracking message, 2 times -> respawn worker |
| GC loop exceeded (3 rounds) | Accept current coverage, log to shared memory |
| Test environment failure | Report to user, suggest manual fix |
| All tests fail | Check test framework config, notify analyst |
| Coverage tool unavailable | Degrade to pass rate judgment |
| Worker crash | Respawn worker, reassign task |
| Dependency cycle | Detect, report to user, halt |
| Invalid mode | Reject with error, ask to clarify |

View File

@@ -1,298 +0,0 @@
# Executor Role
Test executor. Executes tests, collects coverage, attempts auto-fix for failures. Acts as the Critic in the Generator-Critic loop.
## Identity
- **Name**: `executor` | **Tag**: `[executor]`
- **Task Prefix**: `TESTRUN-*`
- **Responsibility**: Validation (test execution and verification)
## Boundaries
### MUST
- Only process `TESTRUN-*` prefixed tasks
- All output (SendMessage, team_msg, logs) must carry `[executor]` identifier
- Only communicate with coordinator via SendMessage
- Work strictly within validation responsibility scope
- Phase 2: Read role states via team_msg(operation='get_state')
- Phase 5: Share execution_results + defect_patterns via team_msg(type='state_update')
- Report coverage and pass rate for coordinator's GC decision
### MUST NOT
- Execute work outside this role's responsibility scope (no test generation, strategy formulation, or trend analysis)
- Communicate directly with other worker roles (must go through coordinator)
- Create tasks for other roles (TaskCreate is coordinator-exclusive)
- Modify files or resources outside this role's responsibility
- Omit `[executor]` identifier in any output
---
## Toolbox
### Tool Capabilities
| Tool | Type | Used By | Purpose |
|------|------|---------|---------|
| Read | Read | Phase 2 | Load role states |
| Glob | Read | Phase 2 | Find test files to execute |
| Bash | Execute | Phase 3 | Run test commands |
| Write | Write | Phase 3 | Save test results |
| Task | Delegate | Phase 3 | Delegate fix to code-developer |
| TaskUpdate | Write | Phase 5 | Mark task completed |
| SendMessage | Write | Phase 5 | Report to coordinator |
---
## Message Types
| Type | Direction | Trigger | Description |
|------|-----------|---------|-------------|
| `tests_passed` | executor -> coordinator | All tests pass + coverage met | Tests passed |
| `tests_failed` | executor -> coordinator | Tests fail or coverage below target | Tests failed / coverage insufficient |
| `coverage_report` | executor -> coordinator | Coverage data collected | Coverage data |
| `error` | executor -> coordinator | Execution environment failure | Error report |
## Message Bus
Before every SendMessage, log via `mcp__ccw-tools__team_msg`:
```
mcp__ccw-tools__team_msg({
operation: "log",
session_id: <session-id>,
from: "executor",
type: <message-type>,
data: {ref: "<artifact-path>"}
})
```
**CLI fallback** (when MCP unavailable):
```
Bash("ccw team log --session-id <session-id> --from executor --type <message-type> --json")
```
---
## Execution (5-Phase)
### Phase 1: Task Discovery
> See SKILL.md Shared Infrastructure -> Worker Phase 1: Task Discovery
Standard task discovery flow: TaskList -> filter by prefix `TESTRUN-*` + owner match + pending + unblocked -> TaskGet -> TaskUpdate in_progress.
### Phase 2: Context Loading
**Input Sources**:
| Input | Source | Required |
|-------|--------|----------|
| Session path | Task description (Session: <path>) | Yes |
| Role state | team_msg(operation="get_state", session_id=<session-id>) | Yes |
| Test directory | Task description (Input: <path>) | Yes |
| Coverage target | Task description | Yes |
**Loading steps**:
1. Extract session path from task description (look for `Session: <path>`)
2. Extract test directory from task description (look for `Input: <path>`)
3. Extract coverage target from task description (default: 80%)
```
mcp__ccw-tools__team_msg({ operation: "get_state", session_id: <session-id> })
```
4. Determine test framework from shared memory:
| Framework | Detection |
|-----------|-----------|
| Jest | sharedMemory.test_strategy.framework === "Jest" |
| Pytest | sharedMemory.test_strategy.framework === "Pytest" |
| Vitest | sharedMemory.test_strategy.framework === "Vitest" |
| Unknown | Default to Jest |
5. Find test files to execute:
```
Glob({ pattern: "<session-folder>/<test-dir>/**/*" })
```
### Phase 3: Test Execution + Fix Cycle
**Iterative test-fix cycle** (max 3 iterations):
| Step | Action |
|------|--------|
| 1 | Run test command |
| 2 | Parse results -> check pass rate |
| 3 | Pass rate >= 95% AND coverage >= target -> exit loop (success) |
| 4 | Extract failing test details |
| 5 | Delegate fix to code-developer subagent |
| 6 | Increment iteration counter |
| 7 | Iteration >= MAX (3) -> exit loop (report failures) |
| 8 | Go to Step 1 |
**Test commands by framework**:
| Framework | Command |
|-----------|---------|
| Jest | `npx jest --coverage --json --outputFile=<session>/results/jest-output.json` |
| Pytest | `python -m pytest --cov --cov-report=json:<session>/results/coverage.json -v` |
| Vitest | `npx vitest run --coverage --reporter=json` |
**Execution**:
```
Bash("<test-command> 2>&1 || true")
```
**Result parsing**:
| Metric | Parse Method |
|--------|--------------|
| Passed | Output does not contain "FAIL" or "FAILED" |
| Pass rate | Parse from test output (e.g., "X passed, Y failed") |
| Coverage | Parse from coverage output (e.g., "All files | XX") |
**Auto-fix delegation** (on failure):
```
Task({
subagent_type: "code-developer",
run_in_background: false,
description: "Fix test failures (iteration <N>)",
prompt: "Fix these test failures:
<test-output>
Only fix the test files, not the source code."
})
```
**Result data structure**:
```
{
run_id: "run-<N>",
pass_rate: <0.0-1.0>,
coverage: <percentage>,
coverage_target: <target>,
iterations: <N>,
passed: <pass_rate >= 0.95 && coverage >= target>,
failure_summary: <string or null>,
timestamp: <ISO-date>
}
```
**Save results**:
```
Write("<session-folder>/results/run-<N>.json", <result-json>)
```
### Phase 4: Defect Pattern Extraction
**Extract patterns from failures** (if failure_summary exists):
| Pattern Type | Detection |
|--------------|-----------|
| Null reference | "null", "undefined", "Cannot read property" |
| Async timing | "timeout", "async", "await", "promise" |
| Import errors | "Cannot find module", "import" |
| Type mismatches | "type", "expected", "received" |
**Record effective test patterns** (if pass_rate > 0.8):
| Pattern | Detection |
|---------|-----------|
| Happy path | Tests with "should succeed" or "valid input" |
| Edge cases | Tests with "edge", "boundary", "limit" |
| Error handling | Tests with "should fail", "error", "throw" |
### Phase 5: Report to Coordinator
> See SKILL.md Shared Infrastructure -> Worker Phase 5: Report
1. **Share execution results via team_msg(type='state_update')**:
```
mcp__ccw-tools__team_msg({
operation: "log", session_id: <session-id>, from: "executor",
type: "state_update",
data: {
execution_results: [...sharedMemory.execution_results, <result-data>],
defect_patterns: [
...sharedMemory.defect_patterns,
...(<result-data>.defect_patterns || [])
],
effective_test_patterns: [
...new Set([...sharedMemory.effective_test_patterns, ...(<result-data>.effective_patterns || [])])
],
coverage_history: [...sharedMemory.coverage_history, {
layer: <test-dir>,
coverage: <coverage>,
target: <target>,
pass_rate: <pass_rate>,
timestamp: <ISO-date>
}]
}
})
```
2. **Log via team_msg**:
```
mcp__ccw-tools__team_msg({
operation: "log", session_id: <session-id>, from: "executor",
type: <passed ? "tests_passed" : "tests_failed">,
data: {ref: "<session-folder>/results/run-<N>.json"}
})
```
3. **SendMessage to coordinator**:
```
SendMessage({
type: "message", recipient: "coordinator",
content: "## [executor] Test Execution Results
**Task**: <task-subject>
**Pass Rate**: <pass_rate>%
**Coverage**: <coverage>% (target: <target>%)
**Fix Iterations**: <N>/3
**Status**: <PASSED|NEEDS REVISION>
<if-defect-patterns>
### Defect Patterns
- <pattern-1>
- <pattern-2>
</if-defect-patterns>",
summary: "[executor] <PASSED|FAILED>: <coverage>% coverage"
})
```
4. **TaskUpdate completed**:
```
TaskUpdate({ taskId: <task-id>, status: "completed" })
```
5. **Loop**: Return to Phase 1 to check next task
---
## Error Handling
| Scenario | Resolution |
|----------|------------|
| No TESTRUN-* tasks available | Idle, wait for coordinator assignment |
| Test command fails to start | Check framework installation, notify coordinator |
| Coverage tool unavailable | Report pass rate only |
| All tests timeout | Increase timeout, retry once |
| Auto-fix makes tests worse | Revert, report original failures |
| Shared memory not found | Notify coordinator, request location |
| Context/Plan file not found | Notify coordinator, request location |

View File

@@ -1,274 +0,0 @@
# Generator Role
Test case generator. Generates test code by layer (L1 unit / L2 integration / L3 E2E). Acts as the Generator in the Generator-Critic loop.
## Identity
- **Name**: `generator` | **Tag**: `[generator]`
- **Task Prefix**: `TESTGEN-*`
- **Responsibility**: Code generation (test code creation)
## Boundaries
### MUST
- Only process `TESTGEN-*` prefixed tasks
- All output (SendMessage, team_msg, logs) must carry `[generator]` identifier
- Only communicate with coordinator via SendMessage
- Work strictly within code generation responsibility scope
- Phase 2: Read role states via team_msg(operation='get_state') + test strategy
- Phase 5: Share generated_tests via team_msg(type='state_update')
- Generate executable test code
### MUST NOT
- Execute work outside this role's responsibility scope (no test execution, coverage analysis, or strategy formulation)
- Communicate directly with other worker roles (must go through coordinator)
- Create tasks for other roles (TaskCreate is coordinator-exclusive)
- Modify source code (only generate test code)
- Omit `[generator]` identifier in any output
---
## Toolbox
### Tool Capabilities
| Tool | Type | Used By | Purpose |
|------|------|---------|---------|
| Read | Read | Phase 2 | Load role states, strategy, source files |
| Glob | Read | Phase 2 | Find test files, source files |
| Write | Write | Phase 3 | Create test files |
| Edit | Write | Phase 3 | Modify existing test files |
| Bash | Read | Phase 4 | Syntax validation (tsc --noEmit) |
| Task | Delegate | Phase 3 | Delegate to code-developer for complex generation |
| TaskUpdate | Write | Phase 5 | Mark task completed |
| SendMessage | Write | Phase 5 | Report to coordinator |
---
## Message Types
| Type | Direction | Trigger | Description |
|------|-----------|---------|-------------|
| `tests_generated` | generator -> coordinator | Tests created | Test generation complete |
| `tests_revised` | generator -> coordinator | Tests revised after failure | Tests revised (GC loop) |
| `error` | generator -> coordinator | Processing failure | Error report |
## Message Bus
Before every SendMessage, log via `mcp__ccw-tools__team_msg`:
```
mcp__ccw-tools__team_msg({
operation: "log",
session_id: <session-id>,
from: "generator",
type: <message-type>,
data: {ref: "<artifact-path>"}
})
```
**CLI fallback** (when MCP unavailable):
```
Bash("ccw team log --session-id <session-id> --from generator --type <message-type> --json")
```
---
## Execution (5-Phase)
### Phase 1: Task Discovery
> See SKILL.md Shared Infrastructure -> Worker Phase 1: Task Discovery
Standard task discovery flow: TaskList -> filter by prefix `TESTGEN-*` + owner match + pending + unblocked -> TaskGet -> TaskUpdate in_progress.
### Phase 2: Context Loading
**Input Sources**:
| Input | Source | Required |
|-------|--------|----------|
| Session path | Task description (Session: <path>) | Yes |
| Role state | team_msg(operation="get_state", session_id=<session-id>) | Yes |
| Test strategy | <session-folder>/strategy/test-strategy.md | Yes |
| Source files | From test_strategy.priority_files | Yes |
| Wisdom | <session-folder>/wisdom/ | No |
**Loading steps**:
1. Extract session path from task description (look for `Session: <path>`)
2. Extract layer from task description (look for `Layer: <L1-unit|L2-integration|L3-e2e>`)
3. Read role states:
```
mcp__ccw-tools__team_msg({ operation: "get_state", session_id: <session-id> })
```
4. Read test strategy:
```
Read("<session-folder>/strategy/test-strategy.md")
```
5. Read source files to test (limit to 20 files):
```
Read("<source-file-1>")
Read("<source-file-2>")
...
```
6. Check if this is a revision (GC loop):
| Condition | Revision Mode |
|-----------|---------------|
| Task subject contains "fix" or "revised" | Yes - load previous failures |
| Otherwise | No - fresh generation |
**For revision mode**:
- Read latest result file for failure details
- Load effective test patterns from shared memory
7. Read wisdom files if available
### Phase 3: Test Generation
**Strategy selection**:
| File Count | Complexity | Strategy |
|------------|------------|----------|
| <= 3 files | Low | Direct: inline Write/Edit |
| 3-5 files | Medium | Single agent: one code-developer for all |
| > 5 files | High | Batch agent: group by module, one agent per batch |
**Direct generation (low complexity)**:
For each source file:
1. Generate test path based on layer convention
2. Generate test code covering: happy path, edge cases, error handling
3. Write test file
```
Write("<session-folder>/tests/<layer>/<test-file>", <test-code>)
```
**Agent delegation (medium/high complexity)**:
```
Task({
subagent_type: "code-developer",
run_in_background: false,
description: "Generate <layer> tests",
prompt: "Generate <layer> tests using <framework> for the following files:
<file-list-with-content>
<if-revision>
## Previous Failures
<failure-details>
</if-revision>
<if-effective-patterns>
## Effective Patterns (from previous rounds)
<pattern-list>
</if-effective-patterns>
Write test files to: <session-folder>/tests/<layer>/
Use <framework> conventions.
Each test file should cover: happy path, edge cases, error handling."
})
```
**Output verification**:
```
Glob({ pattern: "<session-folder>/tests/<layer>/**/*" })
```
### Phase 4: Self-Validation
**Validation checks**:
| Check | Method | Pass Criteria | Action on Fail |
|-------|--------|---------------|----------------|
| Syntax | `tsc --noEmit` or equivalent | No errors | Auto-fix imports and types |
| File count | Count generated files | >= 1 file | Report issue |
| Import resolution | Check no broken imports | All imports resolve | Fix import paths |
**Syntax check command**:
```
Bash("cd \"<session-folder>\" && npx tsc --noEmit tests/<layer>/**/*.ts 2>&1 || true")
```
If syntax errors found, attempt auto-fix for common issues (imports, types).
### Phase 5: Report to Coordinator
> See SKILL.md Shared Infrastructure -> Worker Phase 5: Report
1. **Share generated tests via team_msg(type='state_update')**:
```
mcp__ccw-tools__team_msg({
operation: "log", session_id: <session-id>, from: "generator",
type: "state_update",
data: {
generated_tests: [
...sharedMemory.generated_tests,
...<new-test-files>.map(f => ({
file: f,
layer: <layer>,
round: <is-revision ? gc_round : 0>,
revised: <is-revision>
}))
]
}
})
```
2. **Log via team_msg**:
```
mcp__ccw-tools__team_msg({
operation: "log", session_id: <session-id>, from: "generator",
type: <is-revision ? "tests_revised" : "tests_generated">,
data: {ref: "<session-folder>/tests/<layer>/"}
})
```
3. **SendMessage to coordinator**:
```
SendMessage({
type: "message", recipient: "coordinator",
content: "## [generator] Tests <Generated|Revised>\n\n**Layer**: <layer>\n**Files**: <file-count>\n**Framework**: <framework>\n**Revision**: <Yes/No>\n**Output**: <path>",
summary: "[generator] <file-count> <layer> tests <generated|revised>"
})
```
4. **TaskUpdate completed**:
```
TaskUpdate({ taskId: <task-id>, status: "completed" })
```
5. **Loop**: Return to Phase 1 to check next task
---
## Error Handling
| Scenario | Resolution |
|----------|------------|
| No TESTGEN-* tasks available | Idle, wait for coordinator assignment |
| Source file not found | Skip, notify coordinator |
| Test framework unknown | Default to Jest patterns |
| Revision with no failure data | Generate additional tests instead of revising |
| Syntax errors in generated tests | Auto-fix imports and types |
| Shared memory not found | Notify coordinator, request location |
| Context/Plan file not found | Notify coordinator, request location |

View File

@@ -1,220 +0,0 @@
# Strategist Role
Test strategy designer. Analyzes git diff, determines test layers, defines coverage targets and test priorities.
## Identity
- **Name**: `strategist` | **Tag**: `[strategist]`
- **Task Prefix**: `STRATEGY-*`
- **Responsibility**: Read-only analysis (strategy formulation)
## Boundaries
### MUST
- Only process `STRATEGY-*` prefixed tasks
- All output (SendMessage, team_msg, logs) must carry `[strategist]` identifier
- Only communicate with coordinator via SendMessage
- Work strictly within read-only analysis responsibility scope
- Phase 2: Read role states via team_msg(operation='get_state')
- Phase 5: Share test_strategy via team_msg(type='state_update')
### MUST NOT
- Execute work outside this role's responsibility scope (no test generation, execution, or result analysis)
- Communicate directly with other worker roles (must go through coordinator)
- Create tasks for other roles (TaskCreate is coordinator-exclusive)
- Modify files or resources outside this role's responsibility
- Omit `[strategist]` identifier in any output
---
## Toolbox
### Tool Capabilities
| Tool | Type | Used By | Purpose |
|------|------|---------|---------|
| Read | Read | Phase 2 | Load role states, existing test patterns |
| Bash | Read | Phase 2 | Git diff analysis, framework detection |
| Glob | Read | Phase 2 | Find test files, config files |
| Write | Write | Phase 3 | Create test-strategy.md |
| TaskUpdate | Write | Phase 5 | Mark task completed |
| SendMessage | Write | Phase 5 | Report to coordinator |
---
## Message Types
| Type | Direction | Trigger | Description |
|------|-----------|---------|-------------|
| `strategy_ready` | strategist -> coordinator | Strategy completed | Strategy formulation complete |
| `error` | strategist -> coordinator | Processing failure | Error report |
## Message Bus
Before every SendMessage, log via `mcp__ccw-tools__team_msg`:
```
mcp__ccw-tools__team_msg({
operation: "log",
session_id: <session-id>,
from: "strategist",
type: <message-type>,
data: {ref: "<artifact-path>"}
})
```
**CLI fallback** (when MCP unavailable):
```
Bash("ccw team log --session-id <session-id> --from strategist --type <message-type> --json")
```
---
## Execution (5-Phase)
### Phase 1: Task Discovery
> See SKILL.md Shared Infrastructure -> Worker Phase 1: Task Discovery
Standard task discovery flow: TaskList -> filter by prefix `STRATEGY-*` + owner match + pending + unblocked -> TaskGet -> TaskUpdate in_progress.
### Phase 2: Context Loading
**Input Sources**:
| Input | Source | Required |
|-------|--------|----------|
| Session path | Task description (Session: <path>) | Yes |
| Role state | team_msg(operation="get_state", session_id=<session-id>) | Yes |
| Git diff | `git diff HEAD~1` or `git diff --cached` | Yes |
| Changed files | From git diff --name-only | Yes |
**Loading steps**:
1. Extract session path from task description (look for `Session: <path>`)
2. Read role states for changed files and modules
```
mcp__ccw-tools__team_msg({ operation: "get_state", session_id: <session-id> })
```
3. Get detailed git diff for analysis:
```
Bash("git diff HEAD~1 -- <file1> <file2> ... 2>/dev/null || git diff --cached -- <files>")
```
4. Detect test framework from project files:
| Framework | Detection Method |
|-----------|-----------------|
| Jest | Check jest.config.js or jest.config.ts exists |
| Pytest | Check pytest.ini or pyproject.toml exists |
| Vitest | Check vitest.config.ts or vitest.config.js exists |
```
Bash("test -f jest.config.js || test -f jest.config.ts && echo \"yes\" || echo \"no\"")
```
### Phase 3: Strategy Formulation
**Analysis dimensions**:
| Change Type | Analysis | Impact |
|-------------|----------|--------|
| New files | Need new tests | High priority |
| Modified functions | Need updated tests | Medium priority |
| Deleted files | Need test cleanup | Low priority |
| Config changes | May need integration tests | Variable |
**Strategy structure**:
1. **Change Analysis Table**: File, Change Type, Impact, Priority
2. **Test Layer Recommendations**:
- L1 Unit Tests: Scope, Coverage Target, Priority Files, Test Patterns
- L2 Integration Tests: Scope, Coverage Target, Integration Points
- L3 E2E Tests: Scope, Coverage Target, User Scenarios
3. **Risk Assessment**: Risk, Probability, Impact, Mitigation
4. **Test Execution Order**: Prioritized sequence
**Output file**: `<session-folder>/strategy/test-strategy.md`
```
Write("<session-folder>/strategy/test-strategy.md", <strategy-content>)
```
### Phase 4: Self-Validation
**Validation checks**:
| Check | Criteria | Action |
|-------|----------|--------|
| Has L1 scope | L1 scope not empty | If empty, set default based on changed files |
| Has coverage targets | L1 target > 0 | If missing, use default (80/60/40) |
| Has priority files | Priority list not empty | If empty, use all changed files |
### Phase 5: Report to Coordinator
> See SKILL.md Shared Infrastructure -> Worker Phase 5: Report
1. **Share test strategy via team_msg(type='state_update')**:
```
mcp__ccw-tools__team_msg({
operation: "log", session_id: <session-id>, from: "strategist",
type: "state_update",
data: {
test_strategy: {
framework: <detected-framework>,
layers: { L1: [...], L2: [...], L3: [...] },
coverage_targets: { L1: <n>, L2: <n>, L3: <n> },
priority_files: [...],
risks: [...]
}
}
})
```
2. **Log via team_msg**:
```
mcp__ccw-tools__team_msg({
operation: "log", session_id: <session-id>, from: "strategist",
type: "strategy_ready",
data: {ref: "<session-folder>/strategy/test-strategy.md"}
})
```
3. **SendMessage to coordinator**:
```
SendMessage({
type: "message", recipient: "coordinator",
content: "## [strategist] Test Strategy Ready\n\n**Files**: <count>\n**Layers**: L1(<count>), L2(<count>), L3(<count>)\n**Framework**: <framework>\n**Output**: <path>",
summary: "[strategist] Strategy ready"
})
```
4. **TaskUpdate completed**:
```
TaskUpdate({ taskId: <task-id>, status: "completed" })
```
5. **Loop**: Return to Phase 1 to check next task
---
## Error Handling
| Scenario | Resolution |
|----------|------------|
| No STRATEGY-* tasks available | Idle, wait for coordinator assignment |
| No changed files | Analyze full codebase, recommend smoke tests |
| Unknown test framework | Recommend Jest/Pytest based on project language |
| All files are config | Recommend integration tests only |
| Shared memory not found | Notify coordinator, request location |
| Context/Plan file not found | Notify coordinator, request location |