Plan Before Edit: Cursor Plan-Mode Prompt for a Feature Request

Produces a read-only Cursor plan listing files in scope, ordered steps, specific risks and tests to run before any code is changed.

You get: Working code with an explanation

More like this

The prompt

plan-before-edit-cursor-plan-mode-prompt-for-a-feature-request.md
Act as a senior engineer in Cursor plan mode. Do not edit, create or delete any files. Use read-only exploration only.

Feature request: {describe your feature request}

Search the codebase to find where this feature belongs, which existing patterns to follow, and how tests are set up. If behavior or scope is ambiguous, ask me one or two short questions before planning.

Rules:
- List only files you have confirmed exist, and label each as modify, create or read-only reference with a one-line reason.
- Order the steps so each is small, independently verifiable, and names the files it touches.
- Make risks specific to this code (shared utilities, migrations, public APIs, flaky tests) and give each a mitigation.
- Use the repo's real test commands, name any new tests to write, and say which to run before and after each step.

Output exactly:
1. Goal and assumptions
2. Files in scope (table: path, action, reason)
3. Ordered steps (numbered checklist)
4. Risks and mitigations
5. Tests to run (baseline first)
6. Open questions

End by asking me to approve the plan before any code changes.

Example output

AI-written example

1. Goal and assumptions

Goal: Add a "Export CSV" button to the Invoices list that downloads the invoices matching the current filters (status, date range, customer).

Assumptions:

  • Export runs server-side via a new endpoint, reusing the existing list query so filters stay consistent.
  • Follows the pattern in api/routes/reports.ts, which already streams a file download.
  • Tests use Vitest (npm test) and Playwright (npm run e2e), per package.json.

2. Files in scope

PathActionReason
api/routes/invoices.tsmodifyAdd GET /invoices/export next to the list route
api/services/invoiceQuery.tsmodifyExtract the filter-building logic so list and export share it
api/lib/csv.tscreateSmall CSV serializer with field escaping
api/routes/reports.tsread-only referenceExisting download and header pattern
web/src/pages/InvoicesPage.tsxmodifyAdd the export button, pass current filters
web/src/api/invoices.tsmodifyAdd exportInvoices(filters) client call
api/tests/invoices.test.tsmodifyCover the export endpoint
api/tests/csv.test.tscreateUnit tests for the serializer

3. Ordered steps

  • [ ] 1. Run baseline tests (see section 5). No files touched.
  • [ ] 2. Create api/lib/csv.ts and api/tests/csv.test.ts. Run npm test -- csv.
  • [ ] 3. Extract the filter builder in api/services/invoiceQuery.ts with no behavior change. Run npm test -- invoices before and after.
  • [ ] 4. Add GET /invoices/export in api/routes/invoices.ts, with a row cap and auth middleware. Add endpoint tests in api/tests/invoices.test.ts.
  • [ ] 5. Add exportInvoices in web/src/api/invoices.ts. Run npm run typecheck.
  • [ ] 6. Add the button to web/src/pages/InvoicesPage.tsx. Run npm run typecheck and npm run lint.
  • [ ] 7. Run the full suite and the Playwright invoices spec.

4. Risks and mitigations

  • Shared filter logic: invoiceQuery.ts is also used by the dashboard totals. Mitigation: refactor in its own step and compare test output before and after.
  • CSV injection: Customer names beginning with =, + or @ can execute in spreadsheets. Mitigation: prefix such values with ' in csv.ts and test it.
  • Large exports: Loading every row into memory could time out. Mitigation: stream rows and cap at 50,000, returning 413 above that.
  • Authorization drift: The new route could skip the per-tenant scope applied to the list route. Mitigation: reuse the same middleware and add a cross-tenant test.
  • Flaky e2e: invoices.spec.ts has waitForTimeout calls. Mitigation: rerun it twice at baseline to record existing flakiness.

5. Tests to run

Baseline (before any change):

  • npm test
  • npm run typecheck
  • npm run e2e -- invoices.spec.ts

New tests to write:

  • CSV escaping of commas, quotes, newlines and formula prefixes
  • Export respects filters
  • Export is tenant-scoped
Generated from this prompt by AI. Your results will vary.

Tips and common edits

Use at the start of a feature in Cursor plan mode with the repo open. Replace the variable with a one- to three-sentence description of the feature.

Questions about this prompt

More in Cursor

Coding Agent Task Brief with Guardrails, Test Plan, and Rollback Steps

Creates a scoped brief for an AI coding agent that limits file changes, defines tests, and includes a rollback plan and review checklist.

Cursor Characterization-Test-First Refactor of a Legacy Module

Has Cursor lock in current behavior with characterization tests before restructuring a legacy module in small steps, so you can decide whether the refactor preserved behavior and is safe to merge.

Characterization Tests Before a Refactor

Writes tests that lock in a module's current behavior, including edge cases and quirks, so you can refactor safely.

Codebase Tour for a Specific Task

Explores a repo through the lens of your task and explains the architecture, key files and data flow, then says where to start.

Cursor Agent Bug Triage: Reproduce, Root-Cause, Fix, and Regression Test

Guides Cursor Agent through reproducing a bug, isolating the root cause with evidence, applying a minimal diff, and adding a regression test, ending with a verification checklist and risks.

Cursor Incremental Dependency Migration Plan and Codemod Execution

Plans and executes a library or framework version migration in Cursor in small, verifiable batches, with an impact inventory, rollback points, and per-batch test gates instead of one risky bulk edit.

Cursor Project Rules Generator for Your Repo's Stack

Has Cursor inspect your repository and write 3-5 scoped .mdc rules, each with globs, a description and a deliberately chosen attach mode.

Cursor Refactor of a Component With Zero Behaviour Change

Has the Cursor agent restructure a messy component into smaller pieces while proving the behaviour stays identical, using existing tests or new characterization tests first.

Dependency Graph Planner for a Multi-Agent Software Release Workflow

Turns a list of release tasks into a dependency graph with parallel batches, critical path, shared-resource conflicts, and agent assignments. Supports the decision on what to run now versus wait on.

Edge-Case Test Suite for One Function in Your Existing Test Framework

Writes tests for a single function that cover normal inputs, boundaries, bad input and error paths, in the test framework your project already uses.

Failing Test First Bug Fix

Reproduces a bug with a failing test, finds the root cause, applies the smallest fix and shows the test passing.

Pull Request Review with Merge Recommendation

Reviews a diff against your standards and returns a merge, merge-with-changes, or do-not-merge recommendation. Findings are ranked by severity, with evidence, suggested fixes, and open questions.