mirror of
https://github.com/qingchencloud/clawpanel.git
synced 2026-05-07 05:02:52 +08:00
Close the G7 gap from the v3 integration design. Scenario: A user upgrades Hermes (or manually edits config.yaml and drops the api_server platform block). The next `gateway start` silently produces a Gateway that doesn't expose /v1/runs, and ClawPanel's chat/agent flows fail with confusing errors. Solution: Run a pre-start guardian that checks `platforms.api_server.enabled: true` and auto-heals the file when missing, with a timestamped backup so users can always roll back. Backend (src-tauri/src/commands/hermes.rs): - New pure helpers `config_has_api_server_enabled(raw)` and `patch_yaml_ensure_api_server(raw)` working directly on YAML strings (no serde_yaml dependency needed — we only touch 3 structural keys). - `ensure_api_server_enabled(app)` wraps the helpers with filesystem I/O: reads config.yaml, writes `config.yaml.bak-<epoch>` on mutation, writes the patched content back, emits `hermes-config-patched` so the frontend can show a transparent toast. - Called from `hermes_gateway_action` on every `start` action. If config.yaml doesn't exist, the guardian is a no-op (configure_hermes creates a compliant file on first run). - 7 new unit tests covering: truthy value variants (true/yes/on/1), missing/disabled/commented scenarios, no-op when healthy, appending a full platforms block, injecting into existing platforms, replacing an explicitly disabled api_server subtree. Web mode (scripts/dev-api.js): - Mirrors the three helpers as `_hermesConfigHasApiServerEnabled`, `_hermesPatchYamlEnsureApiServer`, `_hermesEnsureApiServerEnabled`. - Called in `hermes_gateway_action` start path. - Logs to console.warn instead of emitting a Tauri event. Frontend (src/engines/hermes/pages/dashboard.js): - Dashboard subscribes to `hermes-config-patched` and surfaces a toast (6s duration) so the user knows the auto-heal happened and where the backup lives. Verified: cargo fmt / cargo clippy -D warnings / cargo test all green (12 hermes tests pass total: 5 provider registry + 7 guardian). `node --check scripts/dev-api.js` passes. `npm run build` green.