diff --git a/src/resources/extensions/gsd/commands.ts b/src/resources/extensions/gsd/commands.ts index e3dc2f59c..eae9b2214 100644 --- a/src/resources/extensions/gsd/commands.ts +++ b/src/resources/extensions/gsd/commands.ts @@ -448,8 +448,7 @@ function serializePreferencesToFrontmatter(prefs: Record): stri if (Array.isArray(value)) { if (value.length === 0) { - lines.push(`${prefix}${key}: []`); - return; + return; // Omit empty arrays — avoids parse/serialize cycle bug with "[]" strings } lines.push(`${prefix}${key}:`); for (const item of value) { @@ -480,8 +479,7 @@ function serializePreferencesToFrontmatter(prefs: Record): stri if (typeof value === "object") { const entries = Object.entries(value as Record); if (entries.length === 0) { - lines.push(`${prefix}${key}: {}`); - return; + return; // Omit empty objects — avoids parse/serialize cycle bug with "{}" strings } lines.push(`${prefix}${key}:`); for (const [k, v] of entries) { diff --git a/src/resources/extensions/gsd/preferences.ts b/src/resources/extensions/gsd/preferences.ts index 283f2dda4..0d271497b 100644 --- a/src/resources/extensions/gsd/preferences.ts +++ b/src/resources/extensions/gsd/preferences.ts @@ -482,16 +482,20 @@ function parseFrontmatterBlock(frontmatter: string): GSDPreferences { return root as GSDPreferences; } -function parseScalar(value: string): string | number | boolean { +function parseScalar(value: string): unknown { if (value === "true") return true; if (value === "false") return false; + // Recognize empty array/object literals (with or without surrounding quotes) + const unquoted = value.replace(/^['\"]|['\"]$/g, ""); + if (unquoted === "[]") return []; + if (unquoted === "{}") return {}; if (/^-?\d+$/.test(value)) { const n = Number(value); // Keep large integers (e.g. Discord channel IDs) as strings to avoid precision loss if (Number.isSafeInteger(n)) return n; return value; } - return value.replace(/^['\"]|['\"]$/g, ""); + return unquoted; } /**