open-grok-build 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 kenryu42
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # open-grok-build
2
+
3
+ [![CI](https://github.com/kenryu42/open-grok-build/actions/workflows/ci.yml/badge.svg)](https://github.com/kenryu42/open-grok-build/actions/workflows/ci.yml)
4
+ [![Version](https://img.shields.io/github/v/tag/kenryu42/open-grok-build?label=version&color=blue)](https://github.com/kenryu42/open-grok-build)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-red.svg)](https://opensource.org/licenses/MIT)
6
+
7
+
8
+ [OpenCode](https://opencode.ai) plugin that connects xAI's **Grok Build** models (`cli-chat-proxy.grok.com`) to your terminal. Ships OAuth 2.0 + PKCE authentication, a curated model catalog, payload sanitization for xAI API quirks, Cursor-style tool shims, and live billing queries — all as a drop-in plugin.
9
+
10
+ ## Features
11
+
12
+ - **OAuth 2.0 + PKCE** — Browser-based login via `auth.x.ai` with automatic token refresh
13
+ - **Model catalog** — Six Grok Build models with correct cost, context window, and reasoning metadata
14
+ - **Payload sanitization** — Transparent rewrites for xAI's Responses API quirks (reasoning strip, image normalization, system→instructions, `response_format`→`text.format`, and more)
15
+ - **Tool shims** — Cursor-compatible filesystem and shell tools (`Grep`, `Glob`, `LS`, `Read`, `Write`, `StrReplace`, `Edit`, `Delete`, `Shell`)
16
+ - **Billing usage** — `/grok-build-usage` slash command shows live credit quota as a TUI toast (no LLM turn consumed)
17
+
18
+ ## Quick Start
19
+
20
+ ### 1. Install
21
+
22
+ ```bash
23
+ opencode plugin -g open-grok-build
24
+ ```
25
+
26
+ This registers both the server plugin (models, OAuth, payload sanitization, tool shims) and the TUI plugin (`/grok-build-usage` slash command). Restart the TUI after installing.
27
+
28
+ ### 2. Connect
29
+
30
+ ```
31
+ /connect grok-build → Grok Build (cli-chat-proxy)
32
+ ```
33
+
34
+ Or set `GROK_BUILD_OAUTH_TOKEN` for a static token bypass (no auto-refresh).
35
+
36
+ ### Local checkout
37
+
38
+ For development, use an absolute path:
39
+
40
+ ```json
41
+ {
42
+ "plugin": ["/path/to/open-grok-build"]
43
+ }
44
+ ```
45
+
46
+ See [LOCAL_OPENCODE_TESTING.md](docs/LOCAL_OPENCODE_TESTING.md) for the full local testing workflow.
47
+
48
+ ## Models
49
+
50
+ | Model | Context | Max Output | Reasoning | Input |
51
+ |---|---|---|---|---|
52
+ | `grok-composer-2.5-fast` | 200K | 30K | — | text, image |
53
+ | `grok-build` | 512K | 30K | ✓ | text, image |
54
+ | `grok-4.3` | 1M | 30K | ✓ | text, image |
55
+ | `grok-4.20-0309-reasoning` | 2M | 30K | ✓ | text, image |
56
+ | `grok-4.20-0309-non-reasoning` | 2M | 30K | — | text, image |
57
+ | `grok-4.20-multi-agent-0309` | 2M | 30K | ✓ | text, image |
58
+
59
+ Override with `GROK_BUILD_MODELS` (comma-separated model IDs). Unknown IDs get sensible defaults.
60
+
61
+ ## Tool Shims
62
+
63
+ The plugin registers Cursor-compatible tool definitions that Grok Build models can call:
64
+
65
+ | Tool | Description |
66
+ |---|---|
67
+ | `Grep` / `Glob` | Search file contents and filenames |
68
+ | `LS` | List directory contents |
69
+ | `Read` | Read file contents |
70
+ | `Write` / `StrReplace` / `Edit` / `Delete` | Modify files |
71
+ | `Shell` | Execute shell commands |
72
+
73
+ `web_search` / `websearch` are suppressed — Grok Build does not support web search through this endpoint.
74
+
75
+ ## Payload Sanitization
76
+
77
+ The plugin transparently rewrites outgoing requests to handle xAI's Responses API differences from stock OpenAI:
78
+
79
+ - Strips replayed `reasoning` items (cause 400 errors on xAI)
80
+ - Drops empty-string content items
81
+ - Moves `role: "developer"` / `role: "system"` messages to top-level `instructions`
82
+ - Converts `image_url` parts to `input_image` with data URIs
83
+ - Resolves local image paths (`.jpg`, `.jpeg`, `.png`) to base64 — workspace-scoped for security
84
+ - Extracts images from `function_call_output.output` arrays into separate user messages
85
+ - Maps `response_format` → `text.format`
86
+ - Adds `prompt_cache_key` for session-affinity caching
87
+ - Normalizes `reasoning.effort` for models that support it
88
+
89
+ ## Environment Variables
90
+
91
+ | Variable | Default | Description |
92
+ |---|---|---|
93
+ | `GROK_BUILD_BASE_URL` | `https://cli-chat-proxy.grok.com/v1` | API base URL |
94
+ | `GROK_BUILD_MODELS` | *(catalog)* | Comma-separated model IDs to expose |
95
+ | `GROK_BUILD_OAUTH_CLIENT_ID` | *(built-in)* | OAuth client ID override |
96
+ | `GROK_BUILD_CALLBACK_HOST` | `127.0.0.1` | OAuth loopback callback host |
97
+ | `GROK_BUILD_CALLBACK_PORT` | `56122` | OAuth loopback callback port |
98
+ | `GROK_BUILD_OAUTH_TOKEN` | — | Static token bypass (skips OAuth, no refresh) |
99
+ | `GROK_BUILD_TOKEN_TIMEOUT_MS` | `30000` | Timeout for OAuth token requests |
100
+
101
+ ## Development
102
+
103
+ ```bash
104
+ bun install
105
+ bun run check # lint + typecheck + knip + duplicate check + coverage
106
+ bun run test # tests only
107
+ bun run typecheck # tsc --noEmit
108
+ bun run coverage # tests with coverage
109
+ ```
110
+
111
+ See [OPENCODE_PLUGIN_SETUP.md](docs/OPENCODE_PLUGIN_SETUP.md) for packaging details.
112
+
113
+ ## License
114
+
115
+ [MIT](LICENSE)
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "open-grok-build",
3
+ "version": "0.1.0",
4
+ "description": "OpenCode plugin for Grok Build API (OAuth, sanitization, Cursor tool shims).",
5
+ "keywords": [
6
+ "opencode",
7
+ "opencode-plugin",
8
+ "xai",
9
+ "grok",
10
+ "grok-build",
11
+ "oauth",
12
+ "xai-oauth"
13
+ ],
14
+ "type": "module",
15
+ "main": "./src/opencode/plugin.ts",
16
+ "exports": {
17
+ ".": "./src/opencode/plugin.ts",
18
+ "./tui": "./src/opencode/tui.tsx"
19
+ },
20
+ "files": [
21
+ "README.md",
22
+ "src",
23
+ "tsconfig.json"
24
+ ],
25
+ "scripts": {
26
+ "test": "vitest run --reporter=agent",
27
+ "coverage": "vitest run --reporter=agent --coverage",
28
+ "typecheck": "tsc --noEmit",
29
+ "prepack": "bun run test && bun run coverage && bun run typecheck",
30
+ "knip": "knip --production",
31
+ "lint": "biome check --write .",
32
+ "lint:ci": "biome ci .",
33
+ "check": "bun run lint && bun run typecheck && bun run knip && bun run check-duplicates && AGENT=1 bun run coverage",
34
+ "check:ci": "bun run lint:ci && bun run typecheck && bun run knip && bun run check-duplicates && AGENT=1 bun run coverage",
35
+ "prepare": "husky",
36
+ "check-duplicates": "bunx jscpd src tests --exitCode 1 --reporters ai --noTips"
37
+ },
38
+ "author": {
39
+ "name": "J Liew",
40
+ "email": "jliew@420024lab.com"
41
+ },
42
+ "license": "MIT",
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/kenryu42/open-grok-build.git"
46
+ },
47
+ "bugs": {
48
+ "url": "https://github.com/kenryu42/open-grok-build/issues"
49
+ },
50
+ "homepage": "https://github.com/kenryu42/open-grok-build#readme",
51
+ "peerDependencies": {
52
+ "@opencode-ai/plugin": ">=1.15.0",
53
+ "@opentui/solid": "0.2.16"
54
+ },
55
+ "peerDependenciesMeta": {
56
+ "@opentui/solid": {
57
+ "optional": true
58
+ }
59
+ },
60
+ "devDependencies": {
61
+ "@biomejs/biome": "2.4.16",
62
+ "@opencode-ai/plugin": "1.15.13",
63
+ "@opencode-ai/sdk": "1.15.13",
64
+ "@types/node": "^22.0.0",
65
+ "@vitest/coverage-v8": "^4.1.8",
66
+ "husky": "^9.1.7",
67
+ "jscpd": "^4.2.4",
68
+ "knip": "^6.15.0",
69
+ "lint-staged": "^17.0.7",
70
+ "release-tools": "github:kenryu42/release-tools",
71
+ "typescript": "^6.0.3",
72
+ "vitest": "^4.1.8"
73
+ },
74
+ "lint-staged": {
75
+ "*": [
76
+ "biome check --write --no-errors-on-unmatched"
77
+ ]
78
+ }
79
+ }