config-add

A procedure for adding settings that can come from command-line flags, environment variables, or a configuration file. It covers the types, parsing, priority, and validation of those settings.

In plain words
What is it for?
Use it when adding an environment variable, config-file field, global flag, or configuration-priority rule.
Why use it?
It reduces the risk that a new option works in one place but is ignored, misread, or given the wrong priority elsewhere.

Agent

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/modelstudioai/cli/config-add
Clone the repo
git clone --depth 1 https://github.com/modelstudioai/cli
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,067 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01067
Opus 5 $0.00000 $0.00534
Sonnet 5 $0.00000 $0.00213
Haiku 4.5 $0.00000 $0.00107

Measured yesterday against content hash fc73d194aabb, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

config-add scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

docs/agents/config-add.md · 89 lines

How it starts

The opening of the file, as written. The whole thing — 89 lines — stays where its author put it; the contents beside it link to each section on GitHub.

配置项扩展

触发条件

  • 新增 env var(如 DASHSCOPE_* / BAILIAN_* / NO_COLOR)
  • ~/.bailian/config.json 加字段
  • 给全局 flag 加新选项(--xxx)
  • 改 config 字段优先级

配置三层来源

flag (--xxx)   ─┐
                ├─ buildSources() + buildSettings() ─→ Settings(命令读取面)
env (XXX=yyy)  ─┤
                │
config 文件     ─┘
~/.bailian/config.json

优先级一般是 flag > env > config 文件 > 默认值,具体见 packages/core/src/config/loader.ts

必查清单

A. 类型定义

  • packages/core/src/config/schema.ts:
    • Settings(运行时有效配置面)加新字段
    • ConfigFile(disk 形状,snake_case)加新字段(如果允许写文件)
    • parseConfigFile() 解析新字段
    • 如果是 enum 字段,加校验
    • 如果是数组字段,明确“缺失 / 空数组 / 非法值”的不同语义;安全策略字段的非法值必须 fail closed

B. 加载逻辑

  • packages/core/src/config/loader.ts:
    • buildSources() 如需新增来源,把 flag/file/env 纳入 sources
    • buildSettings() 加新字段的合并逻辑(flags.x ?? process.env.XXX ?? file.x ?? default)
    • 校验(数值范围、枚举合法性等)
    • 校验失败抛 BailianError(USAGE)

C. 全局 flag(如果加的是 flag)

  • packages/core/src/types/command.ts:GLOBAL_FLAGS
  • packages/runtime/src/registry.ts自动GLOBAL_FLAGS 生成 root help;tools/generate-reference.ts 会生成 reference/index.md 的全局 flag 段
  • flag 的 type 标注(switch / boolean / number / array / string),让 packages/runtime/src/args.ts 正确解析
  • 改完全局 flag 后跑 pnpm --filter bailian-cli run generate:reference

D. 命令使用方

  • 用到新字段的命令文件直接读 ctx.settings.xxx,不要重复解析 env/config
  • 配置展示 / 修改命令同步:
    • packages/commands/src/commands/config/show.ts 显示新字段
    • packages/commands/src/commands/config/set.tsVALID_KEYS / KEY_ALIASES / description 允许 set
    • packages/commands/src/commands/config/ui.ts / ui-html.ts 能按原类型往返数组字段,不能把 [] 保存成字段缺失

E. 文档

  • README.md / README.zh.md 的 env var 表格

F. 测试

  • 单测覆盖优先级:flag > env > file
  • 校验失败抛错(非法值)
  • 默认值正确
  • 数组配置覆盖 CLI 逗号/JSON 输入、Config UI 往返、去重和显式空数组

完成后自查

# 三个来源都试一遍
pnpm -F bailian-cli exec tsx src/main.ts config show --output json | grep <new-field>
XXX=value pnpm -F bailian-cli exec tsx src/main.ts config show --output json | grep <new-field>
pnpm -F bailian-cli exec tsx src/main.ts config show --xxx value --output json | grep <new-field>

# 写到文件(会改用户 HOME,必要时先用临时 HOME)
pnpm -F bailian-cli exec tsx src/main.ts config set --key <key> --value <value>
cat ~/.bailian/config.json

Read the full file on GitHub · 89 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 89 lines · 0 tokens per session scan A fc73d194aabb

Subscribe to this mod's changes

config-add is an agent published in the GitHub repository modelstudioai/cli (320 stars, last pushed 4d ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 1,067 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.