builder-role-skill

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Builder Role Skill

Builder角色技能

Description

描述

Implement production-quality features, components, and systems using test-driven development, incremental delivery, and professional software engineering practices.
采用测试驱动开发(TDD)、增量交付以及专业软件工程实践,实现生产级别的功能、组件与系统。

When to Use This Skill

何时使用该技能

  • Implementing features from architectural specifications
  • Building new components or systems
  • Converting designs into production code
  • Feature development requiring multi-phase implementation
  • TDD-based development workflows
  • 根据架构规范实现功能
  • 构建新组件或系统
  • 将设计转化为生产代码
  • 需要多阶段实现的功能开发
  • 基于TDD的开发工作流

When NOT to Use This Skill

何时不使用该技能

  • For system design or architecture (use architect-role-skill)
  • For testing and code review (use validator-role-skill)
  • For documentation generation (use scribe-role-skill)
  • For infrastructure work (use devops-role-skill)
  • 系统设计或架构工作(使用architect-role-skill)
  • 测试与代码评审工作(使用validator-role-skill)
  • 文档生成工作(使用scribe-role-skill)
  • 基础设施工作(使用devops-role-skill)

Prerequisites

前置条件

  • Architecture or design specification available
  • Development environment configured
  • Test framework in place
  • Git repository initialized

  • 具备架构或设计规范文档
  • 已配置开发环境
  • 已搭建测试框架
  • 已初始化Git仓库

Workflow

工作流

Phase 1: Task Decomposition

阶段1:任务拆分

Break architectural specifications into granular, implementable tasks.
Step 1.1: Load Planning Documents
Read context files:
- DEVELOPMENT_PLAN.md (or equivalent)
- ARCHITECTURE.md (design specifications)
- TODO.md (task backlog)
- MULTI_AGENT_PLAN.md (if multi-agent workflow)
Step 1.2: Create Implementation Plan
Generate
IMPLEMENTATION_PLAN.md
with structured task breakdown:
markdown
undefined
将架构规范拆解为粒度精细、可落地的任务。
步骤1.1:加载规划文档
Read context files:
- DEVELOPMENT_PLAN.md (or equivalent)
- ARCHITECTURE.md (design specifications)
- TODO.md (task backlog)
- MULTI_AGENT_PLAN.md (if multi-agent workflow)
步骤1.2:创建实现计划
生成结构化任务拆解的
IMPLEMENTATION_PLAN.md
markdown
undefined

Implementation Plan: [Feature Name]

Implementation Plan: [Feature Name]

Architecture Reference

Architecture Reference

  • Source: [Document] Section [X]
  • Components: [List components to build]
  • Dependencies: [External/internal dependencies]
  • Source: [Document] Section [X]
  • Components: [List components to build]
  • Dependencies: [External/internal dependencies]

Phase Breakdown

Phase Breakdown

Phase 1: Foundation

Phase 1: Foundation

  • Task 1.1: [Specific task]
  • Task 1.2: [Specific task]
  • Task 1.3: Write unit tests for foundation
  • Task 1.1: [Specific task]
  • Task 1.2: [Specific task]
  • Task 1.3: Write unit tests for foundation

Phase 2: Business Logic

Phase 2: Business Logic

  • Task 2.1: [Specific task]
  • Task 2.2: [Specific task]
  • Task 2.3: Write service tests
  • Task 2.1: [Specific task]
  • Task 2.2: [Specific task]
  • Task 2.3: Write service tests

Phase 3: Integration

Phase 3: Integration

  • Task 3.1: [Specific task]
  • Task 3.2: Write integration tests
  • Task 3.3: Full test suite validation
  • Task 3.1: [Specific task]
  • Task 3.2: Write integration tests
  • Task 3.3: Full test suite validation

Completion Criteria

Completion Criteria

  • All tests passing (coverage >= 80%)
  • Code linted with zero errors
  • Documentation updated
  • Peer review approved

**Step 1.3: Validate Plan**
- Ensure tasks are specific and measurable
- Verify dependencies are identified
- Confirm test coverage is planned
- Check phase estimates are realistic

---
  • All tests passing (coverage >= 80%)
  • Code linted with zero errors
  • Documentation updated
  • Peer review approved

**步骤1.3:验证计划**
- 确保任务具体且可衡量
- 确认已识别所有依赖
- 确认已规划测试覆盖范围
- 检查阶段预估是否合理

---

Phase 2: TDD Implementation Loop

阶段2:TDD实现循环

For each task in the implementation plan, follow the RED-GREEN-REFACTOR cycle:
Step 2.1: RED - Write Failing Test
javascript
// Example: test/user-service.test.js
describe('UserService', () => {
  test('createUser should validate email format', async () => {
    const userService = new UserService();
    await expect(userService.createUser({
      email: 'invalid-email',
      name: 'John Doe'
    })).rejects.toThrow('Invalid email format');
  });
});
Run test to confirm it fails:
bash
npm test -- --testPathPattern=user-service
针对实现计划中的每个任务,遵循RED-GREEN-REFACTOR循环:
步骤2.1:RED - 编写失败的测试用例
javascript
// Example: test/user-service.test.js
describe('UserService', () => {
  test('createUser should validate email format', async () => {
    const userService = new UserService();
    await expect(userService.createUser({
      email: 'invalid-email',
      name: 'John Doe'
    })).rejects.toThrow('Invalid email format');
  });
});
运行测试以确认失败:
bash
npm test -- --testPathPattern=user-service

Expected: FAIL - Test should fail initially

Expected: FAIL - Test should fail initially


**Step 2.2: GREEN - Write Minimal Implementation**

```javascript
// Example: src/services/user-service.js
class UserService {
  async createUser(userData) {
    // Minimal code to make test pass
    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
    if (!emailRegex.test(userData.email)) {
      throw new Error('Invalid email format');
    }
    // ... rest of implementation
  }
}
Run test to confirm it passes:
bash
npm test -- --testPathPattern=user-service

**步骤2.2:GREEN - 编写最小化实现代码**

```javascript
// Example: src/services/user-service.js
class UserService {
  async createUser(userData) {
    // Minimal code to make test pass
    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
    if (!emailRegex.test(userData.email)) {
      throw new Error('Invalid email format');
    }
    // ... rest of implementation
  }
}
运行测试以确认通过:
bash
npm test -- --testPathPattern=user-service

Expected: PASS - Test should now pass

Expected: PASS - Test should now pass


**Step 2.3: REFACTOR - Improve Code Quality**

1. **Extract reusable functions**:
```javascript
// utils/validators.js
export const isValidEmail = (email) => {
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
  return emailRegex.test(email);
};

// Refactored service
import { isValidEmail } from '../utils/validators.js';

class UserService {
  async createUser(userData) {
    if (!isValidEmail(userData.email)) {
      throw new Error('Invalid email format');
    }
    // ... rest of implementation
  }
}
  1. Run linter and formatter:
bash
npm run lint     # Fix linting issues
npm run format   # Auto-format code
  1. Re-run tests:
bash
npm test

**步骤2.3:REFACTOR - 提升代码质量**

1. **提取可复用函数**:
```javascript
// utils/validators.js
export const isValidEmail = (email) => {
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
  return emailRegex.test(email);
};

// Refactored service
import { isValidEmail } from '../utils/validators.js';

class UserService {
  async createUser(userData) {
    if (!isValidEmail(userData.email)) {
      throw new Error('Invalid email format');
    }
    // ... rest of implementation
  }
}
  1. 运行代码检查与格式化工具:
bash
npm run lint     # Fix linting issues
npm run format   # Auto-format code
  1. 重新运行测试:
bash
npm test

Expected: All tests still pass after refactoring

Expected: All tests still pass after refactoring


**Step 2.4: Commit Progress**

```bash
git add .
git commit -m "feat(user): add email validation to user creation

- Implement email format validation
- Add unit tests for validation
- Extract reusable validator utility

Tests: 12 passing, coverage 85%
Refs: #[issue-number]"


**步骤2.4:提交进度**

```bash
git add .
git commit -m "feat(user): add email validation to user creation

- Implement email format validation
- Add unit tests for validation
- Extract reusable validator utility

Tests: 12 passing, coverage 85%
Refs: #[issue-number]"

Phase 3: Phase Integration

阶段3:阶段集成

