我不断听到聪明人悄悄谈论Antigravity,就像游戏中的隐藏关卡:它不只是一个编辑器,而是真正的AI Agent——可以在编辑器、终端甚至内置浏览器中规划、执行并复查你的代码更改。我花了一周时间深入使用它,把它当作技术主管而非聊天机器人来交流。这些是我的实战笔记和真正有效的50个提示词。
说实话,我第一个小时把Antigravity当成聊天侧边栏来用,它表现得很敷衍。当我开始像技术主管一样分配任务——明确的目标、明确的文件、明确的输出——Agent就活过来了。如果你是新手,从这里开始,熟悉Mission Control(Agent管理器)和Artifacts(它在触碰你的代码前起草的计划/文档)。在让它运行前务必检查Artifacts。
提示词:
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。我快速检查了启动脚本——它发现了一个缺失的环境变量并建议添加到文档中。很靠谱。
提示词:
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藏身之处。
提示词:
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库并链接了一个更安全的替代方案。我交叉检查了包页面,看起来是合法的。
提示词:
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。不要跳过阅读它。
提示词:
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注释。从代码逻辑推断类型。
效果:不是很华丽的工作,但未来的我会感谢自己。
提示词:
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后面的一个多余逗号。节省了两分钟;尊严得以保全。
提示词:
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。
提示词:
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时非常有用。
提示词:
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脚本中引用的环境变量。所以还是要浏览一下。
提示词:
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栈上测试了这些。
提示词:
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和必要的连接。当我要求它添加速率限制时,它干净地更新了中间件。
提示词:
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'表。
反应:它建议了一个我不会记得添加的复合索引。始终检查。
提示词:
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时失效。
反应:它正确地设置了缓存键策略,并在写操作时添加了失效逻辑。
提示词:
Set up a BullMQ job queue for sending welcome emails. Create the producer in the signup route and a separate worker file.
中文:设置一个用于发送欢迎邮件的BullMQ作业队列。在注册路由中创建生产者,并创建一个单独的worker文件。
反应:它甚至添加了重试逻辑和死信队列处理。
提示词:
Implement JWT authentication with refresh tokens. Include middleware for protected routes and a token refresh endpoint.
中文:实现带刷新令牌的JWT认证。包括受保护路由的中间件和令牌刷新端点。
反应:完整的实现,包括令牌黑名单和安全的httpOnly cookie处理。
提示词:
Create a centralized error handling middleware for Express. It should catch all errors, log them appropriately, and return consistent JSON error responses.
中文:为Express创建一个集中的错误处理中间件。它应该捕获所有错误,适当地记录它们,并返回一致的JSON错误响应。
反应:它区分了操作错误和编程错误,并相应地处理它们。
提示词:
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文件夹中。
反应:它分析了请求体并推断出正确的类型,甚至添加了自定义错误消息。
提示词:
Set up Winston logging with different levels for development and production. Include request logging middleware and error tracking.
中文:设置Winston日志,为开发和生产环境使用不同级别。包括请求日志中间件和错误跟踪。
反应:它添加了日志轮换和结构化JSON日志格式。
提示词:
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存储以便跨实例共享。
提示词:
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外观。
提示词:
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类型和适当的可访问性属性。
提示词:
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验证构建一个多步骤注册表单。包括进度指示器和返回上一步的能力。
反应:它正确处理了步骤之间的状态持久化和验证。
提示词:
Convert my desktop-only dashboard layout to be fully responsive. Use Tailwind breakpoints and ensure it works on mobile, tablet, and desktop.
中文:将我的仅桌面版仪表板布局转换为完全响应式。使用Tailwind断点,确保它在移动端、平板和桌面上都能工作。
反应:它添加了适当的断点和移动端优先的样式。
提示词:
Add smooth page transitions using Framer Motion. Include fade-in for new pages and slide animations for modals.
中文:使用Framer Motion添加平滑的页面过渡。包括新页面的淡入和模态框的滑动动画。
反应:动画感觉很自然,它甚至添加了减少动效的媒体查询支持。
提示词:
Set up Zustand for global state management. Create stores for user auth, shopping cart, and UI preferences with TypeScript.
中文:设置Zustand进行全局状态管理。用TypeScript为用户认证、购物车和UI偏好创建stores。
反应:它正确分离了关注点,并添加了持久化中间件。
提示词:
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,带有正确的错误处理和加载状态。
反应:它添加了乐观更新和适当的缓存失效。
提示词:
Audit my components folder for accessibility issues. Fix any missing ARIA labels, keyboard navigation problems, and color contrast issues.
中文:审计我的组件文件夹的可访问性问题。修复任何缺失的ARIA标签、键盘导航问题和颜色对比问题。
反应:它找到了几个我不知道的问题并适当地修复了它们。
提示词:
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持久化。
提示词:
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。为路由设置代码分割。
反应:它识别出了不必要的重新渲染并正确优化了它们。
提示词:
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后才意识到它调试得有多好。它可以读取日志、追踪执行、隔离故障,甚至提出假设。我一直用它来捕捉那些在午夜时让我抓狂的竞态条件。
提示词:
I'm getting this error: [paste error]. Analyze my codebase, find the root cause, and fix it. Explain what went wrong.
中文:我遇到了这个错误:[粘贴错误]。分析我的代码库,找到根本原因,并修复它。解释出了什么问题。
反应:它追踪到了一个在4个文件之前导入的循环依赖。我从来不会自己找到那个。
提示词:
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的。
反应:它在每个转换点添加了日志,我在几分钟内就发现了问题。
提示词:
My React app's memory usage keeps growing. Analyze my components for potential memory leaks from subscriptions, event listeners, or timers.
中文:我的React应用内存使用持续增长。分析我的组件,查找订阅、事件监听器或定时器可能导致的内存泄漏。
反应:它找到了一个没有在useEffect中清理的WebSocket连接。
提示词:
I have intermittent data inconsistency issues in my app. Analyze my async operations and identify potential race conditions.
中文:我的应用有间歇性的数据不一致问题。分析我的异步操作并识别潜在的竞态条件。
反应:它找到了一个可能在组件卸载后解析的Promise。
提示词:
My API calls are failing silently. Add proper error handling to all fetch calls and log the full request/response cycle.
中文:我的API调用在静默失败。为所有fetch调用添加正确的错误处理,并记录完整的请求/响应周期。
反应:它发现了一个CORS问题并建议了修复方案。
提示词:
I have TypeScript errors that I don't understand. Analyze my types and fix any mismatches. Explain why the types were wrong.
中文:我有一些我不理解的TypeScript错误。分析我的类型并修复任何不匹配。解释为什么类型是错误的。
反应:它用清晰的解释修复了类型错误,我实际上学到了东西。
提示词:
npm install is failing with peer dependency conflicts. Analyze my package.json and suggest compatible versions for all packages.
中文:npm install因对等依赖冲突而失败。分析我的package.json并为所有包建议兼容的版本。
反应:它确定了确切的版本冲突并提供了解决方案。
提示词:
My production build is failing. Analyze the webpack/vite config and error logs to find and fix the issue.
中文:我的生产构建失败了。分析webpack/vite配置和错误日志,找到并修复问题。
反应:它发现了一个只在生产模式下出现的环境变量问题。
提示词:
My database queries are slow. Analyze the queries in my repository layer and suggest indexes or query optimizations.
中文:我的数据库查询很慢。分析我存储库层中的查询,并建议索引或查询优化。
反应:它识别出了N+1查询并用适当的join重写了它们。
提示词:
Audit my codebase for common security vulnerabilities: SQL injection, XSS, CSRF, exposed secrets, and insecure dependencies.
中文:审计我的代码库是否存在常见的安全漏洞:SQL注入、XSS、CSRF、暴露的密钥和不安全的依赖。
反应:它找到了一个硬编码的API密钥和几个未清理的输入。
粘贴完整的错误消息和堆栈跟踪。Antigravity越了解上下文,它的诊断就越准确。
测试是我大多数周末消失的地方。Antigravity实际上减少了痛苦——它可以生成测试、运行测试、分析覆盖率,并建议缺失的边缘情况。不完美,但比从头开始好得多。
提示词:
Generate comprehensive unit tests for my utils/helpers.ts file using Jest. Cover all edge cases and error conditions.
中文:使用Jest为我的utils/helpers.ts文件生成全面的单元测试。覆盖所有边缘情况和错误条件。
反应:它生成了我不会想到的测试用例,包括边界值和null检查。
提示词:
Write integration tests for my authentication flow using Supertest. Test login, registration, token refresh, and logout.
中文:使用Supertest为我的认证流程编写集成测试。测试登录、注册、令牌刷新和登出。
反应:它正确设置了测试数据库并在测试之间清理。
提示词:
Create Playwright E2E tests for my checkout flow. Include tests for adding items, applying coupons, and completing purchase.
中文:为我的结账流程创建Playwright E2E测试。包括添加商品、应用优惠券和完成购买的测试。
反应:它使用了正确的等待策略并处理了异步操作。
提示词:
Create comprehensive mocks for my external API calls. Include realistic data that covers success and error scenarios.
中文:为我的外部API调用创建全面的mock。包括涵盖成功和错误场景的真实数据。
反应:mock看起来很真实,它甚至添加了网络延迟模拟。
提示词:
Analyze my test coverage report. Identify untested code paths and generate tests to increase coverage to 80%.
中文:分析我的测试覆盖率报告。识别未测试的代码路径,并生成测试以将覆盖率提高到80%。
反应:它针对具体的未覆盖行,并为它们编写了有意义的测试。
提示词:
My tests are flaky and slow. Analyze and refactor them to be more reliable and faster. Remove any redundant assertions.
中文:我的测试不稳定且缓慢。分析并重构它们,使其更可靠、更快速。删除任何冗余的断言。
反应:它识别出了共享状态问题并正确隔离了测试。
提示词:
Generate API tests for all my REST endpoints. Include tests for authentication, validation errors, and success responses.
中文:为我所有的REST端点生成API测试。包括认证、验证错误和成功响应的测试。
反应:它创建了一个全面的测试套件,带有适当的设置和清理。
提示词:
Write React Testing Library tests for my UserProfile component. Test rendering, user interactions, and error states.
中文:使用React Testing Library为我的UserProfile组件编写测试。测试渲染、用户交互和错误状态。
反应:它遵循了测试最佳实践,测试行为而不是实现。
提示词:
Set up snapshot testing for my UI components. Create meaningful snapshots that capture the important visual aspects.
中文:为我的UI组件设置快照测试。创建有意义的快照,捕捉重要的视觉方面。
反应:它创建了聚焦的快照,不会每次小改动都破坏。
提示词:
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是值得的——特别是一旦你调整好模型级别和终端策略。
关键要点:
把这些提示词加入你的工作流程,你会感受到Agent的魔力——没有炒作。