fix(cli): use raw config instead of runtime-merged config in config set/unset

Fixes #6070

The config set/unset commands were using snapshot.config (which contains
runtime-merged defaults) instead of snapshot.parsed (the raw user config).
This caused runtime defaults like agents.defaults to leak into the written
config file when any value was set or unset.

Changed both set and unset commands to use structuredClone(snapshot.parsed)
to preserve only user-specified config values.
This commit is contained in:
Marcus Castro
2026-02-08 01:26:37 -03:00
committed by Peter Steinberger
parent a067565db5
commit 9e8d9f114d
2 changed files with 196 additions and 2 deletions

View File

@@ -306,7 +306,9 @@ export function registerConfigCli(program: Command) {
}
const parsedValue = parseValue(value, opts);
const snapshot = await loadValidConfig();
const next = snapshot.config as Record<string, unknown>;
// Use snapshot.parsed (raw user config) instead of snapshot.config (runtime-merged with defaults)
// This prevents runtime defaults from leaking into the written config file (issue #6070)
const next = structuredClone(snapshot.parsed) as Record<string, unknown>;
setAtPath(next, parsedPath, parsedValue);
await writeConfigFile(next);
defaultRuntime.log(info(`Updated ${path}. Restart the gateway to apply.`));
@@ -327,7 +329,9 @@ export function registerConfigCli(program: Command) {
throw new Error("Path is empty.");
}
const snapshot = await loadValidConfig();
const next = snapshot.config as Record<string, unknown>;
// Use snapshot.parsed (raw user config) instead of snapshot.config (runtime-merged with defaults)
// This prevents runtime defaults from leaking into the written config file (issue #6070)
const next = structuredClone(snapshot.parsed) as Record<string, unknown>;
const removed = unsetAtPath(next, parsedPath);
if (!removed) {
defaultRuntime.error(danger(`Config path not found: ${path}`));