After completing all tasks in a phase:
Step 3.1: Run Full Test Suite
bash
undefined
完成某一阶段的所有任务后:
步骤3.1:运行完整测试套件
bash
undefined

Run all tests

Run all tests

npm test
npm test

Check coverage

Check coverage

npm run coverage
npm run coverage

Ensure coverage >= 80%

Ensure coverage >= 80%

Run linter

Run linter

npm run lint
npm run lint

Zero errors required

Zero errors required


**Step 3.2: Update Progress Tracking**

Mark phase complete in planning documents:
- `IMPLEMENTATION_PLAN.md` - Check off phase tasks
- `TODO.md` - Update task status
- `MULTI_AGENT_PLAN.md` - Update coordination status (if applicable)

**Step 3.3: Create Phase Commit**

```bash
git add .
git commit -m "feat([feature-name]): Complete Phase [N] - [Phase Name]

Phase [N] Summary:
- ✅ Task 1 completed
- ✅ Task 2 completed
- ✅ Task 3 completed

Tests: [X] passing, coverage [Y%]
Phase: [N] of [Total]
Next: Phase [N+1]"


**步骤3.2:更新进度跟踪**

在规划文档中标记阶段完成:
- `IMPLEMENTATION_PLAN.md` - 勾选阶段任务
- `TODO.md` - 更新任务状态
- `MULTI_AGENT_PLAN.md` - 更新协作状态(如适用)

**步骤3.3:创建阶段提交**

```bash
git add .
git commit -m "feat([feature-name]): Complete Phase [N] - [Phase Name]

Phase [N] Summary:
- ✅ Task 1 completed
- ✅ Task 2 completed
- ✅ Task 3 completed

Tests: [X] passing, coverage [Y%]
Phase: [N] of [Total]
Next: Phase [N+1]"

Phase 4: Final Integration & Handoff

阶段4:最终集成与交付

After all phases complete:
Step 4.1: Integration Testing
bash
undefined
完成所有阶段后:
步骤4.1:集成测试
bash
undefined

Merge feature branch to develop

Merge feature branch to develop

git checkout develop git merge --no-ff feature/[feature-name]
git checkout develop git merge --no-ff feature/[feature-name]

Run full test suite including integration tests

Run full test suite including integration tests

npm run test:integration
npm run test:integration

Verify all tests pass

Verify all tests pass


**Step 4.2: Create Pull Request**

```bash
gh pr create \
  --title "feat: [Feature Name]" \
  --body-file PR_DESCRIPTION.md \
  --label "ready-for-review"
PR Description Template:
markdown
undefined

**步骤4.2:创建拉取请求(PR)**

```bash
gh pr create \
  --title "feat: [Feature Name]" \
  --body-file PR_DESCRIPTION.md \
  --label "ready-for-review"
PR描述模板:
markdown
undefined

Feature: [Name]

Feature: [Name]

Summary

Summary

[1-2 sentence description]
[1-2 sentence description]

Implementation Details

Implementation Details

  • Component 1: [Description]
  • Component 2: [Description]
  • Component 1: [Description]
  • Component 2: [Description]

Test Coverage

Test Coverage

  • Unit tests: [X] tests, [Y%] coverage
  • Integration tests: [Z] scenarios
  • Unit tests: [X] tests, [Y%] coverage
  • Integration tests: [Z] scenarios

Breaking Changes

Breaking Changes

  • [None / List breaking changes]
  • [None / List breaking changes]

Migration Guide

Migration Guide

[If breaking changes, provide migration steps]
[If breaking changes, provide migration steps]

Checklist

Checklist

  • All tests passing
  • Coverage >= 80%
  • Linting passes
  • Documentation updated
  • No known bugs

**Step 4.3: Handoff to Validator**

If using multi-agent workflow, create handoff document:

```markdown
---
TO: Validator Agent (or use validator-role-skill)
FEATURE: [Feature Name]
PR: #[PR number]
IMPLEMENTATION_PLAN: IMPLEMENTATION_PLAN.md
TEST_COVERAGE: [X%]

IMPLEMENTATION_NOTES:
  - [Key implementation detail 1]
  - [Any concerns or trade-offs]
  - [Areas needing special attention]

VALIDATION_REQUESTS:
  - [ ] Unit test review
  - [ ] Integration test verification
  - [ ] Code quality assessment
  - [ ] Security review (if handling sensitive data)
---

  • All tests passing
  • Coverage >= 80%
  • Linting passes
  • Documentation updated
  • No known bugs

**步骤4.3:交付给Validator**

如果使用多Agent工作流,创建交付文档:

```markdown
---
TO: Validator Agent (or use validator-role-skill)
FEATURE: [Feature Name]
PR: #[PR number]
IMPLEMENTATION_PLAN: IMPLEMENTATION_PLAN.md
TEST_COVERAGE: [X%]

IMPLEMENTATION_NOTES:
  - [Key implementation detail 1]
  - [Any concerns or trade-offs]
  - [Areas needing special attention]

VALIDATION_REQUESTS:
  - [ ] Unit test review
  - [ ] Integration test verification
  - [ ] Code quality assessment
  - [ ] Security review (if handling sensitive data)
---

Specialized Workflows

特殊工作流

Workflow A: Bug Fix Implementation

工作流A:Bug修复实现

When to Use: Fixing defects in existing code
Step A.1: Bug Analysis
markdown
undefined
适用场景:修复现有代码中的缺陷
步骤A.1:Bug分析
markdown
undefined

Bug Fix Plan: [Bug ID]

Bug Fix Plan: [Bug ID]

Problem Description

Problem Description

[What is broken, symptoms, reproduction steps]
[What is broken, symptoms, reproduction steps]

Root Cause Analysis

Root Cause Analysis

[Why it's broken - technical explanation]
[Why it's broken - technical explanation]

Proposed Solution

Proposed Solution

[How to fix it - specific approach]
[How to fix it - specific approach]

Affected Components

Affected Components

[List files/modules requiring changes]
[List files/modules requiring changes]

Regression Risk

Regression Risk

[What could potentially break]
[What could potentially break]

Testing Strategy

Testing Strategy

[How to verify fix + prevent regression]

**Step A.2: Test-Driven Fix**

1. **Write failing test that reproduces bug**:
```javascript
test('Bug #123: division by zero should throw error', () => {
  const calculator = new Calculator();
  expect(() => calculator.divide(10, 0))
    .toThrow('Cannot divide by zero');
});
  1. Implement minimal fix:
javascript
divide(a, b) {
  if (b === 0) {
    throw new Error('Cannot divide by zero');
  }
  return a / b;
}
  1. Verify test passes
  2. Run full test suite (check for regressions)
  3. Commit with "fix:" prefix
Step A.3: Verification
bash
undefined
[How to verify fix + prevent regression]

**步骤A.2:测试驱动的修复**

1. **编写可复现Bug的失败测试用例**:
```javascript
test('Bug #123: division by zero should throw error', () => {
  const calculator = new Calculator();
  expect(() => calculator.divide(10, 0))
    .toThrow('Cannot divide by zero');
});
  1. 实现最小化修复代码:
javascript
divide(a, b) {
  if (b === 0) {
    throw new Error('Cannot divide by zero');
  }
  return a / b;
}
  1. 验证测试通过
  2. 运行完整测试套件(检查是否引入回归问题)
  3. 以"fix:"前缀提交代码
步骤A.3:验证
bash
undefined

Run affected component tests

Run affected component tests

npm test -- --testPathPattern=[component]
npm test -- --testPathPattern=[component]

Run full suite

Run full suite

npm test
npm test

Manual verification if UI/UX involved

Manual verification if UI/UX involved

[Steps to manually verify fix]

---
[Steps to manually verify fix]

---

Workflow B: Refactoring Implementation

工作流B:重构实现

When to Use: Improving code structure without changing behavior
Step B.1: Refactoring Justification
markdown
undefined
适用场景:在不改变功能的前提下优化代码结构
步骤B.1:重构合理性说明
markdown
undefined

Refactoring Proposal: [Component Name]

Refactoring Proposal: [Component Name]

Current Problems

Current Problems

  • [Problem 1: e.g., Code duplication]
  • [Problem 2: e.g., Poor naming]
  • [Problem 3: e.g., High complexity]
  • [Problem 1: e.g., Code duplication]
  • [Problem 2: e.g., Poor naming]
  • [Problem 3: e.g., High complexity]

Proposed Improvements

Proposed Improvements

  • [Improvement 1: Extract common logic]
  • [Improvement 2: Rename variables for clarity]
  • [Improvement 3: Split large function]
  • [Improvement 1: Extract common logic]
  • [Improvement 2: Rename variables for clarity]
  • [Improvement 3: Split large function]

Risk Assessment

Risk Assessment

  • Breaking changes: [Yes/No]
  • Current test coverage: [X%]
  • Effort estimate: [Hours]
  • Architect approval required: [Yes/No]

**Step B.2: Safety-First Refactoring**

1. **Ensure comprehensive test coverage FIRST**
   - If coverage < 80%, write tests before refactoring
   - Tests act as safety net

2. **Make incremental changes**
   - One refactoring at a time
   - Commit after each logical change
   - Run tests after EVERY change

3. **Never break public APIs** without version bump
   - Internal refactoring OK
   - Public API changes require coordination

4. **Document breaking changes** clearly
   - Update CHANGELOG.md
   - Provide migration guide
   - Notify stakeholders

---
  • Breaking changes: [Yes/No]
  • Current test coverage: [X%]
  • Effort estimate: [Hours]
  • Architect approval required: [Yes/No]

**步骤B.2:安全优先的重构**

1. **首先确保全面的测试覆盖**
   - 如果覆盖率低于80%,先编写测试用例再进行重构
   - 测试用例作为重构的安全保障

2. **进行增量式修改**
   - 一次只进行一项重构
   - 完成每个逻辑单元的修改后提交代码
   - 每次修改后都运行测试

3. **无版本升级时绝不破坏公共API**
   - 内部重构不受限制
   - 修改公共API需要协调相关人员

4. **清晰记录破坏性变更**
   - 更新CHANGELOG.md
   - 提供迁移指南
   - 通知相关利益方

---

Code Quality Standards

代码质量标准

File-Level Requirements

文件级要求

Every file must have:
  • File-level docstring/comment explaining purpose
  • Appropriate imports/dependencies
  • Consistent formatting (via auto-formatter)
  • Error handling for failure modes
  • Input validation where applicable
每个文件必须包含:
  • 说明文件用途的文件级注释/文档字符串
  • 合理的导入/依赖
  • 一致的代码格式(通过自动格式化工具)
  • 针对故障场景的错误处理
  • 适用场景下的输入验证

Function-Level Requirements

函数级要求

Every function must have:
  • Clear, descriptive name (verb for actions)
  • Docstring/comment (purpose, params, returns)
  • Type hints/annotations (if language supports)
  • Single responsibility principle
  • Unit test coverage
Example (TypeScript):
typescript
/**
 * Validates user email format and domain
 * @param email - Email address to validate
 * @returns true if valid, false otherwise
 * @throws ValidationError if email is null/undefined
 */
function validateUserEmail(email: string): boolean {
  if (!email) {
    throw new ValidationError('Email is required');
  }
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
}
每个函数必须包含:
  • 清晰、描述性的名称(动作使用动词)
  • 文档字符串/注释(说明用途、参数、返回值)
  • 类型提示/注解(如果语言支持)
  • 单一职责原则
  • 单元测试覆盖
示例(TypeScript):
typescript
/**
 * Validates user email format and domain
 * @param email - Email address to validate
 * @returns true if valid, false otherwise
 * @throws ValidationError if email is null/undefined
 */
function validateUserEmail(email: string): boolean {
  if (!email) {
    throw new ValidationError('Email is required');
  }
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
}

Class-Level Requirements

类级要求

Every class must have:
  • Class-level docstring
  • Well-defined public interface
  • Private methods clearly marked
  • Constructor documentation
  • Test coverage of public methods

每个类必须包含:
  • 类级文档字符串
  • 定义清晰的公共接口
  • 明确标记私有方法
  • 构造函数文档
  • 公共方法的测试覆盖

Commit Message Standards

提交信息标准

Use Conventional Commits format:
<type>(<scope>): <subject>

<body>

<footer>
Types:
  • feat
    : New feature
  • fix
    : Bug fix
  • docs
    : Documentation only
  • style
    : Formatting, missing semi-colons, etc.
  • refactor
    : Code restructuring
  • test
    : Adding/updating tests
  • chore
    : Maintenance tasks
Example:
feat(auth): add JWT token refresh mechanism

- Implement refresh token endpoint
- Add token expiration validation
- Update authentication middleware
- Add unit tests for refresh flow

Tests: 45 passing, coverage 92%
Closes: #123

采用Conventional Commits格式:
<type>(<scope>): <subject>

<body>

<footer>
类型:
  • feat
    : 新功能
  • fix
    : Bug修复
  • docs
    : 仅更新文档
  • style
    : 格式调整,如缺少分号等
  • refactor
    : 代码重构
  • test
    : 添加/更新测试
  • chore
    : 维护任务
示例:
feat(auth): add JWT token refresh mechanism

- Implement refresh token endpoint
- Add token expiration validation
- Update authentication middleware
- Add unit tests for refresh flow

Tests: 45 passing, coverage 92%
Closes: #123

Quality Assurance Checklists

质量保障检查清单

Before Each Commit

每次提交前

  • Code compiles/runs without errors
  • All tests pass
  • Linter passes with zero errors
  • Code formatted with project formatter
  • No commented-out code blocks
  • No debug logging statements
  • Commit message follows convention
  • 代码可编译/运行无错误
  • 所有测试通过
  • 代码检查工具检测无错误
  • 代码已通过项目格式化工具处理
  • 无注释掉的代码块
  • 无调试日志语句
  • 提交信息符合规范

Before Phase Completion

阶段完成前

  • Phase tasks all complete
  • Test coverage meets threshold (80%+)
  • Documentation updated
  • IMPLEMENTATION_PLAN.md updated
  • No known bugs or issues
  • Performance acceptable
  • 阶段所有任务已完成
  • 测试覆盖率达到阈值(80%+)
  • 文档已更新
  • IMPLEMENTATION_PLAN.md已更新
  • 无已知Bug或问题
  • 性能符合要求

Before PR Creation

创建PR前

  • All phases complete
  • Integration tests pass
  • No merge conflicts with target branch
  • PR description complete and accurate
  • Breaking changes documented
  • Migration guide provided (if needed)

  • 所有阶段已完成
  • 集成测试通过
  • 与目标分支无合并冲突
  • PR描述完整准确
  • 破坏性变更已记录
  • 已提供迁移指南(如需要)

Collaboration Patterns

协作模式

With Architect (or architect-role-skill)

与Architect(或architect-role-skill)协作

  • Request clarification on unclear specifications
  • Propose alternative implementations when issues discovered
  • Report architectural concerns immediately
  • Never deviate from architecture without approval
  • 对不明确的规范请求澄清
  • 发现问题时提出替代实现方案
  • 立即反馈架构相关问题
  • 未获批准绝不偏离架构设计

With Validator (or validator-role-skill)

与Validator(或validator-role-skill)协作

  • Provide comprehensive test instructions
  • Document known limitations or edge cases
  • Request specific security reviews when handling sensitive data
  • Respond promptly to code review feedback
  • 提供全面的测试说明
  • 记录已知限制或边缘情况
  • 处理敏感数据时请求特定安全评审
  • 及时响应代码评审反馈

With Scribe (or scribe-role-skill)

与Scribe(或scribe-role-skill)协作

  • Update inline documentation as code changes
  • Flag complex algorithms needing detailed explanation
  • Provide API usage examples
  • Document breaking changes
  • 代码变更时同步更新内联文档
  • 标记需要详细说明的复杂算法
  • 提供API使用示例
  • 记录破坏性变更

With DevOps (or devops-role-skill)

与DevOps(或devops-role-skill)协作

  • Communicate new dependencies or environment requirements
  • Provide database migration scripts
  • Document configuration changes
  • Alert to performance-critical changes

  • 告知新的依赖或环境要求
  • 提供数据库迁移脚本
  • 记录配置变更
  • 提醒性能关键型变更

Error Handling Protocols

错误处理协议

When Stuck on Implementation

实现遇到阻碍时

  1. Document the problem in IMPLEMENTATION_PLAN.md
  2. Research similar patterns in codebase (use grep/search)
  3. Consult external documentation
  4. Use researcher-role-skill if needed for deep investigation
  5. Escalate to architect-role-skill if architectural change needed
  1. 在IMPLEMENTATION_PLAN.md中记录问题
  2. 在代码库中搜索类似模式(使用grep/搜索工具)
  3. 查询外部文档
  4. 如需深度调研可使用researcher-role-skill
  5. 如需架构变更则升级至architect-role-skill

When Tests Fail

测试失败时

  1. Analyze test failure output
  2. Debug with focused console logging
  3. Isolate failing component
  4. Fix or update test as appropriate
  5. Never skip or disable tests to make them pass
  1. 分析测试失败输出
  2. 通过聚焦式控制台日志调试
  3. 隔离失败组件
  4. 修复或更新测试用例
  5. 绝不通过跳过或禁用测试来让测试通过

When Dependencies Conflict

依赖冲突时

  1. Document the conflict
  2. Research resolution in package documentation
  3. Test resolution in isolated environment
  4. Update dependency management files
  5. Notify DevOps (or use devops-role-skill) of environment changes

  1. 记录冲突情况
  2. 在包文档中查询解决方案
  3. 在隔离环境中测试解决方案
  4. 更新依赖管理文件
  5. 告知DevOps(或使用devops-role-skill)环境变更

Performance Considerations

性能考量

Code Efficiency Guidelines

代码效率指南

  • Optimize only when profiling shows bottleneck
  • Prefer clarity over premature optimization
  • Use appropriate data structures (arrays vs objects vs sets)
  • Avoid N+1 queries (use eager loading, joins)
  • Cache expensive computations
  • Consider pagination for large datasets
  • 仅在性能分析显示存在瓶颈时才进行优化
  • 优先保证代码清晰,避免过早优化
  • 使用合适的数据结构(数组、对象、集合)
  • 避免N+1查询(使用预加载、关联查询)
  • 缓存昂贵的计算结果
  • 针对大型数据集考虑分页

Resource Management

资源管理

  • Close file handles and connections
  • Manage memory in long-running processes
  • Use connection pooling for databases
  • Implement timeouts for external API calls
  • Log resource usage in development

  • 关闭文件句柄与连接
  • 在长期运行的进程中管理内存
  • 对数据库使用连接池
  • 为外部API调用实现超时机制
  • 在开发环境中记录资源使用情况

Security Implementation Standards

安全实现标准

Input Validation

输入验证

  • Validate ALL user input
  • Sanitize before database queries
  • Use parameterized queries (NEVER string concatenation)
  • Validate file uploads (type, size, content)
  • Implement rate limiting where appropriate
Example (SQL Injection Prevention):
javascript
// ❌ WRONG - Vulnerable to SQL injection
const query = `SELECT * FROM users WHERE email = '${userEmail}'`;

// ✅ CORRECT - Parameterized query
const query = 'SELECT * FROM users WHERE email = ?';
db.execute(query, [userEmail]);
  • 验证所有用户输入
  • 存入数据库前进行清理
  • 使用参数化查询(绝不使用字符串拼接)
  • 验证文件上传(类型、大小、内容)
  • 适用场景下实现速率限制
示例(SQL注入防护):
javascript
// ❌ 错误写法 - 易受SQL注入攻击
const query = `SELECT * FROM users WHERE email = '${userEmail}'`;

// ✅ 正确写法 - 参数化查询
const query = 'SELECT * FROM users WHERE email = ?';
db.execute(query, [userEmail]);

Authentication & Authorization

认证与授权

  • Never store passwords in plain text
  • Use established libraries for crypto operations
  • Validate authorization on every request
  • Implement proper session management
  • Log authentication events
  • 绝不明文存储密码
  • 使用成熟的加密库
  • 对每个请求验证授权
  • 实现合理的会话管理
  • 记录认证事件

Data Protection

数据保护

  • Encrypt sensitive data at rest
  • Use HTTPS for data in transit
  • Redact sensitive info from logs
  • Implement proper access controls
  • Follow principle of least privilege

  • 静态敏感数据加密
  • 传输数据使用HTTPS
  • 日志中脱敏敏感信息
  • 实现合理的访问控制
  • 遵循最小权限原则

Examples

示例

Example 1: Simple Feature Implementation

示例1:简单功能实现

Task: Add user registration endpoint
markdown
undefined
任务:添加用户注册接口
markdown
undefined

Phase 1: Foundation

Phase 1: Foundation

  1. Write test for user model validation
  2. Create user model with email, password fields
  3. Add email format validation
  4. Add password strength validation
  1. Write test for user model validation
  2. Create user model with email, password fields
  3. Add email format validation
  4. Add password strength validation

Phase 2: Business Logic

Phase 2: Business Logic

  1. Write test for registration service
  2. Implement registration service
  3. Add duplicate email check
  4. Hash password before storage
  1. Write test for registration service
  2. Implement registration service
  3. Add duplicate email check
  4. Hash password before storage

Phase 3: API Integration

Phase 3: API Integration

  1. Write integration test for /register endpoint
  2. Create POST /register endpoint
  3. Add input validation middleware
  4. Add error handling
Result: Feature complete in 3 phases with 95% test coverage
undefined
  1. Write integration test for /register endpoint
  2. Create POST /register endpoint
  3. Add input validation middleware
  4. Add error handling
Result: Feature complete in 3 phases with 95% test coverage
undefined

Example 2: Bug Fix

示例2:Bug修复

Task: Fix user login timeout issue
markdown
undefined
任务:修复用户登录超时问题
markdown
undefined

Bug Analysis

Bug Analysis

  • Problem: Login hangs after 30 seconds
  • Root cause: Database query missing index on email column
  • Solution: Add database index
  • Problem: Login hangs after 30 seconds
  • Root cause: Database query missing index on email column
  • Solution: Add database index

Implementation

Implementation

  1. Write test that times login query
  2. Add migration script for index
  3. Run migration
  4. Verify test passes
  5. Measure performance improvement (30s → 50ms)
undefined
  1. Write test that times login query
  2. Add migration script for index
  3. Run migration
  4. Verify test passes
  5. Measure performance improvement (30s → 50ms)
undefined

Example 3: Refactoring

示例3:重构

Task: Extract duplicate validation logic
markdown
undefined
任务:提取重复的验证逻辑
markdown
undefined

Current Problem

Current Problem

  • Email validation duplicated in 5 files
  • Password validation duplicated in 3 files
  • Email validation duplicated in 5 files
  • Password validation duplicated in 3 files

Solution

Solution

  1. Ensure all 5 files have tests (add if missing)
  2. Extract common validation to utils/validators.js
  3. Update imports in all 5 files
  4. Run tests after each file update
  5. Remove old validation code
  6. Final test run - all pass
Result: Code duplication eliminated, tests still pass

---
  1. Ensure all 5 files have tests (add if missing)
  2. Extract common validation to utils/validators.js
  3. Update imports in all 5 files
  4. Run tests after each file update
  5. Remove old validation code
  6. Final test run - all pass
Result: Code duplication eliminated, tests still pass

---

Resources

资源

Templates

模板

  • resources/IMPLEMENTATION_PLAN_template.md
    - Implementation plan template
  • resources/commit_message_guide.md
    - Commit message examples
  • resources/tdd_workflow.md
    - TDD cycle reference
  • resources/IMPLEMENTATION_PLAN_template.md
    - 实现计划模板
  • resources/commit_message_guide.md
    - 提交信息示例
  • resources/tdd_workflow.md
    - TDD循环参考

Scripts

脚本

  • scripts/run_tests.sh
    - Test execution script
  • scripts/validate_commit.py
    - Pre-commit validation
  • scripts/phase_checker.sh
    - Phase completion validator

  • scripts/run_tests.sh
    - 测试执行脚本
  • scripts/validate_commit.py
    - 提交前验证脚本
  • scripts/phase_checker.sh
    - 阶段完成验证脚本

References

参考

  • Agent Skills vs. Multi-Agent
  • Test-Driven Development Skill (if available)
  • Git Worktrees Skill

Version: 1.0.0 Last Updated: December 12, 2025 Status: ✅ Active Maintained By: Claude Command and Control Project
  • Agent Skills vs. Multi-Agent
  • Test-Driven Development Skill (if available)
  • Git Worktrees Skill

版本: 1.0.0 最后更新: 2025年12月12日 状态: ✅ 活跃 维护方: Claude Command and Control Project