Skip to content

fix(hermes): preserve YAML list-at-same-indent style on install (#456)#461

Merged
colbymchenry merged 1 commit into
mainfrom
fix/456-hermes-yaml-list-indent
May 26, 2026
Merged

fix(hermes): preserve YAML list-at-same-indent style on install (#456)#461
colbymchenry merged 1 commit into
mainfrom
fix/456-hermes-yaml-list-indent

Conversation

@colbymchenry
Copy link
Copy Markdown
Owner

Summary

  • Bug (#456): codegraph install --target hermes corrupted ~/.hermes/config.yaml. PyYAML's default block style writes list items at the same indent as the parent key (cli: and - hermes-cli both at column 2). The line-based patcher mistook that first - hermes-cli for the next sibling key, truncated the cli: block, and spliced - mcp-codegraph at indent 4 before the existing items — promoting - browser, - clarify, …, telegram: to invalid positions and breaking YAML parse. Hermes silently fell back to default config, dropping every user override.
  • Fix: a new listChildBlock helper recognizes - as a list-item continuation (not a sibling key), finds the real end of the block at the next sibling key, and detects the existing item indent so mcp-codegraph is appended at the same indent the file already uses. The 4-space-nested layout still works.
  • Coverage: two regression tests added — install on a PyYAML-default config (idempotent + structural assertions) and uninstall reverses it. The existing 4-space-nested install/uninstall tests still pass.

Test plan

  • npx vitest run __tests__/installer-targets.test.ts — 116/116 pass (macOS)
  • npm test — 982/982 pass (macOS)
  • Linux: built node:22-bookworm image, ran installer suite — 116/116 pass; manual end-to-end install on the PyYAML-default config produces parseable YAML
  • Windows: Parallels VM (Node 24, ARM64), npx vitest run __tests__/installer-targets.test.ts — 116/116 pass; PowerShell end-to-end install reproduces the correct output
  • Real Hermes integration test (the part the unit tests don't cover): installed hermes-agent from main into a venv, dropped the exact bug-triggering config from the issue into $HERMES_HOME, ran the installer, and verified:
    • hermes mcp listcodegraph codegraph serve --mcp all ✓ enabled
    • hermes tools --summary → both codegraph and mcp-codegraph enabled in the CLI toolset, alongside the user's original toolsets (browser, file, terminal, web, …)
    • hermes mcp test codegraph✓ Connected (264ms) ✓ Tools discovered: 10 (search, context, callers, callees, impact, node, explore, status, files, trace)
    • Re-running install reports Unchanged; the file still has exactly one mcp-codegraph and one codegraph: server block

Closes #456.

🤖 Generated with Claude Code

Hermes Agent writes ~/.hermes/config.yaml with PyYAML's default block
style, which puts list items at the SAME indent as the parent key:

    platform_toolsets:
      cli:
      - hermes-cli      # indent 2, same as `cli:`
      - browser

The previous line-based YAML patcher used `^  \S` to find the end of
the `cli:` block, which mistook that first `  - hermes-cli` line for
the next sibling key, truncated the block, and spliced
`    - mcp-codegraph` at indent 4 BEFORE the existing items. The
result was unparseable YAML: every subsequent item (`- browser`,
`- clarify`, …) and every sibling platform (`telegram:`, `discord:`)
appeared at the `platform_toolsets:` level. Hermes silently fell back
to the default config, dropping every user override.

The new `listChildBlock` helper recognizes `  - ` as a list-item
continuation (not a sibling key), finds the real end of the block at
the next sibling mapping key, and detects the existing item indent so
the new entry matches it. Two regression tests cover the PyYAML-default
style; the existing 4-space-nested test still passes.

End-to-end verified against a real `hermes-agent` install on the exact
bug-triggering config: `hermes mcp list` shows codegraph as enabled,
`hermes tools --summary` lists both `mcp-codegraph` and `codegraph` in
the CLI toolset, and `hermes mcp test codegraph` connects in 264ms and
discovers all 10 codegraph tools. Re-running `codegraph install`
reports `Unchanged` and the file still has exactly one entry. Closes #456.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@colbymchenry colbymchenry merged commit e76cc54 into main May 26, 2026
@colbymchenry colbymchenry deleted the fix/456-hermes-yaml-list-indent branch May 26, 2026 17:21
jorgerobles pushed a commit to jorgerobles/codegraph that referenced this pull request Jun 1, 2026
…ymchenry#456) (colbymchenry#461)

Hermes Agent writes ~/.hermes/config.yaml with PyYAML's default block
style, which puts list items at the SAME indent as the parent key:

    platform_toolsets:
      cli:
      - hermes-cli      # indent 2, same as `cli:`
      - browser

The previous line-based YAML patcher used `^  \S` to find the end of
the `cli:` block, which mistook that first `  - hermes-cli` line for
the next sibling key, truncated the block, and spliced
`    - mcp-codegraph` at indent 4 BEFORE the existing items. The
result was unparseable YAML: every subsequent item (`- browser`,
`- clarify`, …) and every sibling platform (`telegram:`, `discord:`)
appeared at the `platform_toolsets:` level. Hermes silently fell back
to the default config, dropping every user override.

The new `listChildBlock` helper recognizes `  - ` as a list-item
continuation (not a sibling key), finds the real end of the block at
the next sibling mapping key, and detects the existing item indent so
the new entry matches it. Two regression tests cover the PyYAML-default
style; the existing 4-space-nested test still passes.

End-to-end verified against a real `hermes-agent` install on the exact
bug-triggering config: `hermes mcp list` shows codegraph as enabled,
`hermes tools --summary` lists both `mcp-codegraph` and `codegraph` in
the CLI toolset, and `hermes mcp test codegraph` connects in 264ms and
discovers all 10 codegraph tools. Re-running `codegraph install`
reports `Unchanged` and the file still has exactly one entry. Closes colbymchenry#456.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: codegraph install --target hermes corrupts config.yaml — drops hermes-cli and breaks nested YAML indentation

1 participant