Skip to content

feat(cli): add WebSocket-based network logging and streaming chunk support#18383

Merged
SandyTao520 merged 6 commits intomainfrom
st/activity-logger-final
Feb 7, 2026
Merged

feat(cli): add WebSocket-based network logging and streaming chunk support#18383
SandyTao520 merged 6 commits intomainfrom
st/activity-logger-final

Conversation

@SandyTao520
Copy link
Contributor

@SandyTao520 SandyTao520 commented Feb 5, 2026

Summary

Add WebSocket client support to the activity logger for real-time log transmission to external DevTools, and support streaming chunks in the fetch API by reading ReadableStream.

Details

  • Add WebSocket client in activityLogger.ts for real-time log transmission to DevTools
  • Support streaming chunks by reading ReadableStream from fetch API responses
  • Add reconnection and buffering logic — logs are buffered when disconnected and replayed on reconnect
  • Support GEMINI_CLI_ACTIVITY_LOG_TARGET environment variable for configuring host:port
  • Add parseHostPort utility function
  • Enable/disable network logging dynamically
  • Add ws package dependency

Related Issues

#18007

How to Validate

  1. Set GEMINI_CLI_ACTIVITY_LOG_TARGET=localhost:9100 environment variable
  2. Run the CLI and make a request
  3. Observe that activity logs are sent via WebSocket to the specified host:port
  4. Kill the WebSocket server and verify logs are buffered
  5. Restart the server and verify buffered logs are replayed

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@SandyTao520 SandyTao520 requested review from a team as code owners February 5, 2026 17:47
@gemini-cli
Copy link
Contributor

gemini-cli bot commented Feb 5, 2026

Hi @SandyTao520, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this.

We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines.

Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed.

Thank you for your understanding and for being a part of our community!

@gemini-cli
Copy link
Contributor

gemini-cli bot commented Feb 5, 2026

Hi there! Thank you for your contribution to Gemini CLI.

To improve our contribution process and better track changes, we now require all pull requests to be associated with an existing issue, as announced in our recent discussion and as detailed in our CONTRIBUTING.md.

This pull request is being closed because it is not currently linked to an issue. Once you have updated the description of this PR to link an issue (e.g., by adding Fixes #123 or Related to #123), it will be automatically reopened.

How to link an issue:
Add a keyword followed by the issue number (e.g., Fixes #123) in the description of your pull request. For more details on supported keywords and how linking works, please refer to the GitHub Documentation on linking pull requests to issues.

Thank you for your understanding and for being a part of our community!

@gemini-cli gemini-cli bot closed this Feb 5, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @SandyTao520, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the CLI's activity logging capabilities by integrating WebSocket-based real-time log transmission and enabling detailed streaming of network response chunks. This allows developers to monitor CLI activity and network interactions in external DevTools, improving debugging and observability, especially for long-running or streaming operations. The new system includes robust reconnection and buffering mechanisms to ensure log integrity even during temporary disconnections.

Highlights

  • WebSocket-based Network Logging: Introduces a WebSocket client to the activity logger for real-time transmission of logs to external DevTools, enhancing observability.
  • Streaming Chunk Support: Adds support for streaming chunks in network requests by reading ReadableStream from fetch API responses, allowing for detailed monitoring of partial responses.
  • Robust Connection Handling: Implements reconnection and buffering logic for WebSocket connections, ensuring logs are buffered when disconnected and replayed upon successful reconnection.
  • Configurable Logging Target: Introduces the GEMINI_CLI_ACTIVITY_LOG_TARGET environment variable, allowing users to specify a host:port for WebSocket logging or a file path for traditional logging.
  • Dynamic Logging Control: Enables dynamic control over network logging, allowing it to be activated or deactivated as needed, and includes a utility function to parse host:port strings.
Changelog
  • evals/test-helper.ts
    • Updated test environment variable from GEMINI_CLI_ACTIVITY_LOG_FILE to GEMINI_CLI_ACTIVITY_LOG_TARGET.
  • package-lock.json
    • Added ws and @types/ws dependencies for WebSocket functionality.
  • packages/cli/package.json
    • Added ws and @types/ws as project dependencies.
  • packages/cli/src/nonInteractiveCli.test.ts
    • Modified activity logger tests to reference the new GEMINI_CLI_ACTIVITY_LOG_TARGET environment variable.
  • packages/cli/src/nonInteractiveCli.ts
    • Updated the condition for registering the activity logger to check for GEMINI_CLI_ACTIVITY_LOG_TARGET.
  • packages/cli/src/utils/activityLogger.ts
    • Integrated WebSocket client for network logging.
    • Added parseHostPort utility for environment variable configuration.
    • Extended NetworkLog interface to support chunk data for streaming responses.
    • Introduced methods to enableNetworkLogging, disableNetworkLogging, and check isNetworkLoggingEnabled.
    • Enhanced fetch and http.request interception to handle and emit streaming response chunks.
    • Refactored registerActivityLogger to dynamically switch between file-based and WebSocket-based logging based on GEMINI_CLI_ACTIVITY_LOG_TARGET.
    • Implemented setupNetworkLogging with WebSocket connection, buffering, reconnection, and ping/pong mechanisms.
    • Created setupFileLogging for traditional file-based log output.
Activity
  • The pull request was authored by SandyTao520.
  • The description provides a detailed summary, specific implementation details, and a validation guide.
  • The pre-merge checklist indicates that the changes have been validated on MacOS using npm run.
  • No related issues are noted in the PR description.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@SandyTao520 SandyTao520 reopened this Feb 5, 2026
@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Feb 5, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces significant enhancements to activity logging by adding WebSocket support for real-time log transmission and handling of streaming API responses. The implementation includes robust features like log buffering and automatic reconnection for the WebSocket client. My review identifies a critical regression that restricts the activity logger's activation, breaking existing logging functionality for non-interactive sessions. Additionally, I've found a high-severity issue in the new parseHostPort utility function that can lead to incorrect parsing of certain network addresses. I've provided detailed comments and code suggestions to address these issues, ensuring the new features are both powerful and reliable.

@github-actions
Copy link

github-actions bot commented Feb 5, 2026

Size Change: +6.95 kB (+0.03%)

Total Size: 23.8 MB

Filename Size Change
./bundle/gemini.js 23.8 MB +6.95 kB (+0.03%)
ℹ️ View Unchanged
Filename Size
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB

compressed-size-action

…pport

- Add WebSocket client for real-time log transmission to DevTools
- Support streaming chunks in fetch API by reading ReadableStream
- Add reconnection and buffering logic for network logging
- Support environment variable GEMINI_CLI_ACTIVITY_LOG_TARGET for host:port configuration
- Add parseHostPort utility function
- Enable/disable network logging dynamically
@SandyTao520 SandyTao520 force-pushed the st/activity-logger-final branch from 0e4f063 to 6745463 Compare February 6, 2026 21:36
@SandyTao520 SandyTao520 added this pull request to the merge queue Feb 7, 2026
Merged via the queue into main with commit 7409ce5 Feb 7, 2026
26 checks passed
@SandyTao520 SandyTao520 deleted the st/activity-logger-final branch February 7, 2026 00:30
aswinashok44 pushed a commit to aswinashok44/gemini-cli that referenced this pull request Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants