opencode-kilocode-auth 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,229 @@
1
+ # OpenCode Kilo Code Auth Plugin
2
+
3
+ An OpenCode plugin for authenticating with Kilo Code and accessing various AI models, including the **Giga Potato** model - a stealth model optimized for agentic programming.
4
+
5
+ ## Features
6
+
7
+ - **Kilo Code Authentication**: Login via browser-based device auth or manual token entry
8
+ - **300+ AI Models**: Access to Claude, GPT, Gemini, DeepSeek, Llama, and more
9
+ - **Giga Potato Model**: Free stealth model optimized for agentic programming with vision support
10
+ - **Model Selection**: Browse and select from available models
11
+ - **Zero Configuration**: Automatic request routing through Kilo Code API
12
+
13
+ ## Installation
14
+
15
+ ### Method 1: Add to opencode.json (Recommended)
16
+
17
+ Add the plugin to your OpenCode configuration file (`~/.config/opencode/opencode.json`):
18
+
19
+ ```json
20
+ {
21
+ "$schema": "https://opencode.ai/config.json",
22
+ "plugin": [
23
+ "opencode-kilocode-auth"
24
+ ],
25
+ "provider": {
26
+ "kilocode": {
27
+ "models": {
28
+ "giga-potato": {}
29
+ }
30
+ }
31
+ },
32
+ "model": "kilocode/giga-potato"
33
+ }
34
+ ```
35
+
36
+ ### Method 2: Local Plugin Directory
37
+
38
+ 1. Copy the plugin to your OpenCode plugins directory:
39
+
40
+ ```bash
41
+ # Create plugins directory
42
+ mkdir -p ~/.config/opencode/plugins
43
+
44
+ # Copy plugin file
45
+ cp path/to/opencode-kilocode-auth/src/plugin.ts ~/.config/opencode/plugins/kilocode.ts
46
+ ```
47
+
48
+ 2. OpenCode will automatically load plugins from the `~/.config/opencode/plugins/` directory.
49
+
50
+ ### Method 3: Install via npm/bun
51
+
52
+ ```bash
53
+ # Navigate to your opencode config directory
54
+ cd ~/.config/opencode
55
+
56
+ # Install the plugin
57
+ bun add opencode-kilocode-auth
58
+
59
+ # Or using npm
60
+ npm install opencode-kilocode-auth
61
+ ```
62
+
63
+ Then add to your `opencode.json`:
64
+
65
+ ```json
66
+ {
67
+ "plugin": ["opencode-kilocode-auth"]
68
+ }
69
+ ```
70
+
71
+ ## Authentication
72
+
73
+ When you run OpenCode, you'll see "kilocode" as an available provider. Select it and choose an auth method:
74
+
75
+ 1. **Login with Kilo Code** (OAuth): Opens browser for secure device auth
76
+ 2. **Enter Kilo Code API Token**: Enter your API token directly
77
+
78
+ ### Getting a Kilo Code Token
79
+
80
+ 1. Go to [https://kilo.ai](https://kilo.ai)
81
+ 2. Sign up or log in
82
+ 3. Navigate to Settings → API Keys
83
+ 4. Generate a new API key
84
+
85
+ ## Giga Potato Model
86
+
87
+ The **Giga Potato** model is a stealth model deeply optimized for agentic programming:
88
+
89
+ | Feature | Value |
90
+ |---------|-------|
91
+ | **Model ID** | `giga-potato` |
92
+ | **Context Window** | 256K tokens |
93
+ | **Max Output** | 32K tokens |
94
+ | **Vision Support** | Yes (can analyze images) |
95
+ | **Tool Support** | Yes (write_file, edit_file) |
96
+ | **Reasoning** | Yes |
97
+ | **Price** | **FREE** |
98
+
99
+ ### Using Giga Potato
100
+
101
+ Set it as your default model in `opencode.json`:
102
+
103
+ ```json
104
+ {
105
+ "model": "kilocode/giga-potato"
106
+ }
107
+ ```
108
+
109
+ Or select it interactively when prompted for a model.
110
+
111
+ ## Available Models
112
+
113
+ ### Free Models
114
+
115
+ | Model | Description |
116
+ |-------|-------------|
117
+ | `giga-potato` | Stealth model for agentic programming (256K context, vision) |
118
+ | `x-ai/grok-code-fast-1` | xAI Grok optimized for fast code generation |
119
+ | `mistralai/devstral-2512:free` | Mistral's development model |
120
+ | `corethink:free` | CoreThink reasoning model |
121
+
122
+ ### Premium Models (via Kilo Code subscription)
123
+
124
+ | Model | Description |
125
+ |-------|-------------|
126
+ | `anthropic/claude-opus-4.5` | Latest Claude Opus |
127
+ | `anthropic/claude-sonnet-4.5` | Latest Claude Sonnet |
128
+ | `openai/gpt-5.2` | Latest GPT model |
129
+ | `google/gemini-3-pro-preview` | Gemini 3 Pro |
130
+ | `deepseek/deepseek-r1` | DeepSeek reasoning model |
131
+
132
+ ## Configuration Example
133
+
134
+ Full `opencode.json` example:
135
+
136
+ ```json
137
+ {
138
+ "$schema": "https://opencode.ai/config.json",
139
+ "plugin": [
140
+ "opencode-kilocode-auth"
141
+ ],
142
+ "provider": {
143
+ "kilocode": {
144
+ "models": {
145
+ "giga-potato": {
146
+ "name": "Giga Potato",
147
+ "contextLength": 256000,
148
+ "maxTokens": 32000
149
+ },
150
+ "anthropic/claude-sonnet-4": {},
151
+ "openai/gpt-4o": {}
152
+ }
153
+ }
154
+ },
155
+ "model": "kilocode/giga-potato",
156
+ "agent": {
157
+ "build": {
158
+ "model": "kilocode/giga-potato"
159
+ }
160
+ }
161
+ }
162
+ ```
163
+
164
+ ## Environment Variables
165
+
166
+ | Variable | Description |
167
+ |----------|-------------|
168
+ | `KILOCODE_TOKEN` | Pre-set your Kilo Code API token |
169
+ | `KILOCODE_BACKEND_BASE_URL` | Custom backend URL (for development) |
170
+
171
+ ## How It Works
172
+
173
+ 1. **Authentication**: Uses device auth flow (like GitHub CLI) or direct token entry
174
+ 2. **Request Routing**: Intercepts AI requests and routes them through Kilo Code's OpenRouter-compatible API
175
+ 3. **Model Access**: Provides access to 300+ models through a single authentication
176
+ 4. **Cost Tracking**: Billing is handled by Kilo Code, costs show as $0 in OpenCode
177
+
178
+ ## Troubleshooting
179
+
180
+ ### Plugin not loading
181
+
182
+ Make sure the plugin is properly installed:
183
+
184
+ ```bash
185
+ # Check if plugin is in node_modules
186
+ ls ~/.config/opencode/node_modules/opencode-kilocode-auth
187
+
188
+ # Or check plugins directory
189
+ ls ~/.config/opencode/plugins/
190
+ ```
191
+
192
+ ### Authentication failing
193
+
194
+ 1. Check your internet connection
195
+ 2. Try logging in at [https://kilo.ai](https://kilo.ai) first
196
+ 3. Generate a new API token if the old one expired
197
+
198
+ ### Model not found
199
+
200
+ Make sure you're using the correct model ID format: `kilocode/model-name`
201
+
202
+ For example:
203
+ - `kilocode/giga-potato`
204
+ - `kilocode/anthropic/claude-sonnet-4`
205
+
206
+ ## Development
207
+
208
+ ```bash
209
+ # Clone the repo
210
+ git clone <repo-url>
211
+ cd opencode-kilocode-auth
212
+
213
+ # Install dependencies
214
+ bun install
215
+
216
+ # Test the API
217
+ bun run test/api-test.ts
218
+
219
+ # Build
220
+ bun run build
221
+ ```
222
+
223
+ ## License
224
+
225
+ MIT
226
+
227
+ ## Credits
228
+
229
+ Ported from [Kilo Code](https://kilo.ai) for OpenCode integration.
package/index.ts ADDED
@@ -0,0 +1,11 @@
1
+ // Plugin export - matches opencode-gemini-auth pattern
2
+ export { KilocodeAuthPlugin } from "./src/plugin"
3
+
4
+ // Types only
5
+ export type { KilocodeAuth } from "./src/plugin"
6
+
7
+ export type {
8
+ ModelInfo,
9
+ KilocodeOrganization,
10
+ KilocodeProfileData,
11
+ } from "./src/plugin/types"
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "opencode-kilocode-auth",
3
+ "module": "index.ts",
4
+ "version": "1.0.0",
5
+ "author": "ported from Kilo Code",
6
+ "description": "OpenCode plugin for Kilo Code authentication with support for various models including Giga Potato",
7
+ "files": [
8
+ "index.ts",
9
+ "src"
10
+ ],
11
+ "license": "MIT",
12
+ "type": "module",
13
+ "devDependencies": {
14
+ "@opencode-ai/plugin": "^1.1.25",
15
+ "@types/bun": "latest"
16
+ },
17
+ "peerDependencies": {
18
+ "typescript": "^5.9.3"
19
+ },
20
+ "dependencies": {}
21
+ }
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * CLI tool for selecting Kilo Code models interactively
4
+ *
5
+ * Usage:
6
+ * bun run src/cli/select-model.ts [token]
7
+ *
8
+ * If token is not provided, it will use KILOCODE_TOKEN environment variable
9
+ */
10
+
11
+ import { fetchAllModels, getFeaturedModels, formatModelDisplay, GIGA_POTATO_MODEL } from "../kilocode/models";
12
+ import { getKilocodeDefaultModel } from "../kilocode/auth";
13
+ import type { ModelInfo } from "../plugin/types";
14
+
15
+ async function selectModel(token?: string): Promise<void> {
16
+ const authToken = token || process.env.KILOCODE_TOKEN;
17
+
18
+ if (!authToken) {
19
+ console.log("Kilo Code Model Selector");
20
+ console.log("========================\n");
21
+ console.log("No token provided. Showing featured models:\n");
22
+
23
+ // Show featured models without auth
24
+ console.log("=== FREE Models (Recommended) ===");
25
+ console.log(`1. ${GIGA_POTATO_MODEL.name}`);
26
+ console.log(` ID: ${GIGA_POTATO_MODEL.id}`);
27
+ console.log(` Context: ${GIGA_POTATO_MODEL.contextWindow / 1000}K tokens`);
28
+ console.log(` Max Output: ${GIGA_POTATO_MODEL.maxTokens} tokens`);
29
+ console.log(` Vision: ${GIGA_POTATO_MODEL.supportsImages ? "Yes" : "No"}`);
30
+ console.log(` Reasoning: ${GIGA_POTATO_MODEL.supportsReasoning ? "Yes" : "No"}`);
31
+ console.log(` Price: FREE`);
32
+ console.log(` ${GIGA_POTATO_MODEL.description}\n`);
33
+
34
+ console.log("To see all available models, provide your Kilo Code token:");
35
+ console.log(" KILOCODE_TOKEN=your_token bun run src/cli/select-model.ts");
36
+ console.log(" OR");
37
+ console.log(" bun run src/cli/select-model.ts your_token");
38
+ return;
39
+ }
40
+
41
+ console.log("Kilo Code Model Selector");
42
+ console.log("========================\n");
43
+ console.log("Fetching available models...\n");
44
+
45
+ try {
46
+ const models = await fetchAllModels(authToken);
47
+ const defaultModel = await getKilocodeDefaultModel(authToken);
48
+
49
+ if (models.length === 0) {
50
+ console.log("No models available. Please check your token.");
51
+ return;
52
+ }
53
+
54
+ console.log(`Found ${models.length} models\n`);
55
+ console.log(`Current default: ${defaultModel}\n`);
56
+
57
+ // Group models by category
58
+ const freeModels = models.filter(
59
+ (m) => m.inputPrice === 0 && m.outputPrice === 0
60
+ );
61
+ const paidModels = models.filter(
62
+ (m) => (m.inputPrice ?? 0) > 0 || (m.outputPrice ?? 0) > 0
63
+ );
64
+
65
+ // Show free models first
66
+ console.log("=== FREE Models ===");
67
+ for (const model of freeModels.slice(0, 10)) {
68
+ const isDefault = model.id === defaultModel ? " [DEFAULT]" : "";
69
+ const vision = model.supportsImages ? " [Vision]" : "";
70
+ console.log(` ${model.id}${isDefault}${vision}`);
71
+ console.log(` ${model.name}`);
72
+ if (model.contextWindow) {
73
+ console.log(` Context: ${Math.round(model.contextWindow / 1000)}K tokens`);
74
+ }
75
+ console.log();
76
+ }
77
+
78
+ // Show featured paid models
79
+ console.log("=== Featured Paid Models ===");
80
+ const featuredPaid = paidModels
81
+ .filter((m) => m.preferredIndex !== undefined)
82
+ .sort((a, b) => (a.preferredIndex ?? 999) - (b.preferredIndex ?? 999))
83
+ .slice(0, 10);
84
+
85
+ for (const model of featuredPaid) {
86
+ const isDefault = model.id === defaultModel ? " [DEFAULT]" : "";
87
+ const vision = model.supportsImages ? " [Vision]" : "";
88
+ const price = `$${((model.inputPrice ?? 0) * 1000000).toFixed(2)}/${((model.outputPrice ?? 0) * 1000000).toFixed(2)} per 1M`;
89
+ console.log(` ${model.id}${isDefault}${vision}`);
90
+ console.log(` ${model.name}`);
91
+ console.log(` Price: ${price}`);
92
+ if (model.contextWindow) {
93
+ console.log(` Context: ${Math.round(model.contextWindow / 1000)}K tokens`);
94
+ }
95
+ console.log();
96
+ }
97
+
98
+ console.log("---");
99
+ console.log("To use a model, set it in your OpenCode config:");
100
+ console.log(' provider.options.model = "giga-potato"');
101
+ console.log("\nOr use environment variable:");
102
+ console.log(" OPENCODE_KILOCODE_MODEL=giga-potato");
103
+
104
+ } catch (error) {
105
+ console.error("Error fetching models:", error);
106
+ }
107
+ }
108
+
109
+ // Run the CLI
110
+ const token = process.argv[2];
111
+ selectModel(token);
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Constants used for Kilo Code authentication and API integration.
3
+ */
4
+
5
+ /**
6
+ * Default Kilo Code backend URL for production
7
+ */
8
+ export const DEFAULT_KILOCODE_BACKEND_URL = "https://kilo.ai";
9
+
10
+ /**
11
+ * Kilo Code API base URL for production
12
+ */
13
+ export const KILOCODE_API_BASE_URL = "https://api.kilo.ai";
14
+
15
+ /**
16
+ * Provider identifier shared between the plugin loader and credential store.
17
+ */
18
+ export const KILOCODE_PROVIDER_ID = "kilocode";
19
+
20
+ /**
21
+ * Default headers for Kilo Code API requests
22
+ */
23
+ export const DEFAULT_HEADERS = {
24
+ "Content-Type": "application/json",
25
+ "User-Agent": "opencode-kilocode-auth/1.0.0",
26
+ } as const;
27
+
28
+ /**
29
+ * Kilo Code custom headers
30
+ */
31
+ export const X_KILOCODE_ORGANIZATIONID = "X-KILOCODE-ORGANIZATIONID";
32
+ export const X_KILOCODE_TASKID = "X-KILOCODE-TASKID";
33
+ export const X_KILOCODE_PROJECTID = "X-KILOCODE-PROJECTID";
34
+ export const X_KILOCODE_EDITORNAME = "X-KILOCODE-EDITORNAME";
35
+
36
+ /**
37
+ * Default model ID if none is specified
38
+ * Using Giga Potato as default since it's free and optimized for agentic programming
39
+ */
40
+ export const DEFAULT_MODEL_ID = "giga-potato";
41
+
42
+ /**
43
+ * Giga Potato model ID - a stealth model optimized for agentic programming
44
+ * Features:
45
+ * - 256K context window
46
+ * - 32K max completion tokens
47
+ * - Supports images/vision
48
+ * - Supports tools (write_file, edit_file)
49
+ * - Supports reasoning
50
+ * - FREE
51
+ */
52
+ export const GIGA_POTATO_MODEL_ID = "giga-potato";
53
+
54
+ /**
55
+ * Polling interval for device auth (in ms)
56
+ */
57
+ export const DEVICE_AUTH_POLL_INTERVAL_MS = 3000;
58
+
59
+ /**
60
+ * OpenRouter-compatible endpoint path
61
+ */
62
+ export const OPENROUTER_PATH = "/api/openrouter/";