cursor-docs.ruПопробовать Курсор бесплатно

Coding Agents

Собираем всё вместе

Неофициальный перевод раздела Cursor Learn. Мы переводим английский оригинал и чуть расширяем объяснения — это не материал от Cursor Inc.

Поздравляю — ты прошёл, как работать с coding agents.

Ты умеешь исследовать codebase, быстро собирать фичи, искать баги, ревьюить эффективнее и кастомизировать agents. Этот урок — сквозной пример, где всё сходится.

End-to-end пример

Ты пришёл в команду с ecommerce-платформой. Нужно добавить discount codes в checkout. Codebase незнакомый, шип — к концу недели.

Реалистичная история: сначала explore, потом plan, потом код, потом тесты, потом review, потом merge.

Шаг 1: Понять codebase

До любых правок исследуй checkout. Пусть agent соберёт mental map.

Explore the checkout flow

I need to add discount codes to our checkout flow. Before I make any changes, walk me through how checkout works. What components, API routes, and services are involved? Show me the data flow from the cart to payment confirmation.

Добивай follow-up’ами:

Find where discounts fit

How does our pricing calculation work in src/services/PricingService.ts? Where do we compute the order total, and where would a discount be applied in that flow?

Здесь работают техники из урока про понимание codebase: поиск → трассировка потока → summary.

Шаг 2: План фичи

Переключись в Plan Mode (Shift+Tab) и набросай работу:

# Discount codes

## Overview
Add discount code support to checkout. Users enter a code, the system validates it, and the discount is applied to the order total before tax.

## Approach
- Add DiscountService with validation logic (expiry, usage limits)
- Modify PricingService.calculateTotal() to accept optional discount
- Add discount code input to OrderSummary component
- Add /api/discount/validate endpoint

## Tasks
- [ ] Create discount_codes table migration
- [ ] Create DiscountService with applyDiscount()
- [ ] Add discount step to PricingService.calculateTotal()
- [ ] Add code input UI to OrderSummary component
- [ ] Add /api/discount/validate route
- [ ] Write tests for all discount types and edge cases

Подрежь план: убери слишком амбициозное для первой итерации. Сфокусируйся на core flow: ввести код → посчитать скидку → показать в summary. Потом Build.

Шаг 3: Debug failing edge case

После сборки один тест красный: stacking percentage + fixed-amount даёт разный total в зависимости от порядка скидок.

Debug Mode или прямой запрос:

Debug the root cause

The discount stacking test is failing. The same discounts produce different totals depending on application order. Find out why and fix the ordering of discount application in src/services/DiscountService.ts. Show me the before and after values at each step.

Принцип из урока про баги: не лечи симптомы — найди причину.

Шаг 4: Review и тесты

Перед пушем — self-review:

Self-review before pushing

Review all the changes I’ve made for the discount code feature. Check for bugs, missing error handling, edge cases, and consistency with existing patterns. What would a code reviewer flag?

Если есть cloud agents — запусти несколько на edge cases, которые легко пропустить: unicode в кодах, огромные значения скидок, concurrent usage. Они вернут покрытие кейсов и дыры — добей тестами до merge.

Шаг 5: Запиши rule

Ты кое-что выучил: percentage discounts должны применяться до fixed-amount, иначе результат зависит от порядка входа. Зафиксируй в rule, чтобы agent знал в следующий раз:

# Pricing rules

- Apply percentage discounts before fixed-amount discounts
- Order total must never go below $0
- See src/services/PricingService.ts for the canonical calculation pattern

Петля замкнулась: explore → plan → build → test → debug → review → knowledge в rules.

Продолжай строить

Лучший следующий шаг — взять это и применить на своём проекте.

Tools и модели меняются быстро, конкретные практики будут эволюционировать. Но skill сотрудничать с coding agents компаундится. Это уже один из ключевых навыков в software engineering.

Толкай границы того, что agents умеют — и будешь забирать максимум из каждого нового релиза моделей. Удачи, и оставайся любопытным.