hermes-agent/hermes_cli
Teknium b61d9b297a refactor: consolidate symlink-safe atomic replace into shared helper
Extract the islink/realpath guard from the 16743 fix into a single
atomic_replace() helper in utils.py, then migrate every os.replace()
call site in the codebase to use it.

The original PR #16777 correctly identified and fixed the bug, but
only patched 9 of ~24 call sites. The same bug class (managed
deployments that symlink state files silently losing the link on
every write) still existed at auth.json, sessions file, gateway
config, env_loader, webhook subscriptions, debug store, model
catalog, pairing, google OAuth, nous rate guard, and more.

Rather than add another 10+ copies of the same three-line guard,
consolidate into atomic_replace(tmp, target) which:
- resolves symlinks via os.path.realpath before os.replace
- returns the resolved real path so callers can re-apply permissions
- is a drop-in replacement for os.replace at the use sites

Changes:
- utils.py: new atomic_replace() helper + atomic_json_write /
  atomic_yaml_write now call it instead of inlining the guard
- 16 files: all os.replace() call sites migrated to atomic_replace()
  - agent/{google_oauth, nous_rate_guard, shell_hooks}.py
  - cron/jobs.py
  - gateway/{pairing, session, platforms/telegram}.py
  - hermes_cli/{auth, config, debug, env_loader, model_catalog, webhook}.py
  - tools/{memory_tool, skill_manager_tool, skills_sync}.py

Tests: tests/test_atomic_replace_symlinks.py pins the invariant for
atomic_replace + atomic_json_write + atomic_yaml_write, covers plain
files, first-time creates, broken symlinks, and permission preservation.

Refs #16743
Builds on #16777 by @vominh1919.
2026-04-28 04:58:22 -07:00
..
__init__.py
auth_commands.py
auth.py refactor: consolidate symlink-safe atomic replace into shared helper 2026-04-28 04:58:22 -07:00
azure_detect.py feat(azure-foundry): auto-detect transport, models, context length 2026-04-25 18:48:43 -07:00
backup.py feat(claw-migrate): harden OpenClaw import with plan-first apply, redaction, and pre-migration backup (#16911) 2026-04-28 01:50:23 -07:00
banner.py
callbacks.py
claw.py feat(claw-migrate): harden OpenClaw import with plan-first apply, redaction, and pre-migration backup (#16911) 2026-04-28 01:50:23 -07:00
cli_output.py
clipboard.py
codex_models.py
colors.py
commands.py fix(cli): eliminate ghost status-bar + DSR input leaks from terminal drift 2026-04-27 05:31:47 -07:00
completion.py
config.py refactor: consolidate symlink-safe atomic replace into shared helper 2026-04-28 04:58:22 -07:00
copilot_auth.py
cron.py
curses_ui.py
debug.py refactor: consolidate symlink-safe atomic replace into shared helper 2026-04-28 04:58:22 -07:00
default_soul.py
dingtalk_auth.py
doctor.py feat(providers): add tencent-tokenhub provider support 2026-04-28 03:45:52 -07:00
dump.py
env_loader.py refactor: consolidate symlink-safe atomic replace into shared helper 2026-04-28 04:58:22 -07:00
fallback_cmd.py feat(cli): add 'hermes fallback' command to manage fallback providers (#16052) 2026-04-26 06:19:04 -07:00
gateway.py yuanbao platform (#16298) 2026-04-26 18:50:49 -07:00
hooks.py feat(hooks): add duration_ms to post_tool_call + transform_tool_result (#15429) 2026-04-25 22:13:12 -07:00
logs.py
main.py feat(providers): add tencent-tokenhub provider support 2026-04-28 03:45:52 -07:00
mcp_config.py
memory_setup.py
model_catalog.py refactor: consolidate symlink-safe atomic replace into shared helper 2026-04-28 04:58:22 -07:00
model_normalize.py
model_switch.py fix(bedrock): add live model discovery and region resolution for non-US regions 2026-04-28 03:53:11 -07:00
models.py fix(bedrock): add live model discovery and region resolution for non-US regions 2026-04-28 03:53:11 -07:00
nous_subscription.py fix(cli): coerce use_gateway config flags in tool routing 2026-04-26 19:02:55 -07:00
oneshot.py fix(cli): honor user-defined providers via chat --provider and -m <alias> 2026-04-28 01:47:20 -07:00
pairing.py
platforms.py yuanbao platform (#16298) 2026-04-26 18:50:49 -07:00
plugins_cmd.py
plugins.py feat(plugins): add pre_approval_request / post_approval_response hooks (#16776) 2026-04-27 20:08:33 -07:00
profiles.py
providers.py fix(bedrock): add live model discovery and region resolution for non-US regions 2026-04-28 03:53:11 -07:00
pty_bridge.py
runtime_provider.py fix(providers): honor key_env/api_key_env on Azure Anthropic + accept alias in normalizer (#16935) 2026-04-28 02:12:08 -07:00
setup.py yuanbao platform (#16298) 2026-04-26 18:50:49 -07:00
skills_config.py
skills_hub.py feat(skills): install skills from a direct HTTP(S) URL (#16323) 2026-04-26 20:57:10 -07:00
skin_engine.py
slack_cli.py feat(slack): register every gateway command as a native slash (Discord/Telegram parity) (#16164) 2026-04-26 11:38:32 -07:00
status.py yuanbao platform (#16298) 2026-04-26 18:50:49 -07:00
timeouts.py refactor(timeouts): drop redundant ImportError in except clause 2026-04-26 20:48:20 -07:00
tips.py feat(busy): add 'steer' as a third display.busy_input_mode option (#16279) 2026-04-26 18:21:29 -07:00
tools_config.py revert: computer-use cua-driver (PR #16919) (#16927) 2026-04-28 01:57:21 -07:00
uninstall.py
voice.py
web_server.py fix(tui): run built TUI with production React by default 2026-04-26 21:34:31 -05:00
webhook.py refactor: consolidate symlink-safe atomic replace into shared helper 2026-04-28 04:58:22 -07:00