Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:2aronS Duel Agents deepMerge

From Leeroopedia
Knowledge Sources
Domains Configuration, Data_Structures
Last Updated 2026-10-27 14:00 GMT

Overview

Concrete tool for recursively merging two plain objects where nested objects are combined and arrays and scalars are replaced, provided by @duel-agents/core.

Description

The deepMerge function implements a recursive merge of a patch object into a base object. The semantics are:

  • Plain objects — merged recursively (the patch's keys are combined into the base's keys at each level)
  • Arrays — the patch array replaces the base array entirely (no element-wise merge)
  • Scalars (string, number, boolean, null) — the patch value replaces the base value
  • New keys — added from the patch to the output

This is the merge strategy used by patchOpenClawConfig to combine the Duel patch into an existing OpenClaw config without destroying unrelated nested settings.

Usage

Import this function when you need to:

  • Merge a configuration patch into an existing config object
  • Combine two objects where arrays should be replaced, not concatenated
  • Implement idempotent config patching

Code Reference

Source Location

  • Repository: Duel-Agents
  • File: packages/core/src/config.ts (lines 142-168)

Signature

export function deepMerge(
  base: Record<string, unknown>,
  patch: Record<string, unknown>,
): Record<string, unknown>;

Import

import { deepMerge } from "@duel-agents/core";

I/O Contract

Inputs

Name Type Required Description
base Record<string, unknown> Yes Existing config object
patch Record<string, unknown> Yes Patch to merge in

Outputs

Name Type Description
returns Record<string, unknown> New merged object (inputs not mutated)

Usage Examples

Merge Provider Config

import { deepMerge } from "@duel-agents/core";

const base = { models: { providers: { openai: { baseUrl: "..." } } } };
const patch = { models: { providers: { duel: { baseUrl: "..." } } } };

const merged = deepMerge(base, patch);
// { models: { providers: { openai: { baseUrl: "..." }, duel: { baseUrl: "..." } } } }
// Both providers preserved — objects merged recursively

Arrays Are Replaced

import { deepMerge } from "@duel-agents/core";

const base = { models: [{ id: "old" }] };
const patch = { models: [{ id: "duel-auto" }] };

const merged = deepMerge(base, patch);
// { models: [{ id: "duel-auto" }] }  ← array replaced, not concatenated

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment