An open API service indexing awesome lists of open source software.

https://github.com/gooseware/opencode-antigravity-autopilot

Quota management and model rotation for opencode-antigravity-auth
https://github.com/gooseware/opencode-antigravity-autopilot

antigravity claude gemini model-rotation oh-my-opencode opencode quota-management typescript

Last synced: 4 months ago
JSON representation

Quota management and model rotation for opencode-antigravity-auth

Awesome Lists containing this project

README

          

# OpenCode Antigravity Autopilot

[![npm version](https://img.shields.io/npm/v/opencode-antigravity-autopilot.svg)](https://www.npmjs.com/package/opencode-antigravity-autopilot)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

**Intelligent quota monitoring and automatic model switching for OpenCode with Antigravity.**

Zero OpenCode source modifications required - works as a pure plugin!

## โœจ Features

- ๐Ÿ” **Real-time Quota Monitoring** - Check quota via LLM tools
- ๐Ÿ”„ **Automatic Model Switching** - Switch models when quota exhausted
- ๐ŸŽฏ **Proactive Optimization** - Switch before hitting hard limits
- ๐Ÿ” **Account Rotation** - Automatically rotate between accounts
- ๐Ÿ› ๏ธ **Plugin-Based** - No OpenCode source modifications needed
- ๐Ÿค– **LLM-Aware** - Assistant can check quota and make decisions

## ๐Ÿš€ Quick Start

### ๐Ÿค– Install with LLM

Simply copy and paste this prompt to your OpenCode assistant:

> Please read the documentation at https://github.com/Gooseware/opencode-antigravity-autopilot#readme to understand the installation steps.
> Install the `opencode-antigravity-autopilot` plugin from npm.
> Then, configure `~/.config/opencode/opencode.json` to add `"opencode-antigravity-autopilot"` to the `plugin` list.
> Finally, create a default quota config in `~/.config/opencode/quota.json` with auto-rotation enabled for models like `antigravity-gemini-3-pro-high` and `antigravity-claude-sonnet-4-5`.

### From NPM

```bash
npm install opencode-antigravity-autopilot
```

### From GitHub (Source)

```bash
git clone https://github.com/Gooseware/opencode-antigravity-autopilot.git
cd opencode-antigravity-autopilot
npm install
npm run build
npm link
```

### Prerequisites

- Node.js >= 20.0.0
- [opencode-antigravity-auth](https://github.com/NoeFabris/opencode-antigravity-auth) installed and configured
- OpenCode with plugin support

### Configuration

#### Plugin Registration

Add to `~/.config/opencode/opencode.json`:

```json
{
"plugin": [
"opencode-antigravity-auth",
"opencode-antigravity-autopilot"
]
}
```

#### Quota Configuration

Create `~/.config/opencode/quota.json` to configure thresholds and models:

```json
{
"quotaThreshold": 0.05,
"preferredModels": [
"antigravity-gemini-3-pro-high", // Try this first
"antigravity-claude-sonnet-4-5", // Then this
"antigravity-gemini-3-flash" // Fallback
],
"autoRotate": true
}
```

That's it! The plugin is now active.

## ๐Ÿ“– Usage

### Check Quota via LLM

Simply ask your assistant:

```
"Check my quota status"
"Show detailed quota for all models"
"Can I use antigravity-gemini-3-pro-high right now?"
```

The LLM will call the appropriate tools and show results like:

```
# Quota Status

โœ“ **Current Model:** antigravity-gemini-3-pro-high
**Status:** Quota healthy at 67%

**Accounts:** 1 of 3 active
```

### Available Tools

The plugin exposes three tools to the LLM:

#### `quota_status`
Check current quota with optional detailed view

```typescript
quota_status()
quota_status({ detailed: true })
```

#### `quota_check_model`
Check if a specific model has enough quota

```typescript
quota_check_model({ model: "antigravity-gemini-3-pro-high" })
```

#### `quota_rotate_account`
Manually rotate to next available account

```typescript
quota_rotate_account()
```

### Programmatic Usage

```typescript
import { HardLimitDetector } from 'opencode-antigravity-autopilot';

const detector = new HardLimitDetector({
quotaThreshold: 0.2, // Switch when below 20%
preferredModels: [
'google/antigravity-gemini-3-pro-high',
'google/antigravity-claude-sonnet-4-5'
]
});

// Before using a model
const result = await detector.checkHardLimit('antigravity-gemini-3-pro-high');

if (result.shouldRotate) {
console.log(`Switching to: ${result.nextModel}`);
}
```

## ๐Ÿ—๏ธ Architecture

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ OpenCode (No modifications) โ”‚
โ”‚ โ”‚
โ”‚ LLM Tools: โ”‚
โ”‚ - quota_status โ”‚
โ”‚ - quota_check_model โ”‚
โ”‚ - quota_rotate_account โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”‚
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Autopilot Plugin โ”‚
โ”‚ โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚ ApiQuotaPoller โ”‚ โ”‚
โ”‚ โ”‚ Real-time API data โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚ โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚ HardLimitDetector โ”‚ โ”‚
โ”‚ โ”‚ Auto model switch โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

## ๐Ÿ”ง Configuration

### Quota Threshold

Configure when to proactively switch models:

```typescript
import { QuotaManager } from 'opencode-antigravity-autopilot';

const manager = new QuotaManager({
quotaThreshold: 0.2 // Switch when below 20%
});
```

### Preferred Models

Set model preference order:

```typescript
import { HardLimitDetector } from 'opencode-antigravity-autopilot';

const detector = new HardLimitDetector({
preferredModels: [
'google/antigravity-gemini-3-pro-high', // Try first
'google/antigravity-claude-sonnet-4-5', // Try second
'google/antigravity-gemini-3-flash' // Fallback
]
});
```

## ๐Ÿงช Testing

```bash
# Test hard limit detection
npm run test:quota

# Run full test suite
npm test
```

## ๐Ÿ“Š API Reference

### HardLimitDetector

```typescript
class HardLimitDetector {
constructor(config?: PluginConfig);

checkHardLimit(currentModel: string): Promise;
updateAllQuotas(): Promise;
rotateAccount(): Promise;
}

interface HardLimitCheckResult {
isExhausted: boolean;
shouldRotate: boolean;
nextModel?: string;
message?: string;
}
```

### QuotaManager

```typescript
class QuotaManager {
constructor(config?: PluginConfig);

initialize(): Promise;
getQuotaViaApi(modelName?: string): Promise;
getAllQuotasViaApi(): Promise>;
rotateAccount(): Promise;
}
```

### QuotaCacheUpdater

```typescript
class QuotaCacheUpdater {
constructor(manager: QuotaManager, updateIntervalMs?: number);

updateCache(): Promise;
start(): void;
stop(): void;
}

function startQuotaCacheService(updateIntervalMs?: number): Promise;
```

## ๐Ÿ› ๏ธ Advanced Usage

### Background Quota Service

Run a background service to keep quota cache updated:

```bash
npm run service:start
```

Or programmatically:

```typescript
import { startQuotaCacheService } from 'opencode-antigravity-autopilot';

const updater = await startQuotaCacheService(60000); // Update every 60s
updater.start();

// Later...
updater.stop();
```

### oh-my-opencode Integration

```typescript
import {
createOhMyOpenCodeIntegration,
QuotaManager
} from 'opencode-antigravity-autopilot';

const manager = new QuotaManager();
await manager.initialize();

const integration = createOhMyOpenCodeIntegration(manager, {
defaultModel: 'google/antigravity-gemini-3-flash'
});

const model = await integration.getModelForAgent('oracle');
console.log(`Oracle will use: ${model}`);
```

## ๐Ÿ› Troubleshooting

### Tools Not Showing Up

```bash
# Verify plugin is installed
npm list opencode-antigravity-autopilot

# Check OpenCode config
cat ~/.config/opencode/opencode.json
```

### Quota Check Fails

```bash
# Verify authentication
cat ~/.config/opencode/antigravity-accounts.json

# Test manually
node -e "const {QuotaManager} = require('opencode-antigravity-autopilot'); const m = new QuotaManager(); m.initialize().then(() => m.getQuotaViaApi().then());"
```

### Model Switch Not Working

```bash
# Test hard limit detector
npm run test:quota
```

## ๐Ÿ“ Changelog

See [CHANGELOG.md](CHANGELOG.md) for release history.

## ๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## ๐Ÿ“„ License

MIT ยฉ [gooseware](https://github.com/gooseware)

## ๐Ÿ™ Credits

Built on top of:
- [opencode-antigravity-auth](https://github.com/NoeFabris/opencode-antigravity-auth) by [@NoeFabris](https://github.com/NoeFabris)
- [OpenCode](https://github.com/opencode-ai/opencode)

## ๐Ÿ“š Related Projects

- [opencode-antigravity-auth](https://github.com/NoeFabris/opencode-antigravity-auth) - Authentication for Antigravity
- [opencode-antigravity-quota](https://github.com/gooseware/opencode-antigravity-quota) - Standalone quota checker
- [oh-my-opencode](https://github.com/opencode-ai/oh-my-opencode) - Enhanced OpenCode experience

## ๐Ÿ’ฌ Support

- [GitHub Issues](https://github.com/gooseware/opencode-antigravity-autopilot/issues)
- [Discussions](https://github.com/gooseware/opencode-antigravity-autopilot/discussions)

---

**Made with โค๏ธ for the OpenCode community**