Skip to content

rtk init --agent hermes can write invalid YAML into ~/.hermes/config.yaml, or patch text inside a block scalar — with no backup #3405

Open

Description

@HetCreep

The Hermes installer edits config.yaml with a hand-rolled line editor rather than a YAML parser. Two of its assumptions do not hold on valid YAML, and unlike the Claude, Cursor and Droid paths this one takes no backup.

Provenance: AI-assisted source audit, human-directed, at v0.44.2 (700bdde). Both failures below were reproduced by extracting the functions and running them with rustc; rtk init itself was never executed (it writes to a real home directory).

1. It patches the first enabled: at any depth under plugins:

patch_hermes_config locates plugins: (init.rs:2033), computes the block extent, then takes the first enabled: inside it (:2044-2049). The key test at :2130 is:

let is_key = trimmed == format!("{key}:") || trimmed.starts_with(&format!("{key}:"));

with the only depth constraint being yaml_indent(line) <= min_indent → None. So a nested enabled: belonging to some other plugin is matched before the top-level one.

Reproduced. Input:

plugins:
  some-plugin:
    enabled: true
  enabled:
    - other

Output:

    enabled: true
      - rtk-rewrite

The list item is appended under the wrong key at the wrong indent — the file is no longer valid YAML, so Hermes fails to load all of its settings, and rtk is not enabled either.

2. A plugins: inside a literal block scalar is treated as real YAML

The top-level lookup is find_yaml_key_line(&lines, "plugins", 0, None) (init.rs:2033) — None means no indent floor at all, so any line whose trimmed text starts with plugins: matches, including text inside a | block scalar.

Reproduced: a config with

system_prompt: |
  ... plugins: / enabled: ...

got - rtk-rewrite injected into the prompt text, while the real top-level plugins: below it was left unpatched. The install reports success and does nothing, and the user's system prompt is permanently altered.

3. No backup on this path

init.rs:1876-1884 reads the config, patches it, and calls write_if_changed — no fs::copy to .bak anywhere in the function. The Claude (:1029), Cursor (:3661) and Droid (:3128) installers all take a backup before writing. So when either failure above fires, there is nothing to restore from.

There is also no post-write validation: nothing re-parses the result to check it is still YAML.

Suggested directions (untested — no programmer has reviewed these)

  • Use a YAML library. serde_yaml or similar would eliminate both failures outright. If preserving comments and formatting is the reason for the line editor, yaml-rust2's round-trip or a marked-region approach would be closer to safe than index arithmetic.
  • If the line editor stays: track block-scalar state while scanning so |/> bodies are skipped, require the target key's indent to be exactly one level under plugins: rather than merely greater, and re-parse the result before writing.
  • Take a .bak like the three sibling installers do, and validate after writing — for a file rtk cannot fully parse, a backup is the difference between an annoyance and a lost config.

Testing

The two failures were reproduced against the extracted pure functions under rustc, not by running rtk init (which would write to a real ~/.hermes). I have not tested against a real Hermes installation, so I cannot say how common either shape is in practice — a maintainer with a representative config.yaml can confirm in one run.

Activity

  1. pszymkowiak commented on Aug 4, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 88%

    Summary

    Hermes config patcher in rtk init can write invalid YAML (wrong-depth enabled: match) or corrupt a literal block scalar, and takes no backup unlike the Claude/Cursor/Droid installers — recommend fixing key/indent matching, skipping block-scalar bodies, adding a .bak, and validating output.

    📁 Relevant files
    • init.rs

    Triaged automatically by wshm · This is an automated analysis, not a human review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions