Skip to content

fix(cli): parse commented settings.json in memory bootstrap#28219

Open
syf2211 wants to merge 1 commit into
google-gemini:mainfrom
syf2211:fix/28206-settings-json-comments
Open

fix(cli): parse commented settings.json in memory bootstrap#28219
syf2211 wants to merge 1 commit into
google-gemini:mainfrom
syf2211:fix/28206-settings-json-comments

Conversation

@syf2211

@syf2211 syf2211 commented Jun 30, 2026

Copy link
Copy Markdown

Summary

Fix getMemoryNodeArgs() so the lightweight CLI parent process can read comment-bearing settings.json files without silently falling back to default memory auto-configuration.

Motivation

The parent process reads ~/.gemini/settings.json before relaunching the full CLI. It used raw JSON.parse, which throws on JSON comments. The empty catch block left autoConfigureMemory at its default true, so users who set advanced.autoConfigureMemory: false in a commented config were ignored.

The rest of the CLI already accepts commented JSON via strip-json-comments (e.g. settings.ts).

Fixes #28206

Changes

File Change
packages/cli/index.ts Dynamically import and use parseJsonWithComments in getMemoryNodeArgs()
packages/cli/src/utils/parseJsonWithComments.ts Shared helper: JSON.parse(stripJsonComments(raw))
packages/cli/src/utils/parseJsonWithComments.test.ts Regression test for commented JSON with autoConfigureMemory: false

Tests

  • npm run build --workspace @google/gemini-cli-core
  • npm run test -- src/utils/parseJsonWithComments.test.ts1 passed
  • npx eslint index.ts src/utils/parseJsonWithComments.ts src/utils/parseJsonWithComments.test.tspassed

Notes

  • Dynamic import preserves the lightweight parent-process startup path (avoids eagerly loading deps unless settings are read).
  • Full npm run preflight was not run locally due to monorepo build time; targeted tests and lint were run on changed files.
  • Composer-2.5 review: APPROVE

getMemoryNodeArgs() read ~/.gemini/settings.json with JSON.parse, which
throws on comment-bearing configs that the rest of the CLI accepts via
strip-json-comments. The silent catch left autoConfigureMemory at its
default true, ignoring advanced.autoConfigureMemory: false.

Use the same comment-stripping parse helper as settings loading and add
a regression test for commented JSON.

Fixes google-gemini#28206
@syf2211 syf2211 requested a review from a team as a code owner June 30, 2026 10:07
@google-cla

google-cla Bot commented Jun 30, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@syf2211

syf2211 commented Jun 30, 2026

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@syf2211

syf2211 commented Jun 30, 2026

Copy link
Copy Markdown
Author

recheck

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 addresses an issue where the CLI's parent process failed to correctly parse 'settings.json' files containing comments, causing it to ignore user-defined memory configurations. By replacing the standard 'JSON.parse' with a comment-aware parsing utility, the CLI now correctly interprets configuration files, ensuring consistent behavior across the application.

Highlights

  • Commented JSON Support: Updated the CLI bootstrap process to support settings files containing comments by introducing a helper utility that strips comments before parsing.
  • Configuration Reliability: Ensured that user-defined settings, specifically 'advanced.autoConfigureMemory: false', are correctly respected even when comments are present in the configuration file.
  • Performance Optimization: Implemented dynamic imports for the new parsing utility to maintain a lightweight startup path for the CLI parent process.
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 the 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 counterproductive. 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.

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.

@github-actions github-actions Bot added the size/s A small PR label Jun 30, 2026
@github-actions

Copy link
Copy Markdown

📊 PR Size: size/S

  • Lines changed: 44
  • Additions: +43
  • Deletions: -1
  • Files changed: 3

@syf2211

syf2211 commented Jun 30, 2026

Copy link
Copy Markdown
Author

recheck

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

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.

Code Review

This pull request introduces a utility function parseJsonWithComments in packages/cli/src/utils/parseJsonWithComments.ts that strips comments from a JSON string before parsing it. It updates packages/cli/index.ts to dynamically import and use this utility when reading the CLI settings file, allowing users to include comments in their settings.json. Additionally, a corresponding unit test file is added to verify this behavior. There are no review comments, so I have no feedback to provide.

@gemini-cli

gemini-cli Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Hi there! Thank you for your interest in contributing to Gemini CLI.

To ensure we maintain high code quality and focus on our prioritized roadmap, we only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'.

This PR will be closed in 7 days if it remains without that designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: JSON.parse in cli/index.ts fails to parse settings.json with comments

1 participant