@koreanhole/opencodex 3.2.20 → 3.2.22

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
@@ -43,6 +43,35 @@ applies, including logins stored in the vendor keychain or under a custom
43
43
  `GEMINI_CLI_HOME`. Linux keyring access and the vendor encrypted credential file
44
44
  are preserved for isolated OAuth turns.
45
45
 
46
+ ### Vertex AI (enterprise)
47
+
48
+ Select Vertex AI in the vendor settings and authenticate with Application
49
+ Default Credentials:
50
+
51
+ ```json
52
+ {
53
+ "security": {
54
+ "auth": {
55
+ "selectedType": "vertex-ai"
56
+ }
57
+ }
58
+ }
59
+ ```
60
+
61
+ ```bash
62
+ gcloud auth application-default login
63
+ export GOOGLE_CLOUD_PROJECT="your-project"
64
+ export GOOGLE_CLOUD_LOCATION="us-central1"
65
+ # Optional: use a service-account ADC file instead of the gcloud login.
66
+ export GOOGLE_APPLICATION_CREDENTIALS="/path/to/adc.json"
67
+ ```
68
+
69
+ opencodex mirrors the vendor `vertex-ai` selection into its isolated Gemini
70
+ settings, forwards those three variables unchanged, and adds neither
71
+ `GOOGLE_GENAI_USE_GCA` nor encrypted-storage forcing. Gemini CLI's
72
+ `oauth_creds.json` is not used in this mode; an existing cached OAuth login
73
+ does not override the Vertex selection.
74
+
46
75
  Cline 2.2.0 is the minimum supported release. Newer options are used only when
47
76
  the installed binary advertises them.
48
77
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koreanhole/opencodex",
3
- "version": "3.2.20",
3
+ "version": "3.2.22",
4
4
  "description": "Full opencodex runtime with Cline 2.2.0+ JSON and Gemini CLI headless provider adapters",
5
5
  "type": "module",
6
6
  "main": "./bin/package-main.mjs",
@@ -250,7 +250,20 @@ export async function runGeminiTurn(
250
250
  ...(deps.reapTimeoutMs !== undefined ? { reapTimeoutMs: deps.reapTimeoutMs } : {}),
251
251
  ...(deps.killWindowsProcessTree ? { killWindowsProcessTree: deps.killWindowsProcessTree } : {}),
252
252
  };
253
- const childEnv = buildGeminiHeadlessEnv(sourceEnv, deps.platform ?? process.platform);
253
+ let childEnv: Record<string, string>;
254
+ try {
255
+ childEnv = buildGeminiHeadlessEnv(sourceEnv, deps.platform ?? process.platform);
256
+ } catch (error) {
257
+ emit({
258
+ type: "error",
259
+ message: error instanceof Error ? error.message : String(error),
260
+ status: 400,
261
+ errorType: "invalid_request_error",
262
+ code: "gemini_vertex_adc_missing",
263
+ retryable: false,
264
+ });
265
+ return;
266
+ }
254
267
  let mode;
255
268
  try {
256
269
  mode = await (deps.probeHeadless ?? probeGeminiHeadlessSupport)(binary, childEnv, headlessDeps);
@@ -1,5 +1,5 @@
1
1
  import { spawn as nodeSpawn, type ChildProcess } from "node:child_process";
2
- import { existsSync, readFileSync } from "node:fs";
2
+ import { accessSync, constants, existsSync, readFileSync, statSync } from "node:fs";
3
3
  import { link, lstat, mkdir, mkdtemp, readFile, rm, stat, symlink, writeFile } from "node:fs/promises";
4
4
  import { homedir, tmpdir } from "node:os";
5
5
  import { join, resolve } from "node:path";
@@ -67,7 +67,7 @@ const FORWARDED_ENV_KEYS = [
67
67
 
68
68
  const AUTH_FILE_NAMES = ["oauth_creds.json", "google_accounts.json", ".env"] as const;
69
69
  const OAUTH_AUTH_FILE_NAMES = ["oauth_creds.json", "google_accounts.json", "gemini-credentials.json"] as const;
70
- type GeminiHeadlessAuth = "oauth" | "environment";
70
+ type GeminiHeadlessAuth = "oauth" | "environment" | "vertex";
71
71
 
72
72
  export interface GeminiHeadlessDeps extends CliAgentTurnDeps {
73
73
  env?: NodeJS.ProcessEnv;
@@ -124,9 +124,29 @@ function geminiSelectedAuth(sourceEnv: NodeJS.ProcessEnv): GeminiHeadlessAuth |
124
124
  const selectedType = nonEmpty(asRecord(security?.auth)?.selectedType);
125
125
  if (selectedType === "oauth-personal") return "oauth";
126
126
  if (selectedType === "gemini-api-key") return "environment";
127
+ if (selectedType === "vertex-ai") {
128
+ if (!hasVertexAdc(sourceEnv)) {
129
+ throw new Error(
130
+ "Gemini CLI is configured for Vertex AI, but no Application Default Credentials were found. "
131
+ + "Set GOOGLE_APPLICATION_CREDENTIALS or run `gcloud auth application-default login`. "
132
+ + "Vertex also requires GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION.",
133
+ );
134
+ }
135
+ return "vertex";
136
+ }
127
137
  return undefined;
128
138
  }
129
139
 
140
+ function hasVertexAdc(sourceEnv: NodeJS.ProcessEnv): boolean {
141
+ if (nonEmpty(sourceEnv.GOOGLE_APPLICATION_CREDENTIALS)) return true;
142
+ const home = nonEmpty(sourceEnv.HOME) ?? nonEmpty(sourceEnv.USERPROFILE) ?? homedir();
143
+ const appData = nonEmpty(sourceEnv.APPDATA);
144
+ return [
145
+ join(home, ".config", "gcloud", "application_default_credentials.json"),
146
+ ...(appData ? [join(appData, "gcloud", "application_default_credentials.json")] : []),
147
+ ].some(path => existsSync(path));
148
+ }
149
+
130
150
  function geminiHeadlessAuth(sourceEnv: NodeJS.ProcessEnv): GeminiHeadlessAuth {
131
151
  if (enabled(sourceEnv.GOOGLE_GENAI_USE_GCA)) return "oauth";
132
152
  if (
@@ -153,6 +173,17 @@ function geminiVendorHome(sourceEnv: NodeJS.ProcessEnv): string {
153
173
  ?? homedir();
154
174
  }
155
175
 
176
+ function hasPlaintextGeminiOAuthStore(sourceEnv: NodeJS.ProcessEnv): boolean {
177
+ const path = join(geminiVendorHome(sourceEnv), ".gemini", "oauth_creds.json");
178
+ try {
179
+ const info = statSync(path);
180
+ accessSync(path, constants.R_OK);
181
+ return info.isFile() && info.size > 0;
182
+ } catch {
183
+ return false;
184
+ }
185
+ }
186
+
156
187
  function safeMessage(value: unknown, fallback: string): string {
157
188
  const raw = typeof value === "string"
158
189
  ? value
@@ -193,7 +224,10 @@ export function buildGeminiHeadlessEnv(
193
224
  }
194
225
  if (geminiHeadlessAuth(sourceEnv) === "oauth") {
195
226
  env.GOOGLE_GENAI_USE_GCA = "true";
196
- if (env.GEMINI_FORCE_ENCRYPTED_FILE_STORAGE === undefined) {
227
+ if (
228
+ env.GEMINI_FORCE_ENCRYPTED_FILE_STORAGE === undefined
229
+ && !hasPlaintextGeminiOAuthStore(sourceEnv)
230
+ ) {
197
231
  env.GEMINI_FORCE_ENCRYPTED_FILE_STORAGE = "true";
198
232
  }
199
233
  }
@@ -328,9 +362,8 @@ function geminiSystemSettings(
328
362
  auth: GeminiHeadlessAuth = "oauth",
329
363
  ): string {
330
364
  const settings = JSON.parse(GEMINI_SYSTEM_SETTINGS) as Record<string, unknown>;
331
- if (auth === "oauth") {
332
- settings.security = { auth: { selectedType: "oauth-personal" } };
333
- }
365
+ const selectedType = auth === "oauth" ? "oauth-personal" : auth === "vertex" ? "vertex-ai" : undefined;
366
+ if (selectedType) settings.security = { auth: { selectedType } };
334
367
  settings.tools = { core: mcpServers ? ["mcp_opencodex_*"] : [] };
335
368
  settings.mcp = mcpServers
336
369
  ? { allowed: [GEMINI_MCP_SERVER_NAME], excluded: [] }