clean up version lookup code (#804)

This commit is contained in:
Tommaso Sciortino 2025-06-06 16:21:20 -07:00 committed by GitHub
parent e94a10023d
commit 76ec9122c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 39 additions and 23 deletions

View File

@ -18,11 +18,11 @@ import {
ApprovalMode, ApprovalMode,
} from '@gemini-code/core'; } from '@gemini-code/core';
import { Settings } from './settings.js'; import { Settings } from './settings.js';
import { readPackageUp } from 'read-package-up';
import { import {
getEffectiveModel, getEffectiveModel,
type EffectiveModelCheckResult, type EffectiveModelCheckResult,
} from '../utils/modelCheck.js'; } from '../utils/modelCheck.js';
import { getCliVersion } from '../utils/version.js';
// Simple console logger for now - replace with actual logger if available // Simple console logger for now - replace with actual logger if available
const logger = { const logger = {
@ -239,15 +239,6 @@ export async function loadCliConfig(
} }
async function createUserAgent(): Promise<string> { async function createUserAgent(): Promise<string> {
try { const cliVersion = await getCliVersion();
const packageJsonInfo = await readPackageUp({ cwd: import.meta.url }); return `GeminiCLI/${cliVersion} Node.js/${process.version} (${process.platform}; ${process.arch})`;
const cliVersion = packageJsonInfo?.packageJson.version || 'unknown';
return `GeminiCLI/${cliVersion} Node.js/${process.version} (${process.platform}; ${process.arch})`;
} catch (error: unknown) {
const message = error instanceof Error ? error.message : String(error);
logger.warn(
`Could not determine package version for User-Agent: ${message}`,
);
return `GeminiCLI/unknown Node.js/${process.version} (${process.platform}; ${process.arch})`;
}
} }

View File

@ -9,9 +9,7 @@ import { render } from 'ink';
import { App } from './ui/App.js'; import { App } from './ui/App.js';
import { loadCliConfig } from './config/config.js'; import { loadCliConfig } from './config/config.js';
import { readStdin } from './utils/readStdin.js'; import { readStdin } from './utils/readStdin.js';
import { readPackageUp } from 'read-package-up'; import { getCliVersion } from './utils/version.js';
import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
import { sandbox_command, start_sandbox } from './utils/sandbox.js'; import { sandbox_command, start_sandbox } from './utils/sandbox.js';
import { LoadedSettings, loadSettings } from './config/settings.js'; import { LoadedSettings, loadSettings } from './config/settings.js';
import { themeManager } from './ui/themes/theme-manager.js'; import { themeManager } from './ui/themes/theme-manager.js';
@ -34,9 +32,6 @@ import {
WriteFileTool, WriteFileTool,
} from '@gemini-code/core'; } from '@gemini-code/core';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export async function main() { export async function main() {
// warn about deprecated environment variables // warn about deprecated environment variables
if (process.env.GEMINI_CODE_MODEL) { if (process.env.GEMINI_CODE_MODEL) {
@ -107,9 +102,7 @@ export async function main() {
// Render UI, passing necessary config values. Check that there is no command line question. // Render UI, passing necessary config values. Check that there is no command line question.
if (process.stdin.isTTY && input?.length === 0) { if (process.stdin.isTTY && input?.length === 0) {
const readUpResult = await readPackageUp({ cwd: __dirname }); const cliVersion = await getCliVersion();
const cliVersion =
process.env.CLI_VERSION || readUpResult?.packageJson.version || 'unknown';
render( render(
<React.StrictMode> <React.StrictMode>

View File

@ -501,7 +501,6 @@ export const App = ({
debugMode={config.getDebugMode()} debugMode={config.getDebugMode()}
branchName={branchName} branchName={branchName}
debugMessage={debugMessage} debugMessage={debugMessage}
cliVersion={cliVersion}
corgiMode={corgiMode} corgiMode={corgiMode}
errorCount={errorCount} errorCount={errorCount}
showErrorDetails={showErrorDetails} showErrorDetails={showErrorDetails}

View File

@ -18,7 +18,6 @@ interface FooterProps {
branchName?: string; branchName?: string;
debugMode: boolean; debugMode: boolean;
debugMessage: string; debugMessage: string;
cliVersion: string;
corgiMode: boolean; corgiMode: boolean;
errorCount: number; errorCount: number;
showErrorDetails: boolean; showErrorDetails: boolean;

View File

@ -0,0 +1,34 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { readPackageUp } from 'read-package-up';
import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
let cliVersion: string | undefined;
export async function getCliVersion(): Promise<string> {
if (cliVersion) {
return cliVersion;
}
if (process.env.CLI_VERSION) {
cliVersion = process.env.CLI_VERSION;
return cliVersion;
}
try {
const readUpResult = await readPackageUp({ cwd: __dirname });
cliVersion = readUpResult?.packageJson.version || 'unknown';
} catch (_e) {
cliVersion = 'unknown';
}
return cliVersion;
}