gpt-engineer icon indicating copy to clipboard operation
gpt-engineer copied to clipboard

feat: enhance --sysinfo to include version and masked environment var…

Open KushagraaWadhwa opened this issue 3 weeks ago • 0 comments

Enhance --sysinfo to include version and masked environment variables

🎯 Description

This PR enhances the --sysinfo option to provide more comprehensive debugging information by adding version tracking and environment variable visibility while maintaining security through sensitive data masking.

Addresses the feature request for improved system information output to help diagnose issues more effectively.

✨ Changes

New Functions Added

  1. get_gpt_engineer_version()

    • Detects the exact version of gpt-engineer
    • Identifies installation type (released from pip vs development from GitHub repo)
    • Handles edge cases like .dev, .post, and git hash suffixes
  2. get_environment_variables()

    • Captures relevant environment variables (OPENAI_API_KEY, ANTHROPIC_API_KEY, MODEL_NAME, etc.)
    • Supports wildcard patterns (e.g., GPT_ENGINEER_*)
    • Indicates which variables are set vs "not set"
  3. mask_sensitive_value()

    • Automatically masks API keys, secrets, tokens, passwords, and credentials
    • Shows first 4 and last 4 characters for long values (e.g., sk-p...cdef (length: 24))
    • Shows ****** (length: X) for shorter sensitive values
    • Non-sensitive values displayed in full

Enhanced Features

  • Improved output formatting with clear separators and nested dictionary support
  • Updated get_system_info() to include version and environment information
  • Better readability with structured display

🧪 Testing

  • ✅ Added comprehensive unit tests in tests/applications/cli/test_sysinfo.py
  • ✅ Tests cover all new functions with multiple scenarios
  • ✅ No linting errors introduced
  • ✅ All functions have proper docstrings following NumPy style

📊 Example Output

Before:

os: Darwin
os_version: Darwin Kernel Version 23.0.0
architecture: arm64
python_version: 3.11.0...
packages: openai: 1.0.0
typer: 0.9.0
...

After:

============================================================
System Information
============================================================
os: Darwin
os_version: Darwin Kernel Version 23.0.0
architecture: arm64
python_version: 3.11.0...

gpt_engineer_version:
  version: 0.3.1
  install_type: development (from GitHub repo)

environment_variables:
  OPENAI_API_KEY: sk-p...xyz7 (length: 51)
  ANTHROPIC_API_KEY: not set
  AZURE_OPENAI_API_KEY: not set
  MODEL_NAME: gpt-4
  OPENAI_BASE_URL: not set
  LOCAL_MODEL: not set

packages: openai: 1.0.0
typer: 0.9.0
...
============================================================

🎁 Benefits

  1. Version Tracking

    • Helps diagnose issues by knowing exact version and installation type
    • Distinguishes between released versions and development builds
  2. Environment Configuration Insight

    • Provides valuable context about user's setup
    • Aids in debugging process without compromising security
  3. Security Compliance

    • Masks API keys and other sensitive information
    • Maintains user trust and follows security best practices
    • No sensitive data inadvertently exposed

📝 Files Changed

  • gpt_engineer/applications/cli/main.py (+385 lines)

    • Added 3 new functions
    • Enhanced output formatting
    • Added re import for pattern matching
  • tests/applications/cli/test_sysinfo.py (new file, +269 lines)

    • Comprehensive test coverage
    • Tests for all new functionality
    • Edge case handling

🔍 Breaking Changes

None. This PR only adds new functionality to the existing --sysinfo option without modifying any existing behavior.

✅ Checklist

  • [x] Code follows the project's style guidelines (black, ruff)
  • [x] Added comprehensive tests
  • [x] All tests pass
  • [x] Documentation (docstrings) added
  • [x] No linting errors
  • [x] Commit message follows conventional commits format
  • [x] PR targets the main branch

🔗 Related Issues

This PR is labeled as a good first issue contribution.


Testing Instructions:

To test this PR locally:

# Install the package
poetry install
poetry shell

# Run the enhanced sysinfo
gpt-engineer --sysinfo

# Run the tests
pytest tests/applications/cli/test_sysinfo.py -v

[!IMPORTANT] Enhances --sysinfo to include version and masked environment variables, with new functions and comprehensive tests added.

  • Behavior:
    • Enhances --sysinfo to include version and masked environment variables.
    • Adds get_gpt_engineer_version() to detect version and installation type.
    • Adds get_environment_variables() to capture and mask environment variables.
    • Updates get_system_info() to include new information.
  • Functions:
    • mask_sensitive_value() masks sensitive data in environment variables.
    • Improved output formatting in main.py for better readability.
  • Testing:
    • Adds test_sysinfo.py with comprehensive unit tests for new functions.
    • Tests cover version detection, environment variable masking, and system info structure.
  • Misc:
    • Adds re import in main.py for pattern matching.

This description was created by Ellipsis for 7e7b795f0ceedc62732b788e2106674c990fd7e5. You can customize this summary. It will automatically update as commits are pushed.

KushagraaWadhwa avatar Nov 11 '25 10:11 KushagraaWadhwa