mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-03-10 17:11:04 +08:00
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:
@@ -1,258 +0,0 @@
|
||||
# Command: generate-tests
|
||||
|
||||
> 按层级生成测试代码。根据 strategist 策略和项目现有测试模式,生成 L1/L2/L3 测试用例。
|
||||
|
||||
## When to Use
|
||||
|
||||
- Phase 3 of Generator
|
||||
- 策略已制定,需要生成对应层级的测试代码
|
||||
- GC 循环中修订失败的测试
|
||||
|
||||
**Trigger conditions**:
|
||||
- QAGEN-* 任务进入执行阶段
|
||||
- 测试策略中包含当前层级
|
||||
- GC 循环触发修复任务(QAGEN-fix-*)
|
||||
|
||||
## Strategy
|
||||
|
||||
### Delegation Mode
|
||||
|
||||
**Mode**: Sequential Delegation(复杂时)/ Direct(简单时)
|
||||
**Agent Type**: `code-developer`
|
||||
**Delegation Scope**: Per-layer
|
||||
|
||||
### Decision Logic
|
||||
|
||||
```javascript
|
||||
const focusFiles = layerConfig.focus_files || []
|
||||
const isGCFix = task.subject.includes('fix')
|
||||
|
||||
if (isGCFix) {
|
||||
// GC 修复模式:读取失败信息,针对性修复
|
||||
mode = 'gc-fix'
|
||||
} else if (focusFiles.length <= 3) {
|
||||
// 直接生成:内联 Read → 分析 → Write
|
||||
mode = 'direct'
|
||||
} else {
|
||||
// 委派给 code-developer
|
||||
mode = 'delegate'
|
||||
}
|
||||
```
|
||||
|
||||
## Execution Steps
|
||||
|
||||
### Step 1: Context Preparation
|
||||
|
||||
```javascript
|
||||
// 从 shared memory 获取策略
|
||||
const strategy = sharedMemory.test_strategy || {}
|
||||
const targetLayer = task.description.match(/layer:\s*(L[123])/)?.[1] || 'L1'
|
||||
|
||||
// 确定层级配置
|
||||
const layerConfig = strategy.layers?.find(l => l.level === targetLayer) || {
|
||||
level: targetLayer,
|
||||
name: targetLayer === 'L1' ? 'Unit Tests' : targetLayer === 'L2' ? 'Integration Tests' : 'E2E Tests',
|
||||
target_coverage: targetLayer === 'L1' ? 80 : targetLayer === 'L2' ? 60 : 40,
|
||||
focus_files: []
|
||||
}
|
||||
|
||||
// 学习现有测试模式(必须找 3 个相似测试文件)
|
||||
const existingTests = Glob(`**/*.{test,spec}.{ts,tsx,js,jsx}`)
|
||||
const testPatterns = existingTests.slice(0, 3).map(f => ({
|
||||
path: f,
|
||||
content: Read(f)
|
||||
}))
|
||||
|
||||
// 检测测试约定
|
||||
const testConventions = detectTestConventions(testPatterns)
|
||||
```
|
||||
|
||||
### Step 2: Execute Strategy
|
||||
|
||||
```javascript
|
||||
if (mode === 'gc-fix') {
|
||||
// GC 修复模式
|
||||
// 读取失败信息
|
||||
const failedTests = sharedMemory.execution_results?.[targetLayer]
|
||||
const failureOutput = Read(`${sessionFolder}/results/run-${targetLayer}.json`)
|
||||
|
||||
Task({
|
||||
subagent_type: "code-developer",
|
||||
run_in_background: false,
|
||||
description: `Fix failing ${targetLayer} tests (GC iteration)`,
|
||||
prompt: `## Goal
|
||||
Fix the failing tests based on execution results. Do NOT modify source code.
|
||||
|
||||
## Test Execution Results
|
||||
${JSON.stringify(failedTests, null, 2)}
|
||||
|
||||
## Test Conventions
|
||||
${JSON.stringify(testConventions, null, 2)}
|
||||
|
||||
## Instructions
|
||||
- Read each failing test file
|
||||
- Fix assertions, imports, mocks, or test setup
|
||||
- Ensure tests match actual source behavior
|
||||
- Do NOT skip or ignore tests
|
||||
- Do NOT modify source files`
|
||||
})
|
||||
|
||||
} else if (mode === 'direct') {
|
||||
// 直接生成模式
|
||||
const focusFiles = layerConfig.focus_files || []
|
||||
|
||||
for (const sourceFile of focusFiles) {
|
||||
const sourceContent = Read(sourceFile)
|
||||
|
||||
// 确定测试文件路径(遵循项目约定)
|
||||
const testPath = determineTestPath(sourceFile, testConventions)
|
||||
|
||||
// 检查是否已有测试
|
||||
let existingTest = null
|
||||
try { existingTest = Read(testPath) } catch {}
|
||||
|
||||
if (existingTest) {
|
||||
// 补充现有测试:分析缺失的测试用例
|
||||
const missingCases = analyzeMissingCases(sourceContent, existingTest)
|
||||
if (missingCases.length > 0) {
|
||||
// 追加测试用例
|
||||
Edit({
|
||||
file_path: testPath,
|
||||
old_string: findLastTestBlock(existingTest),
|
||||
new_string: `${findLastTestBlock(existingTest)}\n\n${generateCases(missingCases, testConventions)}`
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// 创建新测试文件
|
||||
const testContent = generateFullTestFile(sourceFile, sourceContent, testConventions, targetLayer)
|
||||
Write(testPath, testContent)
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// 委派模式
|
||||
const focusFiles = layerConfig.focus_files || []
|
||||
|
||||
Task({
|
||||
subagent_type: "code-developer",
|
||||
run_in_background: false,
|
||||
description: `Generate ${targetLayer} tests for ${focusFiles.length} files`,
|
||||
prompt: `## Goal
|
||||
Generate ${layerConfig.name} for the following source files.
|
||||
|
||||
## Test Framework
|
||||
${strategy.test_framework || 'vitest'}
|
||||
|
||||
## Existing Test Patterns (MUST follow these exactly)
|
||||
${testPatterns.map(t => `### ${t.path}\n\`\`\`\n${t.content.substring(0, 800)}\n\`\`\``).join('\n\n')}
|
||||
|
||||
## Test Conventions
|
||||
- Test file location: ${testConventions.location}
|
||||
- Import style: ${testConventions.importStyle}
|
||||
- Describe/it nesting: ${testConventions.nesting}
|
||||
|
||||
## Source Files to Test
|
||||
${focusFiles.map(f => `- ${f}`).join('\n')}
|
||||
|
||||
## Requirements
|
||||
- Follow existing test patterns exactly (import style, naming, structure)
|
||||
- Cover: happy path + edge cases + error cases
|
||||
- Target coverage: ${layerConfig.target_coverage}%
|
||||
- Do NOT modify source files, only create/modify test files
|
||||
- Do NOT use \`any\` type assertions
|
||||
- Do NOT skip or mark tests as TODO without implementation`
|
||||
})
|
||||
}
|
||||
|
||||
// 辅助函数
|
||||
function determineTestPath(sourceFile, conventions) {
|
||||
if (conventions.location === 'colocated') {
|
||||
return sourceFile.replace(/\.(ts|tsx|js|jsx)$/, `.test.$1`)
|
||||
} else if (conventions.location === '__tests__') {
|
||||
const dir = sourceFile.substring(0, sourceFile.lastIndexOf('/'))
|
||||
const name = sourceFile.substring(sourceFile.lastIndexOf('/') + 1)
|
||||
return `${dir}/__tests__/${name.replace(/\.(ts|tsx|js|jsx)$/, `.test.$1`)}`
|
||||
}
|
||||
return sourceFile.replace(/\.(ts|tsx|js|jsx)$/, `.test.$1`)
|
||||
}
|
||||
|
||||
function detectTestConventions(patterns) {
|
||||
const conventions = {
|
||||
location: 'colocated', // or '__tests__'
|
||||
importStyle: 'named', // or 'default'
|
||||
nesting: 'describe-it', // or 'test-only'
|
||||
framework: 'vitest'
|
||||
}
|
||||
|
||||
for (const p of patterns) {
|
||||
if (p.path.includes('__tests__')) conventions.location = '__tests__'
|
||||
if (p.content.includes("import { describe")) conventions.nesting = 'describe-it'
|
||||
if (p.content.includes("from 'vitest'")) conventions.framework = 'vitest'
|
||||
if (p.content.includes("from '@jest'") || p.content.includes("from 'jest'")) conventions.framework = 'jest'
|
||||
}
|
||||
|
||||
return conventions
|
||||
}
|
||||
```
|
||||
|
||||
### Step 3: Result Processing
|
||||
|
||||
```javascript
|
||||
// 收集生成/修改的测试文件
|
||||
const generatedTests = Bash(`git diff --name-only`).split('\n')
|
||||
.filter(f => /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(f))
|
||||
|
||||
// TypeScript 语法检查
|
||||
const syntaxResult = Bash(`npx tsc --noEmit ${generatedTests.join(' ')} 2>&1 || true`)
|
||||
const hasSyntaxErrors = syntaxResult.includes('error TS')
|
||||
|
||||
// 自动修复语法错误(最多 3 次)
|
||||
if (hasSyntaxErrors) {
|
||||
let fixAttempt = 0
|
||||
while (fixAttempt < 3 && syntaxResult.includes('error TS')) {
|
||||
const errors = syntaxResult.split('\n').filter(l => l.includes('error TS')).slice(0, 5)
|
||||
// 尝试修复每个错误...
|
||||
fixAttempt++
|
||||
}
|
||||
}
|
||||
|
||||
// 更新 shared memory
|
||||
const testInfo = {
|
||||
layer: targetLayer,
|
||||
files: generatedTests,
|
||||
count: generatedTests.length,
|
||||
syntax_clean: !hasSyntaxErrors,
|
||||
mode: mode,
|
||||
gc_fix: mode === 'gc-fix'
|
||||
}
|
||||
|
||||
sharedMemory.generated_tests = sharedMemory.generated_tests || {}
|
||||
sharedMemory.generated_tests[targetLayer] = testInfo
|
||||
Write(`${sessionFolder}/.msg/meta.json`, JSON.stringify(sharedMemory, null, 2))
|
||||
```
|
||||
|
||||
## Output Format
|
||||
|
||||
```
|
||||
## Test Generation Results
|
||||
|
||||
### Layer: [L1|L2|L3]
|
||||
### Mode: [direct|delegate|gc-fix]
|
||||
### Files Generated: [count]
|
||||
- [test file path]
|
||||
|
||||
### Syntax Check: PASS/FAIL
|
||||
### Conventions Applied: [framework], [location], [nesting]
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Scenario | Resolution |
|
||||
|----------|------------|
|
||||
| No focus files in strategy | Generate L1 tests for all source files in scope |
|
||||
| No existing test patterns | Use framework defaults (vitest/jest/pytest) |
|
||||
| Sub-agent failure | Retry once, fallback to direct generation |
|
||||
| Syntax errors persist after 3 fixes | Report errors, proceed with available tests |
|
||||
| Source file not found | Skip file, log warning |
|
||||
| Agent/CLI failure | Retry once, then fallback to inline execution |
|
||||
| Timeout (>5 min) | Report partial results, notify coordinator |
|
||||
@@ -1,169 +0,0 @@
|
||||
# Generator Role
|
||||
|
||||
Test case generator. Generate test code according to strategist's strategy and layers. Support L1 unit tests, L2 integration tests, L3 E2E tests. Follow project's existing test patterns and framework conventions.
|
||||
|
||||
## Identity
|
||||
|
||||
- **Name**: `generator` | **Tag**: `[generator]`
|
||||
- **Task Prefix**: `QAGEN-*`
|
||||
- **Responsibility**: Code generation (test code generation)
|
||||
|
||||
## Boundaries
|
||||
|
||||
### MUST
|
||||
- Only process `QAGEN-*` prefixed tasks
|
||||
- All output (SendMessage, team_msg, logs) must carry `[generator]` identifier
|
||||
- Only communicate with coordinator via SendMessage
|
||||
- Follow project's existing test framework and patterns
|
||||
- Generated tests must be runnable
|
||||
- Work strictly within test code generation responsibility scope
|
||||
|
||||
### MUST NOT
|
||||
- Execute work outside this role's responsibility scope
|
||||
- Modify source code (only generate test code)
|
||||
- Execute tests
|
||||
- Communicate directly with other worker roles (must go through coordinator)
|
||||
- Create tasks for other roles (TaskCreate is coordinator-exclusive)
|
||||
- Omit `[generator]` identifier in any output
|
||||
|
||||
---
|
||||
|
||||
## Toolbox
|
||||
|
||||
### Available Commands
|
||||
|
||||
| Command | File | Phase | Description |
|
||||
|---------|------|-------|-------------|
|
||||
| `generate-tests` | [commands/generate-tests.md](commands/generate-tests.md) | Phase 3 | Layer-based test code generation |
|
||||
|
||||
### Tool Capabilities
|
||||
|
||||
| Tool | Type | Used By | Purpose |
|
||||
|------|------|---------|---------|
|
||||
| `code-developer` | subagent | generate-tests.md | Complex test code generation |
|
||||
| `gemini` | CLI | generate-tests.md | Analyze existing test patterns |
|
||||
|
||||
---
|
||||
|
||||
## Message Types
|
||||
|
||||
| Type | Direction | Trigger | Description |
|
||||
|------|-----------|---------|-------------|
|
||||
| `tests_generated` | generator -> coordinator | Test generation complete | Contains generated test file list |
|
||||
| `tests_revised` | generator -> coordinator | Test revision complete | After revision in GC loop |
|
||||
| `error` | generator -> coordinator | Generation failed | Blocking error |
|
||||
|
||||
## 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: <first-test-file> }
|
||||
})
|
||||
```
|
||||
|
||||
**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 `QAGEN-*` + owner match + pending + unblocked -> TaskGet -> TaskUpdate in_progress.
|
||||
|
||||
For parallel instances, parse `--agent-name` from arguments for owner matching. Falls back to `generator` for single-instance execution.
|
||||
|
||||
### Phase 2: Strategy & Pattern Loading
|
||||
|
||||
**Loading steps**:
|
||||
|
||||
1. Extract session path from task description
|
||||
2. Read shared memory to get strategy
|
||||
|
||||
| Input | Source | Required |
|
||||
|-------|--------|----------|
|
||||
| Shared memory | <session-folder>/.msg/meta.json | Yes |
|
||||
| Test strategy | sharedMemory.test_strategy | Yes |
|
||||
| Target layer | task description or strategy.layers[0] | Yes |
|
||||
|
||||
3. Determine target layer config:
|
||||
|
||||
| Layer | Name | Coverage Target |
|
||||
|-------|------|-----------------|
|
||||
| L1 | Unit Tests | 80% |
|
||||
| L2 | Integration Tests | 60% |
|
||||
| L3 | E2E Tests | 40% |
|
||||
|
||||
4. Learn existing test patterns (find 3 similar test files)
|
||||
5. Detect test framework and configuration
|
||||
|
||||
### Phase 3: Test Generation
|
||||
|
||||
Delegate to `commands/generate-tests.md` if available, otherwise execute inline.
|
||||
|
||||
**Implementation Strategy Selection**:
|
||||
|
||||
| Focus File Count | Complexity | Strategy |
|
||||
|------------------|------------|----------|
|
||||
| <= 3 files | Low | Direct: inline Edit/Write |
|
||||
| 3-5 files | Medium | Single code-developer agent |
|
||||
| > 5 files | High | Batch by module, one agent per batch |
|
||||
|
||||
**Direct Generation Flow**:
|
||||
1. Read source file content
|
||||
2. Determine test file path (follow project convention)
|
||||
3. Check if test already exists -> supplement, else create new
|
||||
4. Generate test content based on source exports and existing patterns
|
||||
|
||||
**Test Content Generation**:
|
||||
- Import source exports
|
||||
- Create describe blocks per export
|
||||
- Include happy path, edge cases, error cases tests
|
||||
|
||||
### Phase 4: Self-Validation
|
||||
|
||||
**Validation Checks**:
|
||||
|
||||
| Check | Method | Pass Criteria |
|
||||
|-------|--------|---------------|
|
||||
| Syntax | TypeScript check | No errors |
|
||||
| File existence | Verify all planned files exist | All files present |
|
||||
| Import resolution | Check no broken imports | All imports resolve |
|
||||
|
||||
If validation fails -> attempt auto-fix (max 2 attempts) -> report remaining issues.
|
||||
|
||||
Update shared memory with `generated_tests` field for this layer.
|
||||
|
||||
### Phase 5: Report to Coordinator
|
||||
|
||||
> See SKILL.md Shared Infrastructure -> Worker Phase 5: Report
|
||||
|
||||
Standard report flow: team_msg log -> SendMessage with `[generator]` prefix -> TaskUpdate completed -> Loop to Phase 1 for next task.
|
||||
|
||||
Message type selection: `tests_generated` for new generation, `tests_revised` for fix iterations.
|
||||
|
||||
---
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Scenario | Resolution |
|
||||
|----------|------------|
|
||||
| No QAGEN-* tasks available | Idle, wait for coordinator |
|
||||
| Strategy not found in shared memory | Generate L1 unit tests for changed files |
|
||||
| No existing test patterns found | Use framework defaults |
|
||||
| Sub-agent failure | Retry once, fallback to direct generation |
|
||||
| Syntax errors in generated tests | Auto-fix up to 3 attempts, report remaining |
|
||||
| Source file not found | Skip file, report to coordinator |
|
||||
Reference in New Issue
Block a user