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
26 changes: 25 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"chalk": "^4.1.2",
"cli-spinners": "^2.9.2",
"clipboardy": "^5.0.0",
"color-convert": "^2.0.1",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The color-convert dependency is added here, but it's not used anywhere in the codebase. This suggests an incomplete fix, which is critical for a patch release.

There's a bug in the getLuminance function in packages/cli/src/ui/themes/color-utils.ts where it incorrectly handles non-hex color values (like 'white' or 'black'). This can cause incorrect automatic theme selection. This new dependency was likely intended to fix this.

The current buggy getLuminance function:

export function getLuminance(backgroundColor: string): number {
  let hex = backgroundColor.replace(/^#/, '');
  if (hex.length === 3) {
    hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
  }
  const r = parseInt(hex.substring(0, 2), 16);
  const g = parseInt(hex.substring(2, 4), 16);
  const b = parseInt(hex.substring(4, 6), 16);

  return 0.2126 * r + 0.7152 * g + 0.0722 * b;
}

To correctly fix this, getLuminance should be updated to use color-convert to handle different color formats. Here's a suggested implementation:

import convert from 'color-convert';
import { debugLogger } from '@google/gemini-cli-core';

export function getLuminance(backgroundColor: string): number {
  try {
    const rgb = backgroundColor.startsWith('#')
      ? convert.hex.rgb(backgroundColor.slice(1))
      : convert.keyword.rgb(backgroundColor.toLowerCase() as any);
    const [r, g, b] = rgb;
    return 0.2126 * r + 0.7152 * g + 0.0722 * b;
  } catch (e) {
    debugLogger.warn(`Could not parse color "${backgroundColor}" to calculate luminance.`);
    return 0; // Default to dark for safety
  }
}

Please ensure the full fix is included in this patch release.

import convert from 'color-convert';
import { debugLogger } from '@google/gemini-cli-core';

export function getLuminance(backgroundColor: string): number {
  try {
    const rgb = backgroundColor.startsWith('#')
      ? convert.hex.rgb(backgroundColor.slice(1))
      : convert.keyword.rgb(backgroundColor.toLowerCase() as any);
    const [r, g, b] = rgb;
    return 0.2126 * r + 0.7152 * g + 0.0722 * b;
  } catch (e) {
    debugLogger.warn(`Could not parse color "${backgroundColor}" to calculate luminance.`);
    return 0; // Default to dark for safety
  }
}

"command-exists": "^1.2.9",
"comment-json": "^4.2.5",
"diff": "^8.0.3",
Expand Down
Loading