Guidance for AI agents working with this repository.
OpenCode plugin for Kilo Gateway authentication. Provides device authorization flow and API key authentication for accessing Kilo Gateway's free and paid AI models through OpenCode.
bun install # Install dependencies
bun run typecheck # Type-check only (tsc --noEmit)
bun run build # Compile TypeScriptstrict: trueenabledtarget: ESNext,module: ESNext,moduleResolution: bundler- No path aliases — all imports are relative
- Use
import type { ... }for type-only imports - Named imports preferred
- Relative paths without extensions
- Named exports only — no default exports
- Entry point:
src/index.ts
camelCasefor functions, variables, parametersPascalCasefor types, interfaces, classesUPPER_SNAKE_CASEfor constantskebab-casefor file names
- No
Iprefix on interfaces - Extract to
types.tswhen shared
export async functionfor public APIs- Arrow functions for callbacks
- Async functions with try/catch for API calls
- Defensive try/catch with graceful degradation
- Catch
unknown, log, and convert to domain errors - Never empty catch blocks
src/
├── index.ts # Main entry, plugin registration
├── auth.ts # Device authorization flow
├── provider.ts # OpenRouter-based Kilo provider
├── models.ts # Fetch models from Kilo API
├── constants.ts # API URLs and constants
├── types.ts # TypeScript interfaces
└── polling.ts # Polling utility for device flow
Plugin exports auth hook for kilo provider. The loader function returns provider instance with proper headers and auth.
OAuth-like device flow:
- Request device code from Kilo API
- Display verification URL to user
- Poll for token until user authorizes
- Return auth credentials to OpenCode
Uses @openrouter/ai-sdk-provider with custom base URL pointing to Kilo Gateway.
@opencode-ai/plugin— OpenCode plugin interface@openrouter/ai-sdk-provider— OpenRouter SDK for AI modelsai— Vercel AI SDKopen— Open URLs in browserzod— Schema validation
- Base URL:
https://api.kilo.ai - OpenRouter proxy:
https://api.kilo.ai/api/openrouter - Device auth:
https://api.kilo.ai/v1/oauth/device/code - Token endpoint:
https://api.kilo.ai/v1/oauth/device/token
# In OpenCode TUI
# Select "Connect provider" → "kilo"
# Via CLI (workaround)
# Select "Other" → type "kilo"- README.md — Installation & usage
- CHANGELOG.md — Version history