From 27a773d5b29ce361ea3116578dd3de462030b696 Mon Sep 17 00:00:00 2001 From: DeWitt Clinton Date: Wed, 28 May 2025 00:04:26 -0700 Subject: [PATCH] Display git commit info in the /about section. (#567) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change detects the most recent git commit short hash and writes it to the `GIT_COMMIT_INFO` constant in `packages/cli/src/generated/git-commit.sh`, optionally appending the string "(local modifications)" if additional local changes after that commit are detected. If set, this string is displayed in the `/about` dialog as well as passed into the `/bug` template. Example: ``` > /about ╭───────────────────────────────────────────────────────────────────────────╮ │ │ │ About Gemini CLI │ │ │ │ CLI Version development │ │ Git Commit 43370ab (local modifications) │ │ Model gemini-2.5-pro-preview-05-06 │ │ Sandbox sandbox-exec (minimal) │ │ OS darwin v23.11.0 │ │ │ ╰───────────────────────────────────────────────────────────────────────────╯ ``` Additionally, this change updates `.gitignore` to ignore the generated files, `scripts/clean.sh` to remove them, and adds a `npm run generate` stage for this and any other generators we need to write. --- .gitignore | 3 ++ package.json | 3 +- packages/cli/src/ui/components/AboutBox.tsx | 13 ++++++ .../ui/hooks/slashCommandProcessor.test.ts | 2 + .../cli/src/ui/hooks/slashCommandProcessor.ts | 2 + packages/cli/tsconfig.json | 3 -- scripts/clean.sh | 1 + scripts/generate-git-commit-info.sh | 44 +++++++++++++++++++ 8 files changed, 67 insertions(+), 4 deletions(-) create mode 100755 scripts/generate-git-commit-info.sh diff --git a/.gitignore b/.gitignore index 63a276bb..9aa528c4 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ bundle # Test report files junit.xml packages/*/coverage/ + +# Generated files +packages/cli/src/generated/ diff --git a/package.json b/package.json index 46ec34be..a1159cf2 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "packages/*" ], "scripts": { + "generate": "scripts/generate-git-commit-info.sh", "build": "scripts/build.sh", "build:sandbox": "scripts/build_sandbox.sh", "build:all": "npm run build && npm run build:sandbox", @@ -24,7 +25,7 @@ "auth:docker": "gcloud auth configure-docker us-west1-docker.pkg.dev", "auth": "npm run auth:npm && npm run auth:docker", "prerelease:dev": "npm run prerelease:version --workspaces && npm run prerelease:deps --workspaces", - "bundle": "node_modules/.bin/esbuild packages/cli/index.ts --bundle --outfile=bundle/gemini.js --platform=node --format=esm --banner:js=\"import { createRequire } from 'module'; const require = createRequire(import.meta.url); globalThis.__filename = require('url').fileURLToPath(import.meta.url); globalThis.__dirname = require('path').dirname(globalThis.__filename);\" && bash scripts/copy_bundle_assets.sh" + "bundle": "npm run generate && node_modules/.bin/esbuild packages/cli/index.ts --bundle --outfile=bundle/gemini.js --platform=node --format=esm --banner:js=\"import { createRequire } from 'module'; const require = createRequire(import.meta.url); globalThis.__filename = require('url').fileURLToPath(import.meta.url); globalThis.__dirname = require('path').dirname(globalThis.__filename);\" && bash scripts/copy_bundle_assets.sh" }, "bin": { "gemini": "bundle/gemini.js" diff --git a/packages/cli/src/ui/components/AboutBox.tsx b/packages/cli/src/ui/components/AboutBox.tsx index 9ffa1a90..472bf979 100644 --- a/packages/cli/src/ui/components/AboutBox.tsx +++ b/packages/cli/src/ui/components/AboutBox.tsx @@ -7,6 +7,7 @@ import React from 'react'; import { Box, Text } from 'ink'; import { Colors } from '../colors.js'; +import { GIT_COMMIT_INFO } from '../../generated/git-commit.js'; interface AboutBoxProps { cliVersion: string; @@ -44,6 +45,18 @@ export const AboutBox: React.FC = ({ {cliVersion} + {GIT_COMMIT_INFO && !['N/A'].includes(GIT_COMMIT_INFO) && ( + + + + Git Commit + + + + {GIT_COMMIT_INFO} + + + )} diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts index 4c630d10..1f049658 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts @@ -31,6 +31,7 @@ import { MessageType } from '../types.js'; import { type Config } from '@gemini-code/server'; import * as ShowMemoryCommandModule from './useShowMemoryCommand.js'; +import { GIT_COMMIT_INFO } from '../../generated/git-commit.js'; vi.mock('./useShowMemoryCommand.js', () => ({ SHOW_MEMORY_COMMAND_NAME: '/memory show', @@ -244,6 +245,7 @@ Add any other context about the problem here. ## Diagnostic Information * **CLI Version:** ${cliVersion} +* **Git Commit:** ${GIT_COMMIT_INFO} * **Operating System:** ${osVersion} * **Sandbox Environment:** ${sandboxEnvStr} * **Model Version:** ${modelVersion} diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.ts index 4573303e..d4daa5c9 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.ts @@ -11,6 +11,7 @@ import { UseHistoryManagerReturn } from './useHistoryManager.js'; import { Config } from '@gemini-code/server'; import { Message, MessageType, HistoryItemWithoutId } from '../types.js'; import { createShowMemoryAction } from './useShowMemoryCommand.js'; +import { GIT_COMMIT_INFO } from '../../generated/git-commit.js'; export interface SlashCommandActionReturn { shouldScheduleTool?: boolean; @@ -215,6 +216,7 @@ Add any other context about the problem here. ## Diagnostic Information * **CLI Version:** ${cliVersion} +* **Git Commit:** ${GIT_COMMIT_INFO} * **Operating System:** ${osVersion} * **Sandbox Environment:** ${sandboxEnv} * **Model Version:** ${modelVersion} diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index 7c7539e3..38ef1972 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -4,9 +4,6 @@ "outDir": "dist", "jsx": "react-jsx", "lib": ["DOM", "DOM.Iterable", "ES2020"], - "paths": { - "@gemini-code/*": ["./packages/*"] - }, "types": ["node", "vitest/globals"] }, "include": ["index.ts", "src/**/*.ts", "src/**/*.tsx", "src/**/*.json"], diff --git a/scripts/clean.sh b/scripts/clean.sh index 2dc0232d..2f6bc3c0 100755 --- a/scripts/clean.sh +++ b/scripts/clean.sh @@ -17,4 +17,5 @@ set -euo pipefail # remove npm install/build artifacts rm -rf node_modules +rm -rf packages/cli/src/generated/ npm run clean --workspaces diff --git a/scripts/generate-git-commit-info.sh b/scripts/generate-git-commit-info.sh new file mode 100755 index 00000000..2a64830f --- /dev/null +++ b/scripts/generate-git-commit-info.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -euo pipefail + +GENERATED_DIR="packages/cli/src/generated" +GIT_COMMIT_FILE="$GENERATED_DIR/git-commit.ts" +GIT_COMMIT_INFO="N/A" + +mkdir -p "$GENERATED_DIR" + +if command -v git &> /dev/null && git rev-parse --is-inside-work-tree &> /dev/null; then + GIT_HASH=$(git rev-parse --short HEAD 2>/dev/null || echo "") + if [ -n "$GIT_HASH" ]; then + GIT_COMMIT_INFO="$GIT_HASH" + if [ -n "$(git status --porcelain 2>/dev/null)" ]; then + GIT_COMMIT_INFO="$GIT_HASH (local modifications)" + fi + fi +fi + +cat < "$GIT_COMMIT_FILE" +/** + * @license + * Copyright $(date +%Y) Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +// This file is auto-generated by the build script (scripts/build.sh) +// Do not edit this file manually. +export const GIT_COMMIT_INFO = '$GIT_COMMIT_INFO'; +EOL