CommunityProductivity & Collaborationgithub.com

config-merge

Multi-environment configuration merge and validation tool (default/system/task layers): merges and validates with priority, auto-fixes conflicts, outputs diffs, and supports rollback. Suitable for backend and DevOps managing dev/test/prod multi-environments.

What is config-merge?

The `config-merge` skill provides a pure function implementation (Node ESM, zero dependencies beyond built-in `node:crypto`) for merging three layers of configuration: defaults, system settings, and task-specific parameters, into a single resolved configuration. It automatically validates each layer against an injectable schema, auto-fixes common conflicts (e.g., `delayMax < delayMin`), and records all fixes in `_meta.conflicts` for auditability. The module also includes utilities for config diffing, snapshot/restore, freezing, and running assertions for dry-run validation. This skill is ideal for tools or services that need reliable multi-environment configuration management with conflict resolution, version snapshots, and regression diffs, especially in backend and DevOps contexts.

Works with~Claude Code~Codex CLI~Cursor
npx skills add shuangying0001-beep/config-merge

Installed? Explore more Productivity & Collaboration skills: steipete/gemini, steipete/gh-issues, steipete/skill-creator · View all 6 →

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

config-merge — Configuration Layered Merge & Validation

Merges three layers (defaults / system / task) into a single final configuration, with automatic validation, conflict auto-fix, snapshot and diff support. Pure function implementation (Node ESM, zero dependencies, only uses built-in node:crypto). Schema is injectable.

Use Cases

  • Tools / services with a three-layer configuration: 'global defaults + user settings + per-task parameters'
  • Configuration conflicts need automatic resolution (e.g., delayMax < delayMin → auto-correct)
  • Pre-task dry-run preview, configuration version snapshots, and regression diffs

Provided Functions

FunctionDescription
resolveConfig({defaults,system,task,schema?})Three-layer merge + validation + auto-fix, returns result with _meta/configHash
diffConfigs(c1, c2)Compare two configurations, returns list of differing fields
configSnapshot(resolved) / configFromSnapshot(str)Snapshot archive / restore
freezeConfig(resolved)Freeze into an immutable snapshot
runAssertions(resolved, fns)Run a set of assertions (dry-run validation)
commonAssertionsCommon assertion constructors: range / gte / truthy

Schema field rules:

  • systemOnly: true — Field cannot be overridden by task layer (only system/default)
  • validator(v) — Value validation; if invalid, skip that source
  • autoFix(resolved) — Returns {value, message} to auto-correct and record conflict

Usage

import { resolveConfig, diffConfigs, runAssertions, commonAssertions } from './scripts/config-merge.mjs';

const resolved = resolveConfig({
  defaults: { maxPages: 10, delayMin: 3000, delayMax: 8000 },
  system:   { delayMin: 5000 },
  task:     { maxPages: 5, delayMax: 1000 },  // delayMax < delayMin, will be auto-fixed
  schema: {
    delayMax: { autoFix: (r) => r.delayMax < r.delayMin
      ? { value: r.delayMin + 2000, message: 'max delay less than min delay, auto-corrected' } : null },
  },
});
// resolved.delayMax === 7000; resolved._meta.conflicts contains one auto-fix record

const check = runAssertions(resolved, [commonAssertions.gte('delayMax', 'delayMin')]);
// check.success === true

Design Notes

  • Priority is strictly task > system > default; if validation fails for a source, it falls back to the next lower layer.
  • All auto-fixes are recorded in _meta.conflicts (marked autoFixed:true) for auditability.
  • configHash is generated from the configuration content (excluding _meta) and can be used for cache invalidation.

Self-Test

node scripts/config-merge.mjs --selftest

Related Skills