feat(i18n): add display.language for static message translation (zh/ja/de/es) (#20231)

* revert(gateway): remove stale-code self-check and auto-restart

Removes the _detect_stale_code / _trigger_stale_code_restart mechanism
introduced in #17648 and iterated in #19740. On every incoming message
the gateway compared the boot-time git HEAD SHA to the current SHA on
disk, and if they differed it would reply with

    Gateway code was updated in the background --
    restarting this gateway so your next message runs
    on the new code. Please retry in a moment.

and then kick off a graceful restart. This is unwanted behaviour:
users who run a long-lived gateway and do their own ad-hoc git
operations on the checkout end up with their chat interrupted and
the current message dropped every time HEAD moves, with no way to
opt out.

If an operator really needs the old protection against stale
sys.modules after "hermes update", the SIGKILL-survivor sweep in
hermes update (hermes_cli/main.py, also tagged #17648) already
handles the supervisor-respawn case on its own.

Removed:
  gateway/run.py:
    - _STALE_CODE_SENTINELS, _GIT_SHA_CACHE_TTL_SECS
    - _read_git_head_sha(), _compute_repo_mtime() module helpers
    - class-level _boot_wall_time / _boot_repo_mtime / _boot_git_sha /
      _stale_code_restart_triggered defaults
    - __init__ boot-snapshot block (_boot_*, _cached_current_sha*,
      _repo_root_for_staleness, _stale_code_notified)
    - _current_git_sha_cached(), _detect_stale_code(),
      _trigger_stale_code_restart() methods
    - stale-code check + user-facing restart notice at the top of
      _handle_message()
  tests/gateway/test_stale_code_self_check.py (deleted, 412 lines)

No new logic added. Zero remaining references to any removed
symbol. Gateway test suite passes the same 4589 tests it passed
before; the 3 pre-existing unrelated failures (discord free-channel,
feishu bot admission, teams typing) are unchanged by this commit.

* feat(i18n): add display.language for static message translation (zh/ja/de/es)

Adds a thin-slice i18n layer covering the highest-impact static user-facing
messages: the CLI dangerous-command approval prompt and a handful of gateway
slash-command replies (restart-drain, goal cleared, approval expired, config
read/save errors).

Out of scope (stays English): agent responses, log lines, tool outputs,
slash-command descriptions, error tracebacks.

Infrastructure:
- agent/i18n.py: catalog loader, t() helper, language resolution
  (HERMES_LANGUAGE env var > display.language config > en)
- locales/{en,zh,ja,de,es}.yaml: ~19 translated strings per language
- display.language in DEFAULT_CONFIG (hermes_cli/config.py)

Tests:
- tests/agent/test_i18n.py: 21 tests covering catalog parity, placeholder
  parity across locales, fallback behavior, env-var override, alias
  normalization, missing-key graceful degradation.

Docs:
- website/docs/user-guide/configuration.md: display.language entry plus a
  short section explaining scope so users don't expect agent responses to
  translate via this knob.
This commit is contained in:
Teknium 2026-05-05 08:03:07 -07:00 committed by GitHub
parent b7bd177105
commit 7de3c86c5a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 557 additions and 17 deletions

24
locales/de.yaml Normal file
View file

@ -0,0 +1,24 @@
# Hermes-Katalog für statische Meldungen -- Deutsch
# See locales/en.yaml for the source of truth; keep keys in sync.
approval:
dangerous_header: "⚠️ GEFÄHRLICHER BEFEHL: {description}"
choose_long: " [o]einmal | [s]sitzung | [a]immer | [d]ablehnen"
choose_short: " [o]einmal | [s]sitzung | [d]ablehnen"
prompt_long: " Auswahl [o/s/a/D]: "
prompt_short: " Auswahl [o/s/D]: "
timeout: " ⏱ Zeitüberschreitung Befehl wird abgelehnt"
allowed_once: " ✓ Einmalig erlaubt"
allowed_session: " ✓ Für diese Sitzung erlaubt"
allowed_always: " ✓ Zur dauerhaften Erlaubnisliste hinzugefügt"
denied: " ✗ Abgelehnt"
cancelled: " ✗ Abgebrochen"
blocklist_message: "Dieser Befehl steht auf der unbedingten Sperrliste und kann nicht genehmigt werden."
gateway:
approval_expired: "⚠️ Genehmigung abgelaufen (Agent wartet nicht mehr). Bitten Sie den Agenten, es erneut zu versuchen."
draining: "⏳ Warte auf {count} aktive(n) Agent(en) vor dem Neustart..."
goal_cleared: "✓ Ziel gelöscht."
no_active_goal: "Kein aktives Ziel."
config_read_failed: "⚠️ config.yaml konnte nicht gelesen werden: {error}"
config_save_failed: "⚠️ Konfiguration konnte nicht gespeichert werden: {error}"

35
locales/en.yaml Normal file
View file

@ -0,0 +1,35 @@
# Hermes static-message catalog -- English (baseline / source of truth)
#
# Only user-facing static messages from the CLI approval prompt and a handful
# of gateway slash-command replies live here. Agent-generated output, log
# lines, error tracebacks, tool outputs, and slash-command descriptions stay
# in English and are NOT translated -- see agent/i18n.py for scope rationale.
#
# Keys are dotted paths; nesting below is purely for readability. Values may
# contain {placeholder} tokens for str.format substitution. When adding a
# new key, add it to EVERY locale file (en/zh/ja/de/es) in the same commit --
# tests/agent/test_i18n.py asserts catalog parity.
approval:
# CLI approval prompt -- shown when a dangerous command needs user review.
dangerous_header: "⚠️ DANGEROUS COMMAND: {description}"
choose_long: " [o]nce | [s]ession | [a]lways | [d]eny"
choose_short: " [o]nce | [s]ession | [d]eny"
prompt_long: " Choice [o/s/a/D]: "
prompt_short: " Choice [o/s/D]: "
timeout: " ⏱ Timeout - denying command"
allowed_once: " ✓ Allowed once"
allowed_session: " ✓ Allowed for this session"
allowed_always: " ✓ Added to permanent allowlist"
denied: " ✗ Denied"
cancelled: " ✗ Cancelled"
blocklist_message: "This command is on the unconditional blocklist and cannot be approved."
gateway:
# Messenger replies to slash commands and implicit state changes.
approval_expired: "⚠️ Approval expired (agent is no longer waiting). Ask the agent to try again."
draining: "⏳ Draining {count} active agent(s) before restart..."
goal_cleared: "✓ Goal cleared."
no_active_goal: "No active goal."
config_read_failed: "⚠️ Could not read config.yaml: {error}"
config_save_failed: "⚠️ Could not save config: {error}"

24
locales/es.yaml Normal file
View file

@ -0,0 +1,24 @@
# Catálogo de mensajes estáticos de Hermes -- Español
# See locales/en.yaml for the source of truth; keep keys in sync.
approval:
dangerous_header: "⚠️ COMANDO PELIGROSO: {description}"
choose_long: " [o]una vez | [s]sesión | [a]siempre | [d]denegar"
choose_short: " [o]una vez | [s]sesión | [d]denegar"
prompt_long: " Opción [o/s/a/D]: "
prompt_short: " Opción [o/s/D]: "
timeout: " ⏱ Tiempo agotado — comando denegado"
allowed_once: " ✓ Permitido una vez"
allowed_session: " ✓ Permitido en esta sesión"
allowed_always: " ✓ Añadido a la lista de permitidos permanente"
denied: " ✗ Denegado"
cancelled: " ✗ Cancelado"
blocklist_message: "Este comando está en la lista de bloqueo incondicional y no se puede aprobar."
gateway:
approval_expired: "⚠️ La aprobación ha caducado (el agente ya no está esperando). Pida al agente que lo intente de nuevo."
draining: "⏳ Esperando a que terminen {count} agente(s) activo(s) antes de reiniciar..."
goal_cleared: "✓ Objetivo eliminado."
no_active_goal: "No hay objetivo activo."
config_read_failed: "⚠️ No se pudo leer config.yaml: {error}"
config_save_failed: "⚠️ No se pudo guardar la configuración: {error}"

24
locales/ja.yaml Normal file
View file

@ -0,0 +1,24 @@
# Hermes 静的メッセージカタログ -- 日本語
# See locales/en.yaml for the source of truth; keep keys in sync.
approval:
dangerous_header: "⚠️ 危険なコマンド: {description}"
choose_long: " [o]今回のみ | [s]セッション中 | [a]常に許可 | [d]拒否"
choose_short: " [o]今回のみ | [s]セッション中 | [d]拒否"
prompt_long: " 選択 [o/s/a/D]: "
prompt_short: " 選択 [o/s/D]: "
timeout: " ⏱ タイムアウト — コマンドを拒否しました"
allowed_once: " ✓ 今回のみ許可"
allowed_session: " ✓ このセッション中は許可"
allowed_always: " ✓ 永続的な許可リストに追加"
denied: " ✗ 拒否しました"
cancelled: " ✗ キャンセルしました"
blocklist_message: "このコマンドは無条件ブロックリストに含まれており、承認できません。"
gateway:
approval_expired: "⚠️ 承認の有効期限が切れました(エージェントはもう待機していません)。エージェントに再試行を依頼してください。"
draining: "⏳ 再起動前に {count} 個のアクティブエージェントの終了を待っています..."
goal_cleared: "✓ 目標をクリアしました。"
no_active_goal: "アクティブな目標はありません。"
config_read_failed: "⚠️ config.yaml を読み込めませんでした: {error}"
config_save_failed: "⚠️ 設定を保存できませんでした: {error}"

24
locales/zh.yaml Normal file
View file

@ -0,0 +1,24 @@
# Hermes 静态消息目录 -- 中文(简体)
# See locales/en.yaml for the source of truth; keep keys in sync.
approval:
dangerous_header: "⚠️ 危险命令: {description}"
choose_long: " [o]仅此一次 | [s]本次会话 | [a]永久允许 | [d]拒绝"
choose_short: " [o]仅此一次 | [s]本次会话 | [d]拒绝"
prompt_long: " 选择 [o/s/a/D]: "
prompt_short: " 选择 [o/s/D]: "
timeout: " ⏱ 超时 — 已拒绝命令"
allowed_once: " ✓ 本次允许"
allowed_session: " ✓ 本次会话内允许"
allowed_always: " ✓ 已加入永久允许列表"
denied: " ✗ 已拒绝"
cancelled: " ✗ 已取消"
blocklist_message: "此命令位于无条件拦截列表中,无法被批准。"
gateway:
approval_expired: "⚠️ 批准已过期(代理不再等待)。请让代理重试。"
draining: "⏳ 正在等待 {count} 个活跃代理结束后重启..."
goal_cleared: "✓ 目标已清除。"
no_active_goal: "当前没有活跃的目标。"
config_read_failed: "⚠️ 无法读取 config.yaml{error}"
config_save_failed: "⚠️ 无法保存配置:{error}"