Antigravity最佳编程提示词大全(Top 50)完整指南

分类:AI功能使用

我不断听到聪明人悄悄谈论Antigravity,就像游戏中的隐藏关卡:它不只是一个编辑器,而是真正的AI Agent——可以在编辑器、终端甚至内置浏览器中规划、执行并复查你的代码更改。我花了一周时间深入使用它,把它当作技术主管而非聊天机器人来交流。这些是我的实战笔记和真正有效的50个提示词

📋 目录导航

  1. 入门必备提示词(10个) - 项目分析、代码解释、依赖审计
  2. 后端开发提示词(10个) - API搭建、数据库、缓存、队列
  3. 前端开发提示词(10个) - 组件、样式、动画、表单
  4. 调试提示词(10个) - 错误诊断、性能分析、日志追踪
  5. 测试提示词(10个) - 单元测试、集成测试、端到端测试

一、入门必备提示词:完整指南

说实话,我第一个小时把Antigravity当成聊天侧边栏来用,它表现得很敷衍。当我开始像技术主管一样分配任务——明确的目标、明确的文件、明确的输出——Agent就活过来了。如果你是新手,从这里开始,熟悉Mission Control(Agent管理器)和Artifacts(它在触碰你的代码前起草的计划/文档)。在让它运行前务必检查Artifacts。

1. 项目入门提示词(The Onboarding Prompt)

提示词:

Analyze my entire project structure and create a README.md that explains the architecture, key technologies used, and how to start the development server.

中文:分析我的整个项目结构,创建一个README.md,解释架构、使用的关键技术以及如何启动开发服务器。

效果:一次性生成了不错的README。我快速检查了启动脚本——它发现了一个缺失的环境变量并建议添加到文档中。很靠谱。

2. "像教小孩一样解释"提示词(The 'Explain It Like I'm 5' Prompt)

提示词:

Open utils.py and explain what the process_data function does. Create a text Artifact summarizing its inputs, outputs, and side effects.

中文:打开utils.py并解释process_data函数的作用。创建一个文本Artifact,总结其输入、输出和副作用。

技巧:如果你粘贴一个复杂函数,要求它注明副作用。那里是Bug藏身之处。

3. 技术栈审计提示词(The Tech Stack Auditor)

提示词:

Scan my package.json (or requirements.txt) and list all dependencies. Flag any that are outdated or deprecated and suggest modern alternatives.

中文:扫描我的package.json(或requirements.txt)并列出所有依赖。标记任何过时或已弃用的依赖,并建议现代替代方案。

效果:它标记了一个旧的JWT库并链接了一个更安全的替代方案。我交叉检查了包页面,看起来是合法的。

4. 首次重构提示词(The First Refactor)

提示词:

Identify one file in this directory that violates DRY (Don't Repeat Yourself) principles. Create a plan to refactor it without breaking functionality.

中文:识别此目录中违反DRY(不要重复自己)原则的一个文件。创建一个重构计划,不破坏功能。

技巧:务必检查Artifact。不要跳过阅读它。

5. 注释生成提示词(The Commentator)

提示词:

Go through auth_service.js and add JSDoc/Docstring comments to every function that lacks them. Infer the types from the code logic.

中文:遍历auth_service.js,为每个缺少注释的函数添加JSDoc/Docstring注释。从代码逻辑推断类型。

效果:不是很华丽的工作,但未来的我会感谢自己。

6. 快速修复提示词(The Quick Fix)

提示词:

I have a syntax error in App.tsx that I can't find. Scan the file, fix the error, and explain what was wrong.

中文:我在App.tsx中有一个找不到的语法错误。扫描文件,修复错误,并解释问题所在。

效果:它发现了prop后面的一个多余逗号。节省了两分钟;尊严得以保全。

7. 代码风格执行提示词(The Style Enforcer)

提示词:

Create a .prettierrc (or flake8 config) file for this project with standard industry best practices, then run the formatter on all files.

中文:为这个项目创建一个符合行业标准最佳实践的.prettierrc(或flake8配置)文件,然后对所有文件运行格式化程序。

注意:浏览一下配置——它有时会把行长度设置为80,我个人会调到100。

8. 学习伴侣提示词(The Learning Companion)

提示词:

I want to learn how this API middleware works. Walk me through the code execution flow step-by-step using a temporary log file.

中文:我想学习这个API中间件是如何工作的。使用临时日志文件逐步引导我了解代码执行流程。

效果:临时日志在你不想在生产代码中留下嘈杂的console.log时非常有用。

9. 环境设置提示词(The Environment Setup)

提示词:

Check if I have all necessary environment variables set up for this project. If not, create a .env.example file based on the code's usage of process.env.

中文:检查我是否为这个项目设置了所有必要的环境变量。如果没有,根据代码中process.env的使用情况创建一个.env.example文件。

效果:它漏掉了一个在shell脚本中引用的环境变量。所以还是要浏览一下。

10. "Hello World" Agent提示词(The 'Hello World' Agent)

提示词:

Create a simple Python script that prints 'Hello Antigravity', run it in the terminal, and show me the output.

中文:创建一个简单的Python脚本,打印'Hello Antigravity',在终端运行它,并显示输出。

效果:傻?是的。但它证明了终端访问有效且权限正常。

💡 专业提示

在Antigravity中,Artifact是契约。在Agent运行前批准或编辑它。那是你防止奇怪偏差的护栏。

二、后端开发提示词:最佳实践

后端是Antigravity感觉最像一个能干且不会累的初级开发者的地方。它擅长多文件编辑和schema工作,只要你给它清晰的约束。我在Node/Express和Python栈上测试了这些。

11. API脚手架提示词(The API Scaffolder)

提示词:

Plan and carry out a RESTful API endpoint for POST /users in Express.js. It should validate input using Zod, hash passwords with bcrypt, and save to the MongoDB database.

中文:规划并执行Express.js中POST /users的RESTful API端点。它应该使用Zod验证输入,用bcrypt哈希密码,并保存到MongoDB数据库。

反应:Antigravity快速编写了Zod schemas和必要的连接。当我要求它添加速率限制时,它干净地更新了中间件。

12. 数据库架构师提示词(The Database Architect)

提示词:

Analyze my current database schema. Propose a new table for 'UserPreferences' and write the SQL migration script to link it to the 'Users' table.

中文:分析我当前的数据库schema。为'UserPreferences'提出一个新表,并编写SQL迁移脚本将其链接到'Users'表。

反应:它建议了一个我不会记得添加的复合索引。始终检查。

13. 缓存集成提示词(The Caching Integrator)

提示词:

Add Redis caching to the GET /products endpoint. Cache for 5 minutes and invalidate on any POST/PUT/DELETE to products.

中文:为GET /products端点添加Redis缓存。缓存5分钟,并在任何对products的POST/PUT/DELETE时失效。

反应:它正确地设置了缓存键策略,并在写操作时添加了失效逻辑。

14. 队列管理提示词(The Queue Manager)

提示词:

Set up a BullMQ job queue for sending welcome emails. Create the producer in the signup route and a separate worker file.

中文:设置一个用于发送欢迎邮件的BullMQ作业队列。在注册路由中创建生产者,并创建一个单独的worker文件。

反应:它甚至添加了重试逻辑和死信队列处理。

15. 认证专家提示词(The Auth Expert)

提示词:

Implement JWT authentication with refresh tokens. Include middleware for protected routes and a token refresh endpoint.

中文:实现带刷新令牌的JWT认证。包括受保护路由的中间件和令牌刷新端点。

反应:完整的实现,包括令牌黑名单和安全的httpOnly cookie处理。

16. 错误处理提示词(The Error Handler)

提示词:

Create a centralized error handling middleware for Express. It should catch all errors, log them appropriately, and return consistent JSON error responses.

中文:为Express创建一个集中的错误处理中间件。它应该捕获所有错误,适当地记录它们,并返回一致的JSON错误响应。

反应:它区分了操作错误和编程错误,并相应地处理它们。

17. 数据验证提示词(The Validator)

提示词:

Create Zod schemas for all my API endpoints based on the current route handlers. Put them in a shared validation folder.

中文:根据当前的路由处理程序,为我所有的API端点创建Zod schemas。把它们放在一个共享的validation文件夹中。

反应:它分析了请求体并推断出正确的类型,甚至添加了自定义错误消息。

18. 日志系统提示词(The Logger)

提示词:

Set up Winston logging with different levels for development and production. Include request logging middleware and error tracking.

中文:设置Winston日志,为开发和生产环境使用不同级别。包括请求日志中间件和错误跟踪。

反应:它添加了日志轮换和结构化JSON日志格式。

19. 速率限制提示词(The Rate Limiter)

提示词:

Add rate limiting to my API. Use a sliding window algorithm, limit to 100 requests per minute per IP, and return appropriate headers.

中文:为我的API添加速率限制。使用滑动窗口算法,每个IP每分钟限制100个请求,并返回适当的头信息。

反应:它使用了express-rate-limit并正确配置了Redis存储以便跨实例共享。

20. 文件上传提示词(The File Uploader)

提示词:

Implement file upload to S3 with multer. Include file type validation, size limits, and return the uploaded file URL.

中文:使用multer实现文件上传到S3。包括文件类型验证、大小限制,并返回上传的文件URL。

反应:它甚至添加了带进度跟踪的流式上传和适当的CORS配置。

💡 后端提示技巧

对于后端任务,始终指定你使用的框架和数据库。Antigravity会根据你的技术栈定制解决方案。

三、前端开发提示词:技巧与方法

前端是Antigravity可能让你惊喜(或者生成大量样板代码)的地方。技巧是具体说明组件边界和设计系统,这样Agent就不会默认使用一些它在训练中见过的通用Bootstrap外观。

21. 组件工厂提示词(The Component Factory)

提示词:

Create a reusable Button component in React with TypeScript. Support variants (primary, secondary, danger), sizes (sm, md, lg), loading state, and disabled state.

中文:用React和TypeScript创建一个可复用的Button组件。支持变体(primary、secondary、danger)、尺寸(sm、md、lg)、加载状态和禁用状态。

反应:它生成了一个干净的组件,带有正确的TypeScript类型和适当的可访问性属性。

22. 表单向导提示词(The Form Wizard)

提示词:

Build a multi-step registration form using React Hook Form and Zod validation. Include progress indicator and ability to go back to previous steps.

中文:使用React Hook Form和Zod验证构建一个多步骤注册表单。包括进度指示器和返回上一步的能力。

反应:它正确处理了步骤之间的状态持久化和验证。

23. 响应式大师提示词(The Responsive Master)

提示词:

Convert my desktop-only dashboard layout to be fully responsive. Use Tailwind breakpoints and ensure it works on mobile, tablet, and desktop.

中文:将我的仅桌面版仪表板布局转换为完全响应式。使用Tailwind断点,确保它在移动端、平板和桌面上都能工作。

反应:它添加了适当的断点和移动端优先的样式。

24. 动画工程师提示词(The Animator)

提示词:

Add smooth page transitions using Framer Motion. Include fade-in for new pages and slide animations for modals.

中文:使用Framer Motion添加平滑的页面过渡。包括新页面的淡入和模态框的滑动动画。

反应:动画感觉很自然,它甚至添加了减少动效的媒体查询支持。

25. 状态管理提示词(The State Manager)

提示词:

Set up Zustand for global state management. Create stores for user auth, shopping cart, and UI preferences with TypeScript.

中文:设置Zustand进行全局状态管理。用TypeScript为用户认证、购物车和UI偏好创建stores。

反应:它正确分离了关注点,并添加了持久化中间件。

26. 数据获取提示词(The Data Fetcher)

提示词:

Implement data fetching with React Query. Create custom hooks for CRUD operations on the /products endpoint with proper error handling and loading states.

中文:使用React Query实现数据获取。为/products端点的CRUD操作创建自定义hooks,带有正确的错误处理和加载状态。

反应:它添加了乐观更新和适当的缓存失效。

27. 可访问性审计提示词(The Accessibility Auditor)

提示词:

Audit my components folder for accessibility issues. Fix any missing ARIA labels, keyboard navigation problems, and color contrast issues.

中文:审计我的组件文件夹的可访问性问题。修复任何缺失的ARIA标签、键盘导航问题和颜色对比问题。

反应:它找到了几个我不知道的问题并适当地修复了它们。

28. 暗黑模式提示词(The Dark Mode Implementer)

提示词:

Add dark mode support to my app using CSS variables and a context provider. Include system preference detection and manual toggle.

中文:使用CSS变量和context provider为我的应用添加暗黑模式支持。包括系统偏好检测和手动切换。

反应:它创建了一个干净的实现,带有localStorage持久化。

29. 性能优化提示词(The Performance Optimizer)

提示词:

Analyze my React app for performance issues. Add React.memo, useMemo, and useCallback where appropriate. Set up code splitting for routes.

中文:分析我的React应用的性能问题。在适当的地方添加React.memo、useMemo和useCallback。为路由设置代码分割。

反应:它识别出了不必要的重新渲染并正确优化了它们。

30. 国际化提示词(The Internationalization Expert)

提示词:

Set up i18n using react-i18next. Extract all hardcoded strings from my components into translation files for English and Spanish.

中文:使用react-i18next设置i18n。从我的组件中提取所有硬编码字符串到英语和西班牙语的翻译文件中。

反应:它甚至处理了复数和日期格式化。

💡 前端提示技巧

提及你的设计系统或UI库(Tailwind、Material UI等)。Antigravity会尊重你的约束而不是生成冲突的样式。

四、调试提示词:轻松排错

我到了Antigravity后才意识到它调试得有多好。它可以读取日志、追踪执行、隔离故障,甚至提出假设。我一直用它来捕捉那些在午夜时让我抓狂的竞态条件。

31. 错误诊断提示词(The Error Doctor)

提示词:

I'm getting this error: [paste error]. Analyze my codebase, find the root cause, and fix it. Explain what went wrong.

中文:我遇到了这个错误:[粘贴错误]。分析我的代码库,找到根本原因,并修复它。解释出了什么问题。

反应:它追踪到了一个在4个文件之前导入的循环依赖。我从来不会自己找到那个。

32. 日志侦探提示词(The Log Detective)

提示词:

Add strategic console.log statements to trace the data flow through my checkout process. Help me understand where the cart total becomes NaN.

中文:添加策略性的console.log语句来追踪数据流经我的结账流程。帮我理解购物车总额在哪里变成NaN的。

反应:它在每个转换点添加了日志,我在几分钟内就发现了问题。

33. 内存泄漏猎手提示词(The Memory Leak Hunter)

提示词:

My React app's memory usage keeps growing. Analyze my components for potential memory leaks from subscriptions, event listeners, or timers.

中文:我的React应用内存使用持续增长。分析我的组件,查找订阅、事件监听器或定时器可能导致的内存泄漏。

反应:它找到了一个没有在useEffect中清理的WebSocket连接。

34. 竞态条件侦探提示词(The Race Condition Detective)

提示词:

I have intermittent data inconsistency issues in my app. Analyze my async operations and identify potential race conditions.

中文:我的应用有间歇性的数据不一致问题。分析我的异步操作并识别潜在的竞态条件。

反应:它找到了一个可能在组件卸载后解析的Promise。

35. 网络调试提示词(The Network Debugger)

提示词:

My API calls are failing silently. Add proper error handling to all fetch calls and log the full request/response cycle.

中文:我的API调用在静默失败。为所有fetch调用添加正确的错误处理,并记录完整的请求/响应周期。

反应:它发现了一个CORS问题并建议了修复方案。

36. 类型检查提示词(The Type Checker)

提示词:

I have TypeScript errors that I don't understand. Analyze my types and fix any mismatches. Explain why the types were wrong.

中文:我有一些我不理解的TypeScript错误。分析我的类型并修复任何不匹配。解释为什么类型是错误的。

反应:它用清晰的解释修复了类型错误,我实际上学到了东西。

37. 依赖冲突提示词(The Dependency Conflict Resolver)

提示词:

npm install is failing with peer dependency conflicts. Analyze my package.json and suggest compatible versions for all packages.

中文:npm install因对等依赖冲突而失败。分析我的package.json并为所有包建议兼容的版本。

反应:它确定了确切的版本冲突并提供了解决方案。

38. 构建错误修复提示词(The Build Error Fixer)

提示词:

My production build is failing. Analyze the webpack/vite config and error logs to find and fix the issue.

中文:我的生产构建失败了。分析webpack/vite配置和错误日志,找到并修复问题。

反应:它发现了一个只在生产模式下出现的环境变量问题。

39. 数据库查询分析提示词(The Query Analyzer)

提示词:

My database queries are slow. Analyze the queries in my repository layer and suggest indexes or query optimizations.

中文:我的数据库查询很慢。分析我存储库层中的查询,并建议索引或查询优化。

反应:它识别出了N+1查询并用适当的join重写了它们。

40. 安全审计提示词(The Security Auditor)

提示词:

Audit my codebase for common security vulnerabilities: SQL injection, XSS, CSRF, exposed secrets, and insecure dependencies.

中文:审计我的代码库是否存在常见的安全漏洞:SQL注入、XSS、CSRF、暴露的密钥和不安全的依赖。

反应:它找到了一个硬编码的API密钥和几个未清理的输入。

⚠️ 调试提示

粘贴完整的错误消息和堆栈跟踪。Antigravity越了解上下文,它的诊断就越准确。

五、测试提示词:最大化效率

测试是我大多数周末消失的地方。Antigravity实际上减少了痛苦——它可以生成测试、运行测试、分析覆盖率,并建议缺失的边缘情况。不完美,但比从头开始好得多。

41. 单元测试生成提示词(The Unit Test Generator)

提示词:

Generate comprehensive unit tests for my utils/helpers.ts file using Jest. Cover all edge cases and error conditions.

中文:使用Jest为我的utils/helpers.ts文件生成全面的单元测试。覆盖所有边缘情况和错误条件。

反应:它生成了我不会想到的测试用例,包括边界值和null检查。

42. 集成测试提示词(The Integration Tester)

提示词:

Write integration tests for my authentication flow using Supertest. Test login, registration, token refresh, and logout.

中文:使用Supertest为我的认证流程编写集成测试。测试登录、注册、令牌刷新和登出。

反应:它正确设置了测试数据库并在测试之间清理。

43. E2E测试提示词(The E2E Tester)

提示词:

Create Playwright E2E tests for my checkout flow. Include tests for adding items, applying coupons, and completing purchase.

中文:为我的结账流程创建Playwright E2E测试。包括添加商品、应用优惠券和完成购买的测试。

反应:它使用了正确的等待策略并处理了异步操作。

44. Mock生成提示词(The Mock Generator)

提示词:

Create comprehensive mocks for my external API calls. Include realistic data that covers success and error scenarios.

中文:为我的外部API调用创建全面的mock。包括涵盖成功和错误场景的真实数据。

反应:mock看起来很真实,它甚至添加了网络延迟模拟。

45. 覆盖率分析提示词(The Coverage Analyzer)

提示词:

Analyze my test coverage report. Identify untested code paths and generate tests to increase coverage to 80%.

中文:分析我的测试覆盖率报告。识别未测试的代码路径,并生成测试以将覆盖率提高到80%。

反应:它针对具体的未覆盖行,并为它们编写了有意义的测试。

46. 测试重构提示词(The Test Refactorer)

提示词:

My tests are flaky and slow. Analyze and refactor them to be more reliable and faster. Remove any redundant assertions.

中文:我的测试不稳定且缓慢。分析并重构它们,使其更可靠、更快速。删除任何冗余的断言。

反应:它识别出了共享状态问题并正确隔离了测试。

47. API测试提示词(The API Tester)

提示词:

Generate API tests for all my REST endpoints. Include tests for authentication, validation errors, and success responses.

中文:为我所有的REST端点生成API测试。包括认证、验证错误和成功响应的测试。

反应:它创建了一个全面的测试套件,带有适当的设置和清理。

48. 组件测试提示词(The Component Tester)

提示词:

Write React Testing Library tests for my UserProfile component. Test rendering, user interactions, and error states.

中文:使用React Testing Library为我的UserProfile组件编写测试。测试渲染、用户交互和错误状态。

反应:它遵循了测试最佳实践,测试行为而不是实现。

49. 快照测试提示词(The Snapshot Tester)

提示词:

Set up snapshot testing for my UI components. Create meaningful snapshots that capture the important visual aspects.

中文:为我的UI组件设置快照测试。创建有意义的快照,捕捉重要的视觉方面。

反应:它创建了聚焦的快照,不会每次小改动都破坏。

50. 测试文档提示词(The Test Documenter)

提示词:

Analyze my test suite and generate documentation explaining what each test file covers. Create a testing guide for new contributors.

中文:分析我的测试套件并生成文档,解释每个测试文件覆盖的内容。为新贡献者创建测试指南。

反应:它创建了一个清晰的指南,包括如何运行测试和添加新测试的说明。

💡 测试提示技巧

指定你的测试框架(Jest、Vitest、Pytest等)和测试风格偏好(BDD、TDD)。Antigravity会相应调整生成的测试。

总结

如果你像我一样,关心获得可靠的Agent运行来进行写作、轻量级编码和浏览器检查,Antigravity是值得的——特别是一旦你调整好模型级别和终端策略。

关键要点:

  • 像技术主管一样提示:明确的目标、明确的文件、明确的输出
  • 始终检查Artifact:那是Agent运行前的契约
  • 指定技术栈:框架、库、数据库——越具体越好
  • 迭代提示:如果第一次不完美,要求它改进或添加功能
  • 使用/plan命令:让Agent先规划再执行,减少重试

把这些提示词加入你的工作流程,你会感受到Agent的魔力——没有炒作。