Skip to content

fix(cli): persist JSON object/array values as structured YAML in config set - #40845

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/config-set-json-values
Closed

fix(cli): persist JSON object/array values as structured YAML in config set#40845
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/config-set-json-values

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes hermes config set to persist JSON object and array values as structured YAML mappings/lists instead of quoted strings.

Before:

hermes config set providers.deepseek '{"base_url":"https://api.deepseek.com","key_env":"DEEPSEEK_API_KEY"}'
# → providers.deepseek: '{"base_url": "https://api.deepseek.com", ...}'  # string!

After:

providers:
  deepseek:
    base_url: https://api.deepseek.com
    key_env: DEEPSEEK_API_KEY

Related Issue

Fixes #40545

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • hermes_cli/config.py: After existing scalar coercion (bool/int/float), attempt json.loads() on values starting with { or [. If parsing yields a dict or list, use the parsed structure; otherwise keep the original string.

Testing

Verified with 5 test cases:

  1. JSON object → dict ✓
  2. JSON array → list ✓
  3. Invalid JSON → stays as string ✓
  4. Boolean values → still work ✓
  5. Nested dotted key + JSON → structured ✓

All 26 existing config_set tests pass (no regressions).

…ig set

When a user passes a JSON object or array string to `hermes config set`
(e.g. `hermes config set providers.deepseek '{"base_url": "..."}'`),
the value was persisted as a quoted YAML string instead of a structured
mapping/list.  This forced users to manually edit config.yaml for any
structured config value.

After the existing scalar coercion (bool/int/float), attempt json.loads()
on values that start with '{' or '['.  If parsing succeeds and yields a
dict or list, use the parsed structure; otherwise keep the original string.

Fixes NousResearch#40545
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard area/config Config system, migrations, profiles labels Jun 6, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #40546 — both fix #40545 by adding json.loads() detection for {/[ values in hermes config set so provider blocks persist as structured YAML. Same approach, same file.

@liuhao1024

Copy link
Copy Markdown
Contributor Author

Thanks for the flag @alt-glitch. Confirmed — #40546 by @izumi0uu covers the same issue with a more complete fix (+70/-9 including dedicated test file), while this PR is a minimal +9 approach without tests.

Closing in favor of #40546.

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

Labels

area/config Config system, migrations, profiles comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Hermes config set writes JSON object values as strings in config.yaml

2 participants