fix(config,skills): strip 'export' prefix when parsing .env files - #51163
fix(config,skills): strip 'export' prefix when parsing .env files#51163wukai424 wants to merge 1 commit into
Conversation
The load_env() functions in hermes_cli/config.py and
tools/skills_tool.py used line.partition('=') directly,
producing keys like 'export NOTION_API_KEY' when .env files
used bash-compatible 'export KEY=VALUE' syntax.
On Windows the desktop app doesn't source .env into os.environ,
so every lookup fell back to load_env(), which never found the
real key — making the setup popup reappear endlessly even after
the user entered a valid token.
Fix: strip 'export ' (bash) and 'set ' (cmd) prefixes before
parsing, matching what agent/secret_scope.py (load_env_file)
already did. Also harden both write paths (save_env_value and
remove_env_value) to match existing lines regardless of shell
prefixes.
Duplicate of #6659 — both strip the |
tonydwb
left a comment
There was a problem hiding this comment.
Clean, targeted fix for .env file parsing. The change strips 'export ' (bash) and 'set ' (cmd) prefixes from keys before parsing, so .env files written with export syntax are handled correctly. Implementation is correct and well-scoped to two files.
Reviewed by Hermes Agent
|
Thanks for identifying the write-path gap. The parser portion has already landed on current main in commit Problems
Suggested changes
Automated hermes-sweeper review. |
GottZ
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
Summary
Three PRs address the mishandling of shell-prefixed entries in hand-rolled .env parsing. #6659 and the merged #54482 fix export-prefixed reads across all three parsers, while #51163 overlaps those parser changes but additionally fixes save matching that can append a duplicate and remove matching that otherwise leaves an existing prefixed entry untouched.
Related pull requests
- #6659 [closed]
related— (+6/-0) — superseded: This original parser-only fix stripsexportin config loading, provider detection, and skill loading; it remains relevant because its change was cherry-picked with authorship into merged #54482. - #51163
related— (+36/-4) — keep open for salvage, not merge as-is: Its parser hunks overlap the implementation already merged in #54482, but itssave_env_value()change prevents appending a duplicate when an export-prefixed key is missed, and itsremove_env_value()change allows that prefixed entry to be removed. Consistent with the visible keep_open review on #51163, the writer logic should be rebased onto current main, extended to the analogousmemory_setup.pypath, and covered by save/remove regression tests. - #54482 [merged]
related— (+130/-0) — merged reference implementation: It applies #6659's export-prefix parser fix to config loading, provider detection, and skill loading on the modern code path, with four parser regression tests; it does not address the writer defects identified in #51163.
Duplicates
#6659 and #54482 implement essentially the same three-parser export fix, with #54482 being the merged, tested application of #6659. The parser portion of #51163 is also duplicate/superseded, but its save/remove writer changes are distinct.
Suggested consolidation
Merge #51163 only after rebasing it to retain the distinct writer fix, dropping the parser hunks already covered by #54482, extending matching to the analogous hermes_cli/memory_setup.py writer, and adding update/remove regression tests, as required by the contributor keep_open review. #6659 can remain closed as superseded by merged #54482; #54482 is the canonical parser implementation rather than a candidate for closure.
Cross-PR triage: Reviewed 3 pull requests and 0 issues in this complex. Each diff was read against this issue; Assessment working set: 12 kB of PR diffs, 5 kB of issue/PR text, 14 kB of discussion (6 comments), 1 verify verdict. verdicts reflect diff content, not PR titles. Part of an automated triage batch.
Problem
The
load_env()functions inhermes_cli/config.pyandtools/skills_tool.pyparsed lines withline.partition('=')directly. On.envfiles that use bash-compatibleexport KEY=VALUEsyntax, this produced keys likeexport NOTION_API_KEYinstead ofNOTION_API_KEY.On Windows the Hermes desktop app does not source
.envintoos.environ, so every lookup fell through toload_env(), which never found the real key. This caused theNOTION_API_KEY(and any otherexport-prefixed skill env var) setup popup to reappear endlessly — even after the user entered a valid token through the UI.The same bug existed in the write paths:
save_env_value()andremove_env_value()matchedstartswith('KEY=')which missedexport KEY=...lines, creating duplicate entries on every UI save.Fix
export(bash) andset(cmd) shell prefixes before parsing the key/value pair inload_env()inconfig.pyandskills_tool.pysave_env_value()andremove_env_value()write pathsagent/secret_scope.py(load_env_file()) which already handled theexportprefix correctlyTesting
get_env_value('NOTION_API_KEY')returns the correct value after the fix (previously returnedNone)exportprefix work correctly