Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@slkiser/opencode-quota",
"version": "3.8.5",
"version": "3.8.6",
"packageManager": "pnpm@11.0.0",
"description": "OpenCode quota & tokens usage with zero context window pollution. Supports GitHub Copilot, OpenAI (Plus/Pro), Qwen Code, Chutes AI, Synthetic, Google Antigravity, Z.ai coding plan and more.",
"type": "module",
Expand Down
4 changes: 3 additions & 1 deletion src/lib/google-antigravity-companion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ function normalizeCredential(value: unknown): string {
}

function getCompanionResolvePaths(): string[] {
return [...getOpencodeRuntimeDirCandidates().cacheDirs];
const paths = [...getOpencodeRuntimeDirCandidates().cacheDirs];
return paths;
}

function getRuntimePackageRoots(): string[] {
Expand All @@ -120,6 +121,7 @@ function getRuntimePackageRoots(): string[] {
for (const entry of entries) {
if (entry.isDirectory() && entry.name.startsWith(COMPANION_PACKAGE_NAME)) {
packageRoots.push(join(packagesDir, entry.name));
packageRoots.push(join(packagesDir, entry.name, "node_modules", COMPANION_PACKAGE_NAME));
}
}
} catch {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/google-gemini-cli-companion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ function normalizeCredential(value: unknown): string {
}

function getCompanionResolvePaths(): string[] {
return [...getOpencodeRuntimeDirCandidates().cacheDirs];
const paths = [...getOpencodeRuntimeDirCandidates().cacheDirs];
return paths;
}

function getRuntimePackageRoots(): string[] {
Expand All @@ -120,6 +121,7 @@ function getRuntimePackageRoots(): string[] {
for (const entry of entries) {
if (entry.isDirectory() && entry.name.startsWith(COMPANION_PACKAGE_NAME)) {
packageRoots.push(join(packagesDir, entry.name));
packageRoots.push(join(packagesDir, entry.name, "node_modules", COMPANION_PACKAGE_NAME));
}
}
} catch {
Expand Down
9 changes: 7 additions & 2 deletions src/lib/google-gemini-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "./google-token-cache.js";
import {
clearGeminiCliCompanionCacheForTests as clearGeminiCliCompanionResolutionCacheForTests,
inspectGeminiCliCompanionPresence,
resolveGeminiCliClientCredentials,
type GeminiCliConfiguredCredentials,
} from "./google-gemini-cli-companion.js";
Expand Down Expand Up @@ -264,11 +265,15 @@ export async function inspectGeminiCliAuthPresence(client?: ConfigClient): Promi
}

export async function hasGeminiCliQuotaRuntimeAvailable(client?: ConfigClient): Promise<boolean> {
const authPresence = await inspectGeminiCliAuthPresence(client);
const [authPresence, companionPresence] = await Promise.all([
inspectGeminiCliAuthPresence(client),
inspectGeminiCliCompanionPresence(),
]);

return (
authPresence.state === "present" &&
authPresence.validAccountCount > 0
authPresence.validAccountCount > 0 &&
companionPresence.state === "present"
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/opencode-runtime-paths.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { homedir } from "os";
import { join } from "path";
import { join, dirname } from "path";
import {
xdgCache,
xdgConfig,
Expand Down
22 changes: 22 additions & 0 deletions tests/lib.google-antigravity-companion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,26 @@ describe("google antigravity companion resolution", () => {
state: "invalid",
});
});

it("reads credentials from a nested node_modules structure in runtime packages directory", async () => {
const runtimeCacheDir = join(tempDir, "cache", "opencode");
const packageRoot = join(runtimeCacheDir, "packages", "opencode-antigravity-auth-1.0.0");
const nestedRoot = join(packageRoot, "node_modules", "opencode-antigravity-auth");
const distPath = join(nestedRoot, "dist", "src", "constants.js");
mkdirSync(join(nestedRoot, "dist", "src"), { recursive: true });
writeAntigravityCredentials(distPath, { declaration: "var" });
moduleMocks.runtimeDirs.value = { cacheDirs: [runtimeCacheDir] };
moduleMocks.resolveImpl.mockImplementation(() => {
throw moduleNotFound();
});

const mod = await import("../src/lib/google-antigravity-companion.js");

await expect(mod.resolveAntigravityClientCredentials()).resolves.toMatchObject({
state: "configured",
clientId: "client-id",
clientSecret: "client-secret",
resolvedPath: distPath,
});
});
});
22 changes: 22 additions & 0 deletions tests/lib.google-gemini-cli-companion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,26 @@ describe("google gemini cli companion resolution", () => {
resolvedPath: constantsPath,
});
});

it("reads credentials from a nested node_modules structure in runtime packages directory", async () => {
const runtimeCacheDir = join(tempDir, "cache", "opencode");
const packageRoot = join(runtimeCacheDir, "packages", "opencode-gemini-auth-1.0.0");
const nestedRoot = join(packageRoot, "node_modules", "opencode-gemini-auth");
const distPath = join(nestedRoot, "dist", "index.js");
mkdirSync(join(nestedRoot, "dist"), { recursive: true });
writeGeminiCredentials(distPath, { declaration: "var" });
moduleMocks.runtimeDirs.value = { cacheDirs: [runtimeCacheDir] };
moduleMocks.resolveImpl.mockImplementation(() => {
throw moduleNotFound();
});

const mod = await import("../src/lib/google-gemini-cli-companion.js");

await expect(mod.resolveGeminiCliClientCredentials()).resolves.toMatchObject({
state: "configured",
clientId: "client-id",
clientSecret: "client-secret",
resolvedPath: distPath,
});
});
});
Loading