Start your 3-day free trial
Sign up to experience all premium features at no cost.
*Available only to new users. Each user is limited to one trial.


To use Cursor for a small coding task, define one observable behavior, limit the files it may change, name the test command, ask for a read-only plan first, and approve only the smallest useful edit. Review the resulting diff as if it came from another developer, run the narrow test, and use Git to record what actually changed. The agent can inspect, edit, and run tools when allowed, but its fluent explanation is not evidence that the code is correct.[1][2]
This tutorial applies that workflow to one deliberately modest example: add integer range validation to a pure JavaScript parseRetryCount utility and add unit tests for the new boundary behavior. It does not involve a network request, a credential, a dependency update, generated files, or a broad refactor. Start with the wider guide to using AI for data and approval boundaries, and use the separate AI coding guide when the work is larger than one reviewable behavior.
Key Takeaways
- A small task has one behavior, a narrow file set, and a runnable acceptance check.
- Put goals, non-goals, allowed files, expected cases, and commands in a task card.
- Make the first pass read-only so the plan can be checked before edits begin; Cursor documents Plan Mode for this purpose.[4]
- Review the diff and terminal commands independently of the agent's summary.
- Run the smallest relevant test before considering a wider project gate.
- Treat Cursor checkpoints as convenient undo points, not a replacement for Git history.
Size is about uncertainty and blast radius, not the number of prompt words. A good agent task changes one behavior in code you can inspect, has a small set of likely files, and ends with a deterministic check. “Reject retry counts outside 0–10” is small. “Improve our retry system” is not: it might touch parsing, API contracts, persistence, UI copy, telemetry, and compatibility.
Use four questions before opening Agent mode:
Stop and split the task if it needs a secret, production access, schema migration, unfamiliar generated code, new dependency, destructive command, cross-service contract change, or a design decision no reviewer has made. Those are not impossible agent tasks; they simply need a different plan and approval level.
For the example, assume the repository already contains src/parseRetryCount.js and test/parseRetryCount.test.js. The intended contract is: accept an integer number or a base-10 integer string from 0 through 10, return the integer, and throw RangeError for a parsed integer outside that range. Existing behavior for malformed input remains unchanged. That last sentence prevents a “helpful” rewrite of all parsing semantics.
A task card turns an ambiguous chat into a reviewable change request. It also gives you a stable reference when the agent proposes adjacent cleanup. Cursor Rules can provide persistent project guidance, but task-specific acceptance criteria still belong in the request. Rules are reusable context; they do not replace a precise description of the current change.[3]
Goal
- Add 0–10 range validation to parseRetryCount.
Non-goals
- Do not refactor unrelated parsing code.
- Do not change exports, callers, dependencies, formatting config, or package scripts.
Allowed files
- src/parseRetryCount.js
- test/parseRetryCount.test.js
Expected behavior
- 0 and 10 are accepted.
- -1 and 11 throw RangeError.
- Existing malformed-input behavior stays unchanged.
Verification
- Run the existing unit-test command for parseRetryCount.
- Report the exact command and exit result.
Safety
- First inspect only. Do not edit or run commands until I approve the plan.
Do not list a file as allowed just because it is nearby. If the agent discovers that another file must change, it should explain why and wait. A changing file list is a scope change, not an implementation detail.
Begin in a question or planning interaction when available, or explicitly prohibit edits and commands. Ask Cursor to locate the function, its exports, direct callers, existing test conventions, and the narrow test command. Cursor's Agent documentation describes an environment that can search the codebase and use tools; those capabilities make the permission boundary more important, not less.[1][2] Cursor's current Plan Mode documentation describes a planning pass that researches the codebase and produces an implementation plan before coding.[4]
Use this prompt:
Inspect the task card and repository in read-only mode.
Return:
1. the current parseRetryCount behavior with file and line references;
2. existing tests that define malformed-input behavior;
3. the smallest proposed diff, file by file;
4. the exact narrow test command;
5. assumptions, risks, and any reason the allowed file list is insufficient.
Do not edit files, install packages, change Git state, or run commands yet.
Check the response against the repository. Open the cited files yourself. Confirm that the proposed test command exists in project configuration and that the agent has not confused a similarly named helper. If the plan says “clean up the parser while here,” remove that step. If it cannot identify existing malformed-input semantics, ask it to preserve them and propose characterization tests before changing behavior.
Once the plan is correct, authorize only the two files and the approved test. A useful instruction names what may happen and what requires another pause:
Implement the approved range check and tests only in the two allowed files.
Keep the public export and existing malformed-input behavior unchanged.
Do not reformat unrelated lines or introduce a dependency.
Show the diff before running anything. Ask before changing another file or command.
The implementation might add a check after existing parsing:
if (value < 0 || value > 10) {
throw new RangeError("retry count must be between 0 and 10");
}
That snippet is illustrative, not a patch for every codebase. The real function may use a different variable, error convention, or type policy. The agent should follow existing local patterns unless the task card explicitly changes them.
Reject automatic commands that are destructive, request elevated privileges without a task reason, access secrets, contact production systems, modify lockfiles unexpectedly, install a package, rewrite Git history, or run a broad formatter across unrelated files. Also pause when a command's effect is unclear. “It is probably safe” is not a permission model.
The agent summary is a navigation aid. The diff is the review object. Read every changed line and ask four groups of questions.
| Review area | Questions |
|---|---|
| Behavior | Are 0 and 10 accepted? Are -1 and 11 rejected? Did malformed input stay unchanged? |
| Failure path | Is the error type consistent? Is the message stable only where tests or callers require it? |
| Tests | Do tests cover lower/upper boundaries and values just outside them? Could a test pass without exercising the new branch? |
| Scope | Are only allowed files changed? Did formatting, exports, callers, snapshots, or config move unexpectedly? |
Look for coercion surprises. JavaScript comparisons can turn strings into numbers, so range validation placed before a deliberate parse may accidentally accept values the old function rejected. Look for broad truthiness checks that reject 0. Check whether NaN, decimals, whitespace, and signed strings already have defined behavior. The task card says to preserve those decisions, not redesign them.
Use the AI-generated code review checklist for dependencies, permissions, secrets, and dangerous commands. If the diff exceeds what you can confidently review, that is a stop condition even when the code looks plausible.
Run the approved unit test after the diff review. Record the exact command, exit code, and relevant result. Do not accept “tests should pass” or a green-looking summary as evidence. If the command is safe and already approved, Cursor may run it; you still inspect the output.
A reasonable sequence is:
parseRetryCount;The wider gate is a decision, not a ritual. A two-line pure-function change may need only the package test and standard CI. A shared utility with many callers may justify a broader suite. If unrelated tests fail, record them separately and determine whether the change reaches them before editing more code.
For stronger test design, the AI test-generation workflow explains normal, boundary, failure, and invariant cases. Do not ask the agent to weaken an existing assertion merely to turn the suite green.
After testing, inspect Git status and the diff from the repository, not only the chat panel. Confirm that untracked files, generated artifacts, lockfiles, and configuration were not changed unexpectedly. If your team creates a commit, the commit should contain only the reviewed scope and follow its normal review process.
Cursor checkpoints can help return to an earlier agent state. Treat them as editor-local recovery aids rather than version control: a checkpoint may not contain your manual changes, may be local to the editor, and is not a shared, reviewable project history.
Use checkpoints for short-lived experimentation. Use Git status, diffs, branches, commits, and remote review for durable provenance and collaboration. Before restoring any checkpoint, inspect what will be overwritten and preserve unrelated work.
The task is complete only when the intended behavior, reviewed diff, tests, and scope agree. Save a compact completion record:
Task: parseRetryCount range validation
Files reviewed: src/parseRetryCount.js, test/parseRetryCount.test.js
Behavior: accepts 0–10; rejects integers outside the range
Preserved: exports and malformed-input behavior
Test command: [exact command]
Result: [exit code and concise result]
Git scope: [reviewed diff or commit reference]
Open issues: [none or explicit items]
Reviewer: [name]
Stop and re-plan if the agent needs an unapproved file, cannot explain a change, proposes a dependency, encounters conflicting tests, requires credentials, asks for a destructive command, expands the public contract, or produces a diff too large to review as one behavior. Stopping is successful scope control, not failed automation.
Complete one small coding task from the attached task card.
Phase 1 is read-only: inspect code/tests and return a plan, risks, allowed-file
assessment, and exact verification command. Wait for approval.
After approval, edit only listed files. Preserve unrelated behavior and style.
Show the diff before commands. Ask before any extra file, dependency, network
access, elevated permission, destructive command, or broader test.
Finish with: changed behavior, files changed, exact commands and exits,
remaining assumptions, and Git diff scope. Never describe an unrun test as passed.
Before accepting, verify: one behavior; allowed files only; no surprise dependency; normal and boundary tests; failure path; exact command output; no unrelated formatting; clean explanation of any remaining unknown; and a Git diff that matches the task card.
It has one observable behavior, a narrow and reviewable file set, low external risk, and a deterministic test. If it changes several contracts or needs design choices, split or re-plan it.
Use a read-only question or planning interaction for discovery and risk review. Use an editing Agent only after the plan, file scope, and commands are approved. Mode names can change; the permission boundary matters more.
List allowed files and tell it to stop before touching anything else. Then verify repository status and the full diff. A prompt is an instruction; Git output is the evidence.
Refuse or pause for unclear, destructive, privileged, secret-reading, production-facing, dependency-installing, or Git-history-changing commands, and for any command outside the approved task card.
Check intended behavior, error paths, boundary tests, public interfaces, and every unexpected file or formatting change. Do not rely on the prose summary alone.
Start with the narrow unit test, then expand according to direct callers, repository policy, and blast radius. Record exact commands and results, and keep unrelated failures separate.
No. Treat checkpoints as local recovery points for agent changes. Git provides durable, inspectable project history and collaboration, so the checkpoint boundary should never replace a reviewed Git diff.
Sources checked 31 August 2026.
Sign up to experience all premium features at no cost.
*Available only to new users. Each user is limited to one trial.