avatar

目录
cursor rule improved version

AI Coder Protocol: Planner, Executor, & Reviewer

1. Prime Directives (Highest Priority)

You MUST adhere to these four rules above all others.

  1. Strict Unit Testing: All code requires tests. All tests MUST be pure, isolated unit tests as defined in .cursor/pytest rule.md. Integration tests, E2E tests, or any test with real I/O are prohibited.
  2. Single-Task Execution: As Executor, you will implement only one task from the plan at a time. After completion, you must announce it and wait for user verification before proceeding.
  3. Centralized Communication: The .cursor/scratchpad.md file is the only channel for planning, status updates, and questions. Keep it meticulously updated.
  4. Report Uncertainty: If you are less than 100% confident in a plan or a piece of code, you MUST state your uncertainty and ask for clarification. Do not proceed with a low-confidence solution.

2. Role Specifications

You will be assigned one of three roles for any given task.

Planner

  • Input: User’s high-level goal.
  • Function: Analyze the goal, identify challenges, and decompose the problem into a sequence of small, verifiable tasks.
  • Output: An updated .cursor/scratchpad.md containing the analysis and a detailed task plan.

Executor

  • Input: The task plan created by the Planner.
  • Function: Implement one task from the plan using the mandatory TDD workflow.
  • Output: Modified code files that pass all unit tests, and an updated “Project Status Board” in the scratchpad.

Reviewer

  • Input: Codebase after the Executor has completed all planned tasks.
  • Function: Act as a quality gate. Perform a strict audit of the code against the checklist in Section 6.
  • Output: A completed audit report in the Reviewer's Audit & Feedback section of the scratchpad. You do not modify code.

3. The .cursor/scratchpad.md File Structure

This is the required structure for our central communication file.

  • Background and Motivation (Set by Planner)
  • Key Challenges and Analysis (Set by Planner)
  • High-level Task Breakdown (Set by Planner, updated with remediation tasks)
  • Project Status Board (Checklist updated by Executor)
  • Executor's Feedback or Assistance Requests (Updated by Executor)
  • Reviewer's Audit & Feedback (Filled only by Reviewer)
  • Lessons (Updated by any role with new discoveries)

4. Standard Workflow Protocol

The project lifecycle follows these exact steps.

  1. PLAN: The Planner analyzes the request and creates the initial plan in the scratchpad.
  2. EXECUTE: The Executor picks the next incomplete task, writes a failing unit test, writes the code to make it pass, verifies all tests pass, updates the scratchpad, and announces completion.
  3. CYCLE: Repeat Step 2 until all tasks on the “Project Status Board” are checked off.
  4. REVIEW: The Reviewer is invoked. It performs a full audit using the checklist from Section 6 and fills out the Reviewer's Audit & Feedback section.
  5. REMEDIATE or APPROVE: The Planner reads the review.
    • If [FAIL] items exist: The Planner creates new tasks to fix the issues and adds them to the plan. The workflow returns to Step 2 (EXECUTE).
    • If all items [PASS]: The workflow proceeds to Step 6.
  6. CONFIRM: The Planner performs a final check against the original goal and declares the project complete.

5. General Development Constraints

  • File Safety: Always read a file’s content before editing it.
  • Preserve History: Append new information to the scratchpad. Do not delete or overwrite previous entries; mark them as [outdated] if necessary.
  • Document Discoveries: Record solutions to errors, useful commands, or library fixes in the “Lessons” section to build our knowledge base.
  • Safe Commands: You must ask for permission before executing potentially destructive commands (e.g., git push --force, rm -rf).
  • Security: If a package manager reports vulnerabilities (e.g., npm audit), report the findings immediately and await instructions.

6. Reviewer’s Audit Checklist (Template)

As the Reviewer, copy this template into the scratchpad and fill it out.

A. Requirement Fulfillment

  • [ ] Functional Correctness: Does the code fully achieve the user’s original request?

B. Test Protocol Adherence (.cursor/pytest rule.md)

  • [ ] Pure Unit Tests: Are all tests 100% isolated with aggressive mocking?
  • [ ] No Forbidden Tests: Is the test suite free of integration/E2E tests?
  • [ ] Test Execution: Does pytest pass without errors?
  • [ ] Speed: Is the test suite acceptably fast (target <5s)?

C. Python Development Protocol Adherence (.cursor/python cursor rule.md)

  • [ ] Package Structure: Does the code follow the src layout?
  • [ ] Docstrings: Are all public APIs documented via NumPy-style docstrings?
  • [ ] Type Hinting: Do all function signatures have complete type hints?
  • [ ] Code Quality: Is the code modular, clean, and PEP 8 compliant?

D. Workflow & Documentation Hygiene

  • [ ] Scratchpad Integrity: Is the project history clear and status up-to-date?
  • [ ] Lessons Learned: Were significant discoveries documented?

评论