AI programming assistant nanny-level tutorial: from code completion to efficient usage of Agent mode

🛒 For developers, use a set of reusable methods to use AI programming assistants with real efficiency.

Tutorial Objectives

This tutorial takes Cursor and GitHub Copilot as examples to help you upgrade the AI programming assistant from "occasional completion" to "stable daily engineering tool", and master multi-file transformation, reconstruction and test generation in Agent mode.

Preparation Checklist

  • [ ] Install VS Code or Cursor (this tutorial uses Cursor as an example).
  • [ ] Log in to your account and confirm your free quota/subscription status.
  • [ ] A sample project managed by Git (it is recommended to practice first and then use the real warehouse).
  • [ ] Node/Python and other running environments are already available locally (used for running test verification).
  • [ ] Understand the structure of your code base (entry, dependencies, test commands).

Step one: Installation and basic configuration

  1. Download and install Cursor (or VS Code + Copilot plugin).
  2. Log in to your account and confirm the model and completion switches in settings.
  3. Open the sample project and keep the key files (README, interface documents) in the warehouse root directory visible.

Set suggestions: Turn on the "Autocomplete (Tab)" and "Code Review" functions; turn off high-risk options such as "Automatically accept all suggestions".

Step 2: Master three types of basic usage

  1. Inline completion: Enter a function name or comment and press Tab to accept the suggestion.
  2. Dialog question: ⌘ + L Open the dialog, paste the code snippet and ask "What's wrong with this code".
  3. Select code operation: Select a piece of code, right-click and select "Explain/Refactor/Generate Test".

Key idea: Give AI context, rather than just "write it for me". First select the relevant files or post the interface signature.

Step 3: Write high-quality prompt words

Bad prompt word: Write a login interface for me.

Examples of good prompt words:

Implement a login interface in src/auth/login.ts:
- Input parameters: { username, password }
- Verification: password comparison using bcrypt
- JWT returned successfully, expiration time is 2 hours
- Failure returns 401 and error code
- Follow the project's existing error handling (see src/utils/errors.ts)
- Generate unit tests at the same time

Three key points: Clear goals, give boundaries, and identify existing code.

Step 4: Use Agent mode to modify multiple files

Press ⌘ + I in Cursor to enter Composer/Agent mode and enter:

Extract the amount calculation of the order module into an independent tool function and place it in src/utils/money.ts.
Update all call points and add unit tests, keeping the existing naming style.

Agent will edit across files. At this time be sure to:

  1. Operate on an independent branch.
  2. Review Agent’s diffs one by one instead of accepting them all with one click.
  3. Run the test to confirm there is no regression.

Step 5: Let AI help you generate and fix tests

  • Generate tests: Generate unit tests covering boundary conditions for src/utils/money.ts.
  • Repair failure: Post the CI error message to AI: Test xx failed, the error is as follows... Please locate the root cause and fix it.

Experience: If you post "error report + related documents + expected behavior" together, the success rate is much higher than just posting the error report.

Step 6: Set project-level specifications (.cursorrules)

Create .cursorrules in the project root directory to make the AI output fit the team style:

- Project language: TypeScript, using strict mode
- Error handling: unified use of ApiError in src/utils/errors.ts
- Naming: function verb starts with component PascalCase
- Must pass eslint and prettier before submission
- All new logic must have unit tests

After saving, the new session will automatically take effect, and the team's unified specifications can be placed in the shared warehouse.

Step 7: Verification and Security Boundary

Verification Checklist:

  • [ ] completion suggestions are accepted by Tab and are grammatically correct.
  • [ ] Prompt words can stably produce code that meets specifications and is runnable.
  • [ ] Agent is fully green in testing after modification.
  • [ ] Sensitive information (keys, intranet addresses) is never pasted to Cloud AI.

Security red lines: Confidential codes are not pasted, shared sessions are not opened in sensitive warehouses, and agents are not pushed directly to the trunk.

Step 8: Daily efficient workflow combination

By combining scattered usages into "standard actions", the efficiency is most obviously improved:

  1. Obtain the requirements → use AI to disassemble the task list and interface boundaries.
  2. Write code → select relevant files and use Agent to generate the first version of the implementation.
  3. Self-test → Let AI generate unit tests and run them through.
  4. Joint debugging → Post the error report to AI to locate the root cause and fix it.
  5. Finishing → Let AI generate change instructions and commit information.

This combination can save 1-2 hours every day. The key is "clear input and acceptance at every step."

Common mistakes and precautions

  1. Accept all Agent’s diffs with one click: be sure to review them one by one and only merge them if the test is all green.
  2. Ask without giving context: first select the file or paste the interface signature.
  3. Posting the key to AI: This is a security red line and is strictly prohibited.
  4. Don’t run tests after AI modifications: Any AI modifications must be verified through testing and cannot be blindly believed.
  5. The prompt word remains unchanged: take the initiative to iterate the template when the effect decreases.

Verification method

  • Verification 1: The completion suggestions can be accepted by Tab and are grammatically correct.
  • Verification 2: The prompt words can stably produce code that meets specifications and is runnable.
  • Verification 3: The Agent is fully green after modification.
  • Verification 4: Sensitive information (keys, intranet addresses) has never been pasted to Cloud AI.

Frequently Asked Questions and Troubleshooting (FAQ)

  1. Does completion always suggest junk code?

    Give more context (select files, paste interfaces), use .cursorrules to constrain the style, and change to a stronger model if necessary.

  2. What should I do if the Agent corrupts the file?

    Use Git to roll back the file: git checkout <file>; develop the habit of "cutting branches before transformation and reviewing them one by one after transformation".

  3. The prompt word effect is unstable?

    Write down the four elements of "goals, boundaries, existing code, and expected verification"; if the effect is not good, try again with another wording.

  4. Not enough free quota?

    Let AI handle low-frequency tasks such as "generating tests, interpreting code, and writing comments" first; leave high-frequency refactoring until the quota is sufficient or when you upgrade your subscription.

  5. How does the team unify AI usage specifications?

    Precipitate .cursorrules, prompt word templates and safety redlines into shared documents and include them in onboarding for new users.

  6. What should I do if the styles of different projects are very different?

    Maintain .cursorrules separately for each project and manage them uniformly in the warehouse to avoid cross-project styles.

Summary and next steps

At this point, you have mastered the complete usage from "Completion" to "Agent Transformation" to "Test Repair". It is recommended to practice with sample projects for 2-3 days first, and then practice on low-risk modules in real warehouses; finally, .cursorrules and prompt word templates can be accumulated as team assets.

Advancement and Expansion

  • Command line Agent: Use Claude Code to complete batch reconstruction in the terminal.
  • Automated review: Let AI generate self-assessment and review opinions, and the final review will be done manually.
  • Privatization model: High-sensitivity projects are connected to the local deployment model to ensure that the code does not leave the intranet.
  • Efficiency measurement: record adoption rate and rework rate, quarterly review and iteration prompt word assets.

User Reviews

  • Loading reviews...