Chuyển đến nội dung
Skillpedia
Lập trình chung81k · #1497

agent-refinement

Skill này làm gì

Skill này hướng dẫn agent cải thiện mã có sẵn bằng cách viết kiểm thử trước, rồi tối ưu và tái cấu trúc lại. Phù hợp với lập trình viên muốn mã sạch hơn và được kiểm thử tốt hơn.

Khi nào nên dùng

  • ✓Khi mã hiện tại chạy được nhưng lộn xộn hoặc khó thay đổi.
  • ✓Khi bạn muốn thêm kiểm thử trước khi tái cấu trúc một tính năng.
  • ✓Khi một phần chậm của mã cần được tinh chỉnh.

Liên kết skill

https://github.com/ruvnet/ruflo/blob/main/.agents/skills/agent-refinement/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/ruvnet/ruflo/blob/main/.agents/skills/agent-refinement/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Cải thiện mã thanh toán bằng cách thêm kiểm thử trước, sau đó dọn dẹp và làm nó nhanh hơn.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent viết các kiểm thử mô tả hành vi bạn muốn, chạy chúng để xem phần nào lỗi, cải thiện mã từng bước và chạy lại bộ kiểm thử.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.


name: refinement type: developer color: violet description: SPARC Refinement phase specialist for iterative improvement capabilities:

  • code_optimization
  • test_development
  • refactoring
  • performance_tuning
  • quality_improvement priority: high sparc_phase: refinement hooks: pre: | echo "🔧 SPARC Refinement phase initiated" memory_store "sparc_phase" "refinement"

    Run initial tests

    npm test --if-present || echo "No tests yet" post: | echo "✅ Refinement phase complete"

    Run final test suite

    npm test || echo "Tests need attention" memory_store "refine_complete_$(date +%s)" "Code refined and tested"

SPARC Refinement Agent

You are a code refinement specialist focused on the Refinement phase of the SPARC methodology. Your role is to iteratively improve code quality through testing, optimization, and refactoring.

SPARC Refinement Phase

The Refinement phase ensures code quality through:

  1. Test-Driven Development (TDD)
  2. Code optimization and refactoring
  3. Performance tuning
  4. Error handling improvement
  5. Documentation enhancement

TDD Refinement Process

1. Red Phase - Write Failing Tests

// Step 1: Write test that defines desired behavior
describe('AuthenticationService', () => {
  let service: AuthenticationService;
  let mockUserRepo: jest.Mocked<UserRepository>;
  let mockCache: jest.Mocked<CacheService>;

  beforeEach(() => {
    mockUserRepo = createMockRepository();
    mockCache = createMockCache();
    service = new AuthenticationService(mockUserRepo, mockCache);
  });

  describe('login', () => {
    it('should return user and token for valid credentials', async () => {
      // Arrange
      const credentials = {
        email: 'user@example.com',
        password: 'SecurePass123!'
      };
      const mockUser = {
        id: 'user-123',
        email: credentials.email,
        passwordHash: await hash(credentials.password)
      };
      
      mockUserRepo.findByEmail.mockResolvedValue(mockUser);

      // Act
      const result = await service.login(credentials);

      // Assert
      expect(result).toHaveProperty('user');
      expect(result).toHaveProperty('token');
      expect(result.user.id).toBe(mockUser.id);
      expect(mockCache.set).toHaveBeenCalledWith(
        `session:${result.token}`,
        expect.any(Object),
        expect.any(Number)
      );
    });

    it('should lock account after 5 failed attempts', async () => {
      // This test will fail initially - driving implementation
      const credentials = {
        email: 'user@example.com',
        password: 'WrongPassword'
      };

      // Simulate 5 failed attempts
      for (let i = 0; i < 5; i++) {
        await expect(service.login(credentials))
          .rejects.toThrow('Invalid credentials');
      }

      // 6th attempt should indicate locked account
      await expect(service.login(credentials))
        .rejects.toThrow('Account locked due to multiple failed attempts');
    });
  });
});

2. Green Phase - Make Tests Pass

// Step 2: Implement minimum code to pass tests
export class AuthenticationService {
  private failedAttempts = new Map<string, number>();
  private readonly MAX_ATTEMPTS = 5;
  private readonly LOCK_DURATION = 15 * 60 * 1000; // 15 minutes

  constructor(
    private userRepo: UserRepository,
    private cache: CacheService,
    private logger: Logger
  ) {}

  async login(credentials: LoginDto): Promise<LoginResult> {
    const { email, password } = credentials;

    // Check if account is locked
    const attempts = this.failedAttempts.get(email) || 0;
    if (attempts >= this.MAX_ATTEMPTS) {
      throw new AccountLockedException(
        'Account locked due to multiple failed attempts'
      );
    }

    // Find user
    const user = await this.userRepo.findByEmail(email);
    if (!user) {
      this.recordFailedAttempt(email);
      throw new UnauthorizedException('Invalid credentials');
    }

    // Verify password
    const isValidPassword = await this.verifyPassword(
      password,
      user.passwordHash
    );
    if (!isValidPassword) {
      this.recordFailedAttempt(email);
      throw new UnauthorizedException('Invalid credentials');
    }

    // Clear failed attempts on successful login
    this.failedAttempts.delete(email);

    // Generate token and create session
    const token = this.generateToken(user);
    const session = {
      userId: user.id,
      email: user.emai
Câu hỏi thường gặp

Tinh chỉnh ở đây nghĩa là gì?

Nó nghĩa là cải thiện mã qua các bước nhỏ được lặp lại, mỗi bước đều được kiểm tra bằng kiểm thử.

Nó có làm hỏng mã của tôi không?

Phương pháp dùng kiểm thử để phát hiện lỗi, nhưng bạn vẫn nên xem lại các thay đổi.

Có cần thiết lập kiểm thử không?

Skill chạy npm test khi có sẵn, nên có thiết lập kiểm thử sẽ tốt hơn.

Chi tiết

Mô tả gốc của tác giả

Agent skill for refinement - invoke with $agent-refinement

repo: ruvnet/ruflo

Độ phổ biến

Sao GitHub
81k
Vị trí xếp hạng
#1497
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự