Coverage for src/lilbee/app/agent_configs/merge.py: 100%
14 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-08-14 11:46 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-08-14 11:46 +0000
1"""Non-destructive deep-merge of a lilbee config fragment into a user's agent config."""
3from __future__ import annotations
5from typing import Any
7LILBEE_PROVIDER_KEY = "lilbee"
10def deep_merge(base: dict[str, Any], fragment: dict[str, Any]) -> dict[str, Any]:
11 """Recursively merge *fragment* into *base*; fragment wins on leaf conflicts,
12 dict values merge key-by-key so unrelated keys in *base* survive."""
13 for key, value in fragment.items():
14 existing = base.get(key)
15 if isinstance(existing, dict) and isinstance(value, dict):
16 deep_merge(existing, value)
17 else:
18 base[key] = value
19 return base
22def prune_lilbee(config: dict[str, Any], container_key: str) -> None:
23 """Remove the lilbee entry from ``config[container_key]`` if present (for --no-mcp)."""
24 container = config.get(container_key)
25 if isinstance(container, dict):
26 container.pop(LILBEE_PROVIDER_KEY, None)