Community生产力与协作github.com

shuangying0001-beep/config-merge

多环境配置合并校验工具(默认/系统/任务三层):按优先级合并校验、自动修冲突、出 diff、可回滚。适合 dev/test/prod 多环境管理的后端与运维。

config-merge 是什么?

config-merge is a Claude Code agent skill that 多环境配置合并校验工具(默认/系统/任务三层):按优先级合并校验、自动修冲突、出 diff、可回滚。适合 dev/test/prod 多环境管理的后端与运维。.

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add shuangying0001-beep/config-merge

Installed? Explore more 生产力与协作 skills: steipete/gemini, steipete/gh-issues, steipete/skill-creator · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

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

相关技能