clean up version lookup code (#804)
This commit is contained in:
parent
e94a10023d
commit
76ec9122c0
|
@ -18,11 +18,11 @@ import {
|
|||
ApprovalMode,
|
||||
} from '@gemini-code/core';
|
||||
import { Settings } from './settings.js';
|
||||
import { readPackageUp } from 'read-package-up';
|
||||
import {
|
||||
getEffectiveModel,
|
||||
type EffectiveModelCheckResult,
|
||||
} from '../utils/modelCheck.js';
|
||||
import { getCliVersion } from '../utils/version.js';
|
||||
|
||||
// Simple console logger for now - replace with actual logger if available
|
||||
const logger = {
|
||||
|
@ -239,15 +239,6 @@ export async function loadCliConfig(
|
|||
}
|
||||
|
||||
async function createUserAgent(): Promise<string> {
|
||||
try {
|
||||
const packageJsonInfo = await readPackageUp({ cwd: import.meta.url });
|
||||
const cliVersion = packageJsonInfo?.packageJson.version || 'unknown';
|
||||
const cliVersion = await getCliVersion();
|
||||
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})`;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,7 @@ import { render } from 'ink';
|
|||
import { App } from './ui/App.js';
|
||||
import { loadCliConfig } from './config/config.js';
|
||||
import { readStdin } from './utils/readStdin.js';
|
||||
import { readPackageUp } from 'read-package-up';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { dirname } from 'node:path';
|
||||
import { getCliVersion } from './utils/version.js';
|
||||
import { sandbox_command, start_sandbox } from './utils/sandbox.js';
|
||||
import { LoadedSettings, loadSettings } from './config/settings.js';
|
||||
import { themeManager } from './ui/themes/theme-manager.js';
|
||||
|
@ -34,9 +32,6 @@ import {
|
|||
WriteFileTool,
|
||||
} from '@gemini-code/core';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
export async function main() {
|
||||
// warn about deprecated environment variables
|
||||
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.
|
||||
if (process.stdin.isTTY && input?.length === 0) {
|
||||
const readUpResult = await readPackageUp({ cwd: __dirname });
|
||||
const cliVersion =
|
||||
process.env.CLI_VERSION || readUpResult?.packageJson.version || 'unknown';
|
||||
const cliVersion = await getCliVersion();
|
||||
|
||||
render(
|
||||
<React.StrictMode>
|
||||
|
|
|
@ -501,7 +501,6 @@ export const App = ({
|
|||
debugMode={config.getDebugMode()}
|
||||
branchName={branchName}
|
||||
debugMessage={debugMessage}
|
||||
cliVersion={cliVersion}
|
||||
corgiMode={corgiMode}
|
||||
errorCount={errorCount}
|
||||
showErrorDetails={showErrorDetails}
|
||||
|
|
|
@ -18,7 +18,6 @@ interface FooterProps {
|
|||
branchName?: string;
|
||||
debugMode: boolean;
|
||||
debugMessage: string;
|
||||
cliVersion: string;
|
||||
corgiMode: boolean;
|
||||
errorCount: number;
|
||||
showErrorDetails: boolean;
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue