Agent Skills › xberg-io/xberg › config-loading-precedence

config-loading-precedence

GitHub

说明配置加载优先级与发现机制,涵盖CLI与服务端模式下的参数覆盖顺序、多格式文件自动探测及JSON合并逻辑。

.ai-rulez/skills/config-loading-precedence/SKILL.md xberg-io/xberg

Trigger Scenarios

需要解析或调试配置加载顺序 处理不同来源配置的冲突与合并

Install

npx skills add xberg-io/xberg --skill config-loading-precedence -g -y
More Options

Non-standard path

npx skills add https://github.com/xberg-io/xberg/tree/main/.ai-rulez/skills/config-loading-precedence -g -y

Use without installing

npx skills use xberg-io/xberg@config-loading-precedence

指定 Agent (Claude Code)

npx skills add xberg-io/xberg --skill config-loading-precedence -a claude-code -g -y

安装 repo 全部 skill

npx skills add xberg-io/xberg --all -g -y

预览 repo 内 skill

npx skills add xberg-io/xberg --list

SKILL.md

Frontmatter
{
    "name": "config-loading-precedence",
    "type": "Playbook",
    "paths": [
        "crates\/xberg\/src\/core\/config\/**",
        "crates\/xberg-cli\/src\/**"
    ],
    "title": "Config Loading Precedence",
    "x-ai-rulez": {
        "id": "config-loading-precedence",
        "kind": "skill",
        "metadata": {
            "name": "config-loading-precedence"
        }
    },
    "description": "Resolve config precedence: CLI, server\/MCP, walk-up files, JSON and overrides."
}

Configuration Loading & Precedence

CLI Mode Precedence (highest to lowest)

  1. Individual CLI flags (--ocr, --output-format, --chunk)
  2. Inline JSON config (--config-json or --config-json-base64)
  3. Config file (--config path.toml)
  4. Auto-discovered config (xberg.{toml,yaml,yml,json} in cwd/parents, then the user config dir)
  5. Default values

Server/MCP Mode Precedence

  1. CLI arguments (--host, --port)
  2. Environment variables (XBERG_HOST, XBERG_PORT)
  3. Config file [server] section
  4. Defaults (127.0.0.1:8000)

Config File Discovery

ExtractionConfig::discover() (core/config/extraction/loaders.rs) uses the same deterministic format precedence at every level:

  1. Walks the current directory and its parents, probing xberg.toml, xberg.yaml, xberg.yml, then xberg.json in each directory. The first hit wins.
  2. If that finds nothing, falls back to the per-user global config directory (dirs::config_dir()/xberg) and probes four basenames in a fixed order: xberg.toml, xberg.yaml, xberg.yml, xberg.json.

Inline JSON Config

Field-level merge (not whole-object replacement):

fn merge_json_into_config(base: &ExtractionConfig, json: Value) -> Result<ExtractionConfig> {
    let mut config_json = serde_json::to_value(base)?;
    // Merge fields from json into config_json
    serde_json::from_value(merged)?
}

Use --config-json-base64 for shell escaping.

Config File Formats

TOML (xberg.toml):

use_cache = true
[ocr]
backend = "tesseract"
languages = ["eng", "deu"]
[security_limits]
max_archive_size = 524288000

YAML and JSON follow equivalent structure.

CLI Flag Overrides

crates/xberg-cli/src/commands/overrides/mod.rs: the ExtractionOverrides struct's validate() runs first, then apply(self, config: &mut ExtractionConfig) lays individual CLI flags over the merged config. There is no apply_extraction_overrides() and no commands.rs — commands/ is a directory.

Inline JSON enters through apply_json_overrides(config, config_json, config_json_base64) (crates/xberg-cli/src/input.rs), which delegates to merge_json_into_config.

Two silent no-op mechanisms

Duplicate Default impls. TesseractConfig is defined twice — public (types/formats.rs, binding-friendly types) and internal (ocr/types.rs, engine-side types) — bridged by a From impl, each with its own Default. Changing one default fixes only the routes that materialise that struct. Before changing any config default, grep the bare type name (a pub use module::*; makes a qualified path unsearchable) and check for a second definition.

Unknown keys are rejected. Nearly every config struct under core/config/ (including ExtractionConfig, OcrConfig, PdfConfig, ChunkingConfig and LlmConfig) carries #[serde(deny_unknown_fields)], so a typo'd key fails to parse instead of being ignored. Check the struct's definition before relying on that for a new one. Write config fixtures against the serde wire names (ChunkingConfig's max_characters is max_chars on the wire; the field name is only an alias).

Critical Rules

  1. CLI flags always win over config file
  2. JSON merge is field-level, not whole-object
  3. Auto-discovery probes TOML, YAML, YML, then JSON in each directory before walking to its parent
  4. --config-json-base64 for shell-safe JSON passing
  5. Server config uses [server] section + extraction config

Version History

  • 844bb91 Current 2026-11-03 09:36
  • 3be78fd 2026-10-19 16:30

    修复项目级 YAML 和 JSON 配置文件自动发现逻辑,此前仅支持 TOML;同步更新文档以对齐发现指引。

  • d8e4815 2026-08-28 18:30

    修正了配置自动发现逻辑的描述(不再自动发现 yaml/json),更新了 CLI Flag 覆盖机制的代码路径说明,并补充了关于重复 Default impl 和未知键被忽略的静默无操作机制。

  • 531e0f7 2026-08-20 07:47

Same Skill Collection

.ai-rulez/skills/alef-generated-bindings/SKILL.md
.ai-rulez/skills/api-server-mcp/SKILL.md
.ai-rulez/skills/benchmark-workflow/SKILL.md
.ai-rulez/skills/chunking-embeddings/SKILL.md
.ai-rulez/skills/crate-structure/SKILL.md
.ai-rulez/skills/e2e-fixtures/SKILL.md
.ai-rulez/skills/extraction-pipeline-patterns/SKILL.md
.ai-rulez/skills/feature-flag-conventions/SKILL.md
.ai-rulez/skills/feature-flag-policy/SKILL.md
.ai-rulez/skills/format-specific-extraction/SKILL.md
.ai-rulez/skills/mime-detection-routing/SKILL.md
.ai-rulez/skills/ocr-pipeline-and-quality/SKILL.md
.ai-rulez/skills/pdf-backends/SKILL.md
.ai-rulez/skills/plugin-architecture-patterns/SKILL.md
.ai-rulez/skills/polyrepo-boundaries/SKILL.md
.ai-rulez/skills/release-readiness/SKILL.md
.ai-rulez/skills/release-versioning/SKILL.md
.ai-rulez/skills/test-corpus/SKILL.md
.ai-rulez/skills/wasm-constraints/SKILL.md
.ai-rulez/skills/xberg-release/SKILL.md
.ai-rulez/skills/xberg-typescript-toolchain/SKILL.md
plugin/.ai-rulez/skills/batch-extraction/SKILL.md
plugin/.ai-rulez/skills/chunking/SKILL.md
plugin/.ai-rulez/skills/extracting-keywords/SKILL.md
plugin/.ai-rulez/skills/extracting-tables/SKILL.md
plugin/.ai-rulez/skills/extracting-with-ocr/SKILL.md
plugin/.ai-rulez/skills/picking-a-format/SKILL.md
plugin/.ai-rulez/skills/xberg-batch-extraction/SKILL.md
plugin/.ai-rulez/skills/xberg-chunking/SKILL.md
plugin/.ai-rulez/skills/xberg-extracting-keywords/SKILL.md
plugin/.ai-rulez/skills/xberg-extracting-tables/SKILL.md
plugin/.ai-rulez/skills/xberg-extracting-with-ocr/SKILL.md
plugin/.ai-rulez/skills/xberg-picking-a-format/SKILL.md
plugin/.ai-rulez/skills/xberg/SKILL.md
plugin/.cursor-plugin/skills/batch-extraction/SKILL.md
plugin/.cursor-plugin/skills/chunking/SKILL.md
plugin/.cursor-plugin/skills/extracting-keywords/SKILL.md
plugin/.cursor-plugin/skills/extracting-tables/SKILL.md
plugin/.cursor-plugin/skills/extracting-with-ocr/SKILL.md
plugin/.cursor-plugin/skills/picking-a-format/SKILL.md
plugin/.cursor-plugin/skills/xberg-batch-extraction/SKILL.md
plugin/.cursor-plugin/skills/xberg-chunking/SKILL.md
plugin/.cursor-plugin/skills/xberg-extracting-keywords/SKILL.md
plugin/.cursor-plugin/skills/xberg-extracting-tables/SKILL.md
plugin/.cursor-plugin/skills/xberg-extracting-with-ocr/SKILL.md
plugin/.cursor-plugin/skills/xberg-picking-a-format/SKILL.md
plugin/.cursor-plugin/skills/xberg/SKILL.md
plugin/.opencode/skills/xberg-batch-extraction/SKILL.md
plugin/.opencode/skills/xberg-chunking/SKILL.md

Metadata

Files
0
Version
844bb91
Hash
dcb520de
Indexed
2026-08-20 07:47

trang chủ - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-11-04 19:18
浙ICP备14020137号-1