Ralph Loop for Antigravity - Autonomous AI development loop that keeps the AI agent working until tests pass or max iterations reached.
Inspired by Claude Code's Ralph Wiggum plugin, redesigned for Google Antigravity IDE.
┌──────────────────────────────────────────────────────────────┐
│ RALPH LOOP FOR ANTIGRAVITY │
├──────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌──────────────┐ ┌───────────┐ │
│ │ Inject │─────▶│ Submit + │─────▶│ Wait for │ │
│ │ Prompt │ │ Auto-Accept │ │ AI Complete│ │
│ └─────────────┘ └──────────────┘ └─────┬─────┘ │
│ ▲ │ │
│ │ ┌───────────────────────────────▼────┐ │
│ │ │ Check Completion │ │
│ │ │ • Test command exit code == 0? │ │
│ │ │ • AI output contains "DONE"? │ │
│ │ └─────────────────┬──────────────────┘ │
│ │ │ │
│ │ NO ┌─────────────────┴────────────┐ YES │
│ └────────│ iteration < max_iterations? │────▶ DONE│
│ └──────────────────────────────┘ │
│ │
└──────────────────────────────────────────────────────────────┘
| Aspect | Claude Code | Antigravity For Loop |
|---|---|---|
| Interface | CLI | GUI (VSCode-like) |
| Loop Mechanism | Stop Hook intercepts exit | CDP + setInterval |
| Prompt Injection | Hook re-injects prompt | CDP → Lexical Editor |
| Completion Detection | Hook exit code 2 | Test exit code 0 / "DONE" |
| Auto-Accept | Not needed (CLI) | CDP clicks Accept buttons |
- Ralph Loop - Inject Prompt → Wait for AI → Run Tests → Repeat
- Auto-Accept - Automatically click Accept/Run buttons via CDP
- Smart Detection - Auto-detect test commands for 25+ languages
- Real-time Progress - Status bar shows iteration progress
- Safety Limits -
maxIterationsprevents infinite loops
# Package the extension
npm run package
# Install in Antigravity IDE
code --install-extension antigravity-for-loop-*.vsixAntigravity must have CDP (Chrome DevTools Protocol) enabled for the extension to work.
- After installing the extension, a prompt will appear
- Click "Enable CDP"
- Follow instructions to restart Antigravity
macOS:
open -a "Antigravity.app" --args --remote-debugging-port=9000Windows:
Add to shortcut target: --remote-debugging-port=9000
Linux:
antigravity --remote-debugging-port=9000- Click "For Loop" button in the status bar
- Select "Start Ralph Loop..."
- Enter task description (e.g., "Fix all TypeScript errors")
- Select completion condition (Tests Pass / Build Succeeds / AI Self-Judgment)
- Select maximum iterations
- Go!
| Shortcut | Function |
|---|---|
Cmd+Alt+Shift+L |
Open menu |
Cmd+Alt+Shift+A |
Toggle Auto-Accept |
Cmd+Alt+Shift+C |
Copy Continuation Prompt |
| Option | Description |
|---|---|
| Tests Pass | Auto-detect test command, stop on exit code 0 |
| Build Succeeds | Stop when build completes successfully |
| AI Self-Judgment | Stop when AI outputs "DONE" |
| Custom Command | Enter a custom validation command |
The extension automatically detects test commands for 25+ languages and build systems:
| Category | Languages/Frameworks |
|---|---|
| JavaScript | npm, Deno, Bun |
| Python | pytest, tox, mypy |
| Systems | Rust (cargo), Go, Zig, Nim, V |
| JVM | Java/Kotlin (Maven, Gradle), Scala (sbt), Clojure (lein) |
| Functional | Haskell (stack, cabal), Elixir (mix), Erlang (rebar3), OCaml (dune) |
| Mobile | Swift, Dart/Flutter |
| Web | Ruby (rspec), PHP (phpunit), .NET (dotnet) |
| C/C++ | CMake, Meson, Conan |
| Build Systems | Make, Just, Task, Bazel, Pants, Earthly |
# Run all unit tests (CI/CD compatible)
npm test
# Run specific test suites
npm run test:unit:ralph # RalphLoop tests
npm run test:unit:cdp # CDPManager tests
npm run test:unit:state # State parser tests
npm run test:unit:detect # Test command detection
# Run CDP E2E tests (local only, requires Antigravity IDE)
npm run test:e2e:cdp| Test Suite | Tests | CI/CD | Description |
|---|---|---|---|
ralphLoop.test.js |
37 | ✅ | Loop logic, prompt building, callbacks |
cdpManager.test.js |
29 | ✅ | CDP connection, helper script validation |
stateParser.test.js |
14 | ✅ | State parsing, status bar text |
detectTestCommand.test.js |
11 | ✅ | Test command detection for core languages |
cdp-ralph-loop.e2e.js |
16 | ❌ | Real CDP E2E (requires Antigravity IDE) |
Total: 91 unit tests + 16 E2E tests = 107 tests
These tests require a real Antigravity IDE instance:
# 1. Start Antigravity with CDP enabled
open -a "Antigravity.app" --args --remote-debugging-port=9000
# 2. Open the Agent Panel in Antigravity
# 3. Run E2E tests
npm run test:e2e:cdpantigravity_for_loop/
├── extension.js # VSCode extension entry point
├── package.json # Extension manifest & scripts
├── lib/
│ ├── cdp-manager.js # CDP connection & DOM injection
│ ├── ralph-loop.js # Ralph Loop core logic
│ └── relauncher.js # CDP restart helper
├── test/
│ ├── unit/ # Unit tests (CI/CD compatible)
│ │ ├── ralphLoop.test.js
│ │ ├── cdpManager.test.js
│ │ ├── stateParser.test.js
│ │ └── detectTestCommand.test.js
│ ├── e2e/ # E2E tests (local only)
│ │ └── cdp-ralph-loop.e2e.js
│ └── integration/ # VSCode integration tests
│ └── extension.test.js
├── assets/
│ └── icon.png
└── README.md
The extension uses Chrome DevTools Protocol to interact with Antigravity's webview:
- Connect to CDP on port 9000 (scans 9000-9003)
- Find the
antigravity.agentPaneliframe - Locate the Lexical editor (
[data-lexical-editor="true"]) - Inject text using
execCommand('insertText') - Click Submit and Accept buttons via DOM queries
window.__antigravityForLoop = {
findChatInput() // Find Lexical editor in iframe
findSubmitButton() // Find Submit button
injectPrompt(text) // Inject text into editor
submitPrompt() // Click Submit or press Enter
isAcceptButton(el) // Check if element is Accept button
clickAcceptButtons() // Click all Accept buttons
getAIStatus() // Get AI response status
}1. Start Loop
└─> Connect to CDP
└─> Inject helper script
└─> Start auto-accept interval
2. Each Iteration
└─> Build prompt with context
└─> Inject prompt into Lexical editor
└─> Submit prompt
└─> Wait for AI completion
└─> Run test command
└─> Check success/failure
3. Completion
└─> Tests pass (exit 0) → SUCCESS
└─> AI says "DONE" → SUCCESS
└─> Max iterations reached → FAILURE
└─> User cancels → CANCELLED
- Recommend
git commitbefore using - Use
maxIterationsto limit iterations (default: 10) - Manually confirm high-risk operations (e.g., file deletion)
- CDP requires port 9000, ensure no conflicts
MIT License
Made for Google Antigravity IDE
Inspired by Claude Code Ralph Wiggum