MCPcopy Create free account
hub / github.com/cortexkit/magic-context / deepMergeRawConfig

Function deepMergeRawConfig

packages/plugin/src/config/index.ts:156–189  ·  view source on GitHub ↗

* Deep-merge two raw JSON objects. Both inputs must come from BEFORE Zod * parsing — otherwise Zod-filled defaults appear as if they were explicit * overrides and clobber genuine values from the other source. * * Plain object values merge recursively. Arrays, primitives, and `null` are * replac

(
    base: Record<string, unknown>,
    override: Record<string, unknown>,
)

Source from the content-addressed store, hash-verified

154 * other's entries.
155 */
156function deepMergeRawConfig(
157 base: Record<string, unknown>,
158 override: Record<string, unknown>,
159): Record<string, unknown> {
160 const result: Record<string, unknown> = { ...base };
161 for (const key of Object.keys(override)) {
162 const baseVal = base[key];
163 const overrideVal = override[key];
164 if (
165 baseVal !== null &&
166 typeof baseVal === "object" &&
167 !Array.isArray(baseVal) &&
168 overrideVal !== null &&
169 typeof overrideVal === "object" &&
170 !Array.isArray(overrideVal)
171 ) {
172 result[key] = deepMergeRawConfig(
173 baseVal as Record<string, unknown>,
174 overrideVal as Record<string, unknown>,
175 );
176 } else if (
177 key === "disabled_hooks" &&
178 Array.isArray(baseVal) &&
179 Array.isArray(overrideVal)
180 ) {
181 // Union-merge so user + project can both disable hooks without
182 // one source erasing the other's entries.
183 result[key] = [...new Set([...baseVal, ...overrideVal])];
184 } else {
185 result[key] = overrideVal;
186 }
187 }
188 return result;
189}
190
191/**
192 * Render a config value for a warning message in a way that never leaks resolved

Callers 1

loadPluginConfigDetailedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected