openclaw
Manage OpenClaw (龙虾) instance configurations. Use whenever the user wants to audit, diff, copy, add-model, list, or switch models in an openclaw.json file, or when they mention lobsters, 虾, 甲虾, 乙虾, DeepSeek patch, default model, model aliases, or OpenClaw config validation.
1How It Works & Mechanism
The unified entrypoint is a pure argparse forwarding layer: cli.py uses a SUBCOMMANDS dictionary to map audit/compare/diff/copy/add-model/list/switch to each submodule's main(), where `diff` is merely an alias for `compare` with no distinct business logic.
SUBCOMMANDS = { "audit": audit, "compare": compare, "diff": compare, "copy": copy_provider,
Configuration location employs a three-level fallback: "explicit path → nickname registry → three default paths", with the default path order hardcoded in DEFAULT_CONFIG_PATHS.
DEFAULT_CONFIG_PATHS = [ Path.home() / "workspace" / ".force" / "openclaw" / "openclaw.json", Path.home() / ".kimi_openclaw" / "openclaw.json", Path.home() / ".openclaw" / "openclaw.json", ]
Multi-instance abstraction relies on the lobsters.json nickname registry: it first uses Path to test if the input argument is a real file, and if not, queries the registry for the nickname→path mapping.
registry = load_lobster_registry() if str(name_or_path) in registry: return Path(registry[str(name_or_path)])
All write operations perform an automatic backup with a retention limit: backups are written to <config_dir>/config-backups/<stem>-<UTC_timestamp>.json, and backups exceeding the 20-copy retention limit are pruned sorted by mtime.
ts = datetime.now(timezone.utc).strftime("%Y%m%d-%H%M%S") backup_path = backup_dir / f"{p.stem}-{ts}{p.suffix}" shutil.copy2(p, backup_path)
Modifying the default model preserves its original structure: if agents.defaults.model was originally an object, only primary is updated; if it was originally a string, it remains a string—avoiding forced normalization of the user's existing format.
if isinstance(current, dict): defaults["model"] = {**current, "primary": ref} else: defaults["model"] = ref
Mutating subcommands enforce pre-change health check + abort on error + post-change recheck by default; skipped only via `--no-audit`. This constitutes its auto-audit guardrail.
if any(i["level"] == "error" for i in issues): print("Aborting due to audit errors. Use --no-audit to skip.", file=sys.stderr) return 2
copy performs a "merge" rather than an "overwrite": it only syncs baseUrl/api and matching model definitions; target-exclusive models are not deleted.
for key in ("baseUrl", "api"):
Gateway restart uses a three-tier fallback: first `openclaw gateway restart`, falling back to `systemctl --user restart` on failure, and finally falling back to system-level `systemctl restart`. If all three fail, it issues a warning without raising an exception.
commands = [ ["openclaw", "gateway", "restart"], ["systemctl", "--user", "restart", "openclaw-gateway"], ["systemctl", "restart", "openclaw-gateway"], ]
Codifying hard-learned domain pitfalls into executable assertions: audit includes a DeepSeek anti-pattern heuristic that warns if a provider name starts with deepseek, directing users to the correct path: gateway provider + deepseek-v4-pro.
if pname.lower().startswith("deepseek"):
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| cli | openclaw CLI(gateway restart) |
| cli | systemctl(用户级/系统级服务重启回退) |
| package | Python 3 标准库 only(json/os/shutil/subprocess/argparse/pathlib;无第三方依赖) |
| network | OpenClaw provider baseUrl(仅写在配置里被审计/搬运,skill 自身从不发请求) |
4Recommended Governance & Evidence
- scripts/: Execute local scripts or commands: python3 scripts/cli.py <audit|diff|copy|add-model|list|switch> (or run individual sub-scripts directly)
- 环境变量 / API Key: Read vendor service keys: models.providers.*.apiKey in openclaw.json: read into memory and written back alongside the entire config (the script never extracts this field explicitly); copy/
- 本地工作目录: File read/write and artifact output: <config_dir>/config-backups/<stem>-<UTC_timestamp>.json (backed up prior to every write operation)
5Second-Pass Verification
- [ok] SKILL.md 声明「Backups: every write operation copies the config to config-backups/<stem>-<utc-timestamp>.json」是否与代码一致 — 三条写路径 copy_provider.py / add_model.py / switch_model.py 都在 save_config 之前调用 backup_config(config_path),且 openclaw_config.backup_config 用 datetime.now(timezone.utc) 生成时间戳、文件名格式恰为 f"{p.stem}-{ts}{p.suffix}";SKILL.md 关于「keeps the 20 most recent backups」也对得上 max_backups: int = 20 默认值与 existing[:-max_backups] 裁剪。
- [ok] SKILL.md 声明「switch 是唯一改 agents.defaults.model 的子命令」 — grep set_default_model 的调用点只有 switch_model.py 一处;add_model.py 只写 agents.defaults.models(别名映射),copy_provider.py 只写 models.providers 与别名,compare/list/audit 纯只读,声明成立。
- [ok] SKILL.md「Restart: write subcommands support --restart to restart the OpenClaw gateway after saving」 — 三个写脚本都定义了 --restart 并调用 restart_gateway();且未给 --restart 时会打印「NOTE: You must restart the OpenClaw gateway...」提示,行为与文档一致。副产物确认:restart_gateway 的第三档是系统级 systemctl(无 --user),文档未提及这一越权风险,已写进 verdict.risks。
- [ok] external_deps 里是否漏掉了网络调用(有没有隐藏的 endpoint probe 或遥测) — 反向扫描 scripts/ 全部 8 文件:无 import urllib/requests/socket/httpx,无 curl/wget 字符串,无任何 URL 常量。openclaw 与 openclaw-model-switch 的关键差异(后者文档要求 curl 探针)在此得到对照确认。network 依赖项仅保留「配置里存在 baseUrl 字段」这一事实,并显式标注 skill 自身不请求。
- [ok] 是否读 env 里的 API key / 密钥 — scripts/ 内 os.environ、getenv 零命中;openclaw_config.py 里 import os 的唯一用途是 os.path.getmtime 做备份排序。凭证面仅为「随配置整份读写的 apiKey 字段」与「copy/add-model 把 provider 块连同 apiKey 深拷贝到目标配置」,已在 security.credential_reads 如实登记而非留空。
- [ok] 「copy 不删目标独有模型」是否为真(找反例:有没有静默覆盖整个 provider 的分支) — 反例检查通过:当目标已有该 provider 时走 merge_provider(只按 id 增补/更新、且注释明确 does not remove target-only models),不整块替换;唯一整体替换发生在「目标根本没有该 provider」时(copy.deepcopy(source_provider)),此时不存在目标独有模型可丢。--alias 分支只做 target_aliases[ref] = deepcopy(detail) 的增补,也不删。
- [discrepancy] 备份保留逻辑会不会误删非备份文件 — 发现第一遍未记的边界:裁剪用 backup_dir.glob(f"{p.stem}-*{p.suffix}") 匹配,若用户在 config-backups/ 目录里放了同名模式的其它文件(例如手工备份 openclaw-手工.json,而 stem 恰为 openclaw),mtime 最旧的会被 unlink。属真实但低概率的删除面,已补进 verdict.risks。
- [ok] 功能声明 vs 实际能力夸大检查(SKILL.md / README 有没有说到做不到的事) — SKILL.md 的六子命令、昵称注册表、三级默认路径、备份与 20 份上限、dry-run、restart、自动 audit 全部可在代码中一一落到实处,未发现夸大。唯一「文档比代码多说一句」的是 references/deepseek_patch_sop.md 的示例命令 `add-model gateway-provider references/deepseek_model.json`(相对路径需从 skill 根执行),属示例语境问题而非能力夸大。
6Verdict & Scenarios
c792eb95fa4dde39…