mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-29 23:41:29 -07:00
Log all user settings to enable measurement of experiment impacts (#11354)
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
* @param space - Optional space parameter for formatting (defaults to no formatting)
|
||||
* @returns JSON string with circular references replaced by [Circular]
|
||||
*/
|
||||
import type { Config } from '../config/config.js';
|
||||
|
||||
export function safeJsonStringify(
|
||||
obj: unknown,
|
||||
space?: string | number,
|
||||
@@ -30,3 +32,37 @@ export function safeJsonStringify(
|
||||
space,
|
||||
);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function removeEmptyObjects(data: any): object {
|
||||
const cleanedObject: { [key: string]: unknown } = {};
|
||||
for (const k in data) {
|
||||
const v = data[k];
|
||||
if (v !== null && v !== undefined && typeof v === 'boolean') {
|
||||
cleanedObject[k] = v;
|
||||
}
|
||||
}
|
||||
|
||||
return cleanedObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely stringifies an object to JSON, retaining only non-null, Boolean-valued members.
|
||||
*
|
||||
* @param obj - The object to stringify
|
||||
* @returns JSON string with circular references skipped and only non-null, Boolean member values retained.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function safeJsonStringifyBooleanValuesOnly(obj: any): string {
|
||||
let configSeen = false;
|
||||
return JSON.stringify(removeEmptyObjects(obj), (key, value) => {
|
||||
if ((value as Config) !== null && !configSeen) {
|
||||
configSeen = true;
|
||||
return value;
|
||||
}
|
||||
if (typeof value === 'boolean') {
|
||||
return value;
|
||||
}
|
||||
return '';
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user