- Published on
你在错误地使用Cursor AI...
你在错误地使用Cursor AI...
2025年2月9日
🗞️
我最近发布了一篇对这篇文章的后续博文;本文依然是真实的。你需要了解这些才能掌握在几小时内实现同事数周产出的N倍技术,详见https://ghuntley.com/specs
我犹豫是否应该免费分享这些建议,但我还是决定突破这个犹豫并分享它。你在错误地使用Cursor。
在过去几周里,我与各级软件工程师进行了/zooms交流 - 从初级、到资深级别,一直到首席级别。
以下是我所观察到的:
- 使用Cursor作为Google搜索的替代品。
- 提示词描述不足,不知道如何引导结果,使用低层次思维如"请实现XYZ"。
- 将Cursor视为IDE,而不是将其视为自主代理。
- 对"你可以编程LLM输出结果"这一概念毫不知情。
- 不必要地使用礼貌用语("请"和"您能")对待它,仿佛它是人类。如果它搞砸了,就对它爆粗口 - 用全大写字母叫它小丑。这能舒缓心灵。
好吧,最后一点 - 它并不真正改变Cursor的输出结果,所以让我们专注于其他几点....
Cursor有一个相当强大的功能叫做Cursor Rules,它是一个被忽视/被误解的杀手级功能。通过在GitHub上快速搜索实现案例并探索社区论坛发现,人们使用它们的方式不正确 - 它们大致看起来像这样...
# WordPress PHP Guzzle Gutenberg .cursorrules prompt file
Author: <redacted>
## What you can build
E-commerce Store Integration Plugin: Create a WordPress plugin that integrates various e-commerce platforms using the Guzzle-based HTTP client, allowing users to manage products, orders, and inventory directly from their WordPress dashboard. Include Gutenberg blocks for adding product listings and shopping cart functionality.Social Media Auto Poster: Develop a plugin that automatically shares new WordPress posts to connected social media accounts by utilizing the Guzzle HTTP client for API interactions. Provide Gutenberg blocks for social media settings and customization of post content.Custom Form Builder with REST API Submission: Design a WordPress form builder plugin that creates custom forms with Gutenberg blocks and submits entries via the WP REST API. Include options for saving entries to external databases or services through the Guzzle client.SEO Optimization Toolkit: Build a plugin that offers SEO analysis and recommendations using external APIs accessed via Guzzle. Implement Gutenberg blocks showing SEO scores and suggestions for improving content directly in the editor.Content Syndication Hub: Offer a plugin that enables easy content syndication across multiple WordPress sites and external platforms, leveraging GUzzle for HTTP requests and REST API endpoints for managing syndication settings.Custom Analytics Dashboard: Create a WordPress plugin that presents a personalized analytics dashboard, pulling data from multiple third-party services using Guzzle. Utilize Gutenberg blocks to display graphs, statistics, and insights directly within the WordPress admin.Dynamic Content Importer: Develop a plugin that periodically imports and updates content from specified external sources using Guzzle. Provide Gutenberg blocks for configuring import settings, schedules, and display options for the imported content.Advanced Newsletter Integration: Implement a plugin that connects WordPress to various newsletter services using the Guzzle client, enabling automated email campaigns based on website activity. Include Gutenberg blocks for subscription forms and campaign management.Multilingual Content Manager: Design a plugin for managing multilingual content in WordPress, using the Guzzle client to access and translate content via external translation APIs. Gutenberg blocks can be used for displaying translated content and managing language settings.Real-Time Cryptocurrency Ticker: Create a Gutenberg block plugin that displays real-time cryptocurrency prices and market data by leveraging Guzzle to fetch data from financial APIs. Offer users customizable ticker settings directly within the WordPress dashboard.
## Benefits
## Synopsis
WordPress developers can create a plugin that integrates external APIs using Guzzle, adds custom WP REST endpoints, and introduces Gutenberg blocks, adhering to WordPress coding standards and optimizing code readability.
## Overview of .cursorrules prompt
The .cursorrules file provides guidelines for developing a WordPress plugin that includes a Guzzle-based HTTP client, WP REST endpoint additions, and new Gutenberg editor blocks. It emphasizes using WordPress coding standards for PHP, JavaScript, and TypeScript, with a preference for TypeScript over JavaScript. The file promotes functional programming paradigms and composition over inheritance while ensuring consistency with WordPress ecosystem best practices. Additionally, it stresses the importance of optimizing code for readability and employing type hinting in PHP code.
与其从"实现XYZ代码"的角度来使用Cursor,你应该考虑构建一个由数千条提示规则组成的"stdlib"(标准库),然后像Unix管道一样将它们组合在一起。
每个工程项目应该有的第一条规则是描述存放规则的位置的函数...
---
description: Cursor Rules Location
globs: *.mdc
---
# Cursor Rules Location
Rules for placing and organizing Cursor rule files in the repository.
<rule>
name: cursor_rules_location
description: Standards for placing Cursor rule files in the correct directory
filters:
# Match any .mdc files
- type: file_extension
pattern: "\\.mdc$"
# Match files that look like Cursor rules
- type: content
pattern: "(?s)<rule>.*?</rule>"
# Match file creation events
- type: event
pattern: "file_create"
actions:
- type: reject
conditions:
- pattern: "^(?!\\.\\/\\.cursor\\/rules\\/.*\\.mdc$)"
message: "Cursor rule files (.mdc) must be placed in the .cursor/rules directory"
- type: suggest
message: |
When creating Cursor rules:
1. Always place rule files in PROJECT_ROOT/.cursor/rules/:
.cursor/rules/ ├── your-rule-name.mdc ├── another-rule.mdc └── ...
2. Follow the naming convention:
- Use kebab-case for filenames
- Always use .mdc extension
- Make names descriptive of the rule's purpose
3. Directory structure:
PROJECT_ROOT/ ├── .cursor/ │ └── rules/ │ ├── your-rule-name.mdc │ └── ... └── ...
4. Never place rule files:
- In the project root
- In subdirectories outside .cursor/rules
- In any other location
examples:
- input: |
# Bad: Rule file in wrong location
rules/my-rule.mdc
my-rule.mdc
.rules/my-rule.mdc
# Good: Rule file in correct location
.cursor/rules/my-rule.mdc
output: "Correctly placed Cursor rule file"
metadata:
priority: high
version: 1.0
</rule>
现在,你可能想知道为什么。啊,那是因为人们没有意识到_你可以要求Cursor编写规则_。要构建你的"stdlib",你要像你的职业生涯取决于此一样,要求Cursor 编写规则并用学习到的知识更新规则。
目前的基础LLM模型我估计大约有45%的准确率,需要频繁引导。在完全自动化的YOLO模式下进行会话时,我对编写器的指示大致遵循以下步骤:
- 关于需求的详细讨论,并以编号的项目符号列出需求,以便在需要更改或出现问题时可以引用特定需求。
- 要求cursor将需求写入文件,以便在需要时可以重新注入到上下文窗口中。
- 将@file和@file-test附加到上下文中。具体指示Cursor"检查并描述文件"。
- 要求代理实现"XYZ"需求,编写测试和文档。
- 每次更改后运行构建和测试。
- 如果一切顺利,执行git提交(通过配置的规则)。
当一个需求成功实现后 - 很好,那又怎样?关键是当基础模型让你失望时的干预步骤,以及_在它做对时你所采取的行动_。
这是一场数字游戏,通过你的stdlib,你可以完全控制赔率
我知道你已经读了一段时间,所以这里是最终揭示。
当Cursor在干预后做对时,要求它编写规则或用其学习到的知识更新规则。
在我的单仓库中,我专门使用Nix。然而,Cursor不断推荐涉及Bazel和创建BUILD.bazel
文件的解决方案。在对Cursor进行严厉批评后,我要求它创建一条规则以确保这种情况不再发生。
---
description: No Bazel
globs: *
---
# No Bazel
Strictly prohibits any Bazel-related code, recommendations, or tooling.
<rule>
name: no_bazel
description: Strictly prohibits Bazel usage and recommendations
filters:
# Match any Bazel-related terms
- type: content
pattern: "(?i)\\b(bazel|blaze|bzl|BUILD|WORKSPACE|starlark|\\.star)\\b"
# Match build system recommendations
- type: intent
pattern: "build_system_recommendation"
# Match file extensions
- type: file_extension
pattern: "\\.(bzl|star|bazel)$"
# Match file names
- type: file_name
pattern: "^(BUILD|WORKSPACE)$"
actions:
- type: reject
message: |
Bazel and related tools are not allowed in this codebase:
- No Bazel build files or configurations
- No Starlark (.star/.bzl) files
- No Bazel-related tooling or dependencies
- No recommendations of Bazel as a build system
Please use Nix for build and dependency management.
- type: suggest
message: |
Instead of Bazel, consider:
- Nix for reproducible builds and dependencies
- Make for simple build automation
- Language-native build tools
- Shell scripts for basic automation
examples:
- input: "How should I structure the build?"
output: "Use Nix for reproducible builds and dependency management. See our Nix documentation for examples."
- input: "Can we add a Bazel rule?"
output: "We use Nix overlays instead of Bazel rules. Please convert this to a Nix overlay."
metadata:
priority: critical
version: 2.0
</rule>
从那一刻起,Cursor不再试图强制我使用Bazel。所以是的,你可以_控制和微调回复_。
另一件你可以做的事是提供指令,让你可以执行IF-THIS-THEN-THAT操作。这里有一个例子,当Cursor添加新文件时,它会自动调用我的软件许可工具来添加适当的版权头。
---
description: Depot Add License Header
globs: *
---
# Add License Header
Automatically add license headers to new files.
<rule>
name: add_license_header
description: Automatically add license headers to new files
filters:
- type: file_extension
pattern: "*"
- type: event
pattern: "file_create"
actions:
- type: execute
command: "depot-addlicense \"$FILE\""
- type: suggest
message: |
License headers should follow these formats:
Go files:
```go
// Copyright (c) 2025 Geoffrey Huntley <ghuntley@ghuntley.com>. All rights reserved.
// SPDX-License-Identifier: Proprietary
```
Nix files:
```nix
# Copyright (c) 2025 Geoffrey Huntley <ghuntley@ghuntley.com>. All rights reserved.
# SPDX-License-Identifier: Proprietary
```
Shell files:
```bash
# Copyright (c) 2025 Geoffrey Huntley <ghuntley@ghuntley.com>. All rights reserved.
# SPDX-License-Identifier: Proprietary
```
metadata:
priority: high
version: 1.0
</rule>
好吧,这很有趣但并不酷。如果我们在每个需求成功完成后自动提交到源代码控制会怎样?简单...
# Git Conventional Commits
Rule for automatically committing changes made by CursorAI using conventional commits format.
<rule>
name: conventional_commits
description: Automatically commit changes made by CursorAI using conventional commits format
filters:
- type: event
pattern: "build_success"
- type: file_change
pattern: "*"
actions:
- type: execute
command: |
# Extract the change type and scope from the changes
CHANGE_TYPE=""
case "$CHANGE_DESCRIPTION" in
*"add"*|*"create"*|*"implement"*) CHANGE_TYPE="feat";;
*"fix"*|*"correct"*|*"resolve"*) CHANGE_TYPE="fix";;
*"refactor"*|*"restructure"*) CHANGE_TYPE="refactor";;
*"test"*) CHANGE_TYPE="test";;
*"doc"*|*"comment"*) CHANGE_TYPE="docs";;
*"style"*|*"format"*) CHANGE_TYPE="style";;
*"perf"*|*"optimize"*) CHANGE_TYPE="perf";;
*) CHANGE_TYPE="chore";;
esac
# Extract scope from file path
SCOPE=$(dirname "$FILE" | tr '/' '-')
# Commit the changes
git add "$FILE"
git commit -m "$CHANGE_TYPE($SCOPE): $CHANGE_DESCRIPTION"
- type: suggest
message: |
Changes should be committed using conventional commits format:
Format: <type>(<scope>): <description>
Types:
- feat: A new feature
- fix: A bug fix
- docs: Documentation only changes
- style: Changes that do not affect the meaning of the code
- refactor: A code change that neither fixes a bug nor adds a feature
- perf: A code change that improves performance
- test: Adding missing tests or correcting existing tests
- chore: Changes to the build process or auxiliary tools
The scope should be derived from the file path or affected component.
The description should be clear and concise, written in imperative mood.
examples:
- input: |
# After adding a new function
CHANGE_DESCRIPTION="add user authentication function"
FILE="src/auth/login.ts"
output: "feat(src-auth): add user authentication function"
- input: |
# After fixing a bug
CHANGE_DESCRIPTION="fix incorrect date parsing"
FILE="lib/utils/date.js"
output: "fix(lib-utils): fix incorrect date parsing"
metadata:
priority: high
version: 1.0
</rule>
<!--
Copyright (c) 2025 Geoffrey Huntley <ghuntley@ghuntley.com>. All rights reserved.
SPDX-License-Identifier: Proprietary
-->
在过去的8小时里,我建立了一个相当大的"stdlib",它教会了Cursor关于我的代码库的知识,我正以越来越高的速率获得成功的结果和大奖。
你可以编程出更好的结果
10岁的儿子全程坐在我旁边,目不转睛地盯着屏幕,当我把我的解释直接1:1地输入到Cursor中,他的解释最贴切:
爸爸,这就像你在教它如何制造和骑自行车。首先你描述什么是踏板,它们的用途是什么,以及如何将它们安装到自行车上。当AI试图顺时针拧踏板时,你纠正它为逆时针拧,这样你就永远不必再做一次。最终,你将拥有一辆完全功能的自行车,它可以自己组装另一辆自行车,然后那辆自行车可以用来制造法拉利...
- 我的儿子
以下是我已经完成的工作:
- 了解如何调试nix表达式并进行逐步调试。
- 使用我的约定自动提交。我不再需要输入git commit。
- 自动编写DNS记录并部署它们。
- 如何使用我的单仓库约定通过copybara从GitHub添加//third_party包,并使用nix构建它。
- 如何自主修补Linux内核,以支持我Thinkpad笔记本电脑上的wwlan0调制解调器。
- 如何使用buildGo在nix中构建任何golang应用程序。
- 如何使用_yant_s自动编写nix测试。
- 如何自动格式化和检查代码。
- 如何处理各种预提交失败以及在它们失败时采取的步骤。
现在我已经能够让Cursor每次拉动杠杆都带来大奖,我距离能够编写高级需求以自动构建网站、配置DNS并自动部署基础设施只有一步之遥。一块乐高接一块乐高,我正在提高抽象层次并永久解决问题类别。在待办事项上释放1000个并发的cursors/自主代理的时刻不远了...
如果你认为上面的项目符号列表不令人印象深刻 - 也许你错过了更大的图景?基础模型每天都在变得更好,未来的开发者工具将与我们今天拥有的IDE不同 - 是审查来自1000个正在并行自主完成待办事项的代理的PR。
我希望这些见解能帮助你避开即将席卷我们行业的ngmi。本博文中的所有规则和我的stdlib都是由Cursor自己编写的,当它出错时,我要求它用学到的教训更新stdlib。
[
编程世界的终结
O'Reilly MediaTim O'Reilly
](https://www.oreilly.com/radar/the-end-of-programming-as-we-know-it/?ref=ghuntley.com)
继续前进,构建你的stdlib - 一砖一瓦!
附:社交媒体 @ https://x.com/GeoffreyHuntley/status/1888296890552447320