@anthonyhaussman/opencode-agy-auth 1.5.9 → 1.5.18-alpha.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 CHANGED
@@ -1,4 +1,4 @@
1
- # OpenCode Antigravity CLI Auth Plugin
1
+ # OpenCode Antigravity CLI Plugin
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@anthonyhaussman/opencode-agy-auth)](https://www.npmjs.com/package/@anthonyhaussman/opencode-agy-auth)
4
4
  [![npm downloads](https://img.shields.io/npm/dw/@anthonyhaussman/opencode-agy-auth)](https://www.npmjs.com/package/@anthonyhaussman/opencode-agy-auth)
@@ -17,22 +17,63 @@
17
17
  >
18
18
  > Supported alternatives that do not rely on an Antigravity login:
19
19
  >
20
+ > - The `google-agy-acp` provider of this plugin with the **Gemini API key** or **Vertex** method (see below).
20
21
  > - OpenCode's native `google` provider with a Gemini API key (`GOOGLE_GENERATIVE_AI_API_KEY`, from Google AI Studio).
21
22
  > - OpenCode's native `google-vertex` provider with your own Google Cloud project.
22
23
  >
23
24
  > Use this plugin at your own risk. The maintainer takes no responsibility for any action Google takes against your account.
24
25
 
25
- An [OpenCode](https://opencode.ai/) authentication plugin that enables seamless interaction with the Antigravity CLI (`agy`) by hooking into its authentication, quota retrieval, and dynamic model fetching layers.
26
+ An [OpenCode](https://opencode.ai/) plugin for the Antigravity CLI (`agy`). It ships two providers:
26
27
 
27
- ## Features
28
+ - **`google-agy-acp`** (recommended): drives your local `agy` binary over the Agent Client Protocol (`agy acp`).
29
+ - **`google-agy`** (deprecated): the original direct Code Assist API provider with OAuth. It is kept for existing users and will not receive new features.
30
+
31
+ ## Requirements
32
+
33
+ - OpenCode >= 2.4.0, required by `google-agy-acp` (this package supports the v2 plugin API only; older OpenCode versions cannot load the provider). OpenCode 2.2.3 to 2.3.2 can load the provider, but their system prompt names the Code Mode tool `tools.opencode.session_move`, and agy answers every prompt that contains this string with `RESOURCE_EXHAUSTED (code 429)` ([antigravity-cli#1684](https://github.com/google-antigravity/antigravity-cli/issues/1684)). OpenCode 2.4.0 renamed the tool to `tools.opencode.session.move`.
34
+ - agy >= 1.5.10 for `google-agy-acp`. The binary is `agy` on your `PATH`, or the path in `OPENCODE_AGY_PATH`.
35
+
36
+ ## google-agy-acp provider
37
+
38
+ The provider starts `agy acp --agent opencode` (one process per OpenCode session, no shell) and exposes agy's models in OpenCode. OpenCode keeps ownership of tools: they are presented to agy through a local MCP bridge (127.0.0.1, random port, per-process bearer token) served by an agy plugin named `opencode-bridge`, so file edits and commands still run inside OpenCode with OpenCode's permission prompts. Low, medium and high variants map to agy's `thought_level`. The model list comes from `agy models` shortly after startup and refreshes when agy reports a different list at session start. If `agy models` fails later, the provider keeps the last list that worked for the current account; if agy is missing, too old, or has never answered for that account, the provider lists no models.
39
+
40
+ ### Authentication
41
+
42
+ Pick a method when connecting the `google-agy-acp` provider:
43
+
44
+ - **Gemini API key** (recommended): stored by OpenCode, passed to agy as `GEMINI_API_KEY` in the child environment.
45
+ - **Vertex AI / Agent Platform** (recommended): uses your Application Default Credentials. Nothing is stored by OpenCode.
46
+ - **Google login (personal or Gemini Enterprise / Workspace)**: you sign in with `agy` itself; the plugin never reads, refreshes or forwards agy's OAuth tokens and never reads the OS keyring.
47
+
48
+ ### Disclaimer
49
+
50
+ Google's policy names OpenCode as a third-party tool. Using the Google-login method through this plugin may still get your account disabled. This project makes no claim of Terms of Service compliance for any method. The API key and Vertex methods are the recommended ones.
51
+
52
+ ### What this provider changes on your machine
53
+
54
+ - **Global agy plugin.** On first use the provider runs `agy plugin install` and adds the `opencode-bridge` plugin to agy's global plugins in `~/.gemini/config/plugins/`. A one-time notice is shown. Remove it at any time with `agy plugin uninstall opencode-bridge`. The plugin never edits `~/.gemini/config/*` by hand.
55
+ - **`read_file` is not sandboxed.** agy's own `read_file` can read any file your user can read, including files outside the workspace, without a permission prompt. It is read-only and appears in OpenCode as a provider-executed call. Other agy built-ins (`write_file`, `run_command` and so on) are rejected.
56
+ - **Shared schema cache.** agy caches tool schemas in `~/.gemini/antigravity-cli/mcp/opencode-bridge_bridge/`, shared by all sessions. Concurrent sessions with different tool sets can see each other's schemas; calls to a tool the session does not have are rejected by the bridge.
57
+ - **Other MCP servers are blocked.** MCP servers from other agy plugins are blocked by permission rejection.
58
+ - **Long tool runs.** agy times MCP calls out at 180 s. OpenCode tools that run longer than 170 s return "still running" to agy, and the result is delivered with the next message.
59
+ - **Process lifetime.** agy child processes are not killed when the plugin unloads (the v2 setup hook has no disposer), but they exit after 5 minutes idle or when OpenCode exits.
60
+
61
+ ### Environment variables
62
+
63
+ - `OPENCODE_AGY_PATH`: path to the agy binary (default: `agy` on `PATH`).
64
+ - `AGY_ACP_DEBUG=1`: write a debug log of each agy child process (spawn, ACP JSON-RPC traffic, stderr, exit). The bridge token and the Gemini API key are redacted; prompts and tool output are logged as-is. Off by default.
65
+ - `AGY_ACP_DEBUG_FILE`: debug log path (default: `$XDG_DATA_HOME/opencode/agy-acp/debug.log`, or `~/.local/share/opencode/agy-acp/debug.log`). Created with mode 0600.
66
+
67
+ ## Legacy `google-agy` provider (deprecated)
68
+
69
+ ### Features
28
70
 
29
71
  - **OAuth 2.0 Integration**: Uses Antigravity's OAuth flows for authentication.
30
72
  - **Dynamic Model Retrieval**: Fetches available models based on user tier and current allocations.
31
73
  - **Quota Tracking**: Injects the `agy_quota` tool into OpenCode to check usage limits directly.
32
74
  - **Background Session Requests**: Sends the session-level requests the Antigravity backend expects alongside model calls.
33
- - **Dual OpenCode Compatibility**: Natively supports both OpenCode v1 (>= 1.18.29) and OpenCode v2 out of the box without breaking changes.
34
75
 
35
- ## Installation
76
+ ### Installation
36
77
 
37
78
  Install the plugin from npm (or directly using local file configurations if developing):
38
79
 
@@ -40,7 +81,7 @@ Install the plugin from npm (or directly using local file configurations if deve
40
81
  npm install @anthonyhaussman/opencode-agy-auth
41
82
  ```
42
83
 
43
- ## Configuration
84
+ ### Configuration
44
85
 
45
86
  Update your OpenCode configuration file (typically `opencode.json` at the root of your project or globally at `~/.config/opencode/opencode.json`) to register the plugin and specify your Google Cloud Project ID.
46
87
 
@@ -61,7 +102,7 @@ Update your OpenCode configuration file (typically `opencode.json` at the root o
61
102
  By default, the plugin registers a specialized provider ID to interface with `agy`.
62
103
  You can switch your active OpenCode provider to `agy` or let the plugin inject authentication into your existing sessions.
63
104
 
64
- ### Environment Variables
105
+ #### Environment Variables
65
106
 
66
107
  If you are running OpenCode in environments with specific requirements for Antigravity, you can use the following environment variables:
67
108
 
@@ -70,7 +111,7 @@ If you are running OpenCode in environments with specific requirements for Antig
70
111
  - `OPENCODE_AGY_ENDPOINT`: Override the default internal `daily-cloudcode-pa.googleapis.com` API endpoint.
71
112
  - `OPENCODE_AGY_VERBOSE_LOGS`: Set to `"1"` to enable verbose diagnostic logs for API calls and responses.
72
113
 
73
- ## Usage
114
+ ### Usage
74
115
 
75
116
  Once installed and configured, OpenCode will automatically authenticate against Antigravity CLI when interacting with eligible models. If no active session exists, you will be prompted to complete an OAuth login.
76
117
 
@@ -161,15 +202,6 @@ To test and develop the plugin locally with OpenCode before publishing:
161
202
  3. **Verify the plugin**:
162
203
  Launch OpenCode in your target project. OpenCode will automatically resolve and load your local plugin directory. You can test your changes by running `npm run build` in the plugin directory and restarting your OpenCode session.
163
204
 
164
- ## OpenCode Runtime Compatibility
165
-
166
- The plugin natively supports both OpenCode v1 (>= 1.18.29) and [OpenCode v2](https://opencode.ai/v2/docs) out of the box through a dual-compatibility architecture:
167
-
168
- - **OpenCode v1**: Loaded via the `server(options)` hook with custom OAuth flow and provider setup.
169
- - **OpenCode v2**: Loaded via `Plugin.define` / `setup(ctx)` with native catalog transformations, AI SDK hooks, session interception, and PKCE OAuth integration.
170
-
171
- No special flags or configurations are required - the plugin detects runtime automatically.
172
-
173
205
  ## Pre-release Channel
174
206
 
175
207
  To test bleeding-edge features or upcoming changes before official releases, configure the `@alpha` distribution tag:
@@ -0,0 +1,14 @@
1
+ ---
2
+ name: opencode
3
+ description: Main agent that drives OpenCode tools through the opencode-bridge MCP server
4
+ mainAgent: true
5
+ subagent: false
6
+ enable_mcp_tools: true
7
+ tools: [read_file]
8
+ ---
9
+
10
+ You are the model behind OpenCode. All OpenCode tools are exposed through one MCP server.
11
+
12
+ - Call OpenCode tools only with `call_mcp_tool` and `ServerName: "opencode-bridge_bridge"`.
13
+ - Before the first call of any tool, read its input schema with `read_file` from `~/.gemini/antigravity-cli/mcp/opencode-bridge_bridge/<tool>.json`.
14
+ - Never call any other MCP server.
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env node
2
+ // Stdio -> HTTP MCP proxy launched by agy. Only node: imports are allowed here.
3
+ import readline from "node:readline";
4
+
5
+ const url = process.env.AGY_ACP_BRIDGE_URL;
6
+ const token = process.env.AGY_ACP_BRIDGE_TOKEN;
7
+ let sessionId;
8
+ let failing = false;
9
+
10
+ function write(message) {
11
+ return new Promise((resolve) => {
12
+ process.stdout.write(`${JSON.stringify(message)}\n`, () => resolve());
13
+ });
14
+ }
15
+
16
+ async function fail(message, reason) {
17
+ if (failing) return;
18
+ failing = true;
19
+ const text = `OpenCode bridge unreachable: ${reason}`;
20
+ process.stderr.write(`bridge-proxy: ${text}\n`);
21
+ if (message && message.id !== undefined && message.id !== null) {
22
+ await write({ jsonrpc: "2.0", id: message.id, error: { code: -32000, message: text } });
23
+ }
24
+ process.exit(1);
25
+ }
26
+
27
+ function parseBody(contentType, text) {
28
+ if (!text.trim()) return [];
29
+ const out = [];
30
+ if (contentType.includes("text/event-stream")) {
31
+ for (const block of text.split(/\r?\n\r?\n/)) {
32
+ const data = block
33
+ .split(/\r?\n/)
34
+ .filter((l) => l.startsWith("data:"))
35
+ .map((l) => l.slice(5).trimStart())
36
+ .join("\n");
37
+ if (data) out.push(JSON.parse(data));
38
+ }
39
+ return out;
40
+ }
41
+ const parsed = JSON.parse(text);
42
+ return Array.isArray(parsed) ? parsed : [parsed];
43
+ }
44
+
45
+ async function forward(line) {
46
+ if (!line.trim()) return;
47
+ let message;
48
+ try {
49
+ message = JSON.parse(line);
50
+ } catch {
51
+ process.stderr.write("bridge-proxy: ignoring non-JSON input line\n");
52
+ return;
53
+ }
54
+ if (!url || !token) {
55
+ await fail(message, "AGY_ACP_BRIDGE_URL or AGY_ACP_BRIDGE_TOKEN is not set");
56
+ return;
57
+ }
58
+ try {
59
+ const headers = {
60
+ Authorization: `Bearer ${token}`,
61
+ "Content-Type": "application/json",
62
+ Accept: "application/json, text/event-stream",
63
+ };
64
+ if (sessionId) headers["Mcp-Session-Id"] = sessionId;
65
+ const res = await fetch(url, { method: "POST", headers, body: JSON.stringify(message) });
66
+ const sid = res.headers.get("mcp-session-id");
67
+ if (sid) sessionId = sid;
68
+ const text = await res.text();
69
+ for (const reply of parseBody(res.headers.get("content-type") ?? "", text)) {
70
+ // Transport-level errors (e.g. a pre-initialize server/discover) carry id null; agy
71
+ // drops replies it cannot correlate, so echo the request id.
72
+ if (reply && reply.error && reply.id == null && message.id !== undefined && message.id !== null) {
73
+ reply.id = message.id;
74
+ }
75
+ await write(reply);
76
+ }
77
+ if (!res.ok && !text.trim() && message.id !== undefined) {
78
+ await write({
79
+ jsonrpc: "2.0",
80
+ id: message.id,
81
+ error: { code: -32000, message: `OpenCode bridge returned HTTP ${res.status}` },
82
+ });
83
+ }
84
+ } catch (error) {
85
+ await fail(message, error instanceof Error ? error.message : String(error));
86
+ }
87
+ }
88
+
89
+ const rl = readline.createInterface({ input: process.stdin, crlfDelay: Infinity });
90
+ rl.on("line", (line) => {
91
+ void forward(line);
92
+ });
@@ -0,0 +1 @@
1
+ {"mcpServers":{"bridge":{"command":"__NODE_PATH__","args":["__PROXY_PATH__"]}}}
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "opencode-bridge",
3
+ "version": "1.0.1",
4
+ "description": "Bridges OpenCode tools into agy over MCP for the google-agy-acp provider"
5
+ }
package/dist/index.d.ts CHANGED
@@ -1,8 +1,6 @@
1
- import { AgyCLIOAuthPlugin, GoogleOAuthPlugin } from "./src/plugin";
2
1
  import { setupOpenCodeV2, v2PluginDefinition } from "./src/plugin/v2";
3
- import type { DualOpenCodePlugin } from "./src/plugin/types";
4
- export { AgyCLIOAuthPlugin, GoogleOAuthPlugin };
2
+ import type { OpenCodeV2PluginDefinition } from "./src/plugin/types";
5
3
  export { setupOpenCodeV2, v2PluginDefinition };
6
4
  export * from "./src/plugin/types";
7
- declare const dualPlugin: DualOpenCodePlugin;
8
- export default dualPlugin;
5
+ declare const plugin: OpenCodeV2PluginDefinition;
6
+ export default plugin;