google-gemini / google-gemini/gemini-cli
bug: JSON.parse in cli/index.ts fails to parse settings.json with comments
- Dominant language
- TypeScript
- Stars
- 107k
- Forks
- 14.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 45
Description
### What happened?
In `packages/cli/index.ts`, `getMemoryNodeArgs()` reads the `settings.json` file synchronously and passes it directly to `JSON.parse(rawSettings)`. If the file contains any JSON comments (which are permitted and commonly used/generated in user configurations, especially since `strip-json-comments` is used elsewhere), `JSON.parse` throws an error. This silently swallows the error in the `catch` block and defaults `autoConfigureMemory` to true, ignoring the user's `autoConfigureMemory` configuration settings.
### What did you expect to happen?
The configuration reader in `cli/index.ts` should strip JSON comments from `settings.json` before passing it to `JSON.parse`, matching the behavior of settings loading in `packages/a2a-server/src/config/settings.ts` and `packages/cli/src/config/settings.ts`.
### Client information
Platform: All
Core version: 0.51.0
### Anything else we need to know?
The code in `packages/cli/index.ts`:
```typescript
async function getMemoryNodeArgs(): Promise {
let autoConfigureMemory = true;
try {
const { readFileSync } = await import('node:fs');
const { join } = await import('node:path');
// Respect GEMINI_CLI_HOME environment variable, falling back to os.homedir()
const baseDir =
process.env['GEMINI_CLI_HOME'] || join(os.homedir(), '.gemini');
const settingsPath = join(baseDir, 'settings.json');
const rawSettings = readFileSync(settingsPath, 'utf8');
const settings = JSON.parse(rawSettings);
```
Since this runs at start time prior to full CLI boots (to pass `--max-old-space-size` to node when launching the child process), any comments in user `settings.json` silently bypass this block. We should import/use a lightweight comment-stripping utility or regex.
Contributor guide
Research direction
Start in packages/cli/index.ts at getMemoryNodeArgs(), then compare settings loading in packages/a2a-server/src/config/settings.ts and packages/cli/src/config/settings.ts. Verify that settings.json containing comments is read successfully and that autoConfigureMemory respects the configured value instead of falling back to true.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 84/100