fix(prompt_builder): use TERMINAL_CWD in system prompt when configured#24888
fix(prompt_builder): use TERMINAL_CWD in system prompt when configured#24888liuhao1024 wants to merge 1 commit into
Conversation
When terminal.cwd is set in config.yaml, the gateway bridges it to the TERMINAL_CWD environment variable. However, build_environment_hints() ignored this and always used os.getcwd(), which reflects the daemon's launch directory (e.g. from launchd WorkingDirectory) rather than the user's configured workspace path. Now checks TERMINAL_CWD first and falls back to os.getcwd() when unset. Fixes NousResearch#24882
|
What's the status of this PR? When will this be merged? The wrong working directory in system prompt is really annoying... |
|
When can this pull request be merged? |
|
Hi @perqin @lincannm — sorry for the delay. The fix is ready and passing CI. I've updated the PR body with the Code Intelligence section per the contributing guide. The change is minimal (1 file, 2 lines) and scoped to @maintainers — could you take a look when you have a chance? |
|
This has been implemented on main. Thanks for the focused bug fix and for the follow-up discussion from @perqin and @lincannm confirming the user-visible impact. Automated hermes-sweeper review evidence:
|
What does this PR do?
build_environment_hints()always usesos.getcwd()for the "Current working directory" line in the system prompt, ignoring theterminal.cwdconfig setting. When Hermes runs as a daemon (e.g. via launchd),os.getcwd()reflects the daemon's launch directory rather than the user's configured workspace.Root Cause
In
agent/prompt_builder.py,build_environment_hints()callsos.getcwd()directly (line 775) without checking theTERMINAL_CWDenvironment variable, which the gateway sets fromterminal.cwdin config.yaml.Related Issue
Fixes #24882
Type of Change
Changes Made
How to Test
pytest tests/ -q— all tests should passChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture and workflows — or N/ACode Intelligence
build_environment_hints) inhermes_cli/prompt_builder.pyos.getcwd(), falls back toos.getcwd()if config is unsetbuild_environment_hints()